/[drupal]/contributions/modules/popups/popups.js
ViewVC logotype

Diff of /contributions/modules/popups/popups.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.9.8.11, Fri Mar 20 00:03:03 2009 UTC revision 1.9.8.12, Sat Mar 21 00:57:15 2009 UTC
# Line 1  Line 1 
1  // $Id: popups.js,v 1.9.8.10 2009/03/19 15:53:44 starbow Exp $  // $Id: popups.js,v 1.9.8.11 2009/03/20 00:03:03 starbow Exp $
2    
3  /**  /**
4   * Popup Modal Dialog API   * Popup Modal Dialog API
# Line 26  Line 26 
26   */   */
27    
28  Drupal.behaviors.popups = function(context) {  Drupal.behaviors.popups = function(context) {
29      Popups.saveSettings();
30    
31    var $body = $('body');    var $body = $('body');
32    if(!$body.hasClass('popups-processed')) {    if(!$body.hasClass('popups-processed')) {
33      $body.addClass('popups-processed');      $body.addClass('popups-processed');
# Line 38  Drupal.behaviors.popups = function(conte Line 40  Drupal.behaviors.popups = function(conte
40    }    }
41    
42    // Add the popups-link-in-dialog behavior to links defined in Drupal.settings.popups.links array.    // Add the popups-link-in-dialog behavior to links defined in Drupal.settings.popups.links array.
43    if (Drupal.settings.popups.links) {    // Get these from current Drupal.settings, not Popups.originalSettings, as each page has it's own hooks.
44      if (Drupal.settings.popups && Drupal.settings.popups.links) {
45      jQuery.each(Drupal.settings.popups.links, function (link, options) {      jQuery.each(Drupal.settings.popups.links, function (link, options) {
46        Popups.attach(context, link, Popups.options(options));        Popups.attach(context, link, Popups.options(options));
47      });      });
# Line 48  Drupal.behaviors.popups = function(conte Line 51  Drupal.behaviors.popups = function(conte
51    Popups.attach(context, '.popups-form', Popups.options({updateMethod: 'ajax'})); // ajax reload.    Popups.attach(context, '.popups-form', Popups.options({updateMethod: 'ajax'})); // ajax reload.
52    Popups.attach(context, '.popups-form-reload', Popups.options({updateMethod: 'reload'})); // whole page reload.    Popups.attach(context, '.popups-form-reload', Popups.options({updateMethod: 'reload'})); // whole page reload.
53    Popups.attach(context, '.popups-form-noupdate', Popups.options({updateMethod: 'none'}));  // no reload at all.    Popups.attach(context, '.popups-form-noupdate', Popups.options({updateMethod: 'none'}));  // no reload at all.
 //  Popups.attach(context, '.popups-form-noreload', {noUpdate: true});  // Obsolete.  
54  };  };
55    
56  // ***************************************************************************  // ***************************************************************************
57  // Popups Namespace  // Popups Namespace **********************************************************
58  // ***************************************************************************  // ***************************************************************************
   
59  /**  /**
60   * Create the popups namespace.   * The Popups namespace contains:
61   * The popups namespace contains a set of functions for managing multiple popup objects.   * * An ordered stack of Popup objects,
62     * * The state of the original page,
63     * * Functions for managing both of the above.
64   */   */
65  Popups = function(){};  Popups = function(){};
66    
# Line 65  Popups = function(){}; Line 68  Popups = function(){};
68   * Static variables in the Popups namespace.   * Static variables in the Popups namespace.
69   */   */
70  Popups.popupStack = [];  Popups.popupStack = [];
 Popups.originalSettings = null;  
71  Popups.addedCSS = [];  Popups.addedCSS = [];
72  Popups.addedJS = [];  Popups.addedJS = [];
73    Popups.originalSettings = null; // The initial popup options of the page.
74  /**  /**
75   * Create the Popup class inside of the Popups namespace.   * Each popup object gets it's own set of options.
76   * A popup up is a single modal dialog.   * These are the defaults.
77   *   */
78   * @param options  Popups.defaultOptions = {
79   *   Hash of options controlling how the popups interacts with the underlying page.    doneTest: null, // null, *path*, *regexp*. how do we know when a multiform flow is done?
80   * @param element    updateMethod: 'ajax', // none, ajax, reload, *callback*
81   *   A DOM object containing the element that was clicked to initiate the popup.    updateSource: 'initial', // initial, final. Only used if updateMethod != none.
82      href: null,
83      width: null, // Override the width specified in the css.
84      targetSelectors: null, // Hash of jQuery selectors that define the content to be swapped out.
85      titleSelectors: null, // Array of jQuery selectors to place the new page title.
86      reloadOnError: false, // Force the entire page to reload if the popup href is unaccessable.
87      noMessage: false, // Don't show drupal_set_message messages.
88      skipDirtyCheck: false, // If true, this popup will not check for edits on the originating page.
89      hijackDestination: true // Use the destiination param to force a form submit to return to the originating page.
90    };
91    
92    // ***************************************************************************
93    // Popups.Popup Object *******************************************************
94    // ***************************************************************************
95    /**
96     * A Popup is a single modal dialog.
97     * The popup object encapslated all the info about a single popup.
98   */   */
99  Popups.Popup = function() {  Popups.Popup = function() {
100    this.id = 'popups-' + Popups.nextCounter();    this.id = 'popups-' + Popups.nextCounter();
101    
102    // These properties are needed if the popup contains a form that will be ajax submitted.    // These properties are needed if the popup contains a form that will be ajax submitted.
103    this.parent = null; // null = the original page. Otherwise it is the popup that spawned this one.    this.parent = null; // The popup that spawned this one. If parent is null, this popup was spawned by the original page.
104    this.path = null; // If popup is showing content from a url, this is that path.    this.path = null; // If popup is showing content from a url, this is that path.
105    this.element = null; // The element that was clicked to launch this popup.    this.element = null; // The DOM element that was clicked to launch this popup.
106    this.options = null; // An option array that control how the popup behaves.  See Popups.defaultOptions for explinations.    this.options = null; // An option array that control how the popup behaves.  See Popups.defaultOptions for explainations.
107  };  };
108  Popups.Popup.prototype.$popup = function() {  Popups.Popup.prototype.$popup = function() {
109    return $('#' + this.id);    return $('#' + this.id);
# Line 163  Popups.Popup.prototype.refocus = functio Line 181  Popups.Popup.prototype.refocus = functio
181    $focus.focus();    $focus.focus();
182  };  };
183    
184    /**
185     * Return a selector that will find target content on the layer that spawned this popup.
186     * This is needed for the popup to do ajax updates.
187     */
188  Popups.Popup.prototype.targetLayerSelector = function() {  Popups.Popup.prototype.targetLayerSelector = function() {
189    if (this.parent === null) {    if (this.parent === null) {
190      return 'body';      return 'body'; // Select content in the original page.
191    }    }
192    else {    else {
193      return '#' + this.parent.id;      return '#' + this.parent.id; // Select content in the parent popup.
194    }    }
195  };  };
196    
197    /**
198  // Determine if we are at an end point, or just moving from one popups to another.   * Determine if we are at an end point of a form flow, or just moving from one popups to another.
199     *
200     * @param path
201     *   The path of the page that the form flow has moved to.
202     *   This path is relative to the base_path.
203     *   Ex: node/add/story, not http://localhost/drupal6/node/add/story or drupa6/node/add/story.
204     * @return bool
205     */
206  Popups.Popup.prototype.isDone = function(path) {  Popups.Popup.prototype.isDone = function(path) {
207    //  console.log("Doing isDone for popup: " + this.id + ", now at " + path );
208    var done;    var done;
209    if (this.options.doneTest) {    if (this.options.doneTest) {
210      // See if we are at the path specified by doneTest.      // Test if we are at the path specified by doneTest.
211      done = (path === this.options.doneTest || path.match(this.options.doneTest));      done = (path === this.options.doneTest || path.match(this.options.doneTest));
212    }    }
213    else {    else {
214      if (this.parent) {      if (this.parent) {
215        done = (path === this.parent.path); // We are back to the spawning popup's path. Success.         // Test if we are back to the parent popup's path.
216          done = (path === this.parent.path);
217    //      console.log("Lookin at parent: " + this.parent.path + ". Done = " + done);
218      }      }
219      else {      else {
220        done = (path === Drupal.settings.popups.originalPath); // We are back to the original page's path. Success.         // Test if we are back to the original page's path.
221          done = (path === Popups.originalSettings.popups.originalPath);
222    //      console.log("Lookin at original page: " + Popups.originalSettings.popups.originalPath + ". Done = " + done);
223      }      }
224    };    };
225    return done;    return done;
226  };  };
227    
 // DONE with Popups.Popup object ********************************  
228    
229  // Utility function.  // ***************************************************************************
230    // Popups Functions **********************************************************
231    // ***************************************************************************
232    
233    /**
234     * Test if the param has been set.
235     * Used to distinguish between a value set to null or false and on not yet unset.
236     */
237  Popups.isset = function(v) {  Popups.isset = function(v) {
238    return (typeof(v) !== 'undefined');    return (typeof(v) !== 'undefined');
239  };  };
240    
241    /**
242     * Get the currently active popup in the page.
243     * Currently it is the only one visible, but that could change.
244     */
245  Popups.activePopup = function() {  Popups.activePopup = function() {
246    if (Popups.popupStack.length) {    if (Popups.popupStack.length) {
247      return Popups.popupStack[Popups.popupStack.length - 1]; // top of stack.      return Popups.popupStack[Popups.popupStack.length - 1]; // top of stack.
# Line 207  Popups.activePopup = function() { Line 251  Popups.activePopup = function() {
251    }    }
252  };  };
253    
254    /**
255     * Manage the page wide popupStack.
256     */
257  Popups.push = function(popup) {  Popups.push = function(popup) {
258    Popups.popupStack.push(popup);    Popups.popupStack.push(popup);
259  };  };
   
260  // Should I integrate this with popupRemove??  // Should I integrate this with popupRemove??
261  Popups.pop = function(popup) {  Popups.pop = function(popup) {
262    return Popups.popupStack.pop();    return Popups.popupStack.pop();
263  };  };
264    
265  Popups.defaultOptions = {  /**
266    doneTest: null, // null, *path*, *regexp*. how do we know when a multiform flow is done?   * Build an options hash from defaults.
267    updateMethod: 'ajax', // none, ajax, reload, *callback*   *
268    updateSource: 'initial', // initial, final. Only used if updateMethod != none.   * @param overrides
269    href: null,   *   Hash of values to override the defaults.
270    width: null, // Override the width specified in the css.   */
   targetSelectors: null, // Hash of jQuery selectors that define the content to be swapped out.  
   titleSelectors: null, // Array of jQuery selectors to place the new page title.  
   reloadOnError: false, // Force the entire page to reload if the popup href is unaccessable.  
   noMessage: false, // Don't show drupal_set_message messages.  
   skipDirtyCheck: false, // If true, this popup will not check for edits on the originating page.  
   hijackDestination: true // Use the destiination param to force a form submit to return to the originating page.  
 };  
   
271  Popups.options = function(overrides) {  Popups.options = function(overrides) {
272    var defaults = Popups.defaultOptions;    var defaults = Popups.defaultOptions;
273    return Popups.overrideOptions(defaults, overrides);    return Popups.overrideOptions(defaults, overrides);
274  }  }
275    
276    /**
277     * Build an options hash.
278     * Also maps deprecated options to current options.
279     *
280     * @param defaults
281     *   Hash of default values
282     * @param overrides
283     *   Hash of values to override the defaults with.
284     */
285  Popups.overrideOptions = function(defaults, overrides) {  Popups.overrideOptions = function(defaults, overrides) {
286    var options = {};    var options = {};
287    for(var option in defaults) {    for(var option in defaults) {
# Line 301  Popups.attach = function(context, select Line 348  Popups.attach = function(context, select
348   *   *
349   * @param element   * @param element
350   *   The element that was clicked.   *   The element that was clicked.
351     * @param options
352     *   Hash of options associated with the element.
353   */   */
354  Popups.clickPopupElement = function(element, options) {  Popups.clickPopupElement = function(element, options) {
355      Popups.saveSettings();
356    
357    // If the element contains a on-popups-options attribute, override default options param.    // If the element contains a on-popups-options attribute, override default options param.
358    if ($(element).attr('on-popups-options')) {    if ($(element).attr('on-popups-options')) {
359      var overrides = Drupal.parseJson($(element).attr('on-popups-options'));      var overrides = Drupal.parseJson($(element).attr('on-popups-options'));
360      options = Popups.overrideOptions(options, overrides);      options = Popups.overrideOptions(options, overrides);
361    }    }
362    
363  //  console.log("clickPopupElement:" + element);    // The parent of the new popup is the currently active popup.
 //  console.log(options);  
364    var parent = Popups.activePopup();    var parent = Popups.activePopup();
365    
366    // If the option is distructive, check if the page is already modified, and offer to save.    // If the option is distructive, check if the page is already modified, and offer to save.
# Line 327  Popups.clickPopupElement = function(elem Line 377  Popups.clickPopupElement = function(elem
377  };  };
378    
379  /**  /**
380   * Has the active layer been edited?   * Test if the active layer been edited.
381   * Active layer is either the original page, or the active Popup.   * Active layer is either the original page, or the active Popup.
382   */   */
383  Popups.activeLayerIsEdited = function() {  Popups.activeLayerIsEdited = function() {
384    // TODO: test needs to work on top level (page or popup), not just page.    var layer = Popups.activePopup();
385    // TODO: better test for edited page, maybe capture change event on :inputs.    var $context = Popups.getLayerContext(layer);
386    return $('span.tabledrag-changed').length    // TODO: better test for edited page, maybe capture change event on :inputs.
387      var edited = $context.find('span.tabledrag-changed').length;
388      return edited;
389  }  }
390    
391  /**  /**
392   * Show dialog offering to save current state of page.   * Show dialog offering to save form on parent layer.
  * TODO - Should operate on current level -1, not just original page.  
393   *   *
394   * @param {Object} element   * @param element
395   * @param {Object} options   *   The DOM element that was clicked.
396     * @param options
397     *   The options associated with that element.
398     * @param parent
399     *   The layer that has the unsaved edits.  Null means the underlying page.
400   */   */
401  Popups.offerToSave = function(element, options, parent) {  Popups.offerToSave = function(element, options, parent) {
402    var popup = new Popups.Popup();    var popup = new Popups.Popup();
403    var body = Drupal.t("There are unsaved changes on this page, which you will lose if you continue.");    var body = Drupal.t("There are unsaved changes in the form, which you will lose if you continue.");
404    var buttons = {    var buttons = {
405     'popup_save': {title: Drupal.t('Save Changes'), func: function(){Popups.savePage(element, options, parent);}},     'popup_save': {title: Drupal.t('Save Changes'), func: function(){Popups.saveFormOnLayer(element, options, parent);}},
406     'popup_submit': {title: Drupal.t('Continue'), func: function(){popup.removePopup(); Popups.openPath(element, options, parent);}},     'popup_submit': {title: Drupal.t('Continue'), func: function(){popup.removePopup(); Popups.openPath(element, options, parent);}},
407     'popup_cancel': {title: Drupal.t('Cancel'), func: function(){popup.close();}}     'popup_cancel': {title: Drupal.t('Cancel'), func: function(){popup.close();}}
408    };    };
# Line 372  Popups.offerToSave = function(element, o Line 427  Popups.offerToSave = function(element, o
427   *   Width of new dialog.   *   Width of new dialog.
428   *   *
429   * @return popup object   * @return popup object
  *   Width of new dialog.  
430   */   */
431  Popups.open = function(popup, title, body, buttons, width){  Popups.open = function(popup, title, body, buttons, width){
432    Popups.addOverlay();    Popups.addOverlay();
# Line 423  Popups.open = function(popup, title, bod Line 477  Popups.open = function(popup, title, bod
477    return popup;    return popup;
478  };  };
479    
480    /**
481     * Adjust the popup's height to fit it's content.
482     * Move it to be centered on the screen.
483     * This undoes the effects of popup.hide().
484     *
485     * @param popup
486     */
487  Popups.resizeAndCenter = function(popup) {  Popups.resizeAndCenter = function(popup) {
 //  console.log('resizeAndCenter: ' + popup.id)  
   
488    var $popup = popup.$popup();    var $popup = popup.$popup();
489    
490    // center on the screen, adding in offsets if the window has been scrolled    // center on the screen, adding in offsets if the window has been scrolled
# Line 450  Popups.resizeAndCenter = function(popup) Line 509  Popups.resizeAndCenter = function(popup)
509    
510    
511  /**  /**
512   *  Simple popup dialog that functions like the browser's alert box.   *  Create and show a simple popup dialog that functions like the browser's alert box.
513   */   */
514  Popups.message = function(title, message) {  Popups.message = function(title, message) {
515    message = message || '';    message = message || '';
# Line 573  Popups.close = function(popup) { Line 632  Popups.close = function(popup) {
632  };  };
633    
634  /**  /**
635     * Save the page's original Drupal.settings.
636     */
637    Popups.saveSettings = function() {
638      if (!Popups.originalSettings) {
639        Popups.originalSettings = Drupal.settings;
640      }
641    };
642    
643    /**
644     * Restore the page's original Drupal.settings.
645     */
646    Popups.restoreSettings = function() {
647      Drupal.settings = Popups.originalSettings;
648    };
649    
650    /**
651   * Remove as much of the effects of jit loading as possible.   * Remove as much of the effects of jit loading as possible.
652   */   */
653  Popups.restorePage = function() {  Popups.restorePage = function() {
654    // Restore the page's original Drupal.settings.    Popups.restoreSettings();
655    if (Popups.originalSettings) {    // Remove the CSS files that were jit loaded for popup.
656  //    console.log('restoring page');    for (var i in Popups.addedCSS) {
657      Drupal.settings = Popups.originalSettings;      var link = Popups.addedCSS[i];
658      // Remove the CSS files that were jit loaded for popup.      $('link[href='+ $(link).attr('href') + ']').remove();
659      for (var i in Popups.addedCSS) {    }
660        var link = Popups.addedCSS[i];    Popups.addedCSS = [];
       $('link[href='+ $(link).attr('href') + ']').remove();  
     }  
     Popups.originalSettings = null;  
     Popups.addedCSS = [];  
   }  
661  };  };
662    
663    
# Line 615  Popups.scrollTop = function() { Line 685  Popups.scrollTop = function() {
685   */   */
686  Popups.windowHeight = function() {  Popups.windowHeight = function() {
687    if ($.browser.opera && $.browser.version > "9.5" && $.fn.jquery <= "1.2.6") {    if ($.browser.opera && $.browser.version > "9.5" && $.fn.jquery <= "1.2.6") {
 //    return document.documentElement["clientHeight"];  
688      return document.documentElement.clientHeight;      return document.documentElement.clientHeight;
689    }    }
690    return $(window).height();    return $(window).height();
# Line 627  Popups.windowHeight = function() { Line 696  Popups.windowHeight = function() {
696   */   */
697  Popups.windowWidth = function() {  Popups.windowWidth = function() {
698    if ($.browser.opera && $.browser.version > "9.5" && $.fn.jquery <= "1.2.6") {    if ($.browser.opera && $.browser.version > "9.5" && $.fn.jquery <= "1.2.6") {
 //    return document.documentElement["clientWidth"];  
699      return document.documentElement.clientWidth;      return document.documentElement.clientWidth;
700    }    }
701    return $(window).width();    return $(window).width();
# Line 657  Popups.addCSS = function(css) { Line 725  Popups.addCSS = function(css) {
725        var link = css[type][file];        var link = css[type][file];
726        // Does the page already contain this stylesheet?        // Does the page already contain this stylesheet?
727        if (!$('link[href='+ $(link).attr('href') + ']').length) {        if (!$('link[href='+ $(link).attr('href') + ']').length) {
 //        console.log( "ADDING " + link);  
728          $('head').append(link);          $('head').append(link);
729          Popups.addedCSS.push(link); // Keep a list, so we can remove them later.          Popups.addedCSS.push(link); // Keep a list, so we can remove them later.
730        }        }
# Line 686  Popups.addJS = function(js) { Line 753  Popups.addJS = function(js) {
753    }    }
754    
755    // Add new JS settings to the page, needed for #ahah properties to work.    // Add new JS settings to the page, needed for #ahah properties to work.
   Popups.originalSettings = Drupal.settings; // Cache orginial page settings.  
756    Drupal.settings = js.setting;    Drupal.settings = js.setting;
757    // As an exception, keep the popups settings in place until the popup is closed.  //  console.log('js.setting...');
758    Drupal.settings.popups = Popups.originalSettings.popups;  //  console.log(js.setting);
759    
760    for (var i in scripts) {    for (var i in scripts) {
761      var src = scripts[i];      var src = scripts[i];
# Line 747  Popups.beforeSubmit = function(formData, Line 813  Popups.beforeSubmit = function(formData,
813   ****************************************************************************/   ****************************************************************************/
814    
815  /**  /**
816   * Use Ajax to open the link in a popups window.   * Use Ajax to open a link in a popups window.
817   *   *
818   * @param element   * @param element
819   *   Element that was clicked to open the popups.   *   Element that was clicked to open the popups.
# Line 757  Popups.beforeSubmit = function(formData, Line 823  Popups.beforeSubmit = function(formData,
823   *   If path is being opened from inside another popup, that popup is the parent.   *   If path is being opened from inside another popup, that popup is the parent.
824   */   */
825  Popups.openPath = function(element, options, parent) {  Popups.openPath = function(element, options, parent) {
826      Popups.saveSettings();
827    
828    // Let the user know something is happening.    // Let the user know something is happening.
829    $('body').css("cursor", "wait");    $('body').css("cursor", "wait");
830    
# Line 768  Popups.openPath = function(element, opti Line 836  Popups.openPath = function(element, opti
836    
837    var href = options.href ? options.href : element.href;    var href = options.href ? options.href : element.href;
838    $(document).trigger('popups_open_path', [element, href]); // Broadcast Popup Open Path event.    $(document).trigger('popups_open_path', [element, href]); // Broadcast Popup Open Path event.
   
   // Bit of black magic string math to get current path from href;  
   var start = document.location.href.length - document.location.pathname.length + Drupal.settings.basePath.length;  
   var stop = href.indexOf('?');  
   var path = href.substring(start, stop);  
839    
840    var params = {};    var params = {};
841    // Force the popups to return back to the orignal page when forms are done, unless hijackDestination option is set to FALSE.    // Force the popups to return back to the orignal page when forms are done, unless hijackDestination option is set to FALSE.
842    if (options.hijackDestination) {    if (options.hijackDestination) {
843      var hijackURL = Drupal.settings.popups.originalPath;      var returnPath;
844      if (parent) {      if (parent) {
845        hijackURL = parent.path;        returnPath = parent.path;
846        console.log('hijacking.  Parent is: ');  //      console.log('Popup parent is ...');
847        console.log(parent);  //      console.log(parent);
848      }      }
849        else { // No parent, so bring flow back to original page.
850  //    // If forceReturn, requestor wants data from different page.        returnPath = Popups.originalSettings.popups.originalPath;
851        }
852      href = href.replace(/destination=[^;&]*[;&]?/, ''); // Strip out any existing destination param.      href = href.replace(/destination=[^;&]*[;&]?/, ''); // Strip out any existing destination param.
853      console.log("Hijacking destination to " + hijackURL);  //    console.log("Hijacking destination to " + returnPath);
854      params.destination = hijackURL; // Set the destination to the original page.      params.destination = returnPath; // Set the destination to return to the parent's path.
855    }    }
856    
857    var ajaxOptions = {    var ajaxOptions = {
# Line 798  Popups.openPath = function(element, opti Line 862  Popups.openPath = function(element, opti
862      success: function(json) {      success: function(json) {
863        // Add additional CSS to the page.        // Add additional CSS to the page.
864        Popups.addCSS(json.css);        Popups.addCSS(json.css);
865        var inlines = Popups.addJS(json.js);        var inlines = Popups.addJS(json.js);
866        var popup = Popups.openPathContent(path, json.title, json.messages + json.content, element, options, parent);        var popup = Popups.openPathContent(json.path, json.title, json.messages + json.content, element, options, parent);
867        Popups.addInlineJS(inlines);        Popups.addInlineJS(inlines);
   
868        // Broadcast an event that the path was opened.        // Broadcast an event that the path was opened.
869        $(document).trigger('popups_open_path_done', [element, href, popup]);        $(document).trigger('popups_open_path_done', [element, href, popup]);
870      },      },
# Line 810  Popups.openPath = function(element, opti Line 873  Popups.openPath = function(element, opti
873      }      }
874    };    };
875    
876      var ajaxOptions;
877    if (options.reloadOnError) {    if (options.reloadOnError) {
878      ajaxOptions.error = function() {      ajaxOptions.error = function() {
879        location.reload(); // Reload on error. Is this working?        location.reload(); // Reload on error. Is this working?
# Line 825  Popups.openPath = function(element, opti Line 889  Popups.openPath = function(element, opti
889    return false;    return false;
890  };  };
891    
   
 /*  
 // TODO  
 // json - response from drupal server.  
 Popups.openPathSucess = function(json, element, options, parent, href) {  
   // Add additional CSS to the page.  
   Popups.addCSS(json.css);  
   var inlines = Popups.addJS(json.js);  
   var popup = Popups.openContent(json.title, json.messages + json.content, options, element);  
 //  var popup = Popups.open(null, title, content, null, options.width);  
 //  var popup = Popups.open(null, json.title, json.messages + json.content, null, options.width);  
   Popups.addInlineJS(inlines);  
   
 //  // Add behaviors to content in popups.  
 //  delete Drupal.behaviors.tableHeader; // Work-around for bug in tableheader.js (http://drupal.org/node/234377)  
 //  delete Drupal.behaviors.teaser; // Work-around for bug in teaser.js (sigh).  
 //  Drupal.attachBehaviors(popup.$popupBody());  
 //  // Adding collapse behavior loses focus, so reestablish it.  
 //  popup.refocus();  
   
   // If the popups contains a form, capture submit.  
   var $form = $('form', popup.$popupBody());  
   if ($form.length) {  
     // Set properties on new popup.  They will be needed in formSuccess.  
     popup.parent = parent;  
     popup.element = element;  
     popups.options = options;  
   
     $form.ajaxForm({  
       dataType: 'json',  
       beforeSubmit: Popups.beforeSubmit,  
       beforeSend: Popups.beforeSend,  
       success: function(response, status) {  
         Popups.formSuccess(popup, response);  
       },  
       error: function() {  
         Popups.message("Bad Response form submission");  
       }  
     });  
   }  
   
   // Broadcast an event that the path was opened.  
   $(document).trigger('popups_open_path_done', [popup]);  
 };  
 */  
   
892  /**  /**
893   * Open path's content in an ajax popups.   * Open path's content in an ajax popups.
  * TODO - I think this function can be removed.  
894   *   *
895   * @param title   * @param title
896   *   String title of the popups.   *   String title of the popups.
897   * @param content   * @param content
898   *   HTML to show in the popups.   *   HTML to show in the popups.
  * @param options  
  *   Hash of options controlling how the popups interacts with the underlying page.  
899   * @param element   * @param element
900   *   A DOM object containing the element that was clicked to initiate the popup.   *   A DOM object containing the element that was clicked to initiate the popup.
901     * @param options
902     *   Hash of options controlling how the popups interacts with the underlying page.
903     * @param parent
904     *   Spawning popup, or null if spawned from original page.
905   */   */
906  Popups.openPathContent = function(path, title, content, options, element, parent) {  Popups.openPathContent = function(path, title, content, element, options, parent) {
907    var popup = new Popups.Popup();    var popup = new Popups.Popup();
908    Popups.open(popup, title, content, null, options.width);    Popups.open(popup, title, content, null, options.width);
909    
910    // Set properties on new popup.    // Set properties on new popup.
911    popup.parent = parent;    popup.parent = parent;
912    popup.path = path;    popup.path = path;
913    //  console.log("Setting popup " + popup.id + " originalPath to " + path);
914    popup.options = options;    popup.options = options;
915    popup.element = element;    popup.element = element;
916    
# Line 908  Popups.openPathContent = function(path, Line 928  Popups.openPathContent = function(path,
928        dataType: 'json',        dataType: 'json',
929        beforeSubmit: Popups.beforeSubmit,        beforeSubmit: Popups.beforeSubmit,
930        beforeSend: Popups.beforeSend,        beforeSend: Popups.beforeSend,
931        success: function(response, status) {        success: function(json, status) {
932          Popups.formSuccess(popup, response);          Popups.formSuccess(popup, json);
   //      Popups.formSuccess(response, options, element, targetLayerSelector, popup.parent.path);  
933        },        },
934        error: function() {        error: function() {
935          Popups.message("Bad Response form submission");          Popups.message("Bad Response form submission");
# Line 929  Popups.openPathContent = function(path, Line 948  Popups.openPathContent = function(path,
948   *   The popup object that contained the form that was just submitted.   *   The popup object that contained the form that was just submitted.
949   * @param data   * @param data
950   *   JSON object from server with status of form submission.   *   JSON object from server with status of form submission.
  *  
951   */   */
952  //Popups.formSuccess = function(data, options, element, targetLayerSelector, donePath) {  Popups.formSuccess = function(popup, data) {
 Popups.formSuccess = function(popup, data) {  
   
 /*  
    var done = false;  
   
   console.log('donePath = ' + donePath);  
   if (!options.doneTest) {  
     // TODO - initialURL  
     if (donePath) {  
       done = (data.path === donePath); // We are back where we started. Success.  
     }  
     else {  
       done = (data.path === Drupal.settings.popups.originalPath); // We are back where we started. Success.  
     }  
   }  
   else { // See if we are at the path specified by doneTest.  
     done = (data.path === options.doneTest || data.path.match(options.doneTest));  
   };  
  */  
   
953    // Determine if we are at an end point, or just moving from one popups to another.    // Determine if we are at an end point, or just moving from one popups to another.
954    var done = popup.isDone(data.path);    var done = popup.isDone(data.path);
955    if (!done) { // Not done yet, so show new page in new popups.    if (!done) { // Not done yet, so show new page in new popups.
# Line 967  Popups.formSuccess = function(popup, dat Line 965  Popups.formSuccess = function(popup, dat
965        }        }
966      }      }
967    
 //    if (options.reloadWhenDone) { // Force a complete, non-ajax reload of the page.  
968      if (popup.options.updateMethod === 'reload') { // Force a complete, non-ajax reload of the page.      if (popup.options.updateMethod === 'reload') { // Force a complete, non-ajax reload of the page.
969        if (popup.options.updateSource === 'final') {        if (popup.options.updateSource === 'final') {
970          location.href = data.path;          location.href = Drupal.settings.basePath + data.path; // TODO: Need to test this.
971        }        }
972        else { // Reload originating page.        else { // Reload originating page.
973          location.reload();          location.reload();
974        }        }
975      }      }
976      else { // Normal, targeted ajax, reload behavior.      else { // Normal, targeted ajax, reload behavior.
977        // show messages in dialog and embed the results in the original page.        // Show messages in dialog and embed the results in the original page.
978        var showMessage = data.messages.length && !popup.options.noMessage;        var showMessage = data.messages.length && !popup.options.noMessage;
979        if (showMessage) {        if (showMessage) {
980          var messagePopup = Popups.message(data.messages); // Popup message.          var messagePopup = Popups.message(data.messages); // Popup message.
981          if (Drupal.settings.popups.autoCloseFinalMessage) {          if (Popups.originalSettings.popups.autoCloseFinalMessage) {
982            setTimeout(function(){Popups.close(messagePopup);}, 2500); // Autoclose the message box in 2.5 seconds.            setTimeout(function(){Popups.close(messagePopup);}, 2500); // Autoclose the message box in 2.5 seconds.
983          }          }
984    
985          // Insert the message into the page above the content.          // Insert the message into the page above the content.
986          // Might not be the standard spot, but it is the easiest to find.          // Might not be the standard spot, but it is the easiest to find.
         // TODO - on to layer, not originating page?  
 //        var $next = $(Drupal.settings.popups.defaultTargetSelector);  
         // TODO - test not working!  
987          var $next;          var $next;
988          if (popup.targetLayerSelector() === 'body') {          if (popup.targetLayerSelector() === 'body') {
989            $next = $('body').find(Drupal.settings.popups.defaultTargetSelector);            $next = $('body').find(Popups.originalSettings.popups.defaultTargetSelector);
990          }          }
991          else {          else {
992            $next = $(popup.targetLayerSelector()).find('.popups-body');            $next = $(popup.targetLayerSelector()).find('.popups-body');
# Line 1003  Popups.formSuccess = function(popup, dat Line 997  Popups.formSuccess = function(popup, dat
997    
998        // Update the content area (defined by 'targetSelectors').        // Update the content area (defined by 'targetSelectors').
999        if (popup.options.updateMethod !== 'none') {        if (popup.options.updateMethod !== 'none') {
1000          Popups.testContentSelector();          Popups.testContentSelector(); // Kick up warning message if selector is bad.
1001    
1002            Popups.restoreSettings(); // Need to restore original Drupal.settings.popups.links before running attachBehaviors.  This probably has CSS side effects!
1003          if (popup.options.targetSelectors) { // Pick and choose what returned content goes where.          if (popup.options.targetSelectors) { // Pick and choose what returned content goes where.
1004            jQuery.each(popup.options.targetSelectors, function(t_new, t_old) {            jQuery.each(popup.options.targetSelectors, function(t_new, t_old) {
1005              if(!isNaN(t_new)) {              if(!isNaN(t_new)) {
1006                t_new = t_old; // handle case where targetSelectors is an array, not a hash.                t_new = t_old; // handle case where targetSelectors is an array, not a hash.
1007              }              }
1008              console.log("Updating target " + t_old + ' with ' + t_new);  //            console.log("Updating target " + t_old + ' with ' + t_new);
1009              var new_content = $(t_new, data.content);              var new_content = $(t_new, data.content);
1010              console.log("new content: ");  //            console.log("new content... ");
1011              console.log(new_content);  //            console.log(new_content);
1012              var $c = $(t_old).html(new_content); // Inject the new content into the original page.              var $c = $(popup.targetLayerSelector()).find(t_old).html(new_content); // Inject the new content into the original page.
1013              Drupal.attachBehaviors($c);  
1014                Drupal.attachBehaviors($c);
1015            });            });
1016          }          }
1017          else { // Put the entire new content into default content area.          else { // Put the entire new content into default content area.
1018            var $c = $(Drupal.settings.popups.defaultTargetSelector).html(data.content);            var $c = $(popup.targetLayerSelector()).find(Popups.originalSettings.popups.defaultTargetSelector).html(data.content);
1019    //          console.log("updating entire content area.")
1020            Drupal.attachBehaviors($c);            Drupal.attachBehaviors($c);
1021          }          }
1022        }        }
# Line 1041  Popups.formSuccess = function(popup, dat Line 1039  Popups.formSuccess = function(popup, dat
1039      // Broadcast an event that popup form was done and successful.      // Broadcast an event that popup form was done and successful.
1040      $(document).trigger('popups_form_success', [popup]);      $(document).trigger('popups_form_success', [popup]);
1041    
1042    }  // End of updating original page.    }  // End of updating spawning layer.
1043  };  };
1044    
1045    
1046    /**
1047     * Get a jQuery object for the content of a layer.
1048     * @param layer
1049     *   Either a popup, or null to signify the original page.
1050     */
1051    Popups.getLayerContext = function(layer) {
1052      var $context;
1053      if (!layer) {
1054        $context = $('body').find(Popups.originalSettings.popups.defaultTargetSelector);
1055      }
1056      else {
1057        $context = layer.$popupBody();
1058      }
1059      return $context;
1060    }
1061    
1062  /**  /**
1063   * Submit the page and reload the results, before popping up the real dialog.   * Submit the page and reload the results, before popping up the real dialog.
1064   *   *
1065   * @param element   * @param element
1066   *   Element that was clicked to open the popups.   *   Element that was clicked to open a new popup.
1067   * @param options   * @param options
1068   *   Hash of options controlling how the popups interacts with the underlying page.   *   Hash of options controlling how the popups interacts with the underlying page.
1069     * @param layer
1070     *   Popup with form to save, or null if form is on original page.
1071   */   */
1072  Popups.savePage = function(element, options, parent) {  Popups.saveFormOnLayer = function(element, options, layer) {
1073    var target = Drupal.settings.popups.defaultTargetSelector;    var $context = Popups.getLayerContext(layer);
1074    var $form = $('form', target);    var $form = $context.find('form');
1075    var ajaxOptions = {    var ajaxOptions = {
1076      dataType: 'json',      dataType: 'json',
1077      beforeSubmit: Popups.beforeSubmit,      beforeSubmit: Popups.beforeSubmit,
1078      beforeSend: Popups.beforeSend,      beforeSend: Popups.beforeSend,
1079      success: function(response, status) {      success: function(response, status) {
1080        // Sync up the current page contents with the submit.        // Sync up the current page contents with the submit.
1081        var $c = $(target).html(response.content); // Inject the new content into the page.        var $c = $context.html(response.content); // Inject the new content into the page.
1082        Drupal.attachBehaviors($c);        Drupal.attachBehaviors($c);
1083        // The form has been saved, the page reloaded, now safe to show the link in a popup.        // The form has been saved, the page reloaded, now safe to show the triggering link in a popup.
1084        Popups.openPath(element, options, parent);        Popups.openPath(element, options, layer);
1085      }      }
1086    };    };
1087    $form.ajaxSubmit(ajaxOptions); // Submit the form.    $form.ajaxSubmit(ajaxOptions); // Submit the form.
# Line 1075  Popups.savePage = function(element, opti Line 1092  Popups.savePage = function(element, opti
1092   *   due to mismatch between the theme and the theme's popup setting.   *   due to mismatch between the theme and the theme's popup setting.
1093   */   */
1094  Popups.testContentSelector = function() {  Popups.testContentSelector = function() {
1095    var target = Drupal.settings.popups.defaultTargetSelector;    var target = Popups.originalSettings.popups.defaultTargetSelector;
1096    var hits = $(target).length;    var hits = $(target).length;
1097    if (hits !== 1) { // 1 is the corrent answer.    if (hits !== 1) { // 1 is the corrent answer.
1098      var msg = Drupal.t('The popup content area for this theme is misconfigured.') + '\n';      var msg = Drupal.t('The popup content area for this theme is misconfigured.') + '\n';
# Line 1097  Popups.testContentSelector = function() Line 1114  Popups.testContentSelector = function()
1114    
1115  Drupal.theme.prototype.popupLoading = function() {  Drupal.theme.prototype.popupLoading = function() {
1116    var loading = '<div id="popups-loading">';    var loading = '<div id="popups-loading">';
1117    loading += '<img src="'+ Drupal.settings.basePath + Drupal.settings.popups.modulePath + '/ajax-loader.gif" />';    loading += '<img src="'+ Drupal.settings.basePath + Popups.originalSettings.popups.modulePath + '/ajax-loader.gif" />';
1118    loading += '</div>';    loading += '</div>';
1119    return loading;    return loading;
1120  };  };

Legend:
Removed from v.1.9.8.11  
changed lines
  Added in v.1.9.8.12

  ViewVC Help
Powered by ViewVC 1.1.2