1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,801 @@ |
1 |
+/** |
|
2 |
+ * Copyright (C) 2021 Double Bastion LLC |
|
3 |
+ * |
|
4 |
+ * This file is part of Roundpin, which is licensed under the |
|
5 |
+ * GNU Affero General Public License Version 3.0. The license terms |
|
6 |
+ * are detailed in the "LICENSE.txt" file located in the root directory. |
|
7 |
+ * |
|
8 |
+ * This is a modified version of the original file "jquery.jeegoopopup.1.0.0.js", |
|
9 |
+ * first modified in 2021. The copyright notice for the original |
|
10 |
+ * content follows: |
|
11 |
+ |
|
12 |
+/*! |
|
13 |
+ * Copyright (c) 2009 - 2013 Erik van den Berg (http://www.tweego.nl/jeegoopopup) |
|
14 |
+ * Licensed under MIT (http://www.opensource.org/licenses/mit-license.php) license. |
|
15 |
+ * Consider linking back to author's homepage: http://www.tweego.nl |
|
16 |
+ * |
|
17 |
+ * Version: 1.0.0 |
|
18 |
+ * Requires jQuery 1.4.2+ |
|
19 |
+ */ |
|
20 |
+(function ($) { |
|
21 |
+ |
|
22 |
+ var _popups; |
|
23 |
+ var _init; |
|
24 |
+ var _popupsLeft; |
|
25 |
+ var _fadeIn; |
|
26 |
+ |
|
27 |
+ // Drag & drop & resize vars |
|
28 |
+ var _dragX; |
|
29 |
+ var _dragY; |
|
30 |
+ var _mouseX; |
|
31 |
+ var _mouseY; |
|
32 |
+ var _width; |
|
33 |
+ var _height; |
|
34 |
+ |
|
35 |
+ var _initialize = function () { |
|
36 |
+ if (!_init) |
|
37 |
+ { |
|
38 |
+ |
|
39 |
+ // Add popup container. |
|
40 |
+ $('body').append( |
|
41 |
+ '<div id="jg_popup_overlay"></div>' + |
|
42 |
+ '<div id="jg_popup_inner">' + |
|
43 |
+ '<table id="jg_popup_table" cellpadding="0" cellspacing="0" border="0">' + |
|
44 |
+ '<tr>' + |
|
45 |
+ '<td id="jg_popup_tl"></td>' + |
|
46 |
+ '<td id="jg_popup_title"></td>' + |
|
47 |
+ '<td id="jg_popup_tr"><div id="jg_popup_close"></div></td>' + |
|
48 |
+ '</tr>' + |
|
49 |
+ '<tr>' + |
|
50 |
+ '<td id="jg_popup_l"></td>' + |
|
51 |
+ '<td><div id="jg_popup_content"></div><div id="jg_popup_loader"><div></div></div></td>' + |
|
52 |
+ '<td id="jg_popup_r"></td>' + |
|
53 |
+ '</tr>' + |
|
54 |
+ '<tr>' + |
|
55 |
+ '<td id="jg_popup_bl"></td>' + |
|
56 |
+ '<td id="jg_popup_b"></td>' + |
|
57 |
+ '<td id="jg_popup_br"></td>' + |
|
58 |
+ '</tr>' + |
|
59 |
+ '</table>' + |
|
60 |
+ '<div id="jg_popup_garbage" style="display:none"></div>' + |
|
61 |
+ '</div>' |
|
62 |
+ ); |
|
63 |
+ |
|
64 |
+ // Set defaults. |
|
65 |
+ _fadeIn = 300; |
|
66 |
+ |
|
67 |
+ // Init popup list. |
|
68 |
+ _popups = []; |
|
69 |
+ |
|
70 |
+ _init = true; |
|
71 |
+ } |
|
72 |
+ }; |
|
73 |
+ |
|
74 |
+ var _position = function (close) { |
|
75 |
+ if(_popups.length > 0) |
|
76 |
+ { |
|
77 |
+ var popup = _popups[_popups.length - 1]; |
|
78 |
+ var css = { |
|
79 |
+ position: popup.fixed ? 'fixed' : 'absolute' |
|
80 |
+ }; |
|
81 |
+ |
|
82 |
+ if(close) |
|
83 |
+ { |
|
84 |
+ $('#jg_popup_inner').css(popup.css); |
|
85 |
+ } |
|
86 |
+ else |
|
87 |
+ { |
|
88 |
+ var $window = $(window); |
|
89 |
+ var scrollLeft = $window.scrollLeft(); |
|
90 |
+ var scrollTop = $window.scrollTop(); |
|
91 |
+ |
|
92 |
+ // Determine x-position popup. |
|
93 |
+ if(popup.left != undefined) |
|
94 |
+ { |
|
95 |
+ css.right = 'auto'; |
|
96 |
+ css.left = popup.fixed ? popup.left + 'px' : scrollLeft + popup.left + 'px'; |
|
97 |
+ } |
|
98 |
+ else if(popup.right != undefined) |
|
99 |
+ { |
|
100 |
+ css.left = 'auto'; |
|
101 |
+ css.right = popup.fixed ? popup.right + 'px' : popup.right - scrollLeft + 'px'; |
|
102 |
+ } |
|
103 |
+ else if(popup.center) |
|
104 |
+ { |
|
105 |
+ css.right = 'auto'; |
|
106 |
+ var left = ($window.width() - $('#jg_popup_inner').outerWidth()) / 2; |
|
107 |
+ css.left = popup.fixed ? left + 'px' : scrollLeft + left + 'px'; |
|
108 |
+ } |
|
109 |
+ else |
|
110 |
+ { |
|
111 |
+ css.right = 'auto'; |
|
112 |
+ css.left = popup.fixed ? '0px' : scrollLeft + 'px'; |
|
113 |
+ } |
|
114 |
+ |
|
115 |
+ // Determine y-position popup. |
|
116 |
+ if(popup.top != undefined) |
|
117 |
+ { |
|
118 |
+ css.bottom = 'auto'; |
|
119 |
+ css.top = popup.fixed ? popup.top + 'px' : scrollTop + popup.top + 'px'; |
|
120 |
+ } |
|
121 |
+ else if(popup.bottom != undefined) |
|
122 |
+ { |
|
123 |
+ css.top = 'auto'; |
|
124 |
+ css.bottom = popup.fixed ? popup.bottom + 'px' : popup.bottom - scrollTop + 'px'; |
|
125 |
+ } |
|
126 |
+ else if(popup.center) |
|
127 |
+ { |
|
128 |
+ css.bottom = 'auto'; |
|
129 |
+ var top = ($window.height() - $('#jg_popup_inner').outerHeight()) / 2; |
|
130 |
+ css.top = popup.fixed ? top + 'px' : scrollTop + top + 'px'; |
|
131 |
+ } |
|
132 |
+ else |
|
133 |
+ { |
|
134 |
+ css.bottom = 'auto'; |
|
135 |
+ css.top = popup.fixed ? '0px' : scrollTop + 'px'; |
|
136 |
+ } |
|
137 |
+ |
|
138 |
+ $('#jg_popup_inner').css(css); |
|
139 |
+ popup.css = css; |
|
140 |
+ } |
|
141 |
+ } |
|
142 |
+ }; |
|
143 |
+ |
|
144 |
+ var _close = function (args) { |
|
145 |
+ |
|
146 |
+ if (_popups && _popups.length > 0) |
|
147 |
+ { |
|
148 |
+ var index = _popups.length - 1; |
|
149 |
+ |
|
150 |
+ var onClose = _popups[index].onClose; |
|
151 |
+ |
|
152 |
+ // Remove popup's data. |
|
153 |
+ _popups.pop(); |
|
154 |
+ |
|
155 |
+ // Move popup's content to garbage. |
|
156 |
+ var content = $('#jg_popup_content > div:eq(' + index + ')'); |
|
157 |
+ |
|
158 |
+ // Unload all iframes inside content. |
|
159 |
+ try |
|
160 |
+ { |
|
161 |
+ var iframes = content.find('iframe'); |
|
162 |
+ for(var i = 0; i < iframes.length; i++) |
|
163 |
+ { |
|
164 |
+ $(iframes[i]).attr('src', 'about:blank'); |
|
165 |
+ } |
|
166 |
+ }catch(err){} |
|
167 |
+ |
|
168 |
+ // ie9 hack. |
|
169 |
+ setTimeout(function(){ |
|
170 |
+ content.appendTo('#jg_popup_garbage'); |
|
171 |
+ }, 0); |
|
172 |
+ |
|
173 |
+ // Unbind handlers and reset overflow if last popup. |
|
174 |
+ if (index == 0) |
|
175 |
+ { |
|
176 |
+ $('#jg_popup_close').unbind('click.jg_popup'); |
|
177 |
+ $('#jg_popup_title').unbind('mousedown.jg_popup'); |
|
178 |
+ $('.jg_popup_scroller').removeClass('jg_popup_scroller').css('overflow', 'auto'); |
|
179 |
+ } |
|
180 |
+ |
|
181 |
+ _refresh(true); |
|
182 |
+ |
|
183 |
+ // Invoke popup's onClose callback if present. |
|
184 |
+ if (onClose) |
|
185 |
+ { |
|
186 |
+ if (args) onClose.apply(window, args); |
|
187 |
+ else onClose(); |
|
188 |
+ } |
|
189 |
+ } |
|
190 |
+ }; |
|
191 |
+ |
|
192 |
+ var _refreshWidth = function () { |
|
193 |
+ var content = $('#jg_popup_content'); |
|
194 |
+ var width = _popups[_popups.length - 1].width; |
|
195 |
+ content.css('width', width == 'auto' ? 'auto' : width + 'px'); |
|
196 |
+ }; |
|
197 |
+ |
|
198 |
+ var _refreshHeight = function () { |
|
199 |
+ var content = $('#jg_popup_content'); |
|
200 |
+ var height = _popups[_popups.length - 1].height; |
|
201 |
+ if (_popups[_popups.length - 1].url) |
|
202 |
+ { |
|
203 |
+ if (height != 'auto') |
|
204 |
+ { |
|
205 |
+ $('#jg_popup_content div:eq(' + (_popups.length - 1) + ') > iframe.jg_popup_iframe').attr('height', height); |
|
206 |
+ // Vertically center loader. |
|
207 |
+ var marginTop = (height - $('#jg_popup_loader div').height()) / 2; |
|
208 |
+ $('#jg_popup_loader').css('top', (marginTop + _popups[_popups.length - 1].loaderVerticalOffset) + 'px'); |
|
209 |
+ } |
|
210 |
+ else |
|
211 |
+ $('#jg_popup_content div:eq(' + (_popups.length - 1) + ') > iframe.jg_popup_iframe').removeAttr('height'); |
|
212 |
+ $('#jg_popup_content').height('auto'); |
|
213 |
+ } |
|
214 |
+ else $('#jg_popup_content').height(height); |
|
215 |
+ }; |
|
216 |
+ |
|
217 |
+ var _refreshTitle = function () { |
|
218 |
+ var title = _popups[_popups.length - 1].title; |
|
219 |
+ var maxLength = _popups[_popups.length - 1].maxTitleLength |
|
220 |
+ if (maxLength && title && title.length > maxLength) |
|
221 |
+ $('#jg_popup_title').html(title.substring(0, maxLength) + '...'); |
|
222 |
+ else $('#jg_popup_title').html(title || ''); |
|
223 |
+ }; |
|
224 |
+ |
|
225 |
+ var _refreshParentScrolling = function() { |
|
226 |
+ var parentScrolling = _popups[_popups.length - 1].parentScrolling; |
|
227 |
+ if(parentScrolling) |
|
228 |
+ { |
|
229 |
+ $('.jg_popup_scroller').removeClass('jg_popup_scroller').css('overflow', 'auto'); |
|
230 |
+ } |
|
231 |
+ else // Disable scrolling on parent document. |
|
232 |
+ { |
|
233 |
+ var scroller = $('body'); |
|
234 |
+ if(scroller.css('overflow') == 'hidden') |
|
235 |
+ { |
|
236 |
+ scroller = scroller.find('*').filter(function(){ |
|
237 |
+ return $(this).css('overflow') == 'auto'; |
|
238 |
+ }).first(); |
|
239 |
+ } |
|
240 |
+ |
|
241 |
+ scroller.addClass('jg_popup_scroller').css('overflow', 'hidden'); |
|
242 |
+ } |
|
243 |
+ }; |
|
244 |
+ |
|
245 |
+ var _refreshSkinClass = function(){ |
|
246 |
+ $('#jg_popup_table').removeClass().addClass(_popups[_popups.length - 1].skinClass); |
|
247 |
+ }; |
|
248 |
+ |
|
249 |
+ var _refreshContentClass = function(){ |
|
250 |
+ $('#jg_popup_content').removeClass().addClass(_popups[_popups.length - 1].contentClass); |
|
251 |
+ }; |
|
252 |
+ |
|
253 |
+ var _refreshInnerClass = function(){ |
|
254 |
+ $('#jg_popup_inner').removeClass().addClass(_popups[_popups.length - 1].innerClass); |
|
255 |
+ }; |
|
256 |
+ |
|
257 |
+ var _refreshDraggable = function(){ |
|
258 |
+ $('#jg_popup_title')[_popups[_popups.length - 1].draggable ? 'addClass' : 'removeClass']('jg_popup_draggable'); |
|
259 |
+ }; |
|
260 |
+ |
|
261 |
+ var _refreshResizable = function(){ |
|
262 |
+ $('#jg_popup_br')[_popups[_popups.length - 1].resizable ? 'addClass' : 'removeClass']('jg_popup_resizable'); |
|
263 |
+ }; |
|
264 |
+ |
|
265 |
+ var _refreshOverlay = function(){ |
|
266 |
+ $('#jg_popup_overlay').css('display', _popups[_popups.length - 1].overlay ? 'block' : 'none'); |
|
267 |
+ }; |
|
268 |
+ |
|
269 |
+ var _refreshOverlayColor = function(){ |
|
270 |
+ $('#jg_popup_overlay').css('backgroundColor', _popups[_popups.length - 1].overlayColor); |
|
271 |
+ }; |
|
272 |
+ |
|
273 |
+ var _refreshOpacity = function(){ |
|
274 |
+ $('#jg_popup_overlay').css('opacity', _popups[_popups.length - 1].opacity / 100); |
|
275 |
+ }; |
|
276 |
+ |
|
277 |
+ var _refresh = function (close) { |
|
278 |
+ if (_popups.length <= 0) // No more popups, hide all. |
|
279 |
+ { |
|
280 |
+ _popupsLeft = false; |
|
281 |
+ $('#jg_popup_overlay, #jg_popup_inner').hide(); |
|
282 |
+ } |
|
283 |
+ else |
|
284 |
+ { |
|
285 |
+ var currentContent = $('#jg_popup_content > div:eq(' + (_popups.length - 1) + ')'); |
|
286 |
+ |
|
287 |
+ // Initially hide popup window and show overlay on first popup. |
|
288 |
+ if (!_popupsLeft) |
|
289 |
+ { |
|
290 |
+ $('#jg_popup_inner').css('visibility', 'hidden'); |
|
291 |
+ } |
|
292 |
+ else // Hide previous popup contents, show this one. |
|
293 |
+ { |
|
294 |
+ $('#jg_popup_content > div:lt(' + (_popups.length - 1) + ')').hide(); |
|
295 |
+ currentContent.show(); |
|
296 |
+ } |
|
297 |
+ |
|
298 |
+ _refreshTitle(); |
|
299 |
+ _refreshWidth(); |
|
300 |
+ _refreshHeight(); |
|
301 |
+ _refreshParentScrolling(); |
|
302 |
+ _refreshSkinClass(); |
|
303 |
+ _refreshContentClass(); |
|
304 |
+ _refreshInnerClass(); |
|
305 |
+ _refreshDraggable(); |
|
306 |
+ _refreshResizable(); |
|
307 |
+ _refreshOverlay(); |
|
308 |
+ _refreshOverlayColor(); |
|
309 |
+ _refreshOpacity(); |
|
310 |
+ |
|
311 |
+ // If the popup content consists of an image and with and/or height are auto and the image should be centered, wait for the image to load before positioning and showing the image. |
|
312 |
+ if( |
|
313 |
+ (_popups[_popups.length - 1].width == 'auto' || _popups[_popups.length - 1].height == 'auto') && |
|
314 |
+ _popups[_popups.length - 1].center && |
|
315 |
+ currentContent.find('img').length > 0 && |
|
316 |
+ document.createElement('img').complete != undefined |
|
317 |
+ ){ |
|
318 |
+ var image = currentContent.find('img:eq(0)').get()[0]; |
|
319 |
+ // Start polling the image for completion. |
|
320 |
+ var poller = setInterval(function () { |
|
321 |
+ if (image.complete) |
|
322 |
+ { |
|
323 |
+ // Image is loaded, stop polling. |
|
324 |
+ clearInterval(poller); |
|
325 |
+ if(_popups.length > 0) |
|
326 |
+ { |
|
327 |
+ _position(close); |
|
328 |
+ $('#jg_popup_inner').css({ |
|
329 |
+ visibility: 'visible', |
|
330 |
+ display: 'none' |
|
331 |
+ }); |
|
332 |
+ $('#jg_popup_inner').fadeIn(_fadeIn, function () { |
|
333 |
+ if (_popups.length > 0 && _popups[_popups.length - 1].onOpen) |
|
334 |
+ { |
|
335 |
+ _popups[_popups.length - 1].onOpen(); |
|
336 |
+ } |
|
337 |
+ }); |
|
338 |
+ } |
|
339 |
+ } |
|
340 |
+ }, 50); |
|
341 |
+ } |
|
342 |
+ else |
|
343 |
+ { |
|
344 |
+ _position(close); |
|
345 |
+ |
|
346 |
+ // Fade-in popup if it is the first popup. |
|
347 |
+ if (!_popupsLeft) |
|
348 |
+ { |
|
349 |
+ $('#jg_popup_inner').css({ |
|
350 |
+ visibility: 'visible', |
|
351 |
+ display: 'none' |
|
352 |
+ }); |
|
353 |
+ |
|
354 |
+ $('#jg_popup_inner').fadeIn(_fadeIn, function () { |
|
355 |
+ if (_popups.length > 0 && _popups[_popups.length - 1].onOpen) |
|
356 |
+ _popups[_popups.length - 1].onOpen(); |
|
357 |
+ }); |
|
358 |
+ } |
|
359 |
+ else if (_popups.length > 0 && _popups[_popups.length - 1].onOpen) |
|
360 |
+ { |
|
361 |
+ _popups[_popups.length - 1].onOpen(); |
|
362 |
+ } |
|
363 |
+ } |
|
364 |
+ |
|
365 |
+ _popupsLeft = true; |
|
366 |
+ } |
|
367 |
+ }; |
|
368 |
+ |
|
369 |
+ var _drag = function (e) { |
|
370 |
+ |
|
371 |
+ var popup = _popups[_popups.length - 1]; |
|
372 |
+ if (!popup.draggable) return; |
|
373 |
+ |
|
374 |
+ _mouseX = e.pageX; |
|
375 |
+ _mouseY = e.pageY; |
|
376 |
+ var offset = $('#jg_popup_inner').offset(); |
|
377 |
+ var fixed = $('#jg_popup_inner').css('position') == 'fixed'; |
|
378 |
+ var $window = $(window); |
|
379 |
+ _dragX = offset.left - (fixed ? $window.scrollLeft() : 0); |
|
380 |
+ _dragY = offset.top - (fixed ? $window.scrollTop() : 0); |
|
381 |
+ |
|
382 |
+ // Invoke dragstart callback. |
|
383 |
+ if (popup.onDragStart) |
|
384 |
+ popup.onDragStart(popup); |
|
385 |
+ |
|
386 |
+ // Overlay content with transparant overlay. |
|
387 |
+ $('<div id="jg_drag_aid"></div>').css({ |
|
388 |
+ opacity: 0, |
|
389 |
+ background: '#000', |
|
390 |
+ width: '100%', |
|
391 |
+ height: '100%', |
|
392 |
+ position: 'fixed', |
|
393 |
+ left: 0, |
|
394 |
+ top: 0, |
|
395 |
+ cursor: 'move' |
|
396 |
+ }).appendTo('#jg_popup_content'); |
|
397 |
+ |
|
398 |
+ $(document).unbind('mousemove.jg_popup_drag').bind('mousemove.jg_popup_drag', function (e) { |
|
399 |
+ var left = (_dragX + (e.pageX - _mouseX)); |
|
400 |
+ var top = (_dragY + (e.pageY - _mouseY)); |
|
401 |
+ var css = { |
|
402 |
+ left: left + 'px', |
|
403 |
+ top: top + 'px', |
|
404 |
+ right: 'auto', |
|
405 |
+ bottom: 'auto' |
|
406 |
+ }; |
|
407 |
+ $('#jg_popup_inner').css(css); |
|
408 |
+ // Save new position with popup. |
|
409 |
+ popup.left = left; |
|
410 |
+ popup.top = top; |
|
411 |
+ popup.css = css; |
|
412 |
+ |
|
413 |
+ if (popup.onDrag) |
|
414 |
+ popup.onDrag(popup); |
|
415 |
+ |
|
416 |
+ }).unbind('mouseup.jg_popup_drag').bind('mouseup.jg_popup_drag', function (e) { |
|
417 |
+ // Remove transparant iframe overlay. |
|
418 |
+ $('#jg_drag_aid').remove(); |
|
419 |
+ // Unbind drag handler. |
|
420 |
+ $(this).unbind('.jg_popup_drag'); |
|
421 |
+ // Invoke dragend callback. |
|
422 |
+ if (popup.onDragEnd) |
|
423 |
+ popup.onDragEnd(popup); |
|
424 |
+ }); |
|
425 |
+ }; |
|
426 |
+ |
|
427 |
+ // Resize |
|
428 |
+ var _resize = function (e) { |
|
429 |
+ |
|
430 |
+ var popup = _popups[_popups.length - 1]; |
|
431 |
+ if (!popup.resizable) return; |
|
432 |
+ |
|
433 |
+ _mouseX = e.pageX; |
|
434 |
+ _mouseY = e.pageY; |
|
435 |
+ _width = popup.width; |
|
436 |
+ if(_width == 'auto')_width = $('#jg_popup_content').width(); |
|
437 |
+ _height = _popups[_popups.length - 1].height; |
|
438 |
+ if(_height == 'auto')_height = $('#jg_popup_content').height(); |
|
439 |
+ |
|
440 |
+ // Invoke resizeStart callback. |
|
441 |
+ if (popup.onResizeStart) |
|
442 |
+ popup.onResizeStart(popup); |
|
443 |
+ |
|
444 |
+ // Overlay iframe with transparant overlay. |
|
445 |
+ $('<div id="jg_drag_aid"></div>').css({ |
|
446 |
+ opacity: 0, |
|
447 |
+ background: '#000', |
|
448 |
+ width: '100%', |
|
449 |
+ height: '100%', |
|
450 |
+ position: 'fixed', |
|
451 |
+ left: 0, |
|
452 |
+ top: 0, |
|
453 |
+ cursor: 'move' |
|
454 |
+ }).appendTo('#jg_popup_content'); |
|
455 |
+ |
|
456 |
+ $(document).unbind('mousemove.jg_popup_resize').bind('mousemove.jg_popup_resize', function (e) { |
|
457 |
+ |
|
458 |
+ _popups[_popups.length - 1].width = _width + (e.pageX - _mouseX); |
|
459 |
+ _popups[_popups.length - 1].height = _height + (e.pageY - _mouseY); |
|
460 |
+ |
|
461 |
+ _refreshWidth(); |
|
462 |
+ _refreshHeight(); |
|
463 |
+ |
|
464 |
+ if (popup.onResize) |
|
465 |
+ popup.onResize(popup); |
|
466 |
+ |
|
467 |
+ }).unbind('mouseup.jg_popup_resize').bind('mouseup.jg_popup_resize', function (e) { |
|
468 |
+ |
|
469 |
+ // Remove transparant iframe overlay. |
|
470 |
+ $('#jg_drag_aid').remove(); |
|
471 |
+ |
|
472 |
+ // Unbind resize handler. |
|
473 |
+ $(this).unbind('.jg_popup_resize'); |
|
474 |
+ |
|
475 |
+ // Invoke resizeEnd callback. |
|
476 |
+ if (popup.onResizeEnd) |
|
477 |
+ popup.onResizeEnd(popup); |
|
478 |
+ }); |
|
479 |
+ }; |
|
480 |
+ |
|
481 |
+ var _getValue = function(value) |
|
482 |
+ { |
|
483 |
+ return (_popups && _popups.length > 0) ? _popups[_popups.length - 1][value] : null; |
|
484 |
+ } |
|
485 |
+ |
|
486 |
+ $.jeegoopopup = { |
|
487 |
+ open: function (options) { |
|
488 |
+ |
|
489 |
+ _initialize(); |
|
490 |
+ |
|
491 |
+ // Clear garbage. |
|
492 |
+ try { $('#jg_popup_garbage').empty(); } catch (ex) { } |
|
493 |
+ |
|
494 |
+ // Add new popup. |
|
495 |
+ // Default undefined: |
|
496 |
+ // ============================= |
|
497 |
+ // title, string |
|
498 |
+ // maxTitleLength, int |
|
499 |
+ // fadeIn, int |
|
500 |
+ // url, string |
|
501 |
+ // html, string |
|
502 |
+ // left, int |
|
503 |
+ // top, int |
|
504 |
+ // right, int |
|
505 |
+ // bottom, int |
|
506 |
+ // onOpen, function |
|
507 |
+ // onClose, function |
|
508 |
+ // onDragStart, function |
|
509 |
+ // onDrag, function |
|
510 |
+ // onDragEnd, function |
|
511 |
+ // onResizeStart, function |
|
512 |
+ // onResize, function |
|
513 |
+ // onResizeEnd, function |
|
514 |
+ var popupData = $.extend({ |
|
515 |
+ width: 'auto', |
|
516 |
+ height: 'auto', |
|
517 |
+ scrolling: 'auto', |
|
518 |
+ skinClass: 'jg_popup_basic', |
|
519 |
+ contentClass: 'customContentStyle', |
|
520 |
+ innerClass: 'customInnerClass', |
|
521 |
+ fixed: true, |
|
522 |
+ center: true, |
|
523 |
+ overlay: true, |
|
524 |
+ overlayColor: '#000', |
|
525 |
+ opacity: 50, |
|
526 |
+ loaderVerticalOffset: 0, |
|
527 |
+ parentScrolling: true, |
|
528 |
+ draggable: true, |
|
529 |
+ resizable: true |
|
530 |
+ }, options || {}); |
|
531 |
+ |
|
532 |
+ _popups.push(popupData); |
|
533 |
+ |
|
534 |
+ // Override fadeIn if provided. |
|
535 |
+ if (options && options.fadeIn != undefined) _fadeIn = options.fadeIn; |
|
536 |
+ |
|
537 |
+ // Take-over underlying popup position if popup is not centered and no left, right, top or bottom are defined. |
|
538 |
+ if (_popups.length > 1 && !popupData.center) |
|
539 |
+ { |
|
540 |
+ var offset = $('#jg_popup_inner').offset(); |
|
541 |
+ if (popupData.top == undefined && popupData.bottom == undefined) |
|
542 |
+ { |
|
543 |
+ popupData.top = popupData.fixed ? offset.top - $(window).scrollTop() : offset.top; |
|
544 |
+ } |
|
545 |
+ |
|
546 |
+ if (popupData.left == undefined && popupData.right == undefined) |
|
547 |
+ { |
|
548 |
+ popupData.left = popupData.fixed ? offset.left - $(window).scrollLeft() : offset.left; |
|
549 |
+ } |
|
550 |
+ } |
|
551 |
+ |
|
552 |
+ // Add popup content(html or iframe). |
|
553 |
+ if (popupData.url) // iframe |
|
554 |
+ { |
|
555 |
+ // Generate random id to prevent iframe caching. |
|
556 |
+ var id = "jgpopup" + Math.random().toString().replace(/\D/, ""); |
|
557 |
+ // Show loader animation. |
|
558 |
+ $('#jg_popup_loader').css('visibility', 'visible'); |
|
559 |
+ $('#jg_popup_content').append( |
|
560 |
+ '<div><iframe id="' + id + '" class="jg_popup_iframe" onload="(function(){$(\'#jg_popup_loader\').css(\'visibility\', \'hidden\');})()" frameborder="0" scrolling="' + popupData.scrolling + '" width="100%" ' + (popupData.height == 'auto' ? '' : 'height="' + popupData.height + 'px" ') + 'src="' + popupData.url + '"></iframe></div>' |
|
561 |
+ ); |
|
562 |
+ } |
|
563 |
+ else // html |
|
564 |
+ { |
|
565 |
+ var overflow = popupData.scrolling; |
|
566 |
+ if(overflow == 'yes') overflow = 'scroll'; |
|
567 |
+ else if(overflow == 'no') overflow = 'hidden'; |
|
568 |
+ |
|
569 |
+ $('#jg_popup_content').append('<div style="width:100%;height:100%;overflow:' + overflow + '">' + (popupData.html || '') + '</div>'); |
|
570 |
+ } |
|
571 |
+ |
|
572 |
+ // Attach handlers on first popup. |
|
573 |
+ if (_popups.length == 1) |
|
574 |
+ { |
|
575 |
+ // Attach close handler to close button, wrap in function to prevent calling it with click handler argument (e). |
|
576 |
+ $('#jg_popup_close').unbind('click.jg_popup').bind('click.jg_popup', function () { |
|
577 |
+ _close(); |
|
578 |
+ }); |
|
579 |
+ |
|
580 |
+ // Bind drag handler to title section. |
|
581 |
+ $('#jg_popup_title').unbind('mousedown.jg_popup').bind('mousedown.jg_popup', _drag); |
|
582 |
+ |
|
583 |
+ // Bind resize handler to bottom right corner. |
|
584 |
+ $('#jg_popup_br').unbind('mousedown.jg_popup').bind('mousedown.jg_popup', _resize); |
|
585 |
+ } |
|
586 |
+ |
|
587 |
+ _refresh(); |
|
588 |
+ }, |
|
589 |
+ close: function () { // close topmost popup. |
|
590 |
+ _close(arguments); |
|
591 |
+ }, |
|
592 |
+ // Properties |
|
593 |
+ opacity: function (value) { |
|
594 |
+ if (value == undefined) return _getValue('opacity'); |
|
595 |
+ else if (_popups && _popups.length > 0) |
|
596 |
+ { |
|
597 |
+ _popups[_popups.length - 1].opacity = value; |
|
598 |
+ _refreshOpacity(); |
|
599 |
+ } |
|
600 |
+ return this; |
|
601 |
+ }, |
|
602 |
+ overlay: function (value) { |
|
603 |
+ if (value == undefined) return _getValue('overlay'); |
|
604 |
+ else if (_popups && _popups.length > 0) |
|
605 |
+ { |
|
606 |
+ _popups[_popups.length - 1].overlay = value; |
|
607 |
+ _refreshOverlay(); |
|
608 |
+ } |
|
609 |
+ return this; |
|
610 |
+ }, |
|
611 |
+ overlayColor: function (value) { |
|
612 |
+ if (value == undefined) return _getValue('overlayColor'); |
|
613 |
+ else if (_popups && _popups.length > 0) |
|
614 |
+ { |
|
615 |
+ _popups[_popups.length - 1].overlayColor = value; |
|
616 |
+ _refreshOverlayColor(); |
|
617 |
+ } |
|
618 |
+ return this; |
|
619 |
+ }, |
|
620 |
+ draggable: function (value) { |
|
621 |
+ if (value == undefined) return _getValue('draggable'); |
|
622 |
+ else if (_popups && _popups.length > 0) |
|
623 |
+ { |
|
624 |
+ _popups[_popups.length - 1].draggable = value; |
|
625 |
+ _refreshDraggable(); |
|
626 |
+ } |
|
627 |
+ return this; |
|
628 |
+ }, |
|
629 |
+ resizable: function (value) { |
|
630 |
+ if (value == undefined) return _getValue('resizable'); |
|
631 |
+ else if (_popups && _popups.length > 0) |
|
632 |
+ { |
|
633 |
+ _popups[_popups.length - 1].resizable = value; |
|
634 |
+ _refreshResizable(); |
|
635 |
+ } |
|
636 |
+ return this; |
|
637 |
+ }, |
|
638 |
+ fixed: function (value) { |
|
639 |
+ if (value == undefined) return _getValue('fixed'); |
|
640 |
+ else if (_popups && _popups.length > 0) |
|
641 |
+ { |
|
642 |
+ _popups[_popups.length - 1].fixed = value; |
|
643 |
+ _position(); |
|
644 |
+ } |
|
645 |
+ return this; |
|
646 |
+ }, |
|
647 |
+ height: function (value) { |
|
648 |
+ if (value == undefined) return _getValue('height'); |
|
649 |
+ else if (_popups && _popups.length > 0) |
|
650 |
+ { |
|
651 |
+ _popups[_popups.length - 1].height = value; |
|
652 |
+ _refreshHeight(); |
|
653 |
+ } |
|
654 |
+ return this; |
|
655 |
+ }, |
|
656 |
+ width: function (value) { |
|
657 |
+ if (value == undefined) return _getValue('width'); |
|
658 |
+ else if (_popups && _popups.length > 0) |
|
659 |
+ { |
|
660 |
+ _popups[_popups.length - 1].width = value; |
|
661 |
+ _refreshWidth(); |
|
662 |
+ } |
|
663 |
+ return this; |
|
664 |
+ }, |
|
665 |
+ top: function (value) { |
|
666 |
+ if (value == undefined) return _getValue('top'); |
|
667 |
+ else if (_popups && _popups.length > 0) |
|
668 |
+ { |
|
669 |
+ _popups[_popups.length - 1].top = value; |
|
670 |
+ $('#jg_popup_inner').css({ |
|
671 |
+ top: _getValue('fixed') ? value + 'px' : $(window).scrollTop() + value + 'px', |
|
672 |
+ bottom: 'auto' |
|
673 |
+ }); |
|
674 |
+ } |
|
675 |
+ return this; |
|
676 |
+ }, |
|
677 |
+ left: function (value) { |
|
678 |
+ if (value == undefined) return _getValue('left'); |
|
679 |
+ else if (_popups && _popups.length > 0) |
|
680 |
+ { |
|
681 |
+ _popups[_popups.length - 1].left = value; |
|
682 |
+ $('#jg_popup_inner').css({ |
|
683 |
+ left: _getValue('fixed') ? value + 'px' : $(window).scrollLeft() + value + 'px', |
|
684 |
+ right: 'auto' |
|
685 |
+ }); |
|
686 |
+ } |
|
687 |
+ return this; |
|
688 |
+ }, |
|
689 |
+ right: function (value) { |
|
690 |
+ if (value == undefined) return _getValue('right'); |
|
691 |
+ else if (_popups && _popups.length > 0) |
|
692 |
+ { |
|
693 |
+ _popups[_popups.length - 1].right = value; |
|
694 |
+ _popups[_popups.length - 1].left = undefined; |
|
695 |
+ $('#jg_popup_inner').css({ |
|
696 |
+ right: _getValue('fixed') ? value + 'px' : value - $(window).scrollLeft() + 'px', |
|
697 |
+ left: 'auto' |
|
698 |
+ }); |
|
699 |
+ } |
|
700 |
+ return this; |
|
701 |
+ }, |
|
702 |
+ bottom: function (value) { |
|
703 |
+ if (value == undefined) return _getValue('bottom'); |
|
704 |
+ else if (_popups && _popups.length > 0) |
|
705 |
+ { |
|
706 |
+ _popups[_popups.length - 1].bottom = value; |
|
707 |
+ _popups[_popups.length - 1].top = undefined; |
|
708 |
+ $('#jg_popup_inner').css({ |
|
709 |
+ bottom: _getValue('fixed') ? value + 'px' : value - $(window).scrollTop() + 'px', |
|
710 |
+ top: 'auto' |
|
711 |
+ }); |
|
712 |
+ } |
|
713 |
+ return this; |
|
714 |
+ }, |
|
715 |
+ title: function (value) { |
|
716 |
+ if (value == undefined) return _getValue('title'); |
|
717 |
+ else if (_popups && _popups.length > 0) |
|
718 |
+ { |
|
719 |
+ _popups[_popups.length - 1].title = value; |
|
720 |
+ _refreshTitle(value, _popups[_popups.length - 1].maxTitleLength); |
|
721 |
+ } |
|
722 |
+ return this; |
|
723 |
+ }, |
|
724 |
+ maxTitleLength: function (value) { |
|
725 |
+ if (value == undefined) return _getValue('maxTitleLength'); |
|
726 |
+ else if (_popups && _popups.length > 0) |
|
727 |
+ { |
|
728 |
+ _popups[_popups.length - 1].maxTitleLength = value; |
|
729 |
+ _refreshTitle(_popups[_popups.length - 1].title, value); |
|
730 |
+ } |
|
731 |
+ return this; |
|
732 |
+ }, |
|
733 |
+ skinClass: function (value) { |
|
734 |
+ if (value == undefined) return _getValue('skinClass'); |
|
735 |
+ else if (_popups && _popups.length > 0) |
|
736 |
+ { |
|
737 |
+ _popups[_popups.length - 1].skinClass = value; |
|
738 |
+ _refreshSkinClass(); |
|
739 |
+ } |
|
740 |
+ return this; |
|
741 |
+ }, |
|
742 |
+ contentClass: function (value) { |
|
743 |
+ if (value == undefined) { |
|
744 |
+ return _getValue('contentClass'); |
|
745 |
+ } else if (_popups && _popups.length > 0) { |
|
746 |
+ _popups[_popups.length - 1].contentClass = value; |
|
747 |
+ _refreshContentClass(); |
|
748 |
+ } |
|
749 |
+ return this; |
|
750 |
+ }, |
|
751 |
+ innerClass: function (value) { |
|
752 |
+ if (value == undefined) { |
|
753 |
+ return _getValue('innerClass'); |
|
754 |
+ } else if (_popups && _popups.length > 0) { |
|
755 |
+ _popups[_popups.length - 1].innerClass = value; |
|
756 |
+ _refreshInnerClass(); |
|
757 |
+ } |
|
758 |
+ return this; |
|
759 |
+ }, |
|
760 |
+ parentScrolling: function (value) { |
|
761 |
+ if (value == undefined) return _getValue('parentScrolling'); |
|
762 |
+ else if (_popups && _popups.length > 0) |
|
763 |
+ { |
|
764 |
+ _popups[_popups.length - 1].parentScrolling = value; |
|
765 |
+ _refreshParentScrolling(); |
|
766 |
+ } |
|
767 |
+ return this; |
|
768 |
+ }, |
|
769 |
+ center: function () { // Center popup. |
|
770 |
+ if (_popups && _popups.length > 0) |
|
771 |
+ { |
|
772 |
+ var $window = $(window); |
|
773 |
+ var popup = _popups[_popups.length - 1]; |
|
774 |
+ var left = ($window.width() - $('#jg_popup_inner').outerWidth()) / 2; |
|
775 |
+ var top = ($window.height() - $('#jg_popup_inner').outerHeight()) / 2; |
|
776 |
+ |
|
777 |
+ var css = { |
|
778 |
+ left: popup.fixed ? left + 'px' : $window.scrollLeft() + left + 'px', |
|
779 |
+ top: popup.fixed ? top + 'px' : $window.scrollTop() + top + 'px', |
|
780 |
+ right: 'auto', |
|
781 |
+ bottom: 'auto' |
|
782 |
+ }; |
|
783 |
+ |
|
784 |
+ popup.css = css; |
|
785 |
+ $('#jg_popup_inner').css(css); |
|
786 |
+ } |
|
787 |
+ return this; |
|
788 |
+ }, |
|
789 |
+ refresh: function(){ // Reload iframe. |
|
790 |
+ if (_popups && _popups.length > 0) |
|
791 |
+ { |
|
792 |
+ var iframe = $('#jg_popup_content div:eq(' + (_popups.length - 1) + ') > iframe.jg_popup_iframe'); |
|
793 |
+ if(iframe.length > 0) |
|
794 |
+ { |
|
795 |
+ iframe[0].contentDocument.location.reload(true); |
|
796 |
+ } |
|
797 |
+ } |
|
798 |
+ return this; |
|
799 |
+ } |
|
800 |
+ }; |
|
801 |
+})(jQuery); |
|
0 | 802 |
\ No newline at end of file |