? jquery_362878.patch Index: popups.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/popups/popups.js,v retrieving revision 1.9.8.17 diff -u -p -r1.9.8.17 popups.js --- popups.js 11 Nov 2009 16:45:20 -0000 1.9.8.17 +++ popups.js 30 Nov 2010 21:02:06 -0000 @@ -37,6 +37,19 @@ Drupal.behaviors.popups = function(conte $popit.remove(); Popups.message($popit.html()); } + + $('link[rel="stylesheet"][href]').each(function(i, v) { + Popups.originalCSS[$(this).attr('href').replace(/^(\/.+)\?\w$/, '$1')] = 1; + }); + if (Drupal.settings.popups && Drupal.settings.popups.originalCSS) { + $.extend(Popups.originalCSS, Drupal.settings.popups.originalCSS); + } + $('script[src]').each(function(i, v) { + Popups.originalJS[$(this).attr('src').replace(/^(\/.+)\?\w$/, '$1')] = 1; + }); + if (Drupal.settings.popups && Drupal.settings.popups.originalJS) { + $.extend(Popups.originalJS, Drupal.settings.popups.originalJS); + } } // Add the popups-link-in-dialog behavior to links defined in Drupal.settings.popups.links array. @@ -68,8 +81,10 @@ Popups = function(){}; * Static variables in the Popups namespace. */ Popups.popupStack = []; -Popups.addedCSS = []; -Popups.addedJS = []; +Popups.addedCSS = {}; +Popups.addedJS = {}; +Popups.originalCSS = {}; +Popups.originalJS = {}; Popups.originalSettings = null; // The initial popup options of the page. /** * Each popup object gets it's own set of options. @@ -645,9 +660,8 @@ Popups.restoreSettings = function() { Popups.restorePage = function() { Popups.restoreSettings(); // Remove the CSS files that were jit loaded for popup. - for (var i in Popups.addedCSS) { - var link = Popups.addedCSS[i]; - $('link[href='+ $(link).attr('href') + ']').remove(); + for (var i in Popups.addedCSS) if (Popups.addedCSS.hasOwnProperty(i)) { + $('link[href='+ Popups.addedCSS[i] + ']').remove(); } Popups.addedCSS = []; }; @@ -712,13 +726,14 @@ Popups.nextCounter = function() { */ Popups.addCSS = function(css) { Popups.addedCSS = []; - for (var type in css) { - for (var file in css[type]) { + for (var type in css) if (css.hasOwnProperty(type)) { + for (var file in css[type]) if (css[type].hasOwnProperty(file)) { var link = css[type][file]; + var href = $(link).attr('href'); // Does the page already contain this stylesheet? - if (!$('link[href='+ $(link).attr('href') + ']').length) { + if (!Popups.originalCSS[href.replace(/^(\/.+)\?\w$/, '$1')] && !Popups.addedCSS[href]) { $('head').append(link); - Popups.addedCSS.push(link); // Keep a list, so we can remove them later. + Popups.addedCSS[href] = 1; // Keep a list, so we can remove them later. } } } @@ -731,25 +746,16 @@ Popups.addJS = function(js) { // Parse the json info about the new context. var scripts = []; var inlines = []; - for (var type in js) { + var src; + for (var type in js) if (js.hasOwnProperty(type)) { if (type != 'setting') { - for (var file in js[type]) { + for (var file in js[type]) if (js[type].hasOwnProperty(file)) { if (type == 'inline') { inlines.push($(js[type][file]).text()); } else { - scripts.push($(js[type][file]).attr('src')); - } - } - } - } - - // Add new JS settings to the page, needed for #ahah properties to work. - Drupal.settings = js.setting; - - for (var i in scripts) { - var src = scripts[i]; - if (!$('script[src='+ src + ']').length && !Popups.addedJS[src]) { + src = $(js[type][file]).attr('src'); + if (!Popups.originalJS[src.replace(/^(\/.+)\?\w$/, '$1')] && !Popups.addedJS[src]) { // Get the script from the server and execute it. $.ajax({ type: 'GET', @@ -761,9 +767,15 @@ Popups.addJS = function(js) { } }); // Mark the js as added to the underlying page. - Popups.addedJS[src] = true; + Popups.addedJS[src] = 1; + } + } } } + } + + // Add new JS settings to the page, needed for #ahah properties to work. + Drupal.settings = js.setting; return inlines; }; @@ -779,9 +791,9 @@ Popups.addInlineJS = function(inlines) { // Load the inlines into the page. for (var n in inlines) { // If the script is not already in the page, execute it. - if (!$('script:not([src]):contains(' + inlines[n] + ')').length) { + //if (!$('script:not([src]):contains(' + inlines[n] + ')').length) { eval(inlines[n]); - } + //} } }; Index: popups.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/popups/popups.module,v retrieving revision 1.11.8.11 diff -u -p -r1.11.8.11 popups.module --- popups.module 26 Mar 2009 17:25:19 -0000 1.11.8.11 +++ popups.module 30 Nov 2010 21:02:06 -0000 @@ -80,7 +80,43 @@ function popups_init() { exit; // Do not continue processing request in index.html. } } +} + +/** + * Implementation of hook_preprocess_hook(). + * + * When CSS or JS aggregation is enabled make a list of the CSS/JS incorporated + * in it so we don't re-add it when loading the popup content. + */ +function popups_preprocess_page() { + $base_path = base_path(); + + if (variable_get('preprocess_css', 0)) { + $css_on_page = array(); + foreach (popups_get_css() as $type => $files) { + foreach ($files as $path => $html) { + $css_on_page[$base_path . $path] = 1; + } + } + $settings['popups']['originalCSS'] = $css_on_page; + } + + if (variable_get('preprocess_js', 0)) { + $js_on_page = array(); + $js = popups_get_js(); + // We don't care about settings or inline css. + unset($js['inline'], $js['setting']); + foreach ($js as $type => $files) { + foreach ($files as $path => $html) { + $js_on_page[$base_path . $path] = 1; + } + } + $settings['popups']['originalJS'] = $js_on_page; + } + if (isset($settings)) { + drupal_add_js($settings, 'setting'); + } } /** @@ -132,6 +168,9 @@ function popups_form_alter(&$form, $form * @return $content in a json wrapper with metadata. */ function popups_render_as_json($content) { + // give modules a chance to preprocess the page. + $ignore = theme('page', $content); + $path = $_GET['q']; // Get current path from params. return drupal_json(array( 'title' => drupal_get_title(),