Przeniesienie nazwy utworu na pierwszy tab.
[redakcja.git] / platforma / static / js / jquery.blockui.js
1 /*!\r
2  * jQuery blockUI plugin\r
3  * Version 2.28 (02-DEC-2009)\r
4  * @requires jQuery v1.2.3 or later\r
5  *\r
6  * Examples at: http://malsup.com/jquery/block/\r
7  * Copyright (c) 2007-2008 M. Alsup\r
8  * Dual licensed under the MIT and GPL licenses:\r
9  * http://www.opensource.org/licenses/mit-license.php\r
10  * http://www.gnu.org/licenses/gpl.html\r
11  *\r
12  * Thanks to Amir-Hossein Sobhi for some excellent contributions!\r
13  */\r
14 \r
15 ;(function($) {\r
16 \r
17 if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.1/.test($.fn.jquery)) {\r
18         alert('blockUI requires jQuery v1.2.3 or later!  You are using v' + $.fn.jquery);\r
19         return;\r
20 }\r
21 \r
22 $.fn._fadeIn = $.fn.fadeIn;\r
23 \r
24 // this bit is to ensure we don't call setExpression when we shouldn't (with extra muscle to handle\r
25 // retarded userAgent strings on Vista)\r
26 var mode = document.documentMode || 0;\r
27 var setExpr = $.browser.msie && (($.browser.version < 8 && !mode) || mode < 8);\r
28 var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent) && !mode;\r
29 \r
30 // global $ methods for blocking/unblocking the entire page\r
31 $.blockUI   = function(opts) { install(window, opts); };\r
32 $.unblockUI = function(opts) { remove(window, opts); };\r
33 \r
34 // convenience method for quick growl-like notifications  (http://www.google.com/search?q=growl)\r
35 $.growlUI = function(title, message, timeout, onClose) {\r
36         var $m = $('<div class="growlUI"></div>');\r
37         if (title) $m.append('<h1>'+title+'</h1>');\r
38         if (message) $m.append('<h2>'+message+'</h2>');\r
39         if (timeout == undefined) timeout = 3000;\r
40         $.blockUI({\r
41                 message: $m, fadeIn: 700, fadeOut: 1000, centerY: false,\r
42                 timeout: timeout, showOverlay: false,\r
43                 onUnblock: onClose, \r
44                 css: $.blockUI.defaults.growlCSS\r
45         });\r
46 };\r
47 \r
48 // plugin method for blocking element content\r
49 $.fn.block = function(opts) {\r
50         return this.unblock({ fadeOut: 0 }).each(function() {\r
51                 if ($.css(this,'position') == 'static')\r
52                         this.style.position = 'relative';\r
53                 if ($.browser.msie)\r
54                         this.style.zoom = 1; // force 'hasLayout'\r
55                 install(this, opts);\r
56         });\r
57 };\r
58 \r
59 // plugin method for unblocking element content\r
60 $.fn.unblock = function(opts) {\r
61         return this.each(function() {\r
62                 remove(this, opts);\r
63         });\r
64 };\r
65 \r
66 $.blockUI.version = 2.28; // 2nd generation blocking at no extra cost!\r
67 \r
68 // override these in your code to change the default behavior and style\r
69 $.blockUI.defaults = {\r
70         // message displayed when blocking (use null for no message)\r
71         message:  '<h1>Please wait...</h1>',\r
72 \r
73         title: null,      // title string; only used when theme == true\r
74         draggable: true,  // only used when theme == true (requires jquery-ui.js to be loaded)\r
75         \r
76         theme: false, // set to true to use with jQuery UI themes\r
77         \r
78         // styles for the message when blocking; if you wish to disable\r
79         // these and use an external stylesheet then do this in your code:\r
80         // $.blockUI.defaults.css = {};\r
81         css: {\r
82                 padding:        0,\r
83                 margin:         0,\r
84                 width:          '30%',\r
85                 top:            '40%',\r
86                 left:           '35%',\r
87                 textAlign:      'center',\r
88                 color:          '#000',\r
89                 border:         '3px solid #aaa',\r
90                 backgroundColor:'#fff',\r
91                 cursor:         'wait'\r
92         },\r
93         \r
94         // minimal style set used when themes are used\r
95         themedCSS: {\r
96                 width:  '30%',\r
97                 top:    '40%',\r
98                 left:   '35%'\r
99         },\r
100 \r
101         // styles for the overlay\r
102         overlayCSS:  {\r
103                 backgroundColor: '#000',\r
104                 opacity:                 0.6,\r
105                 cursor:                  'wait'\r
106         },\r
107 \r
108         // styles applied when using $.growlUI\r
109         growlCSS: {\r
110                 width:          '350px',\r
111                 top:            '10px',\r
112                 left:           '',\r
113                 right:          '10px',\r
114                 border:         'none',\r
115                 padding:        '5px',\r
116                 opacity:        0.6,\r
117                 cursor:         'default',\r
118                 color:          '#fff',\r
119                 backgroundColor: '#000',\r
120                 '-webkit-border-radius': '10px',\r
121                 '-moz-border-radius':    '10px'\r
122         },\r
123         \r
124         // IE issues: 'about:blank' fails on HTTPS and javascript:false is s-l-o-w\r
125         // (hat tip to Jorge H. N. de Vasconcelos)\r
126         iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank',\r
127 \r
128         // force usage of iframe in non-IE browsers (handy for blocking applets)\r
129         forceIframe: false,\r
130 \r
131         // z-index for the blocking overlay\r
132         baseZ: 1000,\r
133 \r
134         // set these to true to have the message automatically centered\r
135         centerX: true, // <-- only effects element blocking (page block controlled via css above)\r
136         centerY: true,\r
137 \r
138         // allow body element to be stetched in ie6; this makes blocking look better\r
139         // on "short" pages.  disable if you wish to prevent changes to the body height\r
140         allowBodyStretch: true,\r
141 \r
142         // enable if you want key and mouse events to be disabled for content that is blocked\r
143         bindEvents: true,\r
144 \r
145         // be default blockUI will supress tab navigation from leaving blocking content\r
146         // (if bindEvents is true)\r
147         constrainTabKey: true,\r
148 \r
149         // fadeIn time in millis; set to 0 to disable fadeIn on block\r
150         fadeIn:  200,\r
151 \r
152         // fadeOut time in millis; set to 0 to disable fadeOut on unblock\r
153         fadeOut:  400,\r
154 \r
155         // time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock\r
156         timeout: 0,\r
157 \r
158         // disable if you don't want to show the overlay\r
159         showOverlay: true,\r
160 \r
161         // if true, focus will be placed in the first available input field when\r
162         // page blocking\r
163         focusInput: true,\r
164 \r
165         // suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)\r
166         applyPlatformOpacityRules: true,\r
167 \r
168         // callback method invoked when unblocking has completed; the callback is\r
169         // passed the element that has been unblocked (which is the window object for page\r
170         // blocks) and the options that were passed to the unblock call:\r
171         //       onUnblock(element, options)\r
172         onUnblock: null,\r
173 \r
174         // don't ask; if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493\r
175         quirksmodeOffsetHack: 4\r
176 };\r
177 \r
178 // private data and functions follow...\r
179 \r
180 var pageBlock = null;\r
181 var pageBlockEls = [];\r
182 \r
183 function install(el, opts) {\r
184         var full = (el == window);\r
185         var msg = opts && opts.message !== undefined ? opts.message : undefined;\r
186         opts = $.extend({}, $.blockUI.defaults, opts || {});\r
187         opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});\r
188         var css = $.extend({}, $.blockUI.defaults.css, opts.css || {});\r
189         var themedCSS = $.extend({}, $.blockUI.defaults.themedCSS, opts.themedCSS || {});\r
190         msg = msg === undefined ? opts.message : msg;\r
191 \r
192         // remove the current block (if there is one)\r
193         if (full && pageBlock)\r
194                 remove(window, {fadeOut:0});\r
195 \r
196         // if an existing element is being used as the blocking content then we capture\r
197         // its current place in the DOM (and current display style) so we can restore\r
198         // it when we unblock\r
199         if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {\r
200                 var node = msg.jquery ? msg[0] : msg;\r
201                 var data = {};\r
202                 $(el).data('blockUI.history', data);\r
203                 data.el = node;\r
204                 data.parent = node.parentNode;\r
205                 data.display = node.style.display;\r
206                 data.position = node.style.position;\r
207                 if (data.parent)\r
208                         data.parent.removeChild(node);\r
209         }\r
210 \r
211         var z = opts.baseZ;\r
212 \r
213         // blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;\r
214         // layer1 is the iframe layer which is used to supress bleed through of underlying content\r
215         // layer2 is the overlay layer which has opacity and a wait cursor (by default)\r
216         // layer3 is the message content that is displayed while blocking\r
217 \r
218         var lyr1 = ($.browser.msie || opts.forceIframe) \r
219                 ? $('<iframe class="blockUI" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0" src="'+opts.iframeSrc+'"></iframe>')\r
220                 : $('<div class="blockUI" style="display:none"></div>');\r
221         var lyr2 = $('<div class="blockUI blockOverlay" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>');\r
222         \r
223         var lyr3;\r
224         if (opts.theme && full) {\r
225                 var s = '<div class="blockUI blockMsg blockPage ui-dialog ui-widget ui-corner-all" style="z-index:'+z+';display:none;position:fixed">' +\r
226                                         '<div class="ui-widget-header ui-dialog-titlebar blockTitle">'+(opts.title || '&nbsp;')+'</div>' +\r
227                                         '<div class="ui-widget-content ui-dialog-content"></div>' +\r
228                                 '</div>';\r
229                 lyr3 = $(s);\r
230         }\r
231         else {\r
232                 lyr3 = full ? $('<div class="blockUI blockMsg blockPage" style="z-index:'+z+';display:none;position:fixed"></div>')\r
233                                         : $('<div class="blockUI blockMsg blockElement" style="z-index:'+z+';display:none;position:absolute"></div>');\r
234         }                                                  \r
235 \r
236         // if we have a message, style it\r
237         if (msg) {\r
238                 if (opts.theme) {\r
239                         lyr3.css(themedCSS);\r
240                         lyr3.addClass('ui-widget-content');\r
241                 }\r
242                 else \r
243                         lyr3.css(css);\r
244         }\r
245 \r
246         // style the overlay\r
247         if (!opts.applyPlatformOpacityRules || !($.browser.mozilla && /Linux/.test(navigator.platform)))\r
248                 lyr2.css(opts.overlayCSS);\r
249         lyr2.css('position', full ? 'fixed' : 'absolute');\r
250 \r
251         // make iframe layer transparent in IE\r
252         if ($.browser.msie || opts.forceIframe)\r
253                 lyr1.css('opacity',0.0);\r
254 \r
255         $([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);\r
256         \r
257         if (opts.theme && opts.draggable && $.fn.draggable) {\r
258                 lyr3.draggable({\r
259                         handle: '.ui-dialog-titlebar',\r
260                         cancel: 'li'\r
261                 });\r
262         }\r
263 \r
264         // ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)\r
265         var expr = setExpr && (!$.boxModel || $('object,embed', full ? null : el).length > 0);\r
266         if (ie6 || expr) {\r
267                 // give body 100% height\r
268                 if (full && opts.allowBodyStretch && $.boxModel)\r
269                         $('html,body').css('height','100%');\r
270 \r
271                 // fix ie6 issue when blocked element has a border width\r
272                 if ((ie6 || !$.boxModel) && !full) {\r
273                         var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');\r
274                         var fixT = t ? '(0 - '+t+')' : 0;\r
275                         var fixL = l ? '(0 - '+l+')' : 0;\r
276                 }\r
277 \r
278                 // simulate fixed position\r
279                 $.each([lyr1,lyr2,lyr3], function(i,o) {\r
280                         var s = o[0].style;\r
281                         s.position = 'absolute';\r
282                         if (i < 2) {\r
283                                 full ? s.setExpression('height','Math.max(document.body.scrollHeight, document.body.offsetHeight) - (jQuery.boxModel?0:'+opts.quirksmodeOffsetHack+') + "px"')\r
284                                          : s.setExpression('height','this.parentNode.offsetHeight + "px"');\r
285                                 full ? s.setExpression('width','jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"')\r
286                                          : s.setExpression('width','this.parentNode.offsetWidth + "px"');\r
287                                 if (fixL) s.setExpression('left', fixL);\r
288                                 if (fixT) s.setExpression('top', fixT);\r
289                         }\r
290                         else if (opts.centerY) {\r
291                                 if (full) s.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');\r
292                                 s.marginTop = 0;\r
293                         }\r
294                         else if (!opts.centerY && full) {\r
295                                 var top = (opts.css && opts.css.top) ? parseInt(opts.css.top) : 0;\r
296                                 var expression = '((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"';\r
297                                 s.setExpression('top',expression);\r
298                         }\r
299                 });\r
300         }\r
301 \r
302         // show the message\r
303         if (msg) {\r
304                 if (opts.theme)\r
305                         lyr3.find('.ui-widget-content').append(msg);\r
306                 else\r
307                         lyr3.append(msg);\r
308                 if (msg.jquery || msg.nodeType)\r
309                         $(msg).show();\r
310         }\r
311 \r
312         if (($.browser.msie || opts.forceIframe) && opts.showOverlay)\r
313                 lyr1.show(); // opacity is zero\r
314         if (opts.fadeIn) {\r
315                 if (opts.showOverlay)\r
316                         lyr2._fadeIn(opts.fadeIn);\r
317                 if (msg)\r
318                         lyr3.fadeIn(opts.fadeIn);\r
319         }\r
320         else {\r
321                 if (opts.showOverlay)\r
322                         lyr2.show();\r
323                 if (msg)\r
324                         lyr3.show();\r
325         }\r
326 \r
327         // bind key and mouse events\r
328         bind(1, el, opts);\r
329 \r
330         if (full) {\r
331                 pageBlock = lyr3[0];\r
332                 pageBlockEls = $(':input:enabled:visible',pageBlock);\r
333                 if (opts.focusInput)\r
334                         setTimeout(focus, 20);\r
335         }\r
336         else\r
337                 center(lyr3[0], opts.centerX, opts.centerY);\r
338 \r
339         if (opts.timeout) {\r
340                 // auto-unblock\r
341                 var to = setTimeout(function() {\r
342                         full ? $.unblockUI(opts) : $(el).unblock(opts);\r
343                 }, opts.timeout);\r
344                 $(el).data('blockUI.timeout', to);\r
345         }\r
346 };\r
347 \r
348 // remove the block\r
349 function remove(el, opts) {\r
350         var full = (el == window);\r
351         var $el = $(el);\r
352         var data = $el.data('blockUI.history');\r
353         var to = $el.data('blockUI.timeout');\r
354         if (to) {\r
355                 clearTimeout(to);\r
356                 $el.removeData('blockUI.timeout');\r
357         }\r
358         opts = $.extend({}, $.blockUI.defaults, opts || {});\r
359         bind(0, el, opts); // unbind events\r
360         \r
361         var els;\r
362         if (full) // crazy selector to handle odd field errors in ie6/7\r
363                 els = $('body').children().filter('.blockUI').add('body > .blockUI');\r
364         else\r
365                 els = $('.blockUI', el);\r
366 \r
367         if (full)\r
368                 pageBlock = pageBlockEls = null;\r
369 \r
370         if (opts.fadeOut) {\r
371                 els.fadeOut(opts.fadeOut);\r
372                 setTimeout(function() { reset(els,data,opts,el); }, opts.fadeOut);\r
373         }\r
374         else\r
375                 reset(els, data, opts, el);\r
376 };\r
377 \r
378 // move blocking element back into the DOM where it started\r
379 function reset(els,data,opts,el) {\r
380         els.each(function(i,o) {\r
381                 // remove via DOM calls so we don't lose event handlers\r
382                 if (this.parentNode)\r
383                         this.parentNode.removeChild(this);\r
384         });\r
385 \r
386         if (data && data.el) {\r
387                 data.el.style.display = data.display;\r
388                 data.el.style.position = data.position;\r
389                 if (data.parent)\r
390                         data.parent.appendChild(data.el);\r
391                 $(el).removeData('blockUI.history');\r
392         }\r
393 \r
394         if (typeof opts.onUnblock == 'function')\r
395                 opts.onUnblock(el,opts);\r
396 };\r
397 \r
398 // bind/unbind the handler\r
399 function bind(b, el, opts) {\r
400         var full = el == window, $el = $(el);\r
401 \r
402         // don't bother unbinding if there is nothing to unbind\r
403         if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked')))\r
404                 return;\r
405         if (!full)\r
406                 $el.data('blockUI.isBlocked', b);\r
407 \r
408         // don't bind events when overlay is not in use or if bindEvents is false\r
409         if (!opts.bindEvents || (b && !opts.showOverlay)) \r
410                 return;\r
411 \r
412         // bind anchors and inputs for mouse and key events\r
413         var events = 'mousedown mouseup keydown keypress';\r
414         b ? $(document).bind(events, opts, handler) : $(document).unbind(events, handler);\r
415 \r
416 // former impl...\r
417 //         var $e = $('a,:input');\r
418 //         b ? $e.bind(events, opts, handler) : $e.unbind(events, handler);\r
419 };\r
420 \r
421 // event handler to suppress keyboard/mouse events when blocking\r
422 function handler(e) {\r
423         // allow tab navigation (conditionally)\r
424         if (e.keyCode && e.keyCode == 9) {\r
425                 if (pageBlock && e.data.constrainTabKey) {\r
426                         var els = pageBlockEls;\r
427                         var fwd = !e.shiftKey && e.target == els[els.length-1];\r
428                         var back = e.shiftKey && e.target == els[0];\r
429                         if (fwd || back) {\r
430                                 setTimeout(function(){focus(back)},10);\r
431                                 return false;\r
432                         }\r
433                 }\r
434         }\r
435         // allow events within the message content\r
436         if ($(e.target).parents('div.blockMsg').length > 0)\r
437                 return true;\r
438 \r
439         // allow events for content that is not being blocked\r
440         return $(e.target).parents().children().filter('div.blockUI').length == 0;\r
441 };\r
442 \r
443 function focus(back) {\r
444         if (!pageBlockEls)\r
445                 return;\r
446         var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];\r
447         if (e)\r
448                 e.focus();\r
449 };\r
450 \r
451 function center(el, x, y) {\r
452         var p = el.parentNode, s = el.style;\r
453         var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');\r
454         var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');\r
455         if (x) s.left = l > 0 ? (l+'px') : '0';\r
456         if (y) s.top  = t > 0 ? (t+'px') : '0';\r
457 };\r
458 \r
459 function sz(el, p) {\r
460         return parseInt($.css(el,p))||0;\r
461 };\r
462 \r
463 })(jQuery);\r