(function($){ var popupviewer = function() { }; /* singleton */ var instance = null; $.popupviewer = function() { return instance || (instance = new popupviewer()); }; // Static functions (function(_){ var viewer = null; var content = null; var additionalContent = null; var BASE_URL = DOKU_BASE + 'lib/exe/ajax.php'; var viewerIsFixed = false; var next = null; var previous = null; var internal = {}; _.popupImageStack = null; internal.log = function(message) { // console.log(message); }; _.showViewer = function() { if ( viewer == null ) { viewer = $('
').click(_.hideViewer).appendTo('body'); content = $('
').click(function(e){e.stopPropagation()}); content.current = $(); additionalContent = $('
'); viewerIsFixed = viewer.css('position'); $('
'). append(content). append(additionalContent). append(previous = $('').addClass('visible').click(_.hideViewer)). appendTo(viewer); $(document).keydown(internal.globalKeyHandler); } content.empty(); additionalContent.empty(); $('body').css('overflow', 'hidden'); viewer.show(); return _; }; _.hideViewer = function(e, finalFunction) { if ( viewer != null ) { $('body').css('overflow', 'auto'); additionalContent.animate({ opacity: 0, height: 0 }); content.animate({ width : 208, height : 13, }).parent('.controls').animate({ top : '50%', left : '50%', 'margin-left' : -104 }).parent('#popupviewer').animate({ opacity: finalFunction ? 1 : 0 }, function(){ viewer.hide(); content.empty(); additionalContent.empty(); content.current = null; additionalContent.css({ opacity: 1, height: '' }); content.css({ width : '', height : '', }).parent('.controls').css({ top : '', left : '', 'margin-left' : '' }).parent('#popupviewer').css({ opacity : 1 }); if ( typeof finalFunction == 'function' ) { finalFunction(e); } }); } return _; }; internal.globalKeyHandler = function(e) { if ( !viewer.is(":visible") ) return; switch(e.keyCode) { case 39: // Right e.stopPropagation(); next.click(); break; case 37: // Left e.stopPropagation(); previous.click(); break; case 27: // Escape e.stopPropagation(); _.hideViewer(); break; } }; _.presentViewerWithContent = function(e, popupData) { popupData = popupData || this.popupData || e.target.popupData; // Either as param or from object /* popupData = { isImage: boolean, call: ajax_handler, src: URL, id: alternate_wiki_page, width: width_of_window, height: height_of_window } */ if ( !popupData ) { return; } e && e.preventDefault(); if ( content && !content.is(':empty') ) { e.target.popupData = popupData; _.hideViewer(e, _.presentViewerWithContent); return _; } _.showViewer(); content.current = $(this); internal.log(popupData); if ( popupData.isImage ) { // Load image routine internal.log("loading an image"); popupData.call = popupData.call || '_popup_load_image_meta'; var img = new Image(); img.onload = function() { var image = $(img); var wrapper = $('
').load(BASE_URL, popupData, function() { // Force size for the moment content.css({ width: content.width(), height: content.height(), overflow: 'hidden' }); content.append(image); content.popupData = jQuery.extend(true, {}, popupData); additionalContent.html(wrapper.html()); _.registerCloseHandler(); _.resizePopup(popupData.width, popupData.height, additionalContent.innerHeight(), image, false, popupData.hasNextPrevious); }); }; img.src = popupData.src || this.href; } else { popupData.call = popupData.call || '_popup_load_file'; popupData.src = popupData.src || BASE_URL; var wrapper = $('
').load(popupData.src, popupData, function(response, status, xhr) { var success = function(node) { var popupScriptNode = node; if ( !popupData.do || popupData.do != 'export_xhtmlbody') { popupScriptNode = jQuery('
').append(node.find('popupscript')); node = node.find('div.dokuwiki,body').first(); } node.waitForImages({ finished: function() { // Force size for the moment content.css({ width: content.width(), height: content.height() }); $(this).on( "click", "a", function(){ // Insert base URL, so the link will be correct. hopefully. var base = $(''); $("head").append(base); }); content.html(this); // If we want to have all other pages open as well, go with it. if ( popupData.keepOpen ) { _.propagateClickHandler($(this), popupData); } // Check for Javascript to execute var scripts = popupScriptNode.find('popupscript'); if ( scripts.length > 0 ) { var randomID = Math.ceil(Math.random()*1000000); content.attr('id', randomID); scripts.each(function(){ var script = (this.innerHTML || this.innerText); if ( script.length > 0 ) { try{ $.globalEval("try{\n(function(){\n"+script+"\n}).call(jQuery('div#"+randomID+"').get(0));\n}catch(e){console?console.log(e):null}\n//"); } catch (e) { internal.log("Exception!"); internal.log(e); } } }); _.addGoogleOutboundTrackingInformation( $("div#"+randomID) ); } if ( popupData.postPopupHook && typeof popupData.postPopupHook == 'function' ) { // Post-Hook which as to be a javascript function and my modify the popupData popupData.postPopupHook(this, popupData); } _.registerCloseHandler(); // At the very end we will resize the popup to fit the content. _.resizePopup(popupData.width, popupData.height, null, content, true, popupData.hasNextPrevious); }, waitForAll: true}); }; if ( status == "error") { // Go for an iframe var finished = false; var iframe = null; var messageFunction = function(event) { finished = true; var data = event.data || event.originalEvent.data; // If this message does not come with what we want, discard it. if ((typeof data).toLowerCase() == "string" || !data.message || data.message != 'frameContent') { alert("Could not load page via popupviewer. The page responded with a wrong message."); return; } iframe.remove(); // Clear the window Event after we are done! $(window).unbind("message", messageFunction); success($(data.body)); }; popupData.src = internal.getCurrentLocation(); var iframe = $('