(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; _.popupImageStack = null; _.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(_.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 _; }; _.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; } }; _.clickHandler = function(e, popupData) { popupData = popupData || this.popupData || e.target.popupData; // Either as param or from object if ( !popupData ) { return; } e && e.preventDefault(); _.showViewer(); content.current = $(this); _.log(popupData); if ( popupData.isImage ) { // Load image routine _.log("loading an image"); popupData.call = popupData.call || '_popup_load_image_meta'; $(new Image()).attr('src', popupData.src || this.href).waitForImages(function(){ var image = $(this); 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()); _.setContentSizeAndPosition(popupData.width, popupData.height, additionalContent.innerHeight(), image); }); }); } 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) { node.find('div.dokuwiki,body').first().waitForImages({ finished: function() { // Force size for the moment content.css({ width: content.width(), height: content.height() }) node.find('a[href],form[action]'). each(function(){ // Replace all event handler var element = $(this); urlpart = element.attr('href') || element.attr('action') || ""; if ( urlpart.match(new RegExp("^#.*?$")) ) { // Scroll to anchor element.click(function(){ content.get(0).scrollTop( urlpart == '#' ? 0 : $(urlpart).offset().top); }); } if ( this.getAttribute('popupviewerdata') ) { this.popupData = $.parseJSON(this.getAttribute('popupviewerdata')); this.removeAttribute('popupviewerdata'); } else { this.popupData = jQuery.extend(true, {}, popupData); this.popupData.src = urlpart; delete(this.popupData.id); // or it will always load this file. } $(this).bind('click', function(e){ e.stopPropagation(); e.preventDefault(); _.hideViewer(e, _.clickHandler); }); }); content.html(this); // Check for Javascript to execute var script = ""; node.find('popupscript'). each(function() { script += $.parseJSON((this.innerHTML || this.innerText)); }) var newContext = "jQuery.noConflict(); containerContext = this; ___ = function( selector, context ){return new jQuery.fn.init(selector,context||containerContext);}; ___.fn = ___.prototype = jQuery.fn;jQuery.extend( ___, jQuery );jQuery = ___;\n" if ( script.length > 0 ) { var randomID = Math.ceil(Math.random()*1000000); content.attr('id', randomID); var newContext = "jQuery.noConflict(); containerContext = this; ___ = function( selector, context ){return new jQuery.fn.init(selector,context||containerContext);}; ___.fn = ___.prototype = jQuery.fn;jQuery.extend( ___, jQuery );jQuery = ___;\n" try{ $.globalEval("try{\n(function(){\n"+newContext+script+"\n}).call(jQuery('div#"+randomID+"').get(0));\n}catch(e){}\n//"); } catch (e) { _.log("Exception!"); _.log(e); } } _.setContentSizeAndPosition(popupData.width, popupData.height, null, content, true); }, 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)); }; iframe = $('