added jquery.ui.droppable.js which was missing in jquery.ui.dialog.js;fixes LiquidThr...
[lhc/web/wiklou.git] / resources / jquery.ui / jquery.ui.dialog.js
1 /*
2 * jQuery UI Dialog 1.8.11
3 *
4 * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
5 * Dual licensed under the MIT or GPL Version 2 licenses.
6 * http://jquery.org/license
7 *
8 * http://docs.jquery.com/UI/Dialog
9 *
10 * Depends:
11 * jquery.ui.core.js
12 * jquery.ui.widget.js
13 * jquery.ui.button.js
14 * jquery.ui.draggable.js
15 * jquery.ui.mouse.js
16 * jquery.ui.position.js
17 * jquery.ui.resizable.js
18 * jquery.ui.droppable.js
19 */
20 (function( $, undefined ) {
21
22 var uiDialogClasses =
23 'ui-dialog ' +
24 'ui-widget ' +
25 'ui-widget-content ' +
26 'ui-corner-all ',
27 sizeRelatedOptions = {
28 buttons: true,
29 height: true,
30 maxHeight: true,
31 maxWidth: true,
32 minHeight: true,
33 minWidth: true,
34 width: true
35 },
36 resizableRelatedOptions = {
37 maxHeight: true,
38 maxWidth: true,
39 minHeight: true,
40 minWidth: true
41 };
42
43 $.widget("ui.dialog", {
44 options: {
45 autoOpen: true,
46 buttons: {},
47 closeOnEscape: true,
48 closeText: 'close',
49 dialogClass: '',
50 draggable: true,
51 hide: null,
52 height: 'auto',
53 maxHeight: false,
54 maxWidth: false,
55 minHeight: 150,
56 minWidth: 150,
57 modal: false,
58 position: {
59 my: 'center',
60 at: 'center',
61 collision: 'fit',
62 // ensure that the titlebar is never outside the document
63 using: function(pos) {
64 var topOffset = $(this).css(pos).offset().top;
65 if (topOffset < 0) {
66 $(this).css('top', pos.top - topOffset);
67 }
68 }
69 },
70 resizable: true,
71 show: null,
72 stack: true,
73 title: '',
74 width: 300,
75 zIndex: 1000
76 },
77
78 _create: function() {
79 this.originalTitle = this.element.attr('title');
80 // #5742 - .attr() might return a DOMElement
81 if ( typeof this.originalTitle !== "string" ) {
82 this.originalTitle = "";
83 }
84
85 this.options.title = this.options.title || this.originalTitle;
86 var self = this,
87 options = self.options,
88
89 title = options.title || '&#160;',
90 titleId = $.ui.dialog.getTitleId(self.element),
91
92 uiDialog = (self.uiDialog = $('<div></div>'))
93 .appendTo(document.body)
94 .hide()
95 .addClass(uiDialogClasses + options.dialogClass)
96 .css({
97 zIndex: options.zIndex
98 })
99 // setting tabIndex makes the div focusable
100 // setting outline to 0 prevents a border on focus in Mozilla
101 .attr('tabIndex', -1).css('outline', 0).keydown(function(event) {
102 if (options.closeOnEscape && event.keyCode &&
103 event.keyCode === $.ui.keyCode.ESCAPE) {
104
105 self.close(event);
106 event.preventDefault();
107 }
108 })
109 .attr({
110 role: 'dialog',
111 'aria-labelledby': titleId
112 })
113 .mousedown(function(event) {
114 self.moveToTop(false, event);
115 }),
116
117 uiDialogContent = self.element
118 .show()
119 .removeAttr('title')
120 .addClass(
121 'ui-dialog-content ' +
122 'ui-widget-content')
123 .appendTo(uiDialog),
124
125 uiDialogTitlebar = (self.uiDialogTitlebar = $('<div></div>'))
126 .addClass(
127 'ui-dialog-titlebar ' +
128 'ui-widget-header ' +
129 'ui-corner-all ' +
130 'ui-helper-clearfix'
131 )
132 .prependTo(uiDialog),
133
134 uiDialogTitlebarClose = $('<a href="#"></a>')
135 .addClass(
136 'ui-dialog-titlebar-close ' +
137 'ui-corner-all'
138 )
139 .attr('role', 'button')
140 .hover(
141 function() {
142 uiDialogTitlebarClose.addClass('ui-state-hover');
143 },
144 function() {
145 uiDialogTitlebarClose.removeClass('ui-state-hover');
146 }
147 )
148 .focus(function() {
149 uiDialogTitlebarClose.addClass('ui-state-focus');
150 })
151 .blur(function() {
152 uiDialogTitlebarClose.removeClass('ui-state-focus');
153 })
154 .click(function(event) {
155 self.close(event);
156 return false;
157 })
158 .appendTo(uiDialogTitlebar),
159
160 uiDialogTitlebarCloseText = (self.uiDialogTitlebarCloseText = $('<span></span>'))
161 .addClass(
162 'ui-icon ' +
163 'ui-icon-closethick'
164 )
165 .text(options.closeText)
166 .appendTo(uiDialogTitlebarClose),
167
168 uiDialogTitle = $('<span></span>')
169 .addClass('ui-dialog-title')
170 .attr('id', titleId)
171 .html(title)
172 .prependTo(uiDialogTitlebar);
173
174 //handling of deprecated beforeclose (vs beforeClose) option
175 //Ticket #4669 http://dev.jqueryui.com/ticket/4669
176 //TODO: remove in 1.9pre
177 if ($.isFunction(options.beforeclose) && !$.isFunction(options.beforeClose)) {
178 options.beforeClose = options.beforeclose;
179 }
180
181 uiDialogTitlebar.find("*").add(uiDialogTitlebar).disableSelection();
182
183 if (options.draggable && $.fn.draggable) {
184 self._makeDraggable();
185 }
186 if (options.resizable && $.fn.resizable) {
187 self._makeResizable();
188 }
189
190 self._createButtons(options.buttons);
191 self._isOpen = false;
192
193 if ($.fn.bgiframe) {
194 uiDialog.bgiframe();
195 }
196 },
197
198 _init: function() {
199 if ( this.options.autoOpen ) {
200 this.open();
201 }
202 },
203
204 destroy: function() {
205 var self = this;
206
207 if (self.overlay) {
208 self.overlay.destroy();
209 }
210 self.uiDialog.hide();
211 self.element
212 .unbind('.dialog')
213 .removeData('dialog')
214 .removeClass('ui-dialog-content ui-widget-content')
215 .hide().appendTo('body');
216 self.uiDialog.remove();
217
218 if (self.originalTitle) {
219 self.element.attr('title', self.originalTitle);
220 }
221
222 return self;
223 },
224
225 widget: function() {
226 return this.uiDialog;
227 },
228
229 close: function(event) {
230 var self = this,
231 maxZ, thisZ;
232
233 if (false === self._trigger('beforeClose', event)) {
234 return;
235 }
236
237 if (self.overlay) {
238 self.overlay.destroy();
239 }
240 self.uiDialog.unbind('keypress.ui-dialog');
241
242 self._isOpen = false;
243
244 if (self.options.hide) {
245 self.uiDialog.hide(self.options.hide, function() {
246 self._trigger('close', event);
247 });
248 } else {
249 self.uiDialog.hide();
250 self._trigger('close', event);
251 }
252
253 $.ui.dialog.overlay.resize();
254
255 // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
256 if (self.options.modal) {
257 maxZ = 0;
258 $('.ui-dialog').each(function() {
259 if (this !== self.uiDialog[0]) {
260 thisZ = $(this).css('z-index');
261 if(!isNaN(thisZ)) {
262 maxZ = Math.max(maxZ, thisZ);
263 }
264 }
265 });
266 $.ui.dialog.maxZ = maxZ;
267 }
268
269 return self;
270 },
271
272 isOpen: function() {
273 return this._isOpen;
274 },
275
276 // the force parameter allows us to move modal dialogs to their correct
277 // position on open
278 moveToTop: function(force, event) {
279 var self = this,
280 options = self.options,
281 saveScroll;
282
283 if ((options.modal && !force) ||
284 (!options.stack && !options.modal)) {
285 return self._trigger('focus', event);
286 }
287
288 if (options.zIndex > $.ui.dialog.maxZ) {
289 $.ui.dialog.maxZ = options.zIndex;
290 }
291 if (self.overlay) {
292 $.ui.dialog.maxZ += 1;
293 self.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ);
294 }
295
296 //Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed.
297 // http://ui.jquery.com/bugs/ticket/3193
298 saveScroll = { scrollTop: self.element.attr('scrollTop'), scrollLeft: self.element.attr('scrollLeft') };
299 $.ui.dialog.maxZ += 1;
300 self.uiDialog.css('z-index', $.ui.dialog.maxZ);
301 self.element.attr(saveScroll);
302 self._trigger('focus', event);
303
304 return self;
305 },
306
307 open: function() {
308 if (this._isOpen) { return; }
309
310 var self = this,
311 options = self.options,
312 uiDialog = self.uiDialog;
313
314 self.overlay = options.modal ? new $.ui.dialog.overlay(self) : null;
315 self._size();
316 self._position(options.position);
317 uiDialog.show(options.show);
318 self.moveToTop(true);
319
320 // prevent tabbing out of modal dialogs
321 if (options.modal) {
322 uiDialog.bind('keypress.ui-dialog', function(event) {
323 if (event.keyCode !== $.ui.keyCode.TAB) {
324 return;
325 }
326
327 var tabbables = $(':tabbable', this),
328 first = tabbables.filter(':first'),
329 last = tabbables.filter(':last');
330
331 if (event.target === last[0] && !event.shiftKey) {
332 first.focus(1);
333 return false;
334 } else if (event.target === first[0] && event.shiftKey) {
335 last.focus(1);
336 return false;
337 }
338 });
339 }
340
341 // set focus to the first tabbable element in the content area or the first button
342 // if there are no tabbable elements, set focus on the dialog itself
343 $(self.element.find(':tabbable').get().concat(
344 uiDialog.find('.ui-dialog-buttonpane :tabbable').get().concat(
345 uiDialog.get()))).eq(0).focus();
346
347 self._isOpen = true;
348 self._trigger('open');
349
350 return self;
351 },
352
353 _createButtons: function(buttons) {
354 var self = this,
355 hasButtons = false,
356 uiDialogButtonPane = $('<div></div>')
357 .addClass(
358 'ui-dialog-buttonpane ' +
359 'ui-widget-content ' +
360 'ui-helper-clearfix'
361 ),
362 uiButtonSet = $( "<div></div>" )
363 .addClass( "ui-dialog-buttonset" )
364 .appendTo( uiDialogButtonPane );
365
366 // if we already have a button pane, remove it
367 self.uiDialog.find('.ui-dialog-buttonpane').remove();
368
369 if (typeof buttons === 'object' && buttons !== null) {
370 $.each(buttons, function() {
371 return !(hasButtons = true);
372 });
373 }
374 if (hasButtons) {
375 $.each(buttons, function(name, props) {
376 props = $.isFunction( props ) ?
377 { click: props, text: name } :
378 props;
379 var button = $('<button type="button"></button>')
380 .attr( props, true )
381 .unbind('click')
382 .click(function() {
383 props.click.apply(self.element[0], arguments);
384 })
385 .appendTo(uiButtonSet);
386 if ($.fn.button) {
387 button.button();
388 }
389 });
390 uiDialogButtonPane.appendTo(self.uiDialog);
391 }
392 },
393
394 _makeDraggable: function() {
395 var self = this,
396 options = self.options,
397 doc = $(document),
398 heightBeforeDrag;
399
400 function filteredUi(ui) {
401 return {
402 position: ui.position,
403 offset: ui.offset
404 };
405 }
406
407 self.uiDialog.draggable({
408 cancel: '.ui-dialog-content, .ui-dialog-titlebar-close',
409 handle: '.ui-dialog-titlebar',
410 containment: 'document',
411 start: function(event, ui) {
412 heightBeforeDrag = options.height === "auto" ? "auto" : $(this).height();
413 $(this).height($(this).height()).addClass("ui-dialog-dragging");
414 self._trigger('dragStart', event, filteredUi(ui));
415 },
416 drag: function(event, ui) {
417 self._trigger('drag', event, filteredUi(ui));
418 },
419 stop: function(event, ui) {
420 options.position = [ui.position.left - doc.scrollLeft(),
421 ui.position.top - doc.scrollTop()];
422 $(this).removeClass("ui-dialog-dragging").height(heightBeforeDrag);
423 self._trigger('dragStop', event, filteredUi(ui));
424 $.ui.dialog.overlay.resize();
425 }
426 });
427 },
428
429 _makeResizable: function(handles) {
430 handles = (handles === undefined ? this.options.resizable : handles);
431 var self = this,
432 options = self.options,
433 // .ui-resizable has position: relative defined in the stylesheet
434 // but dialogs have to use absolute or fixed positioning
435 position = self.uiDialog.css('position'),
436 resizeHandles = (typeof handles === 'string' ?
437 handles :
438 'n,e,s,w,se,sw,ne,nw'
439 );
440
441 function filteredUi(ui) {
442 return {
443 originalPosition: ui.originalPosition,
444 originalSize: ui.originalSize,
445 position: ui.position,
446 size: ui.size
447 };
448 }
449
450 self.uiDialog.resizable({
451 cancel: '.ui-dialog-content',
452 containment: 'document',
453 alsoResize: self.element,
454 maxWidth: options.maxWidth,
455 maxHeight: options.maxHeight,
456 minWidth: options.minWidth,
457 minHeight: self._minHeight(),
458 handles: resizeHandles,
459 start: function(event, ui) {
460 $(this).addClass("ui-dialog-resizing");
461 self._trigger('resizeStart', event, filteredUi(ui));
462 },
463 resize: function(event, ui) {
464 self._trigger('resize', event, filteredUi(ui));
465 },
466 stop: function(event, ui) {
467 $(this).removeClass("ui-dialog-resizing");
468 options.height = $(this).height();
469 options.width = $(this).width();
470 self._trigger('resizeStop', event, filteredUi(ui));
471 $.ui.dialog.overlay.resize();
472 }
473 })
474 .css('position', position)
475 .find('.ui-resizable-se').addClass('ui-icon ui-icon-grip-diagonal-se');
476 },
477
478 _minHeight: function() {
479 var options = this.options;
480
481 if (options.height === 'auto') {
482 return options.minHeight;
483 } else {
484 return Math.min(options.minHeight, options.height);
485 }
486 },
487
488 _position: function(position) {
489 var myAt = [],
490 offset = [0, 0],
491 isVisible;
492
493 if (position) {
494 // deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
495 // if (typeof position == 'string' || $.isArray(position)) {
496 // myAt = $.isArray(position) ? position : position.split(' ');
497
498 if (typeof position === 'string' || (typeof position === 'object' && '0' in position)) {
499 myAt = position.split ? position.split(' ') : [position[0], position[1]];
500 if (myAt.length === 1) {
501 myAt[1] = myAt[0];
502 }
503
504 $.each(['left', 'top'], function(i, offsetPosition) {
505 if (+myAt[i] === myAt[i]) {
506 offset[i] = myAt[i];
507 myAt[i] = offsetPosition;
508 }
509 });
510
511 position = {
512 my: myAt.join(" "),
513 at: myAt.join(" "),
514 offset: offset.join(" ")
515 };
516 }
517
518 position = $.extend({}, $.ui.dialog.prototype.options.position, position);
519 } else {
520 position = $.ui.dialog.prototype.options.position;
521 }
522
523 // need to show the dialog to get the actual offset in the position plugin
524 isVisible = this.uiDialog.is(':visible');
525 if (!isVisible) {
526 this.uiDialog.show();
527 }
528 this.uiDialog
529 // workaround for jQuery bug #5781 http://dev.jquery.com/ticket/5781
530 .css({ top: 0, left: 0 })
531 .position($.extend({ of: window }, position));
532 if (!isVisible) {
533 this.uiDialog.hide();
534 }
535 },
536
537 _setOptions: function( options ) {
538 var self = this,
539 resizableOptions = {},
540 resize = false;
541
542 $.each( options, function( key, value ) {
543 self._setOption( key, value );
544
545 if ( key in sizeRelatedOptions ) {
546 resize = true;
547 }
548 if ( key in resizableRelatedOptions ) {
549 resizableOptions[ key ] = value;
550 }
551 });
552
553 if ( resize ) {
554 this._size();
555 }
556 if ( this.uiDialog.is( ":data(resizable)" ) ) {
557 this.uiDialog.resizable( "option", resizableOptions );
558 }
559 },
560
561 _setOption: function(key, value){
562 var self = this,
563 uiDialog = self.uiDialog;
564
565 switch (key) {
566 //handling of deprecated beforeclose (vs beforeClose) option
567 //Ticket #4669 http://dev.jqueryui.com/ticket/4669
568 //TODO: remove in 1.9pre
569 case "beforeclose":
570 key = "beforeClose";
571 break;
572 case "buttons":
573 self._createButtons(value);
574 break;
575 case "closeText":
576 // ensure that we always pass a string
577 self.uiDialogTitlebarCloseText.text("" + value);
578 break;
579 case "dialogClass":
580 uiDialog
581 .removeClass(self.options.dialogClass)
582 .addClass(uiDialogClasses + value);
583 break;
584 case "disabled":
585 if (value) {
586 uiDialog.addClass('ui-dialog-disabled');
587 } else {
588 uiDialog.removeClass('ui-dialog-disabled');
589 }
590 break;
591 case "draggable":
592 var isDraggable = uiDialog.is( ":data(draggable)" );
593 if ( isDraggable && !value ) {
594 uiDialog.draggable( "destroy" );
595 }
596
597 if ( !isDraggable && value ) {
598 self._makeDraggable();
599 }
600 break;
601 case "position":
602 self._position(value);
603 break;
604 case "resizable":
605 // currently resizable, becoming non-resizable
606 var isResizable = uiDialog.is( ":data(resizable)" );
607 if (isResizable && !value) {
608 uiDialog.resizable('destroy');
609 }
610
611 // currently resizable, changing handles
612 if (isResizable && typeof value === 'string') {
613 uiDialog.resizable('option', 'handles', value);
614 }
615
616 // currently non-resizable, becoming resizable
617 if (!isResizable && value !== false) {
618 self._makeResizable(value);
619 }
620 break;
621 case "title":
622 // convert whatever was passed in o a string, for html() to not throw up
623 $(".ui-dialog-title", self.uiDialogTitlebar).html("" + (value || '&#160;'));
624 break;
625 }
626
627 $.Widget.prototype._setOption.apply(self, arguments);
628 },
629
630 _size: function() {
631 /* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content
632 * divs will both have width and height set, so we need to reset them
633 */
634 var options = this.options,
635 nonContentHeight,
636 minContentHeight,
637 isVisible = this.uiDialog.is( ":visible" );
638
639 // reset content sizing
640 this.element.show().css({
641 width: 'auto',
642 minHeight: 0,
643 height: 0
644 });
645
646 if (options.minWidth > options.width) {
647 options.width = options.minWidth;
648 }
649
650 // reset wrapper sizing
651 // determine the height of all the non-content elements
652 nonContentHeight = this.uiDialog.css({
653 height: 'auto',
654 width: options.width
655 })
656 .height();
657 minContentHeight = Math.max( 0, options.minHeight - nonContentHeight );
658
659 if ( options.height === "auto" ) {
660 // only needed for IE6 support
661 if ( $.support.minHeight ) {
662 this.element.css({
663 minHeight: minContentHeight,
664 height: "auto"
665 });
666 } else {
667 this.uiDialog.show();
668 var autoHeight = this.element.css( "height", "auto" ).height();
669 if ( !isVisible ) {
670 this.uiDialog.hide();
671 }
672 this.element.height( Math.max( autoHeight, minContentHeight ) );
673 }
674 } else {
675 this.element.height( Math.max( options.height - nonContentHeight, 0 ) );
676 }
677
678 if (this.uiDialog.is(':data(resizable)')) {
679 this.uiDialog.resizable('option', 'minHeight', this._minHeight());
680 }
681 }
682 });
683
684 $.extend($.ui.dialog, {
685 version: "1.8.11",
686
687 uuid: 0,
688 maxZ: 0,
689
690 getTitleId: function($el) {
691 var id = $el.attr('id');
692 if (!id) {
693 this.uuid += 1;
694 id = this.uuid;
695 }
696 return 'ui-dialog-title-' + id;
697 },
698
699 overlay: function(dialog) {
700 this.$el = $.ui.dialog.overlay.create(dialog);
701 }
702 });
703
704 $.extend($.ui.dialog.overlay, {
705 instances: [],
706 // reuse old instances due to IE memory leak with alpha transparency (see #5185)
707 oldInstances: [],
708 maxZ: 0,
709 events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),
710 function(event) { return event + '.dialog-overlay'; }).join(' '),
711 create: function(dialog) {
712 if (this.instances.length === 0) {
713 // prevent use of anchors and inputs
714 // we use a setTimeout in case the overlay is created from an
715 // event that we're going to be cancelling (see #2804)
716 setTimeout(function() {
717 // handle $(el).dialog().dialog('close') (see #4065)
718 if ($.ui.dialog.overlay.instances.length) {
719 $(document).bind($.ui.dialog.overlay.events, function(event) {
720 // stop events if the z-index of the target is < the z-index of the overlay
721 // we cannot return true when we don't want to cancel the event (#3523)
722 if ($(event.target).zIndex() < $.ui.dialog.overlay.maxZ) {
723 return false;
724 }
725 });
726 }
727 }, 1);
728
729 // allow closing by pressing the escape key
730 $(document).bind('keydown.dialog-overlay', function(event) {
731 if (dialog.options.closeOnEscape && event.keyCode &&
732 event.keyCode === $.ui.keyCode.ESCAPE) {
733
734 dialog.close(event);
735 event.preventDefault();
736 }
737 });
738
739 // handle window resize
740 $(window).bind('resize.dialog-overlay', $.ui.dialog.overlay.resize);
741 }
742
743 var $el = (this.oldInstances.pop() || $('<div></div>').addClass('ui-widget-overlay'))
744 .appendTo(document.body)
745 .css({
746 width: this.width(),
747 height: this.height()
748 });
749
750 if ($.fn.bgiframe) {
751 $el.bgiframe();
752 }
753
754 this.instances.push($el);
755 return $el;
756 },
757
758 destroy: function($el) {
759 var indexOf = $.inArray($el, this.instances);
760 if (indexOf != -1){
761 this.oldInstances.push(this.instances.splice(indexOf, 1)[0]);
762 }
763
764 if (this.instances.length === 0) {
765 $([document, window]).unbind('.dialog-overlay');
766 }
767
768 $el.remove();
769
770 // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
771 var maxZ = 0;
772 $.each(this.instances, function() {
773 maxZ = Math.max(maxZ, this.css('z-index'));
774 });
775 this.maxZ = maxZ;
776 },
777
778 height: function() {
779 var scrollHeight,
780 offsetHeight;
781 // handle IE 6
782 if ($.browser.msie && $.browser.version < 7) {
783 scrollHeight = Math.max(
784 document.documentElement.scrollHeight,
785 document.body.scrollHeight
786 );
787 offsetHeight = Math.max(
788 document.documentElement.offsetHeight,
789 document.body.offsetHeight
790 );
791
792 if (scrollHeight < offsetHeight) {
793 return $(window).height() + 'px';
794 } else {
795 return scrollHeight + 'px';
796 }
797 // handle "good" browsers
798 } else {
799 return $(document).height() + 'px';
800 }
801 },
802
803 width: function() {
804 var scrollWidth,
805 offsetWidth;
806 // handle IE 6
807 if ($.browser.msie && $.browser.version < 7) {
808 scrollWidth = Math.max(
809 document.documentElement.scrollWidth,
810 document.body.scrollWidth
811 );
812 offsetWidth = Math.max(
813 document.documentElement.offsetWidth,
814 document.body.offsetWidth
815 );
816
817 if (scrollWidth < offsetWidth) {
818 return $(window).width() + 'px';
819 } else {
820 return scrollWidth + 'px';
821 }
822 // handle "good" browsers
823 } else {
824 return $(document).width() + 'px';
825 }
826 },
827
828 resize: function() {
829 /* If the dialog is draggable and the user drags it past the
830 * right edge of the window, the document becomes wider so we
831 * need to stretch the overlay. If the user then drags the
832 * dialog back to the left, the document will become narrower,
833 * so we need to shrink the overlay to the appropriate size.
834 * This is handled by shrinking the overlay before setting it
835 * to the full document size.
836 */
837 var $overlays = $([]);
838 $.each($.ui.dialog.overlay.instances, function() {
839 $overlays = $overlays.add(this);
840 });
841
842 $overlays.css({
843 width: 0,
844 height: 0
845 }).css({
846 width: $.ui.dialog.overlay.width(),
847 height: $.ui.dialog.overlay.height()
848 });
849 }
850 });
851
852 $.extend($.ui.dialog.overlay.prototype, {
853 destroy: function() {
854 $.ui.dialog.overlay.destroy(this.$el);
855 }
856 });
857
858 /* jquery.ui.droppable.js */
859
860 $.widget("ui.droppable", {
861 widgetEventPrefix: "drop",
862 options: {
863 accept: '*',
864 activeClass: false,
865 addClasses: true,
866 greedy: false,
867 hoverClass: false,
868 scope: 'default',
869 tolerance: 'intersect'
870 },
871 _create: function() {
872
873 var o = this.options, accept = o.accept;
874 this.isover = 0; this.isout = 1;
875
876 this.accept = $.isFunction(accept) ? accept : function(d) {
877 return d.is(accept);
878 };
879
880 //Store the droppable's proportions
881 this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
882
883 // Add the reference and positions to the manager
884 $.ui.ddmanager.droppables[o.scope] = $.ui.ddmanager.droppables[o.scope] || [];
885 $.ui.ddmanager.droppables[o.scope].push(this);
886
887 (o.addClasses && this.element.addClass("ui-droppable"));
888
889 },
890
891 destroy: function() {
892 var drop = $.ui.ddmanager.droppables[this.options.scope];
893 for ( var i = 0; i < drop.length; i++ )
894 if ( drop[i] == this )
895 drop.splice(i, 1);
896
897 this.element
898 .removeClass("ui-droppable ui-droppable-disabled")
899 .removeData("droppable")
900 .unbind(".droppable");
901
902 return this;
903 },
904
905 _setOption: function(key, value) {
906
907 if(key == 'accept') {
908 this.accept = $.isFunction(value) ? value : function(d) {
909 return d.is(value);
910 };
911 }
912 $.Widget.prototype._setOption.apply(this, arguments);
913 },
914
915 _activate: function(event) {
916 var draggable = $.ui.ddmanager.current;
917 if(this.options.activeClass) this.element.addClass(this.options.activeClass);
918 (draggable && this._trigger('activate', event, this.ui(draggable)));
919 },
920
921 _deactivate: function(event) {
922 var draggable = $.ui.ddmanager.current;
923 if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
924 (draggable && this._trigger('deactivate', event, this.ui(draggable)));
925 },
926
927 _over: function(event) {
928
929 var draggable = $.ui.ddmanager.current;
930 if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
931
932 if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
933 if(this.options.hoverClass) this.element.addClass(this.options.hoverClass);
934 this._trigger('over', event, this.ui(draggable));
935 }
936
937 },
938
939 _out: function(event) {
940
941 var draggable = $.ui.ddmanager.current;
942 if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
943
944 if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
945 if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
946 this._trigger('out', event, this.ui(draggable));
947 }
948
949 },
950
951 _drop: function(event,custom) {
952
953 var draggable = custom || $.ui.ddmanager.current;
954 if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element
955
956 var childrenIntersection = false;
957 this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() {
958 var inst = $.data(this, 'droppable');
959 if(
960 inst.options.greedy
961 && !inst.options.disabled
962 && inst.options.scope == draggable.options.scope
963 && inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element))
964 && $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)
965 ) { childrenIntersection = true; return false; }
966 });
967 if(childrenIntersection) return false;
968
969 if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
970 if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
971 if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
972 this._trigger('drop', event, this.ui(draggable));
973 return this.element;
974 }
975
976 return false;
977
978 },
979
980 ui: function(c) {
981 return {
982 draggable: (c.currentItem || c.element),
983 helper: c.helper,
984 position: c.position,
985 offset: c.positionAbs
986 };
987 }
988
989 });
990
991 $.extend($.ui.droppable, {
992 version: "1.8.11"
993 });
994
995 $.ui.intersect = function(draggable, droppable, toleranceMode) {
996
997 if (!droppable.offset) return false;
998
999 var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
1000 y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height;
1001 var l = droppable.offset.left, r = l + droppable.proportions.width,
1002 t = droppable.offset.top, b = t + droppable.proportions.height;
1003
1004 switch (toleranceMode) {
1005 case 'fit':
1006 return (l <= x1 && x2 <= r
1007 && t <= y1 && y2 <= b);
1008 break;
1009 case 'intersect':
1010 return (l < x1 + (draggable.helperProportions.width / 2) // Right Half
1011 && x2 - (draggable.helperProportions.width / 2) < r // Left Half
1012 && t < y1 + (draggable.helperProportions.height / 2) // Bottom Half
1013 && y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
1014 break;
1015 case 'pointer':
1016 var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left),
1017 draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top),
1018 isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width);
1019 return isOver;
1020 break;
1021 case 'touch':
1022 return (
1023 (y1 >= t && y1 <= b) || // Top edge touching
1024 (y2 >= t && y2 <= b) || // Bottom edge touching
1025 (y1 < t && y2 > b) // Surrounded vertically
1026 ) && (
1027 (x1 >= l && x1 <= r) || // Left edge touching
1028 (x2 >= l && x2 <= r) || // Right edge touching
1029 (x1 < l && x2 > r) // Surrounded horizontally
1030 );
1031 break;
1032 default:
1033 return false;
1034 break;
1035 }
1036
1037 };
1038
1039 /*
1040 This manager tracks offsets of draggables and droppables
1041 */
1042 $.ui.ddmanager = {
1043 current: null,
1044 droppables: { 'default': [] },
1045 prepareOffsets: function(t, event) {
1046
1047 var m = $.ui.ddmanager.droppables[t.options.scope] || [];
1048 var type = event ? event.type : null; // workaround for #2317
1049 var list = (t.currentItem || t.element).find(":data(droppable)").andSelf();
1050
1051 droppablesLoop: for (var i = 0; i < m.length; i++) {
1052
1053 if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) continue; //No disabled and non-accepted
1054 for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item
1055 m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue
1056
1057 if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables
1058
1059 m[i].offset = m[i].element.offset();
1060 m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
1061
1062 }
1063
1064 },
1065 drop: function(draggable, event) {
1066
1067 var dropped = false;
1068 $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
1069
1070 if(!this.options) return;
1071 if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance))
1072 dropped = dropped || this._drop.call(this, event);
1073
1074 if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
1075 this.isout = 1; this.isover = 0;
1076 this._deactivate.call(this, event);
1077 }
1078
1079 });
1080 return dropped;
1081
1082 },
1083 drag: function(draggable, event) {
1084
1085 //If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
1086 if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event);
1087
1088 //Run through all droppables and check their positions based on specific tolerance options
1089 $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
1090
1091 if(this.options.disabled || this.greedyChild || !this.visible) return;
1092 var intersects = $.ui.intersect(draggable, this, this.options.tolerance);
1093
1094 var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null);
1095 if(!c) return;
1096
1097 var parentInstance;
1098 if (this.options.greedy) {
1099 var parent = this.element.parents(':data(droppable):eq(0)');
1100 if (parent.length) {
1101 parentInstance = $.data(parent[0], 'droppable');
1102 parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
1103 }
1104 }
1105
1106 // we just moved into a greedy child
1107 if (parentInstance && c == 'isover') {
1108 parentInstance['isover'] = 0;
1109 parentInstance['isout'] = 1;
1110 parentInstance._out.call(parentInstance, event);
1111 }
1112
1113 this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0;
1114 this[c == "isover" ? "_over" : "_out"].call(this, event);
1115
1116 // we just moved out of a greedy child
1117 if (parentInstance && c == 'isout') {
1118 parentInstance['isout'] = 0;
1119 parentInstance['isover'] = 1;
1120 parentInstance._over.call(parentInstance, event);
1121 }
1122 });
1123
1124 }
1125 };
1126
1127
1128 }(jQuery));