(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 = $('').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(); } }); } 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) { e && e.preventDefault(); _.showViewer(); popupData = popupData || this.popupData; // Either as param or from object content.current = $(this); _.log(popupData); if ( popupData.isImage ) { // Load image routine _.log("loading an image"); 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 = popupData; additionalContent.html(wrapper.html()); _.setContentSizeAndPosition(popupData.width, popupData.height, additionalContent.innerHeight(), image); }); }); } else { popupData.call = '_popup_load_file'; var wrapper = $('
').load(BASE_URL + " div.dokuwiki", popupData, function(response, status, xhr) { var success = function(node) { node.find('body,div.dokuwiki').first().waitForImages({ finished: function() { // Force size for the moment content.css({ width: content.width(), height: content.height() }) node.find('[href],[src],[action]'). extend(node.filter('[href],[src],[action]')). each(function(){ // Replace all event handler if ( this.getAttribute('popupviewerdata') ) { this.popupData = $.parseJSON(this.getAttribute('popupviewerdata')); this.removeAttribute('popupviewerdata'); } else { this.popupData = popupData; this.popupData.id = ''; } $(this).click(_.clickHandler); }); // Check for Javascript to execute var script = ""; node.find('script'). extend(node.filter('script')). each(function(){ script += $(this).text() /*.replace(new RegExp("()", "gi"), "")*/ + "\n"; }) try { eval(script); // This might be a problem! } catch(scriptError) { alert("A script error occurred in PopUpViewer. This problem may not be as problematic and the site will run fine. But please get in contact with the sites owner and tell them what you did.\n\n" + scriptError); } content.html(this); _.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 = $('