|
1 /** |
|
2 * @file |
|
3 * Attaches the behaviors for the Overlay child pages. |
|
4 */ |
|
5 |
|
6 (function ($) { |
|
7 |
|
8 /** |
|
9 * Attach the child dialog behavior to new content. |
|
10 */ |
|
11 Drupal.behaviors.overlayChild = { |
|
12 attach: function (context, settings) { |
|
13 // Make sure this behavior is not processed more than once. |
|
14 if (this.processed) { |
|
15 return; |
|
16 } |
|
17 this.processed = true; |
|
18 |
|
19 // If we cannot reach the parent window, break out of the overlay. |
|
20 if (!parent.Drupal || !parent.Drupal.overlay) { |
|
21 window.location = window.location.href.replace(/([?&]?)render=overlay&?/g, '$1').replace(/\?$/, ''); |
|
22 } |
|
23 |
|
24 var settings = settings.overlayChild || {}; |
|
25 |
|
26 // If the entire parent window should be refreshed when the overlay is |
|
27 // closed, pass that information to the parent window. |
|
28 if (settings.refreshPage) { |
|
29 parent.Drupal.overlay.refreshPage = true; |
|
30 } |
|
31 |
|
32 // If a form has been submitted successfully, then the server side script |
|
33 // may have decided to tell the parent window to close the popup dialog. |
|
34 if (settings.closeOverlay) { |
|
35 parent.Drupal.overlay.bindChild(window, true); |
|
36 // Use setTimeout to close the child window from a separate thread, |
|
37 // because the current one is busy processing Drupal behaviors. |
|
38 setTimeout(function () { |
|
39 if (typeof settings.redirect == 'string') { |
|
40 parent.Drupal.overlay.redirect(settings.redirect); |
|
41 } |
|
42 else { |
|
43 parent.Drupal.overlay.close(); |
|
44 } |
|
45 }, 1); |
|
46 return; |
|
47 } |
|
48 |
|
49 // If one of the regions displaying outside the overlay needs to be |
|
50 // reloaded immediately, let the parent window know. |
|
51 if (settings.refreshRegions) { |
|
52 parent.Drupal.overlay.refreshRegions(settings.refreshRegions); |
|
53 } |
|
54 |
|
55 // Ok, now we can tell the parent window we're ready. |
|
56 parent.Drupal.overlay.bindChild(window); |
|
57 |
|
58 // IE8 crashes on certain pages if this isn't called; reason unknown. |
|
59 window.scrollTo(window.scrollX, window.scrollY); |
|
60 |
|
61 // Attach child related behaviors to the iframe document. |
|
62 Drupal.overlayChild.attachBehaviors(context, settings); |
|
63 |
|
64 // There are two links within the message that informs people about the |
|
65 // overlay and how to disable it. Make sure both links are visible when |
|
66 // either one has focus and add a class to the wrapper for styling purposes. |
|
67 $('#overlay-disable-message', context) |
|
68 .focusin(function () { |
|
69 $(this).addClass('overlay-disable-message-focused'); |
|
70 $('a.element-focusable', this).removeClass('element-invisible'); |
|
71 }) |
|
72 .focusout(function () { |
|
73 $(this).removeClass('overlay-disable-message-focused'); |
|
74 $('a.element-focusable', this).addClass('element-invisible'); |
|
75 }); |
|
76 } |
|
77 }; |
|
78 |
|
79 /** |
|
80 * Overlay object for child windows. |
|
81 */ |
|
82 Drupal.overlayChild = Drupal.overlayChild || { |
|
83 behaviors: {} |
|
84 }; |
|
85 |
|
86 Drupal.overlayChild.prototype = {}; |
|
87 |
|
88 /** |
|
89 * Attach child related behaviors to the iframe document. |
|
90 */ |
|
91 Drupal.overlayChild.attachBehaviors = function (context, settings) { |
|
92 $.each(this.behaviors, function () { |
|
93 this(context, settings); |
|
94 }); |
|
95 }; |
|
96 |
|
97 /** |
|
98 * Capture and handle clicks. |
|
99 * |
|
100 * Instead of binding a click event handler to every link we bind one to the |
|
101 * document and handle events that bubble up. This also allows other scripts |
|
102 * to bind their own handlers to links and also to prevent overlay's handling. |
|
103 */ |
|
104 Drupal.overlayChild.behaviors.addClickHandler = function (context, settings) { |
|
105 $(document).bind('click.drupal-overlay mouseup.drupal-overlay', $.proxy(parent.Drupal.overlay, 'eventhandlerOverrideLink')); |
|
106 }; |
|
107 |
|
108 /** |
|
109 * Modify forms depending on their relation to the overlay. |
|
110 * |
|
111 * By default, forms are assumed to keep the flow in the overlay. Thus their |
|
112 * action attribute get a ?render=overlay suffix. |
|
113 */ |
|
114 Drupal.overlayChild.behaviors.parseForms = function (context, settings) { |
|
115 $('form', context).once('overlay', function () { |
|
116 // Obtain the action attribute of the form. |
|
117 var action = $(this).attr('action'); |
|
118 // Keep internal forms in the overlay. |
|
119 if (action == undefined || (action.indexOf('http') != 0 && action.indexOf('https') != 0)) { |
|
120 action += (action.indexOf('?') > -1 ? '&' : '?') + 'render=overlay'; |
|
121 $(this).attr('action', action); |
|
122 } |
|
123 // Submit external forms into a new window. |
|
124 else { |
|
125 $(this).attr('target', '_new'); |
|
126 } |
|
127 }); |
|
128 }; |
|
129 |
|
130 /** |
|
131 * Replace the overlay title with a message while loading another page. |
|
132 */ |
|
133 Drupal.overlayChild.behaviors.loading = function (context, settings) { |
|
134 var $title; |
|
135 var text = Drupal.t('Loading'); |
|
136 var dots = ''; |
|
137 |
|
138 $(document).bind('drupalOverlayBeforeLoad.drupal-overlay.drupal-overlay-child-loading', function () { |
|
139 $title = $('#overlay-title').text(text); |
|
140 var id = setInterval(function () { |
|
141 dots = (dots.length > 10) ? '' : dots + '.'; |
|
142 $title.text(text + dots); |
|
143 }, 500); |
|
144 }); |
|
145 }; |
|
146 |
|
147 /** |
|
148 * Switch active tab immediately. |
|
149 */ |
|
150 Drupal.overlayChild.behaviors.tabs = function (context, settings) { |
|
151 var $tabsLinks = $('#overlay-tabs > li > a'); |
|
152 |
|
153 $('#overlay-tabs > li > a').bind('click.drupal-overlay', function () { |
|
154 var active_tab = Drupal.t('(active tab)'); |
|
155 $tabsLinks.parent().siblings().removeClass('active').find('element-invisible:contains(' + active_tab + ')').appendTo(this); |
|
156 $(this).parent().addClass('active'); |
|
157 }); |
|
158 }; |
|
159 |
|
160 /** |
|
161 * If the shortcut add/delete button exists, move it to the overlay titlebar. |
|
162 */ |
|
163 Drupal.overlayChild.behaviors.shortcutAddLink = function (context, settings) { |
|
164 // Remove any existing shortcut button markup from the titlebar. |
|
165 $('#overlay-titlebar').find('.add-or-remove-shortcuts').remove(); |
|
166 // If the shortcut add/delete button exists, move it to the titlebar. |
|
167 var $addToShortcuts = $('.add-or-remove-shortcuts'); |
|
168 if ($addToShortcuts.length) { |
|
169 $addToShortcuts.insertAfter('#overlay-title'); |
|
170 } |
|
171 |
|
172 $(document).bind('drupalOverlayBeforeLoad.drupal-overlay.drupal-overlay-child-loading', function () { |
|
173 $('#overlay-titlebar').find('.add-or-remove-shortcuts').remove(); |
|
174 }); |
|
175 }; |
|
176 |
|
177 /** |
|
178 * Use displacement from parent window. |
|
179 */ |
|
180 Drupal.overlayChild.behaviors.alterTableHeaderOffset = function (context, settings) { |
|
181 if (Drupal.settings.tableHeaderOffset) { |
|
182 Drupal.overlayChild.prevTableHeaderOffset = Drupal.settings.tableHeaderOffset; |
|
183 } |
|
184 Drupal.settings.tableHeaderOffset = 'Drupal.overlayChild.tableHeaderOffset'; |
|
185 }; |
|
186 |
|
187 /** |
|
188 * Callback for Drupal.settings.tableHeaderOffset. |
|
189 */ |
|
190 Drupal.overlayChild.tableHeaderOffset = function () { |
|
191 var topOffset = Drupal.overlayChild.prevTableHeaderOffset ? eval(Drupal.overlayChild.prevTableHeaderOffset + '()') : 0; |
|
192 |
|
193 return topOffset + parseInt($(document.body).css('marginTop')); |
|
194 }; |
|
195 |
|
196 })(jQuery); |