PopupInPopup = (function (filename, callback) { // Private variable var popup_in_popup_index = 0; var pub = {} pub.Open = function (filename, callback) { // Create new popup: var background = $("").appendTo(document.body); background.css ( { backgroundImage: 'url("/design/DEFAULT/graphics/semi-transperent.png")', width: $(document).width (), height: $(document).height (), position: 'absolute', top: '0px', left: '0px', zIndex: 102 + popup_in_popup_index }); var dialog = $("").appendTo(background); dialog.css ( { position: 'absolute', zIndex: 102 + popup_in_popup_index + 1 }); dialog.html('Laddar innehåll...'); centerElement(dialog); // Get the content: if (filename.substr(0,1) == "/") { url = filename; } else { url = "ajax/" + filename; } jQuery.get(url, function (data) { if (data.redirect) { document.location = data.redirect; } else if (data.html) { dialog.html(data.html); centerElement(dialog); } else { dialog.html(data); centerElement(dialog); } if (data.script) { eval(data.script); } if (callback != null) { callback(); } } ); popup_in_popup_index++; } return pub; })(); function OpenPopup (filename) { OpenPopup (filename, null); } function OpenPopup(filename, callback, json) { var obj = null; var method = 'get'; var data = {}; if (typeof(filename) == "object") { obj = filename; filename = obj.url; if (obj.method) { method = obj.method; } if (obj.callback) { callback = obj.callback; } if (obj.data) { data = obj.data; } } // Parse url and get variables: var dialog = $('#popup_div'); // Remove previous scrollbars: $('div.customScrollBar').remove (); if (dialog.length == 0) { // Replace background image: var sizey = $(document).height(); var sizex = $(document).width (); bgimage = top.document.createElement('div'); bgimage.style.backgroundImage = 'url("/design/DEFAULT/graphics/semi-transperent.png")'; bgimage.id = 'popup_background_image'; bgimage.style.position = 'absolute'; bgimage.style.top = '0px'; bgimage.style.left = '0px'; bgimage.style.width = sizex + 'px'; bgimage.style.height = sizey + 'px'; bgimage.style.zIndex = 100; top.document.body.appendChild(bgimage); // Open dialog: dialog = $('').appendTo(document.body); } centerElement('popup_div'); // Get the content: if (filename.substr(0,1) == "/") { url = filename; } else { url = "ajax/" + filename; } $.ajax({ url: url, method: method, success: function (data) { if (data.substring(0,10) == "Location: ") { document.location = data.substring(10); return; } if (json) { data = JSON.parse(data); $(dialog).html(data.html); if (data) { eval(data.script); } } else { $(dialog).html(data); } centerElement('popup_div'); if (callback != null) { if ( typeof(callback) == "function" ) { callback.call ($(dialog).get(0), data); } else { eval(callback); } } } }); } function centerElement (e) { var elm = e; if (typeof elm == "string") { elm = $('#' + elm); } var offset_top = $(window).scrollTop() + ($(window).height() / 2) - (elm.height()/2); if (offset_top < 0) { offset_top = 0; } elm.css ( { left: ( $(window).width() / 2) - (elm.width()/2), top: offset_top }); // Scroll if needed: if ( offset_top < $(window).scrollTop() ) { $(window).scrollTop(offset_top); } } function ClosePopup(elm) { // Is it popup in popup? if (elm) { if ( $(elm).closest('div.popup_in_popup').length > 0 ) { // It's popup in popup, close the popup: $(elm).closest('div.popup_in_popup_background').remove (); return; } } // Remove background image: bgimg = top.document.getElementById('popup_background_image'); if (bgimg) { top.document.body.removeChild(bgimg); } // Remove popup: pdiv = top.document.getElementById('popup_div'); if (pdiv) { top.document.body.removeChild(pdiv); } // Remove all scrollbars.. This might cause problems if scrollbars is used in the main page. $('div.customScrollBar').remove (); return true; }