# HG changeset patch # User Mario Ferraro # Date 1250010417 -3600 # Node ID 4e2789b8e86d8b17f63a8a006ca608b2f9302892 # Parent 7fbc98f3addea0a5743d956a993ca6b9a5f226e5 Upgrade jQuery UI to version 1.7. Following our upgrade to JQuery 1.3 we can now upgrade to the most recent version. diff -r 7fbc98f3adde -r 4e2789b8e86d app/jquery/jquery-ui.core.js --- a/app/jquery/jquery-ui.core.js Mon Aug 10 16:58:51 2009 -0700 +++ b/app/jquery/jquery-ui.core.js Tue Aug 11 18:06:57 2009 +0100 @@ -1,21 +1,20 @@ /* - * jQuery UI 1.6 + * jQuery UI 1.7.2 * - * Copyright (c) 2008 AUTHORS.txt (http://ui.jquery.com/about) + * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * http://docs.jquery.com/UI */ -;(function($) { +;jQuery.ui || (function($) { var _remove = $.fn.remove, isFF2 = $.browser.mozilla && (parseFloat($.browser.version) < 1.9); //Helper functions and ui object $.ui = { - - version: "1.6", + version: "1.7.2", // $.ui.plugin is deprecated. Use the proxy pattern instead. plugin: { @@ -28,7 +27,7 @@ }, call: function(instance, name, args) { var set = instance.plugins[name]; - if(!set) { return; } + if(!set || !instance.element[0].parentNode) { return; } for (var i = 0; i < set.length; i++) { if (instance.options[set[i][0]]) { @@ -39,33 +38,9 @@ }, contains: function(a, b) { - var safari2 = $.browser.safari && $.browser.version < 522; - if (a.contains && !safari2) { - return a.contains(b); - } - if (a.compareDocumentPosition) - return !!(a.compareDocumentPosition(b) & 16); - while (b = b.parentNode) - if (b == a) return true; - return false; - }, - - cssCache: {}, - css: function(name) { - if ($.ui.cssCache[name]) { return $.ui.cssCache[name]; } - var tmp = $('
').addClass(name).css({position:'absolute', top:'-5000px', left:'-5000px', display:'block'}).appendTo('body'); - - //if (!$.browser.safari) - //tmp.appendTo('body'); - - //Opera and Safari set width and height to 0px instead of auto - //Safari returns rgba(0,0,0,0) when bgcolor is not set - $.ui.cssCache[name] = !!( - (!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) || - !(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor'))) - ); - try { $('body').get(0).removeChild(tmp.get(0)); } catch(e){} - return $.ui.cssCache[name]; + return document.compareDocumentPosition + ? a.compareDocumentPosition(b) & 16 + : a !== b && a.contains(b); }, hasScroll: function(el, a) { @@ -125,7 +100,6 @@ TAB: 9, UP: 38 } - }; // WAI-ARIA normalization @@ -161,7 +135,6 @@ //jQuery plugins $.fn.extend({ - remove: function() { // Safari has a native remove event which actually removes DOM elements, // so we have to use triggerHandler instead of trigger (#3037). @@ -186,7 +159,6 @@ }, scrollParent: function() { - var scrollParent; if(($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) { scrollParent = this.parents().filter(function() { @@ -199,48 +171,33 @@ } return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent; - - } - }); //Additional selectors $.extend($.expr[':'], { - - data: function(a, i, m) { - return $.data(a, m[3]); + data: function(elem, i, match) { + return !!$.data(elem, match[3]); }, - // TODO: add support for object, area - tabbable: function(a, i, m) { - - var nodeName = a.nodeName.toLowerCase(); - function isVisible(element) { - return !($(element).is(':hidden') || $(element).parents(':hidden').length); - } - - return ( - // in tab order - a.tabIndex >= 0 && - - ( // filter node types that participate in the tab order + focusable: function(element) { + var nodeName = element.nodeName.toLowerCase(), + tabIndex = $.attr(element, 'tabindex'); + return (/input|select|textarea|button|object/.test(nodeName) + ? !element.disabled + : 'a' == nodeName || 'area' == nodeName + ? element.href || !isNaN(tabIndex) + : !isNaN(tabIndex)) + // the element and all of its ancestors must be visible + // the browser may report that the area is hidden + && !$(element)['area' == nodeName ? 'parents' : 'closest'](':hidden').length; + }, - // anchor tag - ('a' == nodeName && a.href) || - - // enabled form element - (/input|select|textarea|button/.test(nodeName) && - 'hidden' != a.type && !a.disabled) - ) && - - // visible on page - isVisible(a) - ); - + tabbable: function(element) { + var tabIndex = $.attr(element, 'tabindex'); + return (isNaN(tabIndex) || tabIndex >= 0) && $(element).is(':focusable'); } - }); @@ -286,7 +243,7 @@ // constructor (!instance && !isMethodCall && - $.data(this, name, new $[namespace][name](this, options))); + $.data(this, name, new $[namespace][name](this, options))._init()); // method call (instance && isMethodCall && $.isFunction(instance[options]) && @@ -299,6 +256,7 @@ $[namespace][name] = function(element, options) { var self = this; + this.namespace = namespace; this.widgetName = name; this.widgetEventPrefix = $[namespace][name].eventPrefix || name; this.widgetBaseClass = namespace + '-' + name; @@ -311,16 +269,18 @@ this.element = $(element) .bind('setData.' + name, function(event, key, value) { - return self._setData(key, value); + if (event.target == element) { + return self._setData(key, value); + } }) .bind('getData.' + name, function(event, key) { - return self._getData(key); + if (event.target == element) { + return self._getData(key); + } }) .bind('remove', function() { return self.destroy(); }); - - this._init(); }; // add widget prototype @@ -334,7 +294,9 @@ $.widget.prototype = { _init: function() {}, destroy: function() { - this.element.removeData(this.widgetName); + this.element.removeData(this.widgetName) + .removeClass(this.widgetBaseClass + '-disabled' + ' ' + this.namespace + '-state-disabled') + .removeAttr('aria-disabled'); }, option: function(key, value) { @@ -360,8 +322,11 @@ this.options[key] = value; if (key == 'disabled') { - this.element[value ? 'addClass' : 'removeClass']( - this.widgetBaseClass + '-disabled'); + this.element + [value ? 'addClass' : 'removeClass']( + this.widgetBaseClass + '-disabled' + ' ' + + this.namespace + '-state-disabled') + .attr("aria-disabled", value); } }, @@ -373,10 +338,27 @@ }, _trigger: function(type, event, data) { - var eventName = (type == this.widgetEventPrefix - ? type : this.widgetEventPrefix + type); - event = event || $.event.fix({ type: eventName, target: this.element[0] }); - return this.element.triggerHandler(eventName, [event, data], this.options[type]); + var callback = this.options[type], + eventName = (type == this.widgetEventPrefix + ? type : this.widgetEventPrefix + type); + + event = $.Event(event); + event.type = eventName; + + // copy original event properties over to the new event + // this would happen if we could call $.event.fix instead of $.Event + // but we don't have a way to force an event to be fixed multiple times + if (event.originalEvent) { + for (var i = $.event.props.length, prop; i;) { + prop = $.event.props[--i]; + event[prop] = event.originalEvent[prop]; + } + } + + this.element.trigger(event, data); + + return !($.isFunction(callback) && callback.call(this.element[0], event, data) === false + || event.isDefaultPrevented()); } }; @@ -398,6 +380,7 @@ .bind('click.'+this.widgetName, function(event) { if(self._preventClickEvent) { self._preventClickEvent = false; + event.stopImmediatePropagation(); return false; } }); @@ -422,6 +405,11 @@ }, _mouseDown: function(event) { + // don't let more than one widget handle mouseStart + // TODO: figure out why we have to use originalEvent + event.originalEvent = event.originalEvent || {}; + if (event.originalEvent.mouseHandled) { return; } + // we may have missed mouseup (out of window) (this._mouseStarted && this._mouseUp(event)); @@ -463,7 +451,9 @@ // preventDefault() is used to prevent the selection of text here - // however, in Safari, this causes select boxes not to be selectable // anymore, so this fix is needed - if(!$.browser.safari) event.preventDefault(); + ($.browser.safari || event.preventDefault()); + + event.originalEvent.mouseHandled = true; return true; }, @@ -494,7 +484,7 @@ if (this._mouseStarted) { this._mouseStarted = false; - this._preventClickEvent = true; + this._preventClickEvent = (event.target == this._mouseDownEvent.target); this._mouseStop(event); } diff -r 7fbc98f3adde -r 4e2789b8e86d app/jquery/jquery-ui.dialog.js --- a/app/jquery/jquery-ui.dialog.js Mon Aug 10 16:58:51 2009 -0700 +++ b/app/jquery/jquery-ui.dialog.js Tue Aug 11 18:06:57 2009 +0100 @@ -1,7 +1,7 @@ /* - * jQuery UI Dialog 1.6 + * jQuery UI Dialog 1.7.2 * - * Copyright (c) 2008 AUTHORS.txt (http://ui.jquery.com/about) + * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * @@ -15,115 +15,117 @@ (function($) { var setDataSwitch = { - dragStart: "start.draggable", - drag: "drag.draggable", - dragStop: "stop.draggable", - maxHeight: "maxHeight.resizable", - minHeight: "minHeight.resizable", - maxWidth: "maxWidth.resizable", - minWidth: "minWidth.resizable", - resizeStart: "start.resizable", - resize: "drag.resizable", - resizeStop: "stop.resizable" -}; + dragStart: "start.draggable", + drag: "drag.draggable", + dragStop: "stop.draggable", + maxHeight: "maxHeight.resizable", + minHeight: "minHeight.resizable", + maxWidth: "maxWidth.resizable", + minWidth: "minWidth.resizable", + resizeStart: "start.resizable", + resize: "drag.resizable", + resizeStop: "stop.resizable" + }, + + uiDialogClasses = + 'ui-dialog ' + + 'ui-widget ' + + 'ui-widget-content ' + + 'ui-corner-all '; $.widget("ui.dialog", { _init: function() { this.originalTitle = this.element.attr('title'); - this.options.title = this.options.title || this.originalTitle; var self = this, options = this.options, - uiDialogContent = this.element - .removeAttr('title') - .addClass('ui-dialog-content') - .wrap('
') - .wrap('
'), - - uiDialogContainer = (this.uiDialogContainer = uiDialogContent.parent()) - .addClass('ui-dialog-container') - .css({ - position: 'relative', - width: '100%', - height: '100%' - }), + title = options.title || this.originalTitle || ' ', + titleId = $.ui.dialog.getTitleId(this.element), - uiDialogTitlebar = (this.uiDialogTitlebar = $('
')) - .addClass('ui-dialog-titlebar') - .mousedown(function() { - self.moveToTop(); - }) - .prependTo(uiDialogContainer), - - uiDialogTitlebarClose = $('') - .addClass('ui-dialog-titlebar-close') - .attr('role', 'button') - .appendTo(uiDialogTitlebar), - - uiDialogTitlebarCloseText = (this.uiDialogTitlebarCloseText = $('')) - .text(options.closeText) - .appendTo(uiDialogTitlebarClose), - - title = options.title || ' ', - titleId = $.ui.dialog.getTitleId(this.element), - uiDialogTitle = $('') - .addClass('ui-dialog-title') - .attr('id', titleId) - .html(title) - .prependTo(uiDialogTitlebar), - - uiDialog = (this.uiDialog = uiDialogContainer.parent()) + uiDialog = (this.uiDialog = $('
')) .appendTo(document.body) .hide() - .addClass('ui-dialog') - .addClass(options.dialogClass) + .addClass(uiDialogClasses + options.dialogClass) .css({ position: 'absolute', - width: options.width, - height: options.height, overflow: 'hidden', zIndex: options.zIndex }) // setting tabIndex makes the div focusable // setting outline to 0 prevents a border on focus in Mozilla - .attr('tabIndex', -1).css('outline', 0).keydown(function(ev) { - (options.closeOnEscape && ev.keyCode - && ev.keyCode == $.ui.keyCode.ESCAPE && self.close()); + .attr('tabIndex', -1).css('outline', 0).keydown(function(event) { + (options.closeOnEscape && event.keyCode + && event.keyCode == $.ui.keyCode.ESCAPE && self.close(event)); }) .attr({ role: 'dialog', 'aria-labelledby': titleId }) - .mouseup(function() { - self.moveToTop(); + .mousedown(function(event) { + self.moveToTop(false, event); }), - uiDialogButtonPane = (this.uiDialogButtonPane = $('
')) - .addClass('ui-dialog-buttonpane') - .css({ - position: 'absolute', - bottom: 0 - }) + uiDialogContent = this.element + .show() + .removeAttr('title') + .addClass( + 'ui-dialog-content ' + + 'ui-widget-content') .appendTo(uiDialog), - uiDialogTitlebarClose = $('.ui-dialog-titlebar-close', uiDialogTitlebar) + uiDialogTitlebar = (this.uiDialogTitlebar = $('
')) + .addClass( + 'ui-dialog-titlebar ' + + 'ui-widget-header ' + + 'ui-corner-all ' + + 'ui-helper-clearfix' + ) + .prependTo(uiDialog), + + uiDialogTitlebarClose = $('
') + .addClass( + 'ui-dialog-titlebar-close ' + + 'ui-corner-all' + ) + .attr('role', 'button') .hover( function() { - $(this).addClass('ui-dialog-titlebar-close-hover'); + uiDialogTitlebarClose.addClass('ui-state-hover'); }, function() { - $(this).removeClass('ui-dialog-titlebar-close-hover'); + uiDialogTitlebarClose.removeClass('ui-state-hover'); } ) + .focus(function() { + uiDialogTitlebarClose.addClass('ui-state-focus'); + }) + .blur(function() { + uiDialogTitlebarClose.removeClass('ui-state-focus'); + }) .mousedown(function(ev) { ev.stopPropagation(); }) - .click(function() { - self.close(); + .click(function(event) { + self.close(event); return false; - }); + }) + .appendTo(uiDialogTitlebar), + + uiDialogTitlebarCloseText = (this.uiDialogTitlebarCloseText = $('')) + .addClass( + 'ui-icon ' + + 'ui-icon-closethick' + ) + .text(options.closeText) + .appendTo(uiDialogTitlebarClose), + + uiDialogTitle = $('') + .addClass('ui-dialog-title') + .attr('id', titleId) + .html(title) + .prependTo(uiDialogTitlebar); uiDialogTitlebar.find("*").add(uiDialogTitlebar).disableSelection(); @@ -135,6 +137,7 @@ (options.bgiframe && $.fn.bgiframe && uiDialog.bgiframe()); (options.autoOpen && this.open()); + }, destroy: function() { @@ -143,27 +146,43 @@ this.element .unbind('.dialog') .removeData('dialog') - .removeClass('ui-dialog-content') + .removeClass('ui-dialog-content ui-widget-content') .hide().appendTo('body'); this.uiDialog.remove(); (this.originalTitle && this.element.attr('title', this.originalTitle)); }, - close: function() { - if (false === this._trigger('beforeclose', null, { options: this.options })) { + close: function(event) { + var self = this; + + if (false === self._trigger('beforeclose', event)) { return; } - (this.overlay && this.overlay.destroy()); - this.uiDialog - .hide(this.options.hide) - .unbind('keypress.ui-dialog'); + (self.overlay && self.overlay.destroy()); + self.uiDialog.unbind('keypress.ui-dialog'); - this._trigger('close', null, { options: this.options }); + (self.options.hide + ? self.uiDialog.hide(self.options.hide, function() { + self._trigger('close', event); + }) + : self.uiDialog.hide() && self._trigger('close', event)); + $.ui.dialog.overlay.resize(); - this._isOpen = false; + self._isOpen = false; + + // adjust the maxZ to allow other modal dialogs to continue to work (see #4309) + if (self.options.modal) { + var maxZ = 0; + $('.ui-dialog').each(function() { + if (this != self.uiDialog[0]) { + maxZ = Math.max(maxZ, $(this).css('z-index')); + } + }); + $.ui.dialog.maxZ = maxZ; + } }, isOpen: function() { @@ -172,39 +191,41 @@ // the force parameter allows us to move modal dialogs to their correct // position on open - moveToTop: function(force) { + moveToTop: function(force, event) { if ((this.options.modal && !force) || (!this.options.stack && !this.options.modal)) { - return this._trigger('focus', null, { options: this.options }); + return this._trigger('focus', event); } - - var maxZ = this.options.zIndex, options = this.options; - $('.ui-dialog:visible').each(function() { - maxZ = Math.max(maxZ, parseInt($(this).css('z-index'), 10) || options.zIndex); - }); - (this.overlay && this.overlay.$el.css('z-index', ++maxZ)); + + if (this.options.zIndex > $.ui.dialog.maxZ) { + $.ui.dialog.maxZ = this.options.zIndex; + } + (this.overlay && this.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = ++$.ui.dialog.maxZ)); //Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed. // http://ui.jquery.com/bugs/ticket/3193 var saveScroll = { scrollTop: this.element.attr('scrollTop'), scrollLeft: this.element.attr('scrollLeft') }; - this.uiDialog.css('z-index', ++maxZ); + this.uiDialog.css('z-index', ++$.ui.dialog.maxZ); this.element.attr(saveScroll); - this._trigger('focus', null, { options: this.options }); + this._trigger('focus', event); }, open: function() { if (this._isOpen) { return; } - this.overlay = this.options.modal ? new $.ui.dialog.overlay(this) : null; - (this.uiDialog.next().length && this.uiDialog.appendTo('body')); - this._position(this.options.position); - this.uiDialog.show(this.options.show); - (this.options.autoResize && this._size()); + var options = this.options, + uiDialog = this.uiDialog; + + this.overlay = options.modal ? new $.ui.dialog.overlay(this) : null; + (uiDialog.next().length && uiDialog.appendTo('body')); + this._size(); + this._position(options.position); + uiDialog.show(options.show); this.moveToTop(true); // prevent tabbing out of modal dialogs - (this.options.modal && this.uiDialog.bind('keypress.ui-dialog', function(event) { + (options.modal && uiDialog.bind('keypress.ui-dialog', function(event) { if (event.keyCode != $.ui.keyCode.TAB) { return; } @@ -224,47 +245,82 @@ } })); - this.uiDialog.find(':tabbable:first').focus(); - this._trigger('open', null, { options: this.options }); + // set focus to the first tabbable element in the content area or the first button + // if there are no tabbable elements, set focus on the dialog itself + $([]) + .add(uiDialog.find('.ui-dialog-content :tabbable:first')) + .add(uiDialog.find('.ui-dialog-buttonpane :tabbable:first')) + .add(uiDialog) + .filter(':first') + .focus(); + + this._trigger('open'); this._isOpen = true; }, _createButtons: function(buttons) { var self = this, hasButtons = false, - uiDialogButtonPane = this.uiDialogButtonPane; + uiDialogButtonPane = $('
') + .addClass( + 'ui-dialog-buttonpane ' + + 'ui-widget-content ' + + 'ui-helper-clearfix' + ); - // remove any existing buttons - uiDialogButtonPane.empty().hide(); + // if we already have a button pane, remove it + this.uiDialog.find('.ui-dialog-buttonpane').remove(); - $.each(buttons, function() { return !(hasButtons = true); }); + (typeof buttons == 'object' && buttons !== null && + $.each(buttons, function() { return !(hasButtons = true); })); if (hasButtons) { - uiDialogButtonPane.show(); $.each(buttons, function(name, fn) { $('') + .addClass( + 'ui-state-default ' + + 'ui-corner-all' + ) .text(name) .click(function() { fn.apply(self.element[0], arguments); }) + .hover( + function() { + $(this).addClass('ui-state-hover'); + }, + function() { + $(this).removeClass('ui-state-hover'); + } + ) + .focus(function() { + $(this).addClass('ui-state-focus'); + }) + .blur(function() { + $(this).removeClass('ui-state-focus'); + }) .appendTo(uiDialogButtonPane); }); + uiDialogButtonPane.appendTo(this.uiDialog); } }, _makeDraggable: function() { var self = this, - options = this.options; + options = this.options, + heightBeforeDrag; this.uiDialog.draggable({ cancel: '.ui-dialog-content', - helper: options.dragHelper, handle: '.ui-dialog-titlebar', + containment: 'document', start: function() { - self.moveToTop(); + heightBeforeDrag = options.height; + $(this).height($(this).height()).addClass("ui-dialog-dragging"); (options.dragStart && options.dragStart.apply(self.element[0], arguments)); }, drag: function() { (options.drag && options.drag.apply(self.element[0], arguments)); }, stop: function() { + $(this).removeClass("ui-dialog-dragging").height(heightBeforeDrag); (options.dragStop && options.dragStop.apply(self.element[0], arguments)); $.ui.dialog.overlay.resize(); } @@ -281,25 +337,28 @@ this.uiDialog.resizable({ cancel: '.ui-dialog-content', - helper: options.resizeHelper, + alsoResize: this.element, maxWidth: options.maxWidth, maxHeight: options.maxHeight, minWidth: options.minWidth, minHeight: options.minHeight, start: function() { + $(this).addClass("ui-dialog-resizing"); (options.resizeStart && options.resizeStart.apply(self.element[0], arguments)); }, resize: function() { - (options.autoResize && self._size.apply(self)); (options.resize && options.resize.apply(self.element[0], arguments)); }, handles: resizeHandles, stop: function() { - (options.autoResize && self._size.apply(self)); + $(this).removeClass("ui-dialog-resizing"); + options.height = $(this).height(); + options.width = $(this).width(); (options.resizeStop && options.resizeStop.apply(self.element[0], arguments)); $.ui.dialog.overlay.resize(); } - }); + }) + .find('.ui-resizable-se').addClass('ui-icon ui-icon-grip-diagonal-se'); }, _position: function(pos) { @@ -339,13 +398,11 @@ pTop += 0; break; case 'bottom': - // Opera check fixes #3564, can go away with jQuery 1.3 - pTop += ($.browser.opera ? window.innerHeight : wnd.height()) - this.uiDialog.outerHeight(); + pTop += wnd.height() - this.uiDialog.outerHeight(); break; default: case 'middle': - // Opera check fixes #3564, can go away with jQuery 1.3 - pTop += (($.browser.opera ? window.innerHeight : wnd.height()) - this.uiDialog.outerHeight()) / 2; + pTop += (wnd.height() - this.uiDialog.outerHeight()) / 2; } } @@ -364,6 +421,11 @@ case "closeText": this.uiDialogTitlebarCloseText.text(value); break; + case "dialogClass": + this.uiDialog + .removeClass(this.options.dialogClass) + .addClass(uiDialogClasses + value); + break; case "draggable": (value ? this._makeDraggable() @@ -388,7 +450,6 @@ // currently non-resizable, becoming resizable (isResizable || this._makeResizable(value)); - break; case "title": $(".ui-dialog-title", this.uiDialogTitlebar).html(value || ' '); @@ -402,37 +463,58 @@ }, _size: function() { - var container = this.uiDialogContainer, - titlebar = this.uiDialogTitlebar, - content = this.element, - tbMargin = (parseInt(content.css('margin-top'), 10) || 0) - + (parseInt(content.css('margin-bottom'), 10) || 0), - lrMargin = (parseInt(content.css('margin-left'), 10) || 0) - + (parseInt(content.css('margin-right'), 10) || 0); - content.height(container.height() - titlebar.outerHeight() - tbMargin); - content.width(container.width() - lrMargin); + /* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content + * divs will both have width and height set, so we need to reset them + */ + var options = this.options; + + // reset content sizing + this.element.css({ + height: 0, + minHeight: 0, + width: 'auto' + }); + + // reset wrapper sizing + // determine the height of all the non-content elements + var nonContentHeight = this.uiDialog.css({ + height: 'auto', + width: options.width + }) + .height(); + + this.element + .css({ + minHeight: Math.max(options.minHeight - nonContentHeight, 0), + height: options.height == 'auto' + ? 'auto' + : Math.max(options.height - nonContentHeight, 0) + }); } - }); $.extend($.ui.dialog, { - version: "1.6", + version: "1.7.2", defaults: { autoOpen: true, - autoResize: true, bgiframe: false, buttons: {}, closeOnEscape: true, closeText: 'close', + dialogClass: '', draggable: true, - height: 200, - minHeight: 100, + hide: null, + height: 'auto', + maxHeight: false, + maxWidth: false, + minHeight: 150, minWidth: 150, modal: false, - overlay: {}, position: 'center', resizable: true, + show: null, stack: true, + title: '', width: 300, zIndex: 1000 }, @@ -440,6 +522,7 @@ getter: 'isOpen', uuid: 0, + maxZ: 0, getTitleId: function($el) { return 'ui-dialog-title-' + ($el.attr('id') || ++this.uuid); @@ -452,6 +535,7 @@ $.extend($.ui.dialog.overlay, { instances: [], + maxZ: 0, events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','), function(event) { return event + '.dialog-overlay'; }).join(' '), create: function(dialog) { @@ -460,32 +544,19 @@ // we use a setTimeout in case the overlay is created from an // event that we're going to be cancelling (see #2804) setTimeout(function() { - $('a, :input').bind($.ui.dialog.overlay.events, function() { - // allow use of the element if inside a dialog and - // - there are no modal dialogs - // - there are modal dialogs, but we are in front of the topmost modal - var allow = false; - var $dialog = $(this).parents('.ui-dialog'); - if ($dialog.length) { - var $overlays = $('.ui-dialog-overlay'); - if ($overlays.length) { - var maxZ = parseInt($overlays.css('z-index'), 10); - $overlays.each(function() { - maxZ = Math.max(maxZ, parseInt($(this).css('z-index'), 10)); - }); - allow = parseInt($dialog.css('z-index'), 10) > maxZ; - } else { - allow = true; - } - } - return allow; - }); + // handle $(el).dialog().dialog('close') (see #4065) + if ($.ui.dialog.overlay.instances.length) { + $(document).bind($.ui.dialog.overlay.events, function(event) { + var dialogZ = $(event.target).parents('.ui-dialog').css('zIndex') || 0; + return (dialogZ > $.ui.dialog.overlay.maxZ); + }); + } }, 1); // allow closing by pressing the escape key $(document).bind('keydown.dialog-overlay', function(event) { (dialog.options.closeOnEscape && event.keyCode - && event.keyCode == $.ui.keyCode.ESCAPE && dialog.close()); + && event.keyCode == $.ui.keyCode.ESCAPE && dialog.close(event)); }); // handle window resize @@ -493,12 +564,10 @@ } var $el = $('
').appendTo(document.body) - .addClass('ui-dialog-overlay').css($.extend({ - borderWidth: 0, margin: 0, padding: 0, - position: 'absolute', top: 0, left: 0, + .addClass('ui-widget-overlay').css({ width: this.width(), height: this.height() - }, dialog.options.overlay)); + }); (dialog.options.bgiframe && $.fn.bgiframe && $el.bgiframe()); @@ -510,10 +579,17 @@ this.instances.splice($.inArray(this.instances, $el), 1); if (this.instances.length === 0) { - $('a, :input').add([document, window]).unbind('.dialog-overlay'); + $([document, window]).unbind('.dialog-overlay'); } $el.remove(); + + // adjust the maxZ to allow other modal dialogs to continue to work (see #4309) + var maxZ = 0; + $.each(this.instances, function() { + maxZ = Math.max(maxZ, this.css('z-index')); + }); + this.maxZ = maxZ; }, height: function() { @@ -533,12 +609,6 @@ } else { return scrollHeight + 'px'; } - // handle Opera - } else if ($.browser.opera) { - return Math.max( - window.innerHeight, - $(document).height() - ) + 'px'; // handle "good" browsers } else { return $(document).height() + 'px'; @@ -562,12 +632,6 @@ } else { return scrollWidth + 'px'; } - // handle Opera - } else if ($.browser.opera) { - return Math.max( - window.innerWidth, - $(document).width() - ) + 'px'; // handle "good" browsers } else { return $(document).width() + 'px'; diff -r 7fbc98f3adde -r 4e2789b8e86d app/jquery/jquery-ui.draggable.js --- a/app/jquery/jquery-ui.draggable.js Mon Aug 10 16:58:51 2009 -0700 +++ b/app/jquery/jquery-ui.draggable.js Tue Aug 11 18:06:57 2009 +0100 @@ -1,7 +1,7 @@ /* - * jQuery UI Draggable 1.6 + * jQuery UI Draggable 1.7.2 * - * Copyright (c) 2008 AUTHORS.txt (http://ui.jquery.com/about) + * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * @@ -19,8 +19,8 @@ if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position"))) this.element[0].style.position = 'relative'; - (this.options.cssNamespace && this.element.addClass(this.options.cssNamespace+"-draggable")); - (this.options.disabled && this.element.addClass('ui-draggable-disabled')); + (this.options.addClasses && this.element.addClass("ui-draggable")); + (this.options.disabled && this.element.addClass("ui-draggable-disabled")); this._mouseInit(); @@ -28,7 +28,12 @@ destroy: function() { if(!this.element.data('draggable')) return; - this.element.removeData("draggable").unbind(".draggable").removeClass('ui-draggable ui-draggable-dragging ui-draggable-disabled'); + this.element + .removeData("draggable") + .unbind(".draggable") + .removeClass("ui-draggable" + + " ui-draggable-dragging" + + " ui-draggable-disabled"); this._mouseDestroy(); }, @@ -90,19 +95,21 @@ relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper }); + //Generate the original position + this.originalPosition = this._generatePosition(event); + this.originalPageX = event.pageX; + this.originalPageY = event.pageY; + //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied if(o.cursorAt) this._adjustOffsetFromHelper(o.cursorAt); - //Generate the original position - this.originalPosition = this._generatePosition(event); - //Set a containment if given in the options if(o.containment) this._setContainment(); //Call plugins and callbacks - this._propagate("start", event); + this._trigger("start", event); //Recache the helper size this._cacheHelperProportions(); @@ -123,7 +130,11 @@ this.positionAbs = this._convertPositionTo("absolute"); //Call plugins and callbacks and use the resulting position if something is returned - if(!noPropagation) this.position = this._propagate("drag", event) || this.position; + if (!noPropagation) { + var ui = this._uiHash(); + this._trigger('drag', event, ui); + this.position = ui.position; + } if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px'; if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px'; @@ -137,16 +148,22 @@ //If we are using droppables, inform the manager about the drop var dropped = false; if ($.ui.ddmanager && !this.options.dropBehaviour) - var dropped = $.ui.ddmanager.drop(this, event); + dropped = $.ui.ddmanager.drop(this, event); + + //if a drop comes from outside (a sortable) + if(this.dropped) { + dropped = this.dropped; + this.dropped = false; + } if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) { var self = this; $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() { - self._propagate("stop", event); + self._trigger("stop", event); self._clear(); }); } else { - this._propagate("stop", event); + this._trigger("stop", event); this._clear(); } @@ -191,9 +208,20 @@ _getParentOffset: function() { - this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset(); //Get the offsetParent and cache its position + //Get the offsetParent and cache its position + this.offsetParent = this.helper.offsetParent(); + var po = this.offsetParent.offset(); - if((this.offsetParent[0] == document.body && $.browser.mozilla) //Ugly FF3 fix + // This is a special case where we need to modify a offset calculated on start, since the following happened: + // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent + // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that + // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag + if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) { + po.left += this.scrollParent.scrollLeft(); + po.top += this.scrollParent.scrollTop(); + } + + if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix po = { top: 0, left: 0 }; @@ -239,21 +267,23 @@ if(o.containment == 'document' || o.containment == 'window') this.containment = [ 0 - this.offset.relative.left - this.offset.parent.left, 0 - this.offset.relative.top - this.offset.parent.top, - $(o.containment == 'document' ? document : window).width() - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.element.css("marginRight"),10) || 0), - ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.element.css("marginBottom"),10) || 0) + $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left, + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top ]; - if(!(/^(document|window|parent)$/).test(o.containment)) { - var ce = $(o.containment)[0]; + if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor != Array) { + var ce = $(o.containment)[0]; if(!ce) return; var co = $(o.containment).offset(); var over = ($(ce).css("overflow") != 'hidden'); this.containment = [ - co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left - this.margins.left, - co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top - this.margins.top, - co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left, - co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top + co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left, + co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top, + co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left, + co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top ]; + } else if(o.containment.constructor == Array) { + this.containment = o.containment; } }, @@ -262,69 +292,81 @@ if(!pos) pos = this.position; var mod = d == "absolute" ? 1 : -1; - var scroll = this[(this.cssPosition == 'absolute' ? 'offset' : 'scroll')+'Parent'], scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); + var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); return { top: ( - pos.top // the calculated relative position - + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent + pos.top // The absolute mouse position + + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border) - + ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod - + this.margins.top * mod //Add the margin (you don't want the margin counting in intersection methods) + - ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod) ), left: ( - pos.left // the calculated relative position - + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent + pos.left // The absolute mouse position + + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border) - + ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : ( scrollIsRootNode ? 0 : scroll.scrollLeft() ) ) * mod - + this.margins.left * mod //Add the margin (you don't want the margin counting in intersection methods) + - ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod) ) }; + }, _generatePosition: function(event) { - var o = this.options, scroll = this[(this.cssPosition == 'absolute' ? 'offset' : 'scroll')+'Parent'], scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); + var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); - var position = { - top: ( - event.pageY // The absolute mouse position - - this.offset.click.top // Click offset (relative to the element) - - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent - - this.offset.parent.top // The offsetParent's offset without borders (offset + border) - + ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) - ), - left: ( - event.pageX // The absolute mouse position - - this.offset.click.left // Click offset (relative to the element) - - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent - - this.offset.parent.left // The offsetParent's offset without borders (offset + border) - + ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) - ) - }; + // This is another very weird special case that only happens for relative elements: + // 1. If the css position is relative + // 2. and the scroll parent is the document or similar to the offset parent + // we have to refresh the relative offset during the scroll so there are no jumps + if(this.cssPosition == 'relative' && !(this.scrollParent[0] != document && this.scrollParent[0] != this.offsetParent[0])) { + this.offset.relative = this._getRelativeOffset(); + } - if(!this.originalPosition) return position; //If we are not dragging yet, we won't check for options + var pageX = event.pageX; + var pageY = event.pageY; /* * - Position constraining - * Constrain the position to a mix of grid, containment. */ - if(this.containment) { - if(position.left < this.containment[0]) position.left = this.containment[0]; - if(position.top < this.containment[1]) position.top = this.containment[1]; - if(position.left > this.containment[2]) position.left = this.containment[2]; - if(position.top > this.containment[3]) position.top = this.containment[3]; + + if(this.originalPosition) { //If we are not dragging yet, we won't check for options + + if(this.containment) { + if(event.pageX - this.offset.click.left < this.containment[0]) pageX = this.containment[0] + this.offset.click.left; + if(event.pageY - this.offset.click.top < this.containment[1]) pageY = this.containment[1] + this.offset.click.top; + if(event.pageX - this.offset.click.left > this.containment[2]) pageX = this.containment[2] + this.offset.click.left; + if(event.pageY - this.offset.click.top > this.containment[3]) pageY = this.containment[3] + this.offset.click.top; + } + + if(o.grid) { + var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1]; + pageY = this.containment ? (!(top - this.offset.click.top < this.containment[1] || top - this.offset.click.top > this.containment[3]) ? top : (!(top - this.offset.click.top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; + + var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0]; + pageX = this.containment ? (!(left - this.offset.click.left < this.containment[0] || left - this.offset.click.left > this.containment[2]) ? left : (!(left - this.offset.click.left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; + } + } - if(o.grid) { - var top = this.originalPosition.top + Math.round((position.top - this.originalPosition.top) / o.grid[1]) * o.grid[1]; - position.top = this.containment ? (!(top < this.containment[1] || top > this.containment[3]) ? top : (!(top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; + return { + top: ( + pageY // The absolute mouse position + - this.offset.click.top // Click offset (relative to the element) + - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent + - this.offset.parent.top // The offsetParent's offset without borders (offset + border) + + ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) )) + ), + left: ( + pageX // The absolute mouse position + - this.offset.click.left // Click offset (relative to the element) + - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent + - this.offset.parent.left // The offsetParent's offset without borders (offset + border) + + ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() )) + ) + }; - var left = this.originalPosition.left + Math.round((position.left - this.originalPosition.left) / o.grid[0]) * o.grid[0]; - position.left = this.containment ? (!(left < this.containment[0] || left > this.containment[2]) ? left : (!(left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; - } - - return position; }, _clear: function() { @@ -337,10 +379,11 @@ // From now on bulk stuff - mainly helpers - _propagate: function(n, event) { - $.ui.plugin.call(this, n, [event, this._uiHash()]); - if(n == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins - return this.element.triggerHandler(n == "drag" ? n : "drag"+n, [event, this._uiHash()], this.options[n]); + _trigger: function(type, event, ui) { + ui = ui || this._uiHash(); + $.ui.plugin.call(this, type, [event, ui]); + if(type == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins + return $.widget.prototype._trigger.call(this, type, event, ui); }, plugins: {}, @@ -349,31 +392,32 @@ return { helper: this.helper, position: this.position, - absolutePosition: this.positionAbs, - options: this.options + absolutePosition: this.positionAbs, //deprecated + offset: this.positionAbs }; } })); $.extend($.ui.draggable, { - version: "1.6", + version: "1.7.2", + eventPrefix: "drag", defaults: { + addClasses: true, appendTo: "parent", axis: false, - cancel: ":input", + cancel: ":input,option", connectToSortable: false, containment: false, - cssNamespace: "ui", - cursor: "default", - cursorAt: null, + cursor: "auto", + cursorAt: false, delay: 0, distance: 1, grid: false, handle: false, helper: "original", iframeFix: false, - opacity: 1, + opacity: false, refreshPositions: false, revert: false, revertDuration: 500, @@ -385,57 +429,58 @@ snapMode: "both", snapTolerance: 20, stack: false, - zIndex: null + zIndex: false } }); $.ui.plugin.add("draggable", "connectToSortable", { start: function(event, ui) { - var inst = $(this).data("draggable"); + var inst = $(this).data("draggable"), o = inst.options, + uiSortable = $.extend({}, ui, { item: inst.element }); inst.sortables = []; - $(ui.options.connectToSortable).each(function() { - // 'this' points to a string, and should therefore resolved as query, but instead, if the string is assigned to a variable, it loops through the strings properties, - // so we have to append '' to make it anonymous again - $(this+'').each(function() { - if($.data(this, 'sortable')) { - var sortable = $.data(this, 'sortable'); - inst.sortables.push({ - instance: sortable, - shouldRevert: sortable.options.revert - }); - sortable._refreshItems(); //Do a one-time refresh at start to refresh the containerCache - sortable._propagate("activate", event, inst); - } - }); + $(o.connectToSortable).each(function() { + var sortable = $.data(this, 'sortable'); + if (sortable && !sortable.options.disabled) { + inst.sortables.push({ + instance: sortable, + shouldRevert: sortable.options.revert + }); + sortable._refreshItems(); //Do a one-time refresh at start to refresh the containerCache + sortable._trigger("activate", event, uiSortable); + } }); }, stop: function(event, ui) { //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper - var inst = $(this).data("draggable"); + var inst = $(this).data("draggable"), + uiSortable = $.extend({}, ui, { item: inst.element }); $.each(inst.sortables, function() { if(this.instance.isOver) { + this.instance.isOver = 0; + inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work) - if(this.shouldRevert) this.instance.options.revert = true; //revert here + + //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: 'valid/invalid' + if(this.shouldRevert) this.instance.options.revert = true; + + //Trigger the stop of the sortable this.instance._mouseStop(event); - //Also propagate receive event, since the sortable is actually receiving a element - this.instance.element.triggerHandler("sortreceive", [event, $.extend(this.instance._ui(), { sender: inst.element })], this.instance.options["receive"]); + this.instance.options.helper = this.instance.options._helper; - this.instance.options.helper = this.instance.options._helper; - - if(inst.options.helper == 'original') { + //If the helper has been the original item, restore properties in the sortable + if(inst.options.helper == 'original') this.instance.currentItem.css({ top: 'auto', left: 'auto' }); - } } else { this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance - this.instance._propagate("deactivate", event, inst); + this.instance._trigger("deactivate", event, uiSortable); } }); @@ -455,11 +500,17 @@ }; $.each(inst.sortables, function(i) { - - if(checkPos.call(inst, this.instance.containerCache)) { + + //Copy over some variables to allow calling the sortable's native _intersectsWith + this.instance.positionAbs = inst.positionAbs; + this.instance.helperProportions = inst.helperProportions; + this.instance.offset.click = inst.offset.click; + + if(this.instance._intersectsWith(this.instance.containerCache)) { //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once if(!this.instance.isOver) { + this.instance.isOver = 1; //Now we fake the start of dragging for the sortable instance, //by cloning the list group item, appending it to the sortable and using it as inst.currentItem @@ -478,7 +529,11 @@ this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left; this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top; - inst._propagate("toSortable", event); + inst._trigger("toSortable", event); + inst.dropped = this.instance.element; //draggable revert needs that + //hack so receive/update callbacks work (mostly) + inst.currentItem = inst.element; + this.instance.fromOutside = inst; } @@ -490,9 +545,16 @@ //If it doesn't intersect with the sortable, and it intersected before, //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval if(this.instance.isOver) { + this.instance.isOver = 0; this.instance.cancelHelperRemoval = true; - this.instance.options.revert = false; //No revert here + + //Prevent reverting on this forced stop + this.instance.options.revert = false; + + // The out event needs to be triggered independently + this.instance._trigger('out', event, this.instance._uiHash(this.instance)); + this.instance._mouseStop(event, true); this.instance.options.helper = this.instance.options._helper; @@ -500,7 +562,8 @@ this.instance.currentItem.remove(); if(this.instance.placeholder) this.instance.placeholder.remove(); - inst._propagate("fromSortable", event); + inst._trigger("fromSortable", event); + inst.dropped = false; //draggable revert needs that } }; @@ -512,18 +575,20 @@ $.ui.plugin.add("draggable", "cursor", { start: function(event, ui) { - var t = $('body'); - if (t.css("cursor")) ui.options._cursor = t.css("cursor"); - t.css("cursor", ui.options.cursor); + var t = $('body'), o = $(this).data('draggable').options; + if (t.css("cursor")) o._cursor = t.css("cursor"); + t.css("cursor", o.cursor); }, stop: function(event, ui) { - if (ui.options._cursor) $('body').css("cursor", ui.options._cursor); + var o = $(this).data('draggable').options; + if (o._cursor) $('body').css("cursor", o._cursor); } }); $.ui.plugin.add("draggable", "iframeFix", { start: function(event, ui) { - $(ui.options.iframeFix === true ? "iframe" : ui.options.iframeFix).each(function() { + var o = $(this).data('draggable').options; + $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() { $('
') .css({ width: this.offsetWidth+"px", height: this.offsetHeight+"px", @@ -540,89 +605,74 @@ $.ui.plugin.add("draggable", "opacity", { start: function(event, ui) { - var t = $(ui.helper); - if(t.css("opacity")) ui.options._opacity = t.css("opacity"); - t.css('opacity', ui.options.opacity); + var t = $(ui.helper), o = $(this).data('draggable').options; + if(t.css("opacity")) o._opacity = t.css("opacity"); + t.css('opacity', o.opacity); }, stop: function(event, ui) { - if(ui.options._opacity) $(ui.helper).css('opacity', ui.options._opacity); + var o = $(this).data('draggable').options; + if(o._opacity) $(ui.helper).css('opacity', o._opacity); } }); $.ui.plugin.add("draggable", "scroll", { start: function(event, ui) { - var o = ui.options; var i = $(this).data("draggable"); - if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset(); - }, drag: function(event, ui) { - var o = ui.options, scrolled = false; - var i = $(this).data("draggable"); + var i = $(this).data("draggable"), o = i.options, scrolled = false; if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') { - if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) - i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed; - else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity) - i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed; + if(!o.axis || o.axis != 'x') { + if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) + i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed; + else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity) + i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed; + } - if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) - i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed; - else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity) - i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed; + if(!o.axis || o.axis != 'y') { + if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) + i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed; + else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity) + i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed; + } } else { - if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) - scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed); - else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) - scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); + if(!o.axis || o.axis != 'x') { + if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) + scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed); + else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) + scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); + } - if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) - scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); - else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) - scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); + if(!o.axis || o.axis != 'y') { + if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) + scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); + else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) + scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); + } } if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(i, event); - - - // This is a special case where we need to modify a offset calculated on start, since the following happened: - // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent - // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that - // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag - if(scrolled !== false && i.cssPosition == 'absolute' && i.scrollParent[0] != document && $.ui.contains(i.scrollParent[0], i.offsetParent[0])) { - i.offset.parent = i._getParentOffset(); - - } - - // This is another very weird special case that only happens for relative elements: - // 1. If the css position is relative - // 2. and the scroll parent is the document or similar to the offset parent - // we have to refresh the relative offset during the scroll so there are no jumps - if(scrolled !== false && i.cssPosition == 'relative' && !(i.scrollParent[0] != document && i.scrollParent[0] != i.offsetParent[0])) { - i.offset.relative = i._getRelativeOffset(); - } - - } }); $.ui.plugin.add("draggable", "snap", { start: function(event, ui) { - var inst = $(this).data("draggable"); - inst.snapElements = []; + var i = $(this).data("draggable"), o = i.options; + i.snapElements = []; - $(ui.options.snap.constructor != String ? ( ui.options.snap.items || ':data(draggable)' ) : ui.options.snap).each(function() { + $(o.snap.constructor != String ? ( o.snap.items || ':data(draggable)' ) : o.snap).each(function() { var $t = $(this); var $o = $t.offset(); - if(this != inst.element[0]) inst.snapElements.push({ + if(this != i.element[0]) i.snapElements.push({ item: this, width: $t.outerWidth(), height: $t.outerHeight(), top: $o.top, left: $o.left @@ -632,11 +682,11 @@ }, drag: function(event, ui) { - var inst = $(this).data("draggable"); - var d = ui.options.snapTolerance; + var inst = $(this).data("draggable"), o = inst.options; + var d = o.snapTolerance; - var x1 = ui.absolutePosition.left, x2 = x1 + inst.helperProportions.width, - y1 = ui.absolutePosition.top, y2 = y1 + inst.helperProportions.height; + var x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width, + y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height; for (var i = inst.snapElements.length - 1; i >= 0; i--){ @@ -650,28 +700,28 @@ continue; } - if(ui.options.snapMode != 'inner') { + if(o.snapMode != 'inner') { var ts = Math.abs(t - y2) <= d; var bs = Math.abs(b - y1) <= d; var ls = Math.abs(l - x2) <= d; var rs = Math.abs(r - x1) <= d; - if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top; - if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top; - if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left; - if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left; + if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top; + if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top; + if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left; + if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left; } var first = (ts || bs || ls || rs); - if(ui.options.snapMode != 'outer') { + if(o.snapMode != 'outer') { var ts = Math.abs(t - y1) <= d; var bs = Math.abs(b - y2) <= d; var ls = Math.abs(l - x1) <= d; var rs = Math.abs(r - x2) <= d; - if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top; - if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top; - if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left; - if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left; + if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top; + if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top; + if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left; + if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left; } if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first)) @@ -685,26 +735,31 @@ $.ui.plugin.add("draggable", "stack", { start: function(event, ui) { - var group = $.makeArray($(ui.options.stack.group)).sort(function(a,b) { - return (parseInt($(a).css("zIndex"),10) || ui.options.stack.min) - (parseInt($(b).css("zIndex"),10) || ui.options.stack.min); + + var o = $(this).data("draggable").options; + + var group = $.makeArray($(o.stack.group)).sort(function(a,b) { + return (parseInt($(a).css("zIndex"),10) || o.stack.min) - (parseInt($(b).css("zIndex"),10) || o.stack.min); }); $(group).each(function(i) { - this.style.zIndex = ui.options.stack.min + i; + this.style.zIndex = o.stack.min + i; }); - this[0].style.zIndex = ui.options.stack.min + group.length; + this[0].style.zIndex = o.stack.min + group.length; + } }); $.ui.plugin.add("draggable", "zIndex", { start: function(event, ui) { - var t = $(ui.helper); - if(t.css("zIndex")) ui.options._zIndex = t.css("zIndex"); - t.css('zIndex', ui.options.zIndex); + var t = $(ui.helper), o = $(this).data("draggable").options; + if(t.css("zIndex")) o._zIndex = t.css("zIndex"); + t.css('zIndex', o.zIndex); }, stop: function(event, ui) { - if(ui.options._zIndex) $(ui.helper).css('zIndex', ui.options._zIndex); + var o = $(this).data("draggable").options; + if(o._zIndex) $(ui.helper).css('zIndex', o._zIndex); } }); diff -r 7fbc98f3adde -r 4e2789b8e86d app/jquery/jquery-ui.sortable.js --- a/app/jquery/jquery-ui.sortable.js Mon Aug 10 16:58:51 2009 -0700 +++ b/app/jquery/jquery-ui.sortable.js Tue Aug 11 18:06:57 2009 +0100 @@ -1,7 +1,7 @@ /* - * jQuery UI Sortable 1.6 + * jQuery UI Sortable 1.7.2 * - * Copyright (c) 2008 AUTHORS.txt (http://ui.jquery.com/about) + * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * @@ -80,7 +80,7 @@ _mouseStart: function(event, overrideHandle, noActivation) { - var o = this.options; + var o = this.options, self = this; this.currentContainer = this; //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture @@ -105,7 +105,6 @@ //The element's absolute position on the page minus margins this.offset = this.currentItem.offset(); - this.offset = { top: this.offset.top - this.margins.top, left: this.offset.left - this.margins.left @@ -125,13 +124,15 @@ relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper }); + //Generate the original position + this.originalPosition = this._generatePosition(event); + this.originalPageX = event.pageX; + this.originalPageY = event.pageY; + //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied if(o.cursorAt) this._adjustOffsetFromHelper(o.cursorAt); - //Generate the original position - this.originalPosition = this._generatePosition(event); - //Cache the former DOM position this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] }; @@ -147,8 +148,27 @@ if(o.containment) this._setContainment(); - //Call plugins and callbacks - this._propagate("start", event); + if(o.cursor) { // cursor option + if ($('body').css("cursor")) this._storedCursor = $('body').css("cursor"); + $('body').css("cursor", o.cursor); + } + + if(o.opacity) { // opacity option + if (this.helper.css("opacity")) this._storedOpacity = this.helper.css("opacity"); + this.helper.css("opacity", o.opacity); + } + + if(o.zIndex) { // zIndex option + if (this.helper.css("zIndex")) this._storedZIndex = this.helper.css("zIndex"); + this.helper.css("zIndex", o.zIndex); + } + + //Prepare scrolling + if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') + this.overflowOffset = this.scrollParent.offset(); + + //Call callbacks + this._trigger("start", event, this._uiHash()); //Recache the helper size if(!this._preserveHelperProportions) @@ -157,7 +177,7 @@ //Post 'activate' events to possible containers if(!noActivation) { - for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._propagate("activate", event, this); } + for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, self._uiHash(this)); } } //Prepare possible droppables @@ -169,7 +189,7 @@ this.dragging = true; - this.helper.addClass('ui-sortable-helper'); + this.helper.addClass("ui-sortable-helper"); this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position return true; @@ -185,8 +205,38 @@ this.lastPositionAbs = this.positionAbs; } - //Call the internal plugins - $.ui.plugin.call(this, "sort", [event, this._ui()]); + //Do scrolling + if(this.options.scroll) { + var o = this.options, scrolled = false; + if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') { + + if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) + this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed; + else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) + this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed; + + if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) + this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed; + else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) + this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed; + + } else { + + if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) + scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed); + else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) + scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); + + if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) + scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); + else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) + scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); + + } + + if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) + $.ui.ddmanager.prepareOffsets(this, event); + } //Regenerate the absolute position used for position checks this.positionAbs = this._convertPositionTo("absolute"); @@ -211,12 +261,12 @@ this.direction = intersection == 1 ? "down" : "up"; if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) { - this.options.sortIndicator.call(this, event, item); + this._rearrange(event, item); } else { break; } - this._propagate("change", event); //Call plugins and callbacks + this._trigger("change", event, this._uiHash()); break; } } @@ -228,7 +278,7 @@ if($.ui.ddmanager) $.ui.ddmanager.drag(this, event); //Call callbacks - this._trigger('sort', event, this._ui()); + this._trigger('sort', event, this._uiHash()); this.lastPositionAbs = this.positionAbs; return false; @@ -265,6 +315,8 @@ cancel: function() { + var self = this; + if(this.dragging) { this._mouseUp(); @@ -276,9 +328,9 @@ //Post deactivating events to containers for (var i = this.containers.length - 1; i >= 0; i--){ - this.containers[i]._propagate("deactivate", null, this); + this.containers[i]._trigger("deactivate", null, self._uiHash(this)); if(this.containers[i].containerCache.over) { - this.containers[i]._propagate("out", null, this); + this.containers[i]._trigger("out", null, self._uiHash(this)); this.containers[i].containerCache.over = 0; } } @@ -410,15 +462,23 @@ this.refreshPositions(); }, + _connectWith: function() { + var options = this.options; + return options.connectWith.constructor == String + ? [options.connectWith] + : options.connectWith; + }, + _getItemsAsjQuery: function(connected) { var self = this; var items = []; var queries = []; + var connectWith = this._connectWith(); - if(this.options.connectWith && connected) { - for (var i = this.options.connectWith.length - 1; i >= 0; i--){ - var cur = $(this.options.connectWith[i]); + if(connectWith && connected) { + for (var i = connectWith.length - 1; i >= 0; i--){ + var cur = $(connectWith[i]); for (var j = cur.length - 1; j >= 0; j--){ var inst = $.data(cur[j], 'sortable'); if(inst && inst != this && !inst.options.disabled) { @@ -462,10 +522,11 @@ var items = this.items; var self = this; var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]]; + var connectWith = this._connectWith(); - if(this.options.connectWith) { - for (var i = this.options.connectWith.length - 1; i >= 0; i--){ - var cur = $(this.options.connectWith[i]); + if(connectWith) { + for (var i = connectWith.length - 1; i >= 0; i--){ + var cur = $(connectWith[i]); for (var j = cur.length - 1; j >= 0; j--){ var inst = $.data(cur[j], 'sortable'); if(inst && inst != this && !inst.options.disabled) { @@ -513,14 +574,8 @@ var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item; if (!fast) { - if (this.options.accurateIntersection) { - item.width = t.outerWidth(); - item.height = t.outerHeight(); - } - else { - item.width = t[0].offsetWidth; - item.height = t[0].offsetHeight; - } + item.width = t.outerWidth(); + item.height = t.outerHeight(); } var p = t.offset(); @@ -553,21 +608,20 @@ var el = $(document.createElement(self.currentItem[0].nodeName)) .addClass(className || self.currentItem[0].className+" ui-sortable-placeholder") - .removeClass('ui-sortable-helper')[0]; + .removeClass("ui-sortable-helper")[0]; - if(!className) { + if(!className) el.style.visibility = "hidden"; - document.body.appendChild(el); - // Name attributes are removed, otherwice causes elements to be unchecked - // Expando attributes also have to be removed because of stupid IE (no condition, doesn't hurt in other browsers) - el.innerHTML = self.currentItem[0].innerHTML.replace(/name\=\"[^\"\']+\"/g, '').replace(/jQuery[0-9]+\=\"[^\"\']+\"/g, ''); - document.body.removeChild(el); - }; return el; }, update: function(container, p) { + + // 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that + // 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified if(className && !o.forcePlaceholderSize) return; + + //If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item if(!p.height()) { p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10)); }; if(!p.width()) { p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10)); }; } @@ -607,21 +661,21 @@ continue; this.currentContainer = this.containers[i]; - itemWithLeastDistance ? this.options.sortIndicator.call(this, event, itemWithLeastDistance, null, true) : this.options.sortIndicator.call(this, event, null, this.containers[i].element, true); - this._propagate("change", event); //Call plugins and callbacks - this.containers[i]._propagate("change", event, this); //Call plugins and callbacks + itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[i].element, true); + this._trigger("change", event, this._uiHash()); + this.containers[i]._trigger("change", event, this._uiHash(this)); //Update the placeholder this.options.placeholder.update(this.currentContainer, this.placeholder); } - this.containers[i]._propagate("over", event, this); + this.containers[i]._trigger("over", event, this._uiHash(this)); this.containers[i].containerCache.over = 1; } } else { if(this.containers[i].containerCache.over) { - this.containers[i]._propagate("out", event, this); + this.containers[i]._trigger("out", event, this._uiHash(this)); this.containers[i].containerCache.over = 0; } } @@ -656,10 +710,21 @@ _getParentOffset: function() { + //Get the offsetParent and cache its position - this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset(); + this.offsetParent = this.helper.offsetParent(); + var po = this.offsetParent.offset(); - if((this.offsetParent[0] == document.body && $.browser.mozilla) //Ugly FF3 fix + // This is a special case where we need to modify a offset calculated on start, since the following happened: + // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent + // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that + // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag + if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) { + po.left += this.scrollParent.scrollLeft(); + po.top += this.scrollParent.scrollTop(); + } + + if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix po = { top: 0, left: 0 }; @@ -705,8 +770,8 @@ if(o.containment == 'document' || o.containment == 'window') this.containment = [ 0 - this.offset.relative.left - this.offset.parent.left, 0 - this.offset.relative.top - this.offset.parent.top, - $(o.containment == 'document' ? document : window).width() - this.offset.relative.left - this.offset.parent.left - this.margins.left - (parseInt(this.currentItem.css("marginRight"),10) || 0), - ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.offset.relative.top - this.offset.parent.top - this.margins.top - (parseInt(this.currentItem.css("marginBottom"),10) || 0) + $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left, + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top ]; if(!(/^(document|window|parent)$/).test(o.containment)) { @@ -715,10 +780,10 @@ var over = ($(ce).css("overflow") != 'hidden'); this.containment = [ - co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left - this.margins.left, - co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top - this.margins.top, - co.left + (over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left - this.margins.left, - co.top + (over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top - this.margins.top + co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left, + co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top, + co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left, + co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top ]; } @@ -728,69 +793,81 @@ if(!pos) pos = this.position; var mod = d == "absolute" ? 1 : -1; - var scroll = this[(this.cssPosition == 'absolute' ? 'offset' : 'scroll')+'Parent'], scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); + var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); return { top: ( - pos.top // the calculated relative position - + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent + pos.top // The absolute mouse position + + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border) - + ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod - + this.margins.top * mod //Add the margin (you don't want the margin counting in intersection methods) + - ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod) ), left: ( - pos.left // the calculated relative position - + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent + pos.left // The absolute mouse position + + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border) - + ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : ( scrollIsRootNode ? 0 : scroll.scrollLeft() ) ) * mod - + this.margins.left * mod //Add the margin (you don't want the margin counting in intersection methods) + - ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod) ) }; + }, _generatePosition: function(event) { - var o = this.options, scroll = this[(this.cssPosition == 'absolute' ? 'offset' : 'scroll')+'Parent'], scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); + var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); - var position = { - top: ( - event.pageY // The absolute mouse position - - this.offset.click.top // Click offset (relative to the element) - - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent - - this.offset.parent.top // The offsetParent's offset without borders (offset + border) - + ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) - ), - left: ( - event.pageX // The absolute mouse position - - this.offset.click.left // Click offset (relative to the element) - - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent - - this.offset.parent.left // The offsetParent's offset without borders (offset + border) - + ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : ( scrollIsRootNode ? 0 : scroll.scrollLeft() ) ) - ) - }; + // This is another very weird special case that only happens for relative elements: + // 1. If the css position is relative + // 2. and the scroll parent is the document or similar to the offset parent + // we have to refresh the relative offset during the scroll so there are no jumps + if(this.cssPosition == 'relative' && !(this.scrollParent[0] != document && this.scrollParent[0] != this.offsetParent[0])) { + this.offset.relative = this._getRelativeOffset(); + } - if(!this.originalPosition) return position; //If we are not dragging yet, we won't check for options + var pageX = event.pageX; + var pageY = event.pageY; /* * - Position constraining - * Constrain the position to a mix of grid, containment. */ - if(this.containment) { - if(position.left < this.containment[0]) position.left = this.containment[0]; - if(position.top < this.containment[1]) position.top = this.containment[1]; - if(position.left + this.helperProportions.width > this.containment[2]) position.left = this.containment[2] - this.helperProportions.width; - if(position.top + this.helperProportions.height > this.containment[3]) position.top = this.containment[3] - this.helperProportions.height; + + if(this.originalPosition) { //If we are not dragging yet, we won't check for options + + if(this.containment) { + if(event.pageX - this.offset.click.left < this.containment[0]) pageX = this.containment[0] + this.offset.click.left; + if(event.pageY - this.offset.click.top < this.containment[1]) pageY = this.containment[1] + this.offset.click.top; + if(event.pageX - this.offset.click.left > this.containment[2]) pageX = this.containment[2] + this.offset.click.left; + if(event.pageY - this.offset.click.top > this.containment[3]) pageY = this.containment[3] + this.offset.click.top; + } + + if(o.grid) { + var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1]; + pageY = this.containment ? (!(top - this.offset.click.top < this.containment[1] || top - this.offset.click.top > this.containment[3]) ? top : (!(top - this.offset.click.top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; + + var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0]; + pageX = this.containment ? (!(left - this.offset.click.left < this.containment[0] || left - this.offset.click.left > this.containment[2]) ? left : (!(left - this.offset.click.left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; + } + } - if(o.grid) { - var top = this.originalPosition.top + Math.round((position.top - this.originalPosition.top) / o.grid[1]) * o.grid[1]; - position.top = this.containment ? (!(top < this.containment[1] || top > this.containment[3]) ? top : (!(top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; + return { + top: ( + pageY // The absolute mouse position + - this.offset.click.top // Click offset (relative to the element) + - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent + - this.offset.parent.top // The offsetParent's offset without borders (offset + border) + + ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) )) + ), + left: ( + pageX // The absolute mouse position + - this.offset.click.left // Click offset (relative to the element) + - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent + - this.offset.parent.left // The offsetParent's offset without borders (offset + border) + + ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() )) + ) + }; - var left = this.originalPosition.left + Math.round((position.left - this.originalPosition.left) / o.grid[0]) * o.grid[0]; - position.left = this.containment ? (!(left < this.containment[0] || left > this.containment[2]) ? left : (!(left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; - } - - return position; }, _rearrange: function(event, i, a, hardRefresh) { @@ -814,9 +891,13 @@ _clear: function(event, noPropagation) { this.reverting = false; + // We delay all events that have to be triggered to after the point where the placeholder has been removed and + // everything else normalized again + var delayedTriggers = [], self = this; - //We first have to update the dom position of the actual currentItem - if(!this._noFinalSort) this.placeholder.before(this.currentItem); + // We first have to update the dom position of the actual currentItem + // Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088) + if(!this._noFinalSort && this.currentItem[0].parentNode) this.placeholder.before(this.currentItem); this._noFinalSort = null; if(this.helper[0] == this.currentItem[0]) { @@ -828,60 +909,73 @@ this.currentItem.show(); } - if(this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) this._propagate("update", event, null, noPropagation); //Trigger update callback if the DOM position has changed + if(this.fromOutside && !noPropagation) delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); }); + if((this.fromOutside || this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) && !noPropagation) delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed if(!$.ui.contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element - this._propagate("remove", event, null, noPropagation); + if(!noPropagation) delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); }); for (var i = this.containers.length - 1; i >= 0; i--){ - if($.ui.contains(this.containers[i].element[0], this.currentItem[0])) { - this.containers[i]._propagate("update", event, this, noPropagation); - this.containers[i]._propagate("receive", event, this, noPropagation); + if($.ui.contains(this.containers[i].element[0], this.currentItem[0]) && !noPropagation) { + delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.containers[i])); + delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.containers[i])); } }; }; //Post events to containers for (var i = this.containers.length - 1; i >= 0; i--){ - this.containers[i]._propagate("deactivate", event, this, noPropagation); + if(!noPropagation) delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i])); if(this.containers[i].containerCache.over) { - this.containers[i]._propagate("out", event, this); + delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); }; }).call(this, this.containers[i])); this.containers[i].containerCache.over = 0; } } + //Do what was originally in plugins + if(this._storedCursor) $('body').css("cursor", this._storedCursor); //Reset cursor + if(this._storedOpacity) this.helper.css("opacity", this._storedOpacity); //Reset cursor + if(this._storedZIndex) this.helper.css("zIndex", this._storedZIndex == 'auto' ? '' : this._storedZIndex); //Reset z-index + this.dragging = false; if(this.cancelHelperRemoval) { - this._propagate("beforeStop", event, null, noPropagation); - this._propagate("stop", event, null, noPropagation); + if(!noPropagation) { + this._trigger("beforeStop", event, this._uiHash()); + for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events + this._trigger("stop", event, this._uiHash()); + } return false; } - this._propagate("beforeStop", event, null, noPropagation); + if(!noPropagation) this._trigger("beforeStop", event, this._uiHash()); //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node! this.placeholder[0].parentNode.removeChild(this.placeholder[0]); - if(this.options.helper != "original") this.helper.remove(); this.helper = null; - this._propagate("stop", event, null, noPropagation); + if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null; + if(!noPropagation) { + for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events + this._trigger("stop", event, this._uiHash()); + } + + this.fromOutside = false; return true; }, - _propagate: function(n, event, inst, noPropagation) { - $.ui.plugin.call(this, n, [event, this._ui(inst)]); - var dontCancel = !noPropagation ? this.element.triggerHandler(n == "sort" ? n : "sort"+n, [event, this._ui(inst)], this.options[n]) : true; - if(dontCancel === false) this.cancel(); + _trigger: function() { + if ($.widget.prototype._trigger.apply(this, arguments) === false) { + this.cancel(); + } }, - plugins: {}, - - _ui: function(inst) { + _uiHash: function(inst) { var self = inst || this; return { helper: self.helper, placeholder: self.placeholder || $([]), position: self.position, - absolutePosition: self.positionAbs, + absolutePosition: self.positionAbs, //deprecated + offset: self.positionAbs, item: self.currentItem, sender: inst ? inst.element : null }; @@ -891,125 +985,35 @@ $.extend($.ui.sortable, { getter: "serialize toArray", - version: "1.6", + version: "1.7.2", + eventPrefix: "sort", defaults: { - accurateIntersection: true, appendTo: "parent", - cancel: ":input", + axis: false, + cancel: ":input,option", + connectWith: false, + containment: false, + cursor: 'auto', + cursorAt: false, delay: 0, distance: 1, dropOnEmpty: true, forcePlaceholderSize: false, forceHelperSize: false, + grid: false, + handle: false, helper: "original", items: '> *', - scope: "default", + opacity: false, + placeholder: false, + revert: false, scroll: true, scrollSensitivity: 20, scrollSpeed: 20, - sortIndicator: $.ui.sortable.prototype._rearrange, - tolerance: "default", + scope: "default", + tolerance: "intersect", zIndex: 1000 } }); -/* - * Sortable Extensions - */ - -$.ui.plugin.add("sortable", "cursor", { - start: function(event, ui) { - var t = $('body'), i = $(this).data('sortable'); - if (t.css("cursor")) i.options._cursor = t.css("cursor"); - t.css("cursor", i.options.cursor); - }, - beforeStop: function(event, ui) { - var i = $(this).data('sortable'); - if (i.options._cursor) $('body').css("cursor", i.options._cursor); - } -}); - -$.ui.plugin.add("sortable", "opacity", { - start: function(event, ui) { - var t = ui.helper, i = $(this).data('sortable'); - if(t.css("opacity")) i.options._opacity = t.css("opacity"); - t.css('opacity', i.options.opacity); - }, - beforeStop: function(event, ui) { - var i = $(this).data('sortable'); - if(i.options._opacity) $(ui.helper).css('opacity', i.options._opacity); - } -}); - -$.ui.plugin.add("sortable", "scroll", { - start: function(event, ui) { - var i = $(this).data("sortable"), o = i.options; - if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset(); - }, - sort: function(event, ui) { - - var i = $(this).data("sortable"), o = i.options, scrolled = false; - - if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') { - - if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) - i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed; - else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity) - i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed; - - if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) - i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed; - else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity) - i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed; - - } else { - - if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) - scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed); - else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) - scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); - - if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) - scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); - else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) - scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); - - } - - if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) - $.ui.ddmanager.prepareOffsets(i, event); - - - - //This is a special case where we need to modify a offset calculated on start, since the following happened: - // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent - // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that - // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag - if(scrolled !== false && i.cssPosition == 'absolute' && i.scrollParent[0] != document && $.ui.contains(i.scrollParent[0], i.offsetParent[0])) { - i.offset.parent = i._getParentOffset(); - } - - // This is another very weird special case that only happens for relative elements: - // 1. If the css position is relative - // 2. and the scroll parent is the document or similar to the offset parent - // we have to refresh the relative offset during the scroll so there are no jumps - if(scrolled !== false && i.cssPosition == 'relative' && !(i.scrollParent[0] != document && i.scrollParent[0] != i.offsetParent[0])) { - i.offset.relative = i._getRelativeOffset(); - } - - } -}); - -$.ui.plugin.add("sortable", "zIndex", { - start: function(event, ui) { - var t = ui.helper, i = $(this).data('sortable'); - if(t.css("zIndex")) i.options._zIndex = t.css("zIndex"); - t.css('zIndex', i.options.zIndex); - }, - beforeStop: function(event, ui) { - var i = $(this).data('sortable'); - if(i.options._zIndex) $(ui.helper).css('zIndex', i.options._zIndex == 'auto' ? '' : i.options._zIndex); - } -}); - })(jQuery);