From 05b1d23990fac44996fb0c8c88275260d7f869fb Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Tue, 27 Sep 2011 21:10:59 -0400
Subject: [PATCH 001/190] Draggable: Initial commit for new implementation,
clone is only usable option
---
ui/jquery.ui.draggable.js | 860 ++++++--------------------------------
1 file changed, 137 insertions(+), 723 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 6475ebd6116..c3d3d8e9262 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -1,5 +1,5 @@
/*
- * jQuery UI Draggable @VERSION
+ * jQuery UI Draggable 2.0.0
*
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
@@ -9,812 +9,226 @@
*
* Depends:
* jquery.ui.core.js
- * jquery.ui.mouse.js
* jquery.ui.widget.js
*/
(function( $, undefined ) {
-$.widget("ui.draggable", $.ui.mouse, {
- version: "@VERSION",
+$.widget("ui.draggable", {
widgetEventPrefix: "drag",
options: {
- addClasses: true,
- appendTo: "parent",
- axis: false,
- connectToSortable: false,
- containment: false,
- cursor: "auto",
- cursorAt: false,
- grid: false,
- handle: false,
- helper: "original",
- iframeFix: false,
- opacity: false,
- refreshPositions: false,
- revert: false,
- revertDuration: 500,
- scope: "default",
- scroll: true,
- scrollSensitivity: 20,
- scrollSpeed: 20,
- snap: false,
- snapMode: "both",
- snapTolerance: 20,
- stack: false,
- zIndex: false
- },
- _create: function() {
-
- if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
- this.element[0].style.position = 'relative';
-
- (this.options.addClasses && this.element.addClass("ui-draggable"));
- (this.options.disabled && this.element.addClass("ui-draggable-disabled"));
-
- this._mouseInit();
-
- },
- destroy: function() {
- if(!this.element.data('draggable')) return;
- this.element
- .removeData("draggable")
- .unbind(".draggable")
- .removeClass("ui-draggable"
- + " ui-draggable-dragging"
- + " ui-draggable-disabled");
- this._mouseDestroy();
+ helper : false
- return this;
},
- _mouseCapture: function(event) {
-
- var o = this.options;
-
- // among others, prevent a drag on a resizable-handle
- if (this.helper || o.disabled || $(event.target).is('.ui-resizable-handle'))
- return false;
-
- //Quit if we're not on a valid handle
- this.handle = this._getHandle(event);
- if (!this.handle)
- return false;
-
- $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() {
- $('')
- .css({
- width: this.offsetWidth+"px", height: this.offsetHeight+"px",
- position: "absolute", opacity: "0.001", zIndex: 1000
- })
- .css($(this).offset())
- .appendTo("body");
- });
+ drag_el : false, // either element or the helper
- return true;
+ position : {},
+ offset : {},
- },
-
- _mouseStart: function(event) {
-
- var o = this.options;
-
- //Create and append the visible helper
- this.helper = this._createHelper(event);
-
- //Cache the helper size
- this._cacheHelperProportions();
-
- //If ddmanager is used for droppables, set the global draggable
- if($.ui.ddmanager)
- $.ui.ddmanager.current = this;
-
- /*
- * - Position generation -
- * This block generates everything position related - it's the core of draggables.
- */
-
- //Cache the margins of the original element
- this._cacheMargins();
-
- //Store the helper's css position
- this.cssPosition = this.helper.css("position");
- this.scrollParent = this.helper.scrollParent();
-
- //The element's absolute position on the page minus margins
- this.offset = this.positionAbs = this.element.offset();
- this.offset = {
- top: this.offset.top - this.margins.top,
- left: this.offset.left - this.margins.left
- };
+ _start_coords : {}, // start X/Y coords of mouse before drag
+ _start_position : {}, // start position of element before drag
+ _start_offset : {}, // start offset of element before drag
- $.extend(this.offset, {
- click: { //Where the click happened, relative to the element
- left: event.pageX - this.offset.left,
- top: event.pageY - this.offset.top
- },
- parent: this._getParentOffset(),
- 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.position = this._generatePosition(event);
- this.originalPageX = event.pageX;
- this.originalPageY = event.pageY;
-
- //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
- (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
-
- //Set a containment if given in the options
- if(o.containment)
- this._setContainment();
-
- //Trigger event + callbacks
- if(this._trigger("start", event) === false) {
- this._clear();
- return false;
- }
-
- //Recache the helper size
- this._cacheHelperProportions();
-
- //Prepare the droppable offsets
- if ($.ui.ddmanager && !o.dropBehaviour)
- $.ui.ddmanager.prepareOffsets(this, event);
-
- this.helper.addClass("ui-draggable-dragging");
- this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
-
- //If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
- if ( $.ui.ddmanager ) $.ui.ddmanager.dragStart(this, event);
-
- return true;
- },
+ _create: function() {
- _mouseDrag: function(event, noPropagation) {
+ this.scrollParent = this.element.scrollParent();
- //Compute the helpers position
- this.position = this._generatePosition(event);
- this.positionAbs = this._convertPositionTo("absolute");
+ // Static position elements can't be moved with top/left
+ if ( this.element.css( "position" ) === "static" ) {
+ this.element.css( "position", "relative" );
+ }
- //Call plugins and callbacks and use the resulting position if something is returned
- if (!noPropagation) {
- var ui = this._uiHash();
- if(this._trigger('drag', event, ui) === false) {
- this._mouseUp({});
- return false;
- }
- this.position = ui.position;
- }
+ // Prevent browser from hijacking drag
+ this.element.disableSelection();
- 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';
- if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
+ // Using proxy to avoid anon functions using self to pass "this" along
+ this.element.bind( "mousedown." + this.widgetName, $.proxy( this._mouseDown, this ) );
- return false;
- },
+ }, // _create
- _mouseStop: function(event) {
-
- //If we are using droppables, inform the manager about the drop
- var dropped = false;
- if ($.ui.ddmanager && !this.options.dropBehaviour)
- dropped = $.ui.ddmanager.drop(this, event);
-
- //if a drop comes from outside (a sortable)
- if(this.dropped) {
- dropped = this.dropped;
- this.dropped = false;
- }
-
- //if the original element is removed, don't bother to continue
- if(!this.element[0] || !this.element[0].parentNode)
- return 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() {
- if(self._trigger("stop", event) !== false) {
- self._clear();
- }
- });
- } else {
- if(this._trigger("stop", event) !== false) {
- this._clear();
- }
- }
-
- return false;
- },
-
- _mouseUp: function(event) {
- if (this.options.iframeFix === true) {
- $("div.ui-draggable-iframeFix").each(function() {
- this.parentNode.removeChild(this);
- }); //Remove frame helpers
- }
-
- //If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003)
- if( $.ui.ddmanager ) $.ui.ddmanager.dragStop(this, event);
-
- return $.ui.mouse.prototype._mouseUp.call(this, event);
- },
-
- cancel: function() {
-
- if(this.helper.is(".ui-draggable-dragging")) {
- this._mouseUp({});
- } else {
- this._clear();
- }
-
+ destroy: function() {
return this;
-
- },
-
- _getHandle: function(event) {
-
- var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
- $(this.options.handle, this.element)
- .find("*")
- .andSelf()
- .each(function() {
- if(this == event.target) handle = true;
- });
-
- return handle;
-
- },
-
- _createHelper: function(event) {
-
- var o = this.options;
- var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper == 'clone' ? this.element.clone().removeAttr('id') : this.element);
-
- if(!helper.parents('body').length)
- helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo));
-
- if(helper[0] != this.element[0] && !(/(fixed|absolute)/).test(helper.css("position")))
- helper.css("position", "absolute");
-
- return helper;
-
- },
-
- _adjustOffsetFromHelper: function(obj) {
- if (typeof obj == 'string') {
- obj = obj.split(' ');
- }
- if ($.isArray(obj)) {
- obj = {left: +obj[0], top: +obj[1] || 0};
- }
- if ('left' in obj) {
- this.offset.click.left = obj.left + this.margins.left;
- }
- if ('right' in obj) {
- this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
- }
- if ('top' in obj) {
- this.offset.click.top = obj.top + this.margins.top;
- }
- if ('bottom' in obj) {
- this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
- }
- },
-
- _getParentOffset: function() {
-
- //Get the offsetParent and cache its position
- this.offsetParent = this.helper.offsetParent();
- var po = this.offsetParent.offset();
+ }, // destroy
- // 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 && $.contains(this.scrollParent[0], this.offsetParent[0])) {
- po.left += this.scrollParent.scrollLeft();
- po.top += this.scrollParent.scrollTop();
- }
+ _setPosition : function() {
- 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 };
+ var left, top, position, css_position;
- return {
- top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
- left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
- };
+ // Helper is appended to body so offset of element is all that's needed
+ if ( this.options.helper === true ) {
+ return this.element.offset();
+ }
- },
+ css_position = this.drag_el.css( "position" );;
- _getRelativeOffset: function() {
+ // If fixed or absolute
+ if ( css_position !== "relative" ) {
- if(this.cssPosition == "relative") {
- var p = this.element.position();
- return {
- top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
- left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
- };
- } else {
- return { top: 0, left: 0 };
- }
+ position = this.drag_el.position();
- },
+ if ( css_position === "absolute" ) {
+ return position;
+ }
- _cacheMargins: function() {
- this.margins = {
- left: (parseInt(this.element.css("marginLeft"),10) || 0),
- top: (parseInt(this.element.css("marginTop"),10) || 0),
- right: (parseInt(this.element.css("marginRight"),10) || 0),
- bottom: (parseInt(this.element.css("marginBottom"),10) || 0)
- };
- },
+ // Take into account scrollbar for fixed position
+ position.top = position.top - this.scrollParent.scrollTop();
+ position.left = position.left - this.scrollParent.scrollLeft();
- _cacheHelperProportions: function() {
- this.helperProportions = {
- width: this.helper.outerWidth(),
- height: this.helper.outerHeight()
- };
- },
+ return position;
- _setContainment: function() {
-
- var o = this.options;
- if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
- if(o.containment == 'document' || o.containment == 'window') this.containment = [
- o.containment == 'document' ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
- o.containment == 'document' ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top,
- (o.containment == 'document' ? 0 : $(window).scrollLeft()) + $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left,
- (o.containment == 'document' ? 0 : $(window).scrollTop()) + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
- ];
-
- if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor != Array) {
- var c = $(o.containment);
- var ce = c[0]; if(!ce) return;
- var co = c.offset();
- var over = ($(ce).css("overflow") != 'hidden');
-
- this.containment = [
- (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0),
- (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0),
- (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 - this.margins.right,
- (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 - this.margins.bottom
- ];
- this.relative_container = c;
-
- } else if(o.containment.constructor == Array) {
- this.containment = o.containment;
- }
+ } // css_position !+== absolute
- },
+ /** When using relative, css values are checked **/
- _convertPositionTo: function(d, pos) {
+ left = this.drag_el.css( "left" );
+ top = this.drag_el.css( "top" );
- if(!pos) pos = this.position;
- var mod = d == "absolute" ? 1 : -1;
- var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
+ // Webkit will give back auto if there is nothing inline yet
+ left = ( left === "auto" ) ? 0 : parseInt( left, 10 );
+ top = ( top === "auto" ) ? 0 : parseInt( top, 10 );
- return {
- top: (
- 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)
- - ($.browser.safari && $.browser.version < 526 && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
- ),
- left: (
- 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)
- - ($.browser.safari && $.browser.version < 526 && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
- )
- };
+ return {
- },
+ left : left,
+ top : top
- _generatePosition: function(event) {
-
- var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
- var pageX = event.pageX;
- var pageY = event.pageY;
-
- /*
- * - Position constraining -
- * Constrain the position to a mix of grid, containment.
- */
-
- if(this.originalPosition) { //If we are not dragging yet, we won't check for options
- var containment;
- if(this.containment) {
- if (this.relative_container){
- var co = this.relative_container.offset();
- containment = [ this.containment[0] + co.left,
- this.containment[1] + co.top,
- this.containment[2] + co.left,
- this.containment[3] + co.top ];
- }
- else {
- containment = this.containment;
- }
-
- if(event.pageX - this.offset.click.left < containment[0]) pageX = containment[0] + this.offset.click.left;
- if(event.pageY - this.offset.click.top < containment[1]) pageY = containment[1] + this.offset.click.top;
- if(event.pageX - this.offset.click.left > containment[2]) pageX = containment[2] + this.offset.click.left;
- if(event.pageY - this.offset.click.top > containment[3]) pageY = containment[3] + this.offset.click.top;
- }
-
- if(o.grid) {
- //Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950)
- var top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY;
- pageY = containment ? (!(top - this.offset.click.top < containment[1] || top - this.offset.click.top > containment[3]) ? top : (!(top - this.offset.click.top < containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
-
- var left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX;
- pageX = containment ? (!(left - this.offset.click.left < containment[0] || left - this.offset.click.left > containment[2]) ? left : (!(left - this.offset.click.left < containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
- }
-
- }
+ };
- 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 && $.browser.version < 526 && 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 && $.browser.version < 526 && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
- )
- };
+ }, // _setPosition
- },
+ _mouseDown : function( event ) {
- _clear: function() {
- this.helper.removeClass("ui-draggable-dragging");
- if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval) this.helper.remove();
- //if($.ui.ddmanager) $.ui.ddmanager.current = null;
- this.helper = null;
- this.cancelHelperRemoval = false;
- },
+ var el_position;
+
+ this.drag_el = this.element;
- // From now on bulk stuff - mainly helpers
+ // Helper required, so clone, hide, and set reference
+ if ( this.options.helper === true ) {
- _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);
- },
+ this.drag_el = this.element.clone();
- plugins: {},
+ // If source element has an ID, change ID of helper to avoid overlap
+ if ( this.element.attr( 'id' ) ) {
- _uiHash: function(event) {
- return {
- helper: this.helper,
- position: this.position,
- originalPosition: this.originalPosition,
- offset: this.positionAbs
- };
- }
+ this.drag_el
+ .css({
+ position : 'absolute',
+ display : 'none'
+ })
+ .disableSelection()
+ .attr( 'id', this.element.attr( 'id' ) + '-' + this.widgetName );
-});
+ } // id
-$.ui.plugin.add("draggable", "connectToSortable", {
- start: function(event, ui) {
-
- var inst = $(this).data("draggable"), o = inst.options,
- uiSortable = $.extend({}, ui, { item: inst.element });
- inst.sortables = [];
- $(o.connectToSortable).each(function() {
- var sortable = $.data(this, 'sortable');
- if (sortable && !sortable.options.disabled) {
- inst.sortables.push({
- instance: sortable,
- shouldRevert: sortable.options.revert
- });
- sortable.refreshPositions(); // Call the sortable's refreshPositions at drag start to refresh the containerCache since the sortable container cache is used in drag and needs to be up to date (this will ensure it's initialised as well as being kept in step with any changes that might have happened on the page).
- sortable._trigger("activate", event, uiSortable);
- }
- });
+ $('body').append( this.drag_el );
- },
- stop: function(event, ui) {
+ } // if this.options.helper = true
- //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
- var inst = $(this).data("draggable"),
- uiSortable = $.extend({}, ui, { item: inst.element });
+ // Cache starting absolute and relative positions
+ this._start_position = this._setPosition();
+ this._start_offset = this.drag_el.offset();
- $.each(inst.sortables, function() {
- if(this.instance.isOver) {
+ // Cache current position and offset
+ this.position = $.extend( {}, this._start_position );
+ this.offset = $.extend( {}, this._start_offset );
- this.instance.isOver = 0;
+ this._start_coords = {
+ left : event.clientX,
+ top : event.clientY
+ };
- 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)
+ this._trigger( "start", event );
- //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;
+ $(document).bind( "mousemove." + this.widgetName, $.proxy( this._mouseMove, this ) );
+ $(document).bind( "mouseup." + this.widgetName, $.proxy( this._mouseUp, this ) );
- //Trigger the stop of the sortable
- this.instance._mouseStop(event);
- this.instance.options.helper = this.instance.options._helper;
+ // Set the helper up by actual element
+ if ( this.options.helper === true ) {
- //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' });
+ // get the absolute position of element so that helper will know where to go
+ el_offset = this.element.offset();
- } else {
- this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
- this.instance._trigger("deactivate", event, uiSortable);
- }
+ this.drag_el.css({
+ display : 'block',
+ top : el_offset.top + 'px',
+ left : el_offset.left + 'px'
+ });
- });
+ } // this.options.height = true
- },
- drag: function(event, ui) {
+ }, // _mouseDown
- var inst = $(this).data("draggable"), self = this;
+ _mouseMove : function( event ) {
- var checkPos = function(o) {
- var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
- var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
- var itemHeight = o.height, itemWidth = o.width;
- var itemTop = o.top, itemLeft = o.left;
+ var left_diff = event.clientX - this._start_coords.left,
+ top_diff = event.clientY - this._start_coords.top,
+ new_left = left_diff + this._start_position.left,
+ new_top = top_diff + this._start_position.top;
- return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth);
- };
+ this.position = {
+ left : new_left,
+ top : new_top
+ };
- $.each(inst.sortables, function(i) {
-
- //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
- //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
- this.instance.currentItem = $(self).clone().removeAttr('id').appendTo(this.instance.element).data("sortable-item", true);
- this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
- this.instance.options.helper = function() { return ui.helper[0]; };
-
- event.target = this.instance.currentItem[0];
- this.instance._mouseCapture(event, true);
- this.instance._mouseStart(event, true, true);
-
- //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
- this.instance.offset.click.top = inst.offset.click.top;
- this.instance.offset.click.left = inst.offset.click.left;
- 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._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;
-
- }
-
- //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
- if(this.instance.currentItem) this.instance._mouseDrag(event);
-
- } else {
-
- //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;
-
- //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;
-
- //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
- this.instance.currentItem.remove();
- if(this.instance.placeholder) this.instance.placeholder.remove();
-
- inst._trigger("fromSortable", event);
- inst.dropped = false; //draggable revert needs that
- }
-
- };
-
- });
-
- }
-});
+ // Refresh offset cache with new positions
+ this.offset.left = this._start_offset.left + new_left;
+ this.offset.top = this._start_offset.top + new_top;
-$.ui.plugin.add("draggable", "cursor", {
- start: function(event, ui) {
- 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) {
- var o = $(this).data('draggable').options;
- if (o._cursor) $('body').css("cursor", o._cursor);
- }
-});
+ this._trigger( "drag", event );
-$.ui.plugin.add("draggable", "opacity", {
- start: function(event, ui) {
- 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) {
- var o = $(this).data('draggable').options;
- if(o._opacity) $(ui.helper).css('opacity', o._opacity);
- }
-});
+ // User overriding left/top so shortcut math is no longer valid
+ if ( new_left !== this.position.left || new_top !== this.position.top ) {
-$.ui.plugin.add("draggable", "scroll", {
- start: function(event, ui) {
- var i = $(this).data("draggable");
- if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset();
- },
- drag: function(event, ui) {
+ // refresh offset using slower functions
+ this.offset = this.drag_el.offset();
- var i = $(this).data("draggable"), o = i.options, scrolled = false;
+ }
- if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') {
+ this.drag_el.css({
- 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;
- }
+ left : this.position.left + 'px',
+ top : this.position.top + 'px'
- 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 {
+ }, // _mouseMove
- 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);
- }
+ _mouseUp : function( event ) {
- 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);
- }
+ this._trigger( "stop", event );
- }
+ this._start_coords = {};
- if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
- $.ui.ddmanager.prepareOffsets(i, event);
+ if ( this.options.helper === true ) {
+ this.drag_el.remove();
+ }
- }
-});
+ $(document).unbind( "mousemove." + this.widgetName );
+ $(document).unbind( "mouseup." + this.widgetName );
-$.ui.plugin.add("draggable", "snap", {
- start: function(event, ui) {
+ }, // _mouseUp
- var i = $(this).data("draggable"), o = i.options;
- i.snapElements = [];
+ _trigger: function(type, event, ui) {
- $(o.snap.constructor != String ? ( o.snap.items || ':data(draggable)' ) : o.snap).each(function() {
- var $t = $(this); var $o = $t.offset();
- if(this != i.element[0]) i.snapElements.push({
- item: this,
- width: $t.outerWidth(), height: $t.outerHeight(),
- top: $o.top, left: $o.left
- });
- });
+ ui = ui || this._uiHash();
- },
- drag: function(event, ui) {
-
- var inst = $(this).data("draggable"), o = inst.options;
- var d = o.snapTolerance;
-
- 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--){
-
- var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width,
- t = inst.snapElements[i].top, b = t + inst.snapElements[i].height;
-
- //Yes, I know, this is insane ;)
- if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) {
- if(inst.snapElements[i].snapping) (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
- inst.snapElements[i].snapping = false;
- continue;
- }
-
- 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 - 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(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 - 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))
- (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
- inst.snapElements[i].snapping = (ts || bs || ls || rs || first);
+ return $.Widget.prototype._trigger.call(this, type, event, ui);
+ }, // _trigger
+ _uiHash: function(event) {
+ return {
+ position : this.position,
+ offset : this.offset
};
+ } // _uiHash
- }
});
-$.ui.plugin.add("draggable", "stack", {
- start: function(event, ui) {
-
- var o = $(this).data("draggable").options;
-
- var group = $.makeArray($(o.stack)).sort(function(a,b) {
- return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0);
- });
- if (!group.length) { return; }
-
- var min = parseInt(group[0].style.zIndex) || 0;
- $(group).each(function(i) {
- this.style.zIndex = min + i;
- });
-
- this[0].style.zIndex = min + group.length;
-
- }
+$.extend($.ui.draggable, {
+ version: "2.0.0"
});
-$.ui.plugin.add("draggable", "zIndex", {
- start: function(event, ui) {
- 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) {
- var o = $(this).data("draggable").options;
- if(o._zIndex) $(ui.helper).css('zIndex', o._zIndex);
- }
-});
})(jQuery);
From cb828a52bd814c540cc7dece45b5066c1191c23d Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Tue, 27 Sep 2011 21:33:38 -0400
Subject: [PATCH 002/190] Draggable: Code style better matching style guideline
---
ui/jquery.ui.draggable.js | 268 ++++++++++++++++++++------------------
1 file changed, 139 insertions(+), 129 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index c3d3d8e9262..64f66741922 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -14,215 +14,225 @@
(function( $, undefined ) {
$.widget("ui.draggable", {
+
widgetEventPrefix: "drag",
+
options: {
- helper : false
+ helper : false
},
- drag_el : false, // either element or the helper
+ // Either initialized element or the helper
+ dragEl : false,
- position : {},
- offset : {},
+ position : {},
+ offset : {},
- _start_coords : {}, // start X/Y coords of mouse before drag
- _start_position : {}, // start position of element before drag
- _start_offset : {}, // start offset of element before drag
+ // Start X/Y coords of mouse before drag
+ startCoords : {},
- _create: function() {
+ // Start position of element before drag
+ startPosition : {},
- this.scrollParent = this.element.scrollParent();
+ // Start offset of element before drag
+ startOffset : {},
- // Static position elements can't be moved with top/left
- if ( this.element.css( "position" ) === "static" ) {
- this.element.css( "position", "relative" );
- }
+ // TODO: actually remove data
+ destroy: function() {
+ return this;
+ },
- // Prevent browser from hijacking drag
- this.element.disableSelection();
+ _create: function() {
- // Using proxy to avoid anon functions using self to pass "this" along
- this.element.bind( "mousedown." + this.widgetName, $.proxy( this._mouseDown, this ) );
+ this.scrollParent = this.element.scrollParent();
- }, // _create
+ // Static position elements can"t be moved with top/left
+ if ( this.element.css( "position" ) === "static" ) {
+ this.element.css( "position", "relative" );
+ }
- destroy: function() {
- return this;
- }, // destroy
+ // Prevent browser from hijacking drag
+ this.element.disableSelection();
+
+ // Using proxy to avoid anon functions using self to pass "this" along
+ this.element.bind( "mousedown." + this.widgetName, $.proxy( this._mouseDown, this ) );
- _setPosition : function() {
+ },
- var left, top, position, css_position;
+ _setPosition : function() {
- // Helper is appended to body so offset of element is all that's needed
- if ( this.options.helper === true ) {
- return this.element.offset();
- }
+ var left, top, position, cssPosition;
- css_position = this.drag_el.css( "position" );;
+ // Helper is appended to body so offset of element is all that"s needed
+ if ( this.options.helper === true ) {
+ return this.element.offset();
+ }
- // If fixed or absolute
- if ( css_position !== "relative" ) {
+ cssPosition = this.dragEl.css( "position" );;
- position = this.drag_el.position();
+ // If fixed or absolute
+ if ( cssPosition !== "relative" ) {
- if ( css_position === "absolute" ) {
- return position;
- }
+ position = this.dragEl.position();
- // Take into account scrollbar for fixed position
- position.top = position.top - this.scrollParent.scrollTop();
- position.left = position.left - this.scrollParent.scrollLeft();
+ if ( cssPosition === "absolute" ) {
+ return position;
+ }
- return position;
+ // Take into account scrollbar for fixed position
+ position.top = position.top - this.scrollParent.scrollTop();
+ position.left = position.left - this.scrollParent.scrollLeft();
- } // css_position !+== absolute
+ return position;
- /** When using relative, css values are checked **/
+ } // cssPosition !+== absolute
- left = this.drag_el.css( "left" );
- top = this.drag_el.css( "top" );
+ /** When using relative, css values are checked **/
- // Webkit will give back auto if there is nothing inline yet
- left = ( left === "auto" ) ? 0 : parseInt( left, 10 );
- top = ( top === "auto" ) ? 0 : parseInt( top, 10 );
+ left = this.dragEl.css( "left" );
+ top = this.dragEl.css( "top" );
- return {
+ // Webkit will give back auto if there is nothing inline yet
+ left = ( left === "auto" ) ? 0 : parseInt( left, 10 );
+ top = ( top === "auto" ) ? 0 : parseInt( top, 10 );
+
+ return {
- left : left,
- top : top
+ left : left,
+ top : top
- };
+ };
- }, // _setPosition
+ },
- _mouseDown : function( event ) {
+ _mouseDown : function( event ) {
- var el_position;
-
- this.drag_el = this.element;
+ this.dragEl = this.element;
- // Helper required, so clone, hide, and set reference
- if ( this.options.helper === true ) {
+ // Helper required, so clone, hide, and set reference
+ if ( this.options.helper === true ) {
- this.drag_el = this.element.clone();
+ this.dragEl = this.element.clone();
- // If source element has an ID, change ID of helper to avoid overlap
- if ( this.element.attr( 'id' ) ) {
+ // If source element has an ID, change ID of helper to avoid overlap
+ if ( this.element.attr( "id" ) ) {
- this.drag_el
- .css({
- position : 'absolute',
- display : 'none'
- })
- .disableSelection()
- .attr( 'id', this.element.attr( 'id' ) + '-' + this.widgetName );
+ this.dragEl
+ .css({
+ position : "absolute",
+ display : "none"
+ })
+ .disableSelection()
+ .attr( "id", this.element.attr( "id" ) + "-" + this.widgetName );
- } // id
+ } // id
- $('body').append( this.drag_el );
+ $( "body" ).append( this.dragEl );
- } // if this.options.helper = true
+ } // if this.options.helper = true
- // Cache starting absolute and relative positions
- this._start_position = this._setPosition();
- this._start_offset = this.drag_el.offset();
+ // Cache starting absolute and relative positions
+ this.startPosition = this._setPosition();
+ this.startOffset = this.dragEl.offset();
- // Cache current position and offset
- this.position = $.extend( {}, this._start_position );
- this.offset = $.extend( {}, this._start_offset );
+ // Cache current position and offset
+ this.position = $.extend( {}, this.startPosition );
+ this.offset = $.extend( {}, this.startOffset );
- this._start_coords = {
- left : event.clientX,
- top : event.clientY
- };
+ this.startCoords = {
+ left : event.clientX,
+ top : event.clientY
+ };
- this._trigger( "start", event );
+ this._trigger( "start", event );
- $(document).bind( "mousemove." + this.widgetName, $.proxy( this._mouseMove, this ) );
- $(document).bind( "mouseup." + this.widgetName, $.proxy( this._mouseUp, this ) );
+ $(document).bind( "mousemove." + this.widgetName, $.proxy( this._mouseMove, this ) );
+ $(document).bind( "mouseup." + this.widgetName, $.proxy( this._mouseUp, this ) );
- // Set the helper up by actual element
- if ( this.options.helper === true ) {
+ // Set the helper up by actual element
+ if ( this.options.helper === true ) {
- // get the absolute position of element so that helper will know where to go
- el_offset = this.element.offset();
+ // get the absolute position of element so that helper will know where to go
+ elOffset = this.element.offset();
- this.drag_el.css({
- display : 'block',
- top : el_offset.top + 'px',
- left : el_offset.left + 'px'
- });
+ this.dragEl.css({
+ display : "block",
+ top : elOffset.top + "px",
+ left : elOffset.left + "px"
+ });
- } // this.options.height = true
+ } // this.options.height = true
- }, // _mouseDown
+ },
- _mouseMove : function( event ) {
+ _mouseMove : function( event ) {
- var left_diff = event.clientX - this._start_coords.left,
- top_diff = event.clientY - this._start_coords.top,
- new_left = left_diff + this._start_position.left,
- new_top = top_diff + this._start_position.top;
+ var leftDiff = event.clientX - this.startCoords.left,
+ topDiff = event.clientY - this.startCoords.top,
+ newLeft = leftDiff + this.startPosition.left,
+ newTop = topDiff + this.startPosition.top;
- this.position = {
- left : new_left,
- top : new_top
- };
+ this.position = {
+ left : newLeft,
+ top : newTop
+ };
- // Refresh offset cache with new positions
- this.offset.left = this._start_offset.left + new_left;
- this.offset.top = this._start_offset.top + new_top;
+ // Refresh offset cache with new positions
+ this.offset.left = this.startOffset.left + newLeft;
+ this.offset.top = this.startOffset.top + newTop;
- this._trigger( "drag", event );
+ this._trigger( "drag", event );
- // User overriding left/top so shortcut math is no longer valid
- if ( new_left !== this.position.left || new_top !== this.position.top ) {
+ // User overriding left/top so shortcut math is no longer valid
+ if ( newLeft !== this.position.left || newTop !== this.position.top ) {
- // refresh offset using slower functions
- this.offset = this.drag_el.offset();
+ // refresh offset using slower functions
+ this.offset = this.dragEl.offset();
- }
+ }
- this.drag_el.css({
+ this.dragEl.css({
- left : this.position.left + 'px',
- top : this.position.top + 'px'
+ left : this.position.left + "px",
+ top : this.position.top + "px"
- });
+ });
- }, // _mouseMove
+ },
_mouseUp : function( event ) {
- this._trigger( "stop", event );
+ this._trigger( "stop", event );
- this._start_coords = {};
+ this.startCoords = {};
- if ( this.options.helper === true ) {
- this.drag_el.remove();
- }
+ if ( this.options.helper === true ) {
+ this.dragEl.remove();
+ }
- $(document).unbind( "mousemove." + this.widgetName );
- $(document).unbind( "mouseup." + this.widgetName );
+ $(document).unbind( "mousemove." + this.widgetName );
+ $(document).unbind( "mouseup." + this.widgetName );
- }, // _mouseUp
+ },
- _trigger: function(type, event, ui) {
+ _trigger: function( type, event, ui ) {
ui = ui || this._uiHash();
- return $.Widget.prototype._trigger.call(this, type, event, ui);
- }, // _trigger
+ return $.Widget.prototype._trigger.call( this, type, event, ui );
+
+ },
_uiHash: function(event) {
+
return {
position : this.position,
- offset : this.offset
+ offset : this.offset
};
- } // _uiHash
+
+ }
});
From d85c67dd9677d75b6d7046b048173573f3379a2c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?=
Date: Tue, 27 Sep 2011 22:02:07 -0400
Subject: [PATCH 003/190] whitespace
---
ui/jquery.ui.draggable.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 64f66741922..bdef17f22fd 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -13,7 +13,7 @@
*/
(function( $, undefined ) {
-$.widget("ui.draggable", {
+$.widget( "ui.draggable", {
widgetEventPrefix: "drag",
From 1f23656fe28ba413e7d9a927a644b24c39b8270f Mon Sep 17 00:00:00 2001
From: =
Date: Sat, 1 Oct 2011 12:05:36 -0400
Subject: [PATCH 004/190] Draggable: Fixed coding style, moved properties out
of prototype
---
ui/jquery.ui.draggable.js | 94 +++++++++++++++++++--------------------
1 file changed, 47 insertions(+), 47 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index bdef17f22fd..13cd22b2ce1 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -19,31 +19,31 @@ $.widget( "ui.draggable", {
options: {
- helper : false
+ helper: false
},
- // Either initialized element or the helper
- dragEl : false,
-
- position : {},
- offset : {},
-
- // Start X/Y coords of mouse before drag
- startCoords : {},
-
- // Start position of element before drag
- startPosition : {},
-
- // Start offset of element before drag
- startOffset : {},
-
// TODO: actually remove data
destroy: function() {
- return this;
+ return this;
},
_create: function() {
+
+ // Either initialized element or the helper
+ this.dragEl = false,
+
+ this.position = {},
+ this.offset = {},
+
+ // Start X/Y coords of mouse before drag
+ this.startCoords = {},
+
+ // Start position of element before drag
+ this.startPosition = {},
+
+ // Start offset of element before drag
+ this.startOffset = {},
this.scrollParent = this.element.scrollParent();
@@ -60,7 +60,7 @@ $.widget( "ui.draggable", {
},
- _setPosition : function() {
+ _setPosition: function() {
var left, top, position, cssPosition;
@@ -81,7 +81,7 @@ $.widget( "ui.draggable", {
}
// Take into account scrollbar for fixed position
- position.top = position.top - this.scrollParent.scrollTop();
+ position.top = position.top - this.scrollParent.scrollTop();
position.left = position.left - this.scrollParent.scrollLeft();
return position;
@@ -91,22 +91,22 @@ $.widget( "ui.draggable", {
/** When using relative, css values are checked **/
left = this.dragEl.css( "left" );
- top = this.dragEl.css( "top" );
+ top = this.dragEl.css( "top" );
// Webkit will give back auto if there is nothing inline yet
- left = ( left === "auto" ) ? 0 : parseInt( left, 10 );
- top = ( top === "auto" ) ? 0 : parseInt( top, 10 );
+ left = ( left === "auto" ) ? 0: parseInt( left, 10 );
+ top = ( top === "auto" ) ? 0: parseInt( top, 10 );
return {
- left : left,
- top : top
+ left: left,
+ top: top
};
},
- _mouseDown : function( event ) {
+ _mouseDown: function( event ) {
this.dragEl = this.element;
@@ -120,8 +120,8 @@ $.widget( "ui.draggable", {
this.dragEl
.css({
- position : "absolute",
- display : "none"
+ position: "absolute",
+ display: "none"
})
.disableSelection()
.attr( "id", this.element.attr( "id" ) + "-" + this.widgetName );
@@ -134,15 +134,15 @@ $.widget( "ui.draggable", {
// Cache starting absolute and relative positions
this.startPosition = this._setPosition();
- this.startOffset = this.dragEl.offset();
+ this.startOffset = this.dragEl.offset();
// Cache current position and offset
this.position = $.extend( {}, this.startPosition );
- this.offset = $.extend( {}, this.startOffset );
+ this.offset = $.extend( {}, this.startOffset );
this.startCoords = {
- left : event.clientX,
- top : event.clientY
+ left: event.clientX,
+ top: event.clientY
};
this._trigger( "start", event );
@@ -158,30 +158,30 @@ $.widget( "ui.draggable", {
elOffset = this.element.offset();
this.dragEl.css({
- display : "block",
- top : elOffset.top + "px",
- left : elOffset.left + "px"
+ display: "block",
+ top: elOffset.top + "px",
+ left: elOffset.left + "px"
});
} // this.options.height = true
},
- _mouseMove : function( event ) {
+ _mouseMove: function( event ) {
var leftDiff = event.clientX - this.startCoords.left,
- topDiff = event.clientY - this.startCoords.top,
- newLeft = leftDiff + this.startPosition.left,
- newTop = topDiff + this.startPosition.top;
+ topDiff = event.clientY - this.startCoords.top,
+ newLeft = leftDiff + this.startPosition.left,
+ newTop = topDiff + this.startPosition.top;
this.position = {
- left : newLeft,
- top : newTop
+ left: newLeft,
+ top: newTop
};
// Refresh offset cache with new positions
this.offset.left = this.startOffset.left + newLeft;
- this.offset.top = this.startOffset.top + newTop;
+ this.offset.top = this.startOffset.top + newTop;
this._trigger( "drag", event );
@@ -189,20 +189,20 @@ $.widget( "ui.draggable", {
if ( newLeft !== this.position.left || newTop !== this.position.top ) {
// refresh offset using slower functions
- this.offset = this.dragEl.offset();
+ this.offset = this.dragEl.offset();
}
this.dragEl.css({
- left : this.position.left + "px",
- top : this.position.top + "px"
+ left: this.position.left + "px",
+ top: this.position.top + "px"
});
},
- _mouseUp : function( event ) {
+ _mouseUp: function( event ) {
this._trigger( "stop", event );
@@ -228,8 +228,8 @@ $.widget( "ui.draggable", {
_uiHash: function(event) {
return {
- position : this.position,
- offset : this.offset
+ position: this.position,
+ offset: this.offset
};
}
From 7ef6df95ebcd487e5f7284264fa59814a771ceb6 Mon Sep 17 00:00:00 2001
From: =
Date: Sat, 1 Oct 2011 12:38:48 -0400
Subject: [PATCH 005/190] Draggable: Helper option can now take function that
returns DOMElement
---
ui/jquery.ui.draggable.js | 60 ++++++++++++++++++++++++++-------------
1 file changed, 41 insertions(+), 19 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 13cd22b2ce1..0ac364bc9c1 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -29,7 +29,7 @@ $.widget( "ui.draggable", {
},
_create: function() {
-
+
// Either initialized element or the helper
this.dragEl = false,
@@ -59,13 +59,17 @@ $.widget( "ui.draggable", {
this.element.bind( "mousedown." + this.widgetName, $.proxy( this._mouseDown, this ) );
},
+
+ _usingHelper : function() {
+ return ( this.options.helper === true || typeof this.options.helper === 'function' );
+ },
_setPosition: function() {
var left, top, position, cssPosition;
- // Helper is appended to body so offset of element is all that"s needed
- if ( this.options.helper === true ) {
+ // Helper is appended to body so offset of element is all that's needed
+ if ( this._usingHelper() ) {
return this.element.offset();
}
@@ -86,7 +90,7 @@ $.widget( "ui.draggable", {
return position;
- } // cssPosition !+== absolute
+ }
/** When using relative, css values are checked **/
@@ -108,29 +112,47 @@ $.widget( "ui.draggable", {
_mouseDown: function( event ) {
+ // The actual dragging element, should always be a jQuery object
this.dragEl = this.element;
// Helper required, so clone, hide, and set reference
- if ( this.options.helper === true ) {
+ if ( this._usingHelper() ) {
+
+ // If getting a cloned helper
+ if ( this.options.helper === true ) {
+
+ this.dragEl = this.element.clone();
- this.dragEl = this.element.clone();
+ // If source element has an ID, change ID of helper to avoid overlap
+ if ( this.element.attr( "id" ) ) {
- // If source element has an ID, change ID of helper to avoid overlap
- if ( this.element.attr( "id" ) ) {
+ this.dragEl.attr( "id", this.element.attr( "id" ) + "-" + this.widgetName );
- this.dragEl
+ }
+
+ } else {
+
+ this.dragEl = this.options.helper();
+
+ // If function was passed, it should return a DOMElement
+ if ( typeof this.dragEl.nodeType !== 'number' ) {
+ throw "Helper function must return a DOMElement";
+ }
+
+ this.dragEl = $( this.dragEl );
+
+ }
+
+ // Automatically make helper absolute
+ this.dragEl
.css({
- position: "absolute",
- display: "none"
+ position: "absolute"
})
- .disableSelection()
- .attr( "id", this.element.attr( "id" ) + "-" + this.widgetName );
-
- } // id
+ .disableSelection();
$( "body" ).append( this.dragEl );
- } // if this.options.helper = true
+ }
// Cache starting absolute and relative positions
this.startPosition = this._setPosition();
@@ -152,7 +174,7 @@ $.widget( "ui.draggable", {
// Set the helper up by actual element
- if ( this.options.helper === true ) {
+ if ( this._usingHelper() ) {
// get the absolute position of element so that helper will know where to go
elOffset = this.element.offset();
@@ -163,7 +185,7 @@ $.widget( "ui.draggable", {
left: elOffset.left + "px"
});
- } // this.options.height = true
+ }
},
@@ -208,7 +230,7 @@ $.widget( "ui.draggable", {
this.startCoords = {};
- if ( this.options.helper === true ) {
+ if ( this._usingHelper() ) {
this.dragEl.remove();
}
From 7745d61a24ccaded65cabc54659825565fca2cfd Mon Sep 17 00:00:00 2001
From: =
Date: Sat, 8 Oct 2011 23:30:03 -0400
Subject: [PATCH 006/190] Draggable: No longer using disableSelection in favor
of preventDefault
---
ui/jquery.ui.draggable.js | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 0ac364bc9c1..b4e166d3e1a 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -52,9 +52,6 @@ $.widget( "ui.draggable", {
this.element.css( "position", "relative" );
}
- // Prevent browser from hijacking drag
- this.element.disableSelection();
-
// Using proxy to avoid anon functions using self to pass "this" along
this.element.bind( "mousedown." + this.widgetName, $.proxy( this._mouseDown, this ) );
@@ -111,6 +108,9 @@ $.widget( "ui.draggable", {
},
_mouseDown: function( event ) {
+
+ // Stop browser from highlighting, among other things
+ event.preventDefault();
// The actual dragging element, should always be a jQuery object
this.dragEl = this.element;
@@ -147,8 +147,7 @@ $.widget( "ui.draggable", {
this.dragEl
.css({
position: "absolute"
- })
- .disableSelection();
+ });
$( "body" ).append( this.dragEl );
From e43ce91212745beb0cca0fe75e18f9a89a8d6222 Mon Sep 17 00:00:00 2001
From: =
Date: Sat, 8 Oct 2011 23:34:26 -0400
Subject: [PATCH 007/190] Draggable: No longer overwriting _trigger
---
ui/jquery.ui.draggable.js | 8 --------
1 file changed, 8 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index b4e166d3e1a..5816ca6a8b0 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -238,14 +238,6 @@ $.widget( "ui.draggable", {
},
- _trigger: function( type, event, ui ) {
-
- ui = ui || this._uiHash();
-
- return $.Widget.prototype._trigger.call( this, type, event, ui );
-
- },
-
_uiHash: function(event) {
return {
From c8e13708eb90728978a119c6adeef3010ff332e7 Mon Sep 17 00:00:00 2001
From: =
Date: Sun, 9 Oct 2011 00:54:47 -0400
Subject: [PATCH 008/190] Draggable: Scrollbars being handled when scrollParent
is document
---
ui/jquery.ui.draggable.js | 107 +++++++++++++++++++++++++++-----------
1 file changed, 77 insertions(+), 30 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 5816ca6a8b0..2fa52cc809d 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -19,6 +19,8 @@ $.widget( "ui.draggable", {
options: {
+ scrollSpeed: 20,
+ scrollSensitivity:20,
helper: false
},
@@ -47,43 +49,48 @@ $.widget( "ui.draggable", {
this.scrollParent = this.element.scrollParent();
+ // Offset of scrollParent, used for auto-scrolling
+ this.overflowOffset = {};
+
+ // Height of scrollParent, used for auto-scrolling
+ this.overflowHeight = 0;
+
+ // Width of scrollParent, used for auto-scrolling
+ this.overflowWidth = 0;
+
// Static position elements can"t be moved with top/left
if ( this.element.css( "position" ) === "static" ) {
this.element.css( "position", "relative" );
}
-
+
// Using proxy to avoid anon functions using self to pass "this" along
this.element.bind( "mousedown." + this.widgetName, $.proxy( this._mouseDown, this ) );
},
-
+
_usingHelper : function() {
return ( this.options.helper === true || typeof this.options.helper === 'function' );
},
_setPosition: function() {
- var left, top, position, cssPosition;
+ var left, top, position,
+ scrollTop = this.scrollParent.scrollTop(),
+ scrollLeft = this.scrollParent.scrollLeft();
// Helper is appended to body so offset of element is all that's needed
if ( this._usingHelper() ) {
return this.element.offset();
}
- cssPosition = this.dragEl.css( "position" );;
-
// If fixed or absolute
- if ( cssPosition !== "relative" ) {
+ if ( this.cssPosition !== "relative" ) {
position = this.dragEl.position();
- if ( cssPosition === "absolute" ) {
- return position;
- }
-
- // Take into account scrollbar for fixed position
- position.top = position.top - this.scrollParent.scrollTop();
- position.left = position.left - this.scrollParent.scrollLeft();
+ // Take into account scrollbar
+ position.top = position.top - scrollTop;
+ position.left = position.left - scrollLeft
return position;
@@ -100,20 +107,22 @@ $.widget( "ui.draggable", {
return {
- left: left,
- top: top
+ left: left - scrollLeft,
+ top: top - scrollTop
};
},
_mouseDown: function( event ) {
-
+
// Stop browser from highlighting, among other things
event.preventDefault();
// The actual dragging element, should always be a jQuery object
this.dragEl = this.element;
+
+ this.cssPosition = this.dragEl.css( "position" );
// Helper required, so clone, hide, and set reference
if ( this._usingHelper() ) {
@@ -131,16 +140,16 @@ $.widget( "ui.draggable", {
}
} else {
-
+
this.dragEl = this.options.helper();
-
+
// If function was passed, it should return a DOMElement
if ( typeof this.dragEl.nodeType !== 'number' ) {
throw "Helper function must return a DOMElement";
}
-
+
this.dragEl = $( this.dragEl );
-
+
}
// Automatically make helper absolute
@@ -166,10 +175,15 @@ $.widget( "ui.draggable", {
top: event.clientY
};
+ // Cache the offset of scrollParent
+ this.overflowOffset = this.scrollParent.offset();
+ this.overflowHeight = ( this.scrollParent[0] === document ) ? $(window).height() : this.scrollParent.height();
+ this.overflowWidth = ( this.scrollParent[0] === document ) ? $(window).width() : this.scrollParent.width();
+
this._trigger( "start", event );
- $(document).bind( "mousemove." + this.widgetName, $.proxy( this._mouseMove, this ) );
- $(document).bind( "mouseup." + this.widgetName, $.proxy( this._mouseUp, this ) );
+ $(document).bind( "mousemove." + this.widgetName, $.proxy( this._mouseMove, this ) )
+ .bind( "mouseup." + this.widgetName, $.proxy( this._mouseUp, this ) );
// Set the helper up by actual element
@@ -189,11 +203,11 @@ $.widget( "ui.draggable", {
},
_mouseMove: function( event ) {
-
+
var leftDiff = event.clientX - this.startCoords.left,
- topDiff = event.clientY - this.startCoords.top,
- newLeft = leftDiff + this.startPosition.left,
- newTop = topDiff + this.startPosition.top;
+ topDiff = event.clientY - this.startCoords.top,
+ newLeft = leftDiff + this.startPosition.left,
+ newTop = topDiff + this.startPosition.top;
this.position = {
left: newLeft,
@@ -213,18 +227,51 @@ $.widget( "ui.draggable", {
this.offset = this.dragEl.offset();
}
+
+ newLeft = this.position.left;
+ newTop = this.position.top;
+
+ if ( this.cssPosition !== 'fixed' ) {
+
+ newLeft = newLeft + this.scrollParent.scrollLeft();
+ newTop = newTop + this.scrollParent.scrollTop();
+
+ }
this.dragEl.css({
- left: this.position.left + "px",
- top: this.position.top + "px"
+ left: newLeft + "px",
+ top: newTop + "px"
});
+
+ // Scroll the scrollParent, if needed
+ this._handleScrolling( event );
+
+ },
+
+ _handleScrolling: function( event ) {
+
+ var doc = $(document),
+ scrollTop = doc.scrollTop(),
+ scrollLeft = doc.scrollLeft();
+
+ // Handle vertical scrolling
+ if ( ( ( this.overflowHeight + scrollTop ) - event.pageY ) < this.options.scrollSensitivity ) {
+ doc.scrollTop( scrollTop + this.options.scrollSpeed );
+ }
+
+ // Handle horizontal scrolling
+ if ( ( ( this.overflowWidth + scrollLeft ) - event.pageX ) < this.options.scrollSensitivity ) {
+ doc.scrollLeft( scrollLeft + this.options.scrollSpeed );
+ }
},
_mouseUp: function( event ) {
+ var doc = $(document);
+
this._trigger( "stop", event );
this.startCoords = {};
@@ -233,8 +280,8 @@ $.widget( "ui.draggable", {
this.dragEl.remove();
}
- $(document).unbind( "mousemove." + this.widgetName );
- $(document).unbind( "mouseup." + this.widgetName );
+ doc.unbind( "mousemove." + this.widgetName );
+ doc.unbind( "mouseup." + this.widgetName );
},
From ee094ccf4ddc20e75cf0b6c3ed752f1302336eb4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?=
Date: Fri, 14 Oct 2011 14:19:04 -0400
Subject: [PATCH 009/190] Draggable: Cleanup.
---
ui/jquery.ui.draggable.js | 239 +++++++++++++-------------------------
1 file changed, 78 insertions(+), 161 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 2fa52cc809d..1e9fb4cda3b 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -1,11 +1,11 @@
/*
- * jQuery UI Draggable 2.0.0
+ * jQuery UI Draggable @VERSION
*
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
- * http://docs.jquery.com/UI/Draggables
+ * http://docs.jquery.com/UI/Draggable
*
* Depends:
* jquery.ui.core.js
@@ -14,90 +14,59 @@
(function( $, undefined ) {
$.widget( "ui.draggable", {
-
+ version: "@VERSION",
widgetEventPrefix: "drag",
options: {
-
- scrollSpeed: 20,
- scrollSensitivity:20,
- helper: false
-
+ helper: false,
+ scrollSensitivity: 20,
+ scrollSpeed: 20
},
- // TODO: actually remove data
- destroy: function() {
- return this;
- },
+ // dragEl: element being dragged (original or helper)
+ // position: CSS position of dragEl
+ // offset: offset of dragEl
+ // startCoords: clientX/Y of the mousedown (offset of pointer)
+ // startPosition: CSS position prior to drag start
+ // startOffset: offset prior to drag start
+ // overflowOffset: offset of scroll parent
+ // overflowHeight: height of scroll parent
+ // overflowWidth: width of scroll parent
_create: function() {
-
- // Either initialized element or the helper
- this.dragEl = false,
-
- this.position = {},
- this.offset = {},
-
- // Start X/Y coords of mouse before drag
- this.startCoords = {},
-
- // Start position of element before drag
- this.startPosition = {},
-
- // Start offset of element before drag
- this.startOffset = {},
+ // TODO: add these to the base widget
+ this.doc = $( this.element[0].ownerDocument );
+ this.win = $( this.doc[0].defaultView );
this.scrollParent = this.element.scrollParent();
- // Offset of scrollParent, used for auto-scrolling
- this.overflowOffset = {};
-
- // Height of scrollParent, used for auto-scrolling
- this.overflowHeight = 0;
-
- // Width of scrollParent, used for auto-scrolling
- this.overflowWidth = 0;
-
- // Static position elements can"t be moved with top/left
+ // Static position elements can't be moved with top/left
if ( this.element.css( "position" ) === "static" ) {
this.element.css( "position", "relative" );
}
-
- // Using proxy to avoid anon functions using self to pass "this" along
- this.element.bind( "mousedown." + this.widgetName, $.proxy( this._mouseDown, this ) );
-
- },
- _usingHelper : function() {
- return ( this.options.helper === true || typeof this.options.helper === 'function' );
+ // TODO: use _bind()
+ this.element.bind( "mousedown." + this.widgetName, $.proxy( this, "_mouseDown" ) );
},
- _setPosition: function() {
-
+ // TODO: why is relative handled differently than fixed/absolute?
+ _getPosition: function() {
var left, top, position,
- scrollTop = this.scrollParent.scrollTop(),
- scrollLeft = this.scrollParent.scrollLeft();
-
- // Helper is appended to body so offset of element is all that's needed
- if ( this._usingHelper() ) {
- return this.element.offset();
- }
+ scrollTop = this.scrollParent.scrollTop(),
+ scrollLeft = this.scrollParent.scrollLeft();
// If fixed or absolute
if ( this.cssPosition !== "relative" ) {
-
position = this.dragEl.position();
// Take into account scrollbar
- position.top = position.top - scrollTop;
- position.left = position.left - scrollLeft
+ position.top -= scrollTop;
+ position.left -= scrollLeft
return position;
-
}
- /** When using relative, css values are checked **/
-
+ // When using relative, css values are checked
left = this.dragEl.css( "left" );
top = this.dragEl.css( "top" );
@@ -106,64 +75,42 @@ $.widget( "ui.draggable", {
top = ( top === "auto" ) ? 0: parseInt( top, 10 );
return {
-
left: left - scrollLeft,
top: top - scrollTop
-
};
-
},
_mouseDown: function( event ) {
-
- // Stop browser from highlighting, among other things
- event.preventDefault();
+ // Prevent text selection, among other things
+ event.preventDefault();
// The actual dragging element, should always be a jQuery object
this.dragEl = this.element;
-
this.cssPosition = this.dragEl.css( "position" );
- // Helper required, so clone, hide, and set reference
- if ( this._usingHelper() ) {
-
- // If getting a cloned helper
+ // Helper required
+ if ( this.options.helper ) {
+ // clone
if ( this.options.helper === true ) {
-
- this.dragEl = this.element.clone();
-
// If source element has an ID, change ID of helper to avoid overlap
+ this.dragEl = this.element.clone();
if ( this.element.attr( "id" ) ) {
-
this.dragEl.attr( "id", this.element.attr( "id" ) + "-" + this.widgetName );
-
}
-
} else {
-
- this.dragEl = this.options.helper();
-
- // If function was passed, it should return a DOMElement
- if ( typeof this.dragEl.nodeType !== 'number' ) {
- throw "Helper function must return a DOMElement";
- }
-
- this.dragEl = $( this.dragEl );
-
+ // TODO: figure out the signature for this; see #4957
+ this.dragEl = $( this.options.helper() );
}
- // Automatically make helper absolute
this.dragEl
- .css({
- position: "absolute"
- });
-
- $( "body" ).append( this.dragEl );
-
+ // TODO: should we move this to the stylesheet and use a class?
+ .css( "position", "absolute" )
+ .appendTo( this.doc[0].body )
+ .offset( this.element.offset() );
}
// Cache starting absolute and relative positions
- this.startPosition = this._setPosition();
+ this.startPosition = this._getPosition();
this.startOffset = this.dragEl.offset();
// Cache current position and offset
@@ -176,38 +123,28 @@ $.widget( "ui.draggable", {
};
// Cache the offset of scrollParent
+ // TODO: store overflow height/width in a hash instead of separate properties
this.overflowOffset = this.scrollParent.offset();
- this.overflowHeight = ( this.scrollParent[0] === document ) ? $(window).height() : this.scrollParent.height();
- this.overflowWidth = ( this.scrollParent[0] === document ) ? $(window).width() : this.scrollParent.width();
-
- this._trigger( "start", event );
-
- $(document).bind( "mousemove." + this.widgetName, $.proxy( this._mouseMove, this ) )
- .bind( "mouseup." + this.widgetName, $.proxy( this._mouseUp, this ) );
-
-
- // Set the helper up by actual element
- if ( this._usingHelper() ) {
-
- // get the absolute position of element so that helper will know where to go
- elOffset = this.element.offset();
-
- this.dragEl.css({
- display: "block",
- top: elOffset.top + "px",
- left: elOffset.left + "px"
- });
-
- }
-
+ this.overflowHeight = ( this.scrollParent[0] === this.doc[0] ) ?
+ this.win.height() : this.scrollParent.height();
+ this.overflowWidth = ( this.scrollParent[0] === this.doc[0] ) ?
+ this.win.width() : this.scrollParent.width();
+
+ // TODO: allow modifying position, just like during drag
+ this._trigger( "start", event, this._uiHash() );
+
+ // TODO: use ._bind()
+ // TODO: rename _bind() to _on(); add _off()
+ this.doc
+ .bind( "mousemove." + this.widgetName, $.proxy( this, "_mouseMove" ) )
+ .bind( "mouseup." + this.widgetName, $.proxy( this, "_mouseUp" ) );
},
_mouseMove: function( event ) {
-
var leftDiff = event.clientX - this.startCoords.left,
- topDiff = event.clientY - this.startCoords.top,
- newLeft = leftDiff + this.startPosition.left,
- newTop = topDiff + this.startPosition.top;
+ topDiff = event.clientY - this.startCoords.top,
+ newLeft = leftDiff + this.startPosition.left,
+ newTop = topDiff + this.startPosition.top;
this.position = {
left: newLeft,
@@ -218,87 +155,67 @@ $.widget( "ui.draggable", {
this.offset.left = this.startOffset.left + newLeft;
this.offset.top = this.startOffset.top + newTop;
- this._trigger( "drag", event );
+ this._trigger( "drag", event, this._uiHash() );
// User overriding left/top so shortcut math is no longer valid
if ( newLeft !== this.position.left || newTop !== this.position.top ) {
-
+ // TODO: can we just store the previous offset values
+ // and not go through .offset()?
// refresh offset using slower functions
this.offset = this.dragEl.offset();
-
}
-
+
newLeft = this.position.left;
newTop = this.position.top;
-
- if ( this.cssPosition !== 'fixed' ) {
-
+
+ // TODO: does this work with nested scrollable parents?
+ if ( this.cssPosition !== "fixed" ) {
newLeft = newLeft + this.scrollParent.scrollLeft();
newTop = newTop + this.scrollParent.scrollTop();
-
}
this.dragEl.css({
-
left: newLeft + "px",
top: newTop + "px"
-
});
-
+
// Scroll the scrollParent, if needed
this._handleScrolling( event );
-
},
_handleScrolling: function( event ) {
-
- var doc = $(document),
- scrollTop = doc.scrollTop(),
- scrollLeft = doc.scrollLeft();
+ var scrollTop = this.doc.scrollTop(),
+ scrollLeft = this.doc.scrollLeft();
// Handle vertical scrolling
if ( ( ( this.overflowHeight + scrollTop ) - event.pageY ) < this.options.scrollSensitivity ) {
- doc.scrollTop( scrollTop + this.options.scrollSpeed );
+ this.doc.scrollTop( scrollTop + this.options.scrollSpeed );
}
-
+
// Handle horizontal scrolling
if ( ( ( this.overflowWidth + scrollLeft ) - event.pageX ) < this.options.scrollSensitivity ) {
- doc.scrollLeft( scrollLeft + this.options.scrollSpeed );
+ this.doc.scrollLeft( scrollLeft + this.options.scrollSpeed );
}
-
},
_mouseUp: function( event ) {
+ this._trigger( "stop", event, this._uiHash() );
- var doc = $(document);
-
- this._trigger( "stop", event );
-
- this.startCoords = {};
-
- if ( this._usingHelper() ) {
+ if ( this.options.helper ) {
this.dragEl.remove();
}
- doc.unbind( "mousemove." + this.widgetName );
- doc.unbind( "mouseup." + this.widgetName );
-
+ this.doc
+ .unbind( "mousemove." + this.widgetName )
+ .unbind( "mouseup." + this.widgetName );
},
- _uiHash: function(event) {
-
+ _uiHash: function( event ) {
return {
position: this.position,
offset: this.offset
};
-
}
-
-});
-
-$.extend($.ui.draggable, {
- version: "2.0.0"
});
-
-})(jQuery);
+})( jQuery );
From c4df28939c8c2c0e94778333129b76e0bece35bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?=
Date: Fri, 14 Oct 2011 15:03:10 -0400
Subject: [PATCH 010/190] Draggable: Use ._bind().
---
ui/jquery.ui.draggable.js | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 1e9fb4cda3b..ef6af1086a0 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -45,8 +45,7 @@ $.widget( "ui.draggable", {
this.element.css( "position", "relative" );
}
- // TODO: use _bind()
- this.element.bind( "mousedown." + this.widgetName, $.proxy( this, "_mouseDown" ) );
+ this._bind({ mousedown: "_mouseDown" });
},
// TODO: why is relative handled differently than fixed/absolute?
@@ -133,11 +132,10 @@ $.widget( "ui.draggable", {
// TODO: allow modifying position, just like during drag
this._trigger( "start", event, this._uiHash() );
- // TODO: use ._bind()
- // TODO: rename _bind() to _on(); add _off()
- this.doc
- .bind( "mousemove." + this.widgetName, $.proxy( this, "_mouseMove" ) )
- .bind( "mouseup." + this.widgetName, $.proxy( this, "_mouseUp" ) );
+ this._bind( this.doc, {
+ mousemove: "_mouseMove",
+ mouseup: "_mouseUp"
+ });
},
_mouseMove: function( event ) {
@@ -205,9 +203,7 @@ $.widget( "ui.draggable", {
this.dragEl.remove();
}
- this.doc
- .unbind( "mousemove." + this.widgetName )
- .unbind( "mouseup." + this.widgetName );
+ this.doc.unbind( "." + this.widgetName );
},
_uiHash: function( event ) {
From a0946d0364e9f87ea45777d2ab8d099ae0913647 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?=
Date: Mon, 17 Oct 2011 08:26:12 -0400
Subject: [PATCH 011/190] Draggable: Remove all ids when using helper: true.
---
ui/jquery.ui.draggable.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index ef6af1086a0..6abfe7a522d 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -91,11 +91,11 @@ $.widget( "ui.draggable", {
if ( this.options.helper ) {
// clone
if ( this.options.helper === true ) {
- // If source element has an ID, change ID of helper to avoid overlap
- this.dragEl = this.element.clone();
- if ( this.element.attr( "id" ) ) {
- this.dragEl.attr( "id", this.element.attr( "id" ) + "-" + this.widgetName );
- }
+ this.dragEl = this.element.clone()
+ .removeAttr( "id" )
+ .find( "[id]" )
+ .removeAttr( "id" )
+ .end();
} else {
// TODO: figure out the signature for this; see #4957
this.dragEl = $( this.options.helper() );
From 1337573adc9fd4411ce67a764e0dda0c59701107 Mon Sep 17 00:00:00 2001
From: =
Date: Tue, 25 Oct 2011 21:54:03 -0400
Subject: [PATCH 012/190] Squashed commit of the following:
Draggable:
Fixed when cssPosition is being set.
Scrolling handles non-doc overflow.
_handleScrolling handles scrolling up and left now
Made window, doc, and window part of base widget
All parts of drag may be stopped via stopPropagation
User can now override position of draggable on start, drag, and stop
Whitespace fix
Moved overflowWidth and overflowHeight into overflow.width and overflow.height
---
ui/jquery.ui.draggable.js | 174 ++++++++++++++++++++++++++++----------
ui/jquery.ui.widget.js | 3 +
2 files changed, 133 insertions(+), 44 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 6abfe7a522d..390c85a0522 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -24,20 +24,16 @@ $.widget( "ui.draggable", {
},
// dragEl: element being dragged (original or helper)
- // position: CSS position of dragEl
+ // position: final CSS position of dragEl
// offset: offset of dragEl
// startCoords: clientX/Y of the mousedown (offset of pointer)
// startPosition: CSS position prior to drag start
// startOffset: offset prior to drag start
+ // tempPosition: overridable CSS position of dragEl
// overflowOffset: offset of scroll parent
- // overflowHeight: height of scroll parent
- // overflowWidth: width of scroll parent
+ // overflow: object containing width and height keys of scroll parent
_create: function() {
- // TODO: add these to the base widget
- this.doc = $( this.element[0].ownerDocument );
- this.win = $( this.doc[0].defaultView );
-
this.scrollParent = this.element.scrollParent();
// Static position elements can't be moved with top/left
@@ -79,13 +75,62 @@ $.widget( "ui.draggable", {
};
},
+ _handleScrolling: function( event ) {
+ // TODO: what is expected behavior of absolute/fixed draggable inside a div having overflow:scroll?
+ var scrollTop = this.scrollParent.scrollTop(),
+ scrollLeft = this.scrollParent.scrollLeft();
+
+ // overflowOffset is only set when scrollParent is not doc/html
+ if ( !this.overflowOffset ) {
+
+ // Handle vertical scrolling
+ if ( ( ( this.overflow.height + scrollTop ) - event.pageY ) < this.options.scrollSensitivity ) {
+ this.scrollParent.scrollTop( scrollTop + this.options.scrollSpeed );
+ }
+ else if ( event.pageY < ( scrollTop + this.options.scrollSensitivity ) ) {
+ this.scrollParent.scrollTop( scrollTop - this.options.scrollSpeed );
+ }
+
+ // Handle horizontal scrolling
+ if ( ( ( this.overflow.width + scrollLeft ) - event.pageX ) < this.options.scrollSensitivity ) {
+ this.scrollParent.scrollLeft( scrollLeft + this.options.scrollSpeed );
+ }
+ else if ( event.pageX < ( scrollLeft + this.options.scrollSensitivity ) ) {
+ this.scrollParent.scrollLeft( scrollLeft - this.options.scrollSpeed );
+ }
+
+ } else {
+
+
+ // Handle vertical scrolling
+ if ( ( event.pageY + this.options.scrollSensitivity ) > ( this.overflow.height + this.overflowOffset.top ) ) {
+ this.scrollParent.scrollTop( scrollTop + this.options.scrollSpeed );
+ }
+ else if ( ( event.pageY - this.options.scrollSensitivity ) < this.overflowOffset.top ) {
+ this.scrollParent.scrollTop( scrollTop - this.options.scrollSpeed );
+ }
+
+ // Handle horizontal scrolling
+ if ( ( event.pageX + this.options.scrollSensitivity ) > ( this.overflow.width + this.overflowOffset.left ) ) {
+ this.scrollParent.scrollLeft( scrollLeft + this.options.scrollSpeed );
+ }
+ else if ( ( event.pageX - this.options.scrollSensitivity ) < this.overflowOffset.left ) {
+ this.scrollParent.scrollLeft( scrollLeft - this.options.scrollSpeed );
+ }
+
+
+ }
+
+ },
+
_mouseDown: function( event ) {
+ var newLeft, newTop;
+
// Prevent text selection, among other things
event.preventDefault();
// The actual dragging element, should always be a jQuery object
this.dragEl = this.element;
- this.cssPosition = this.dragEl.css( "position" );
// Helper required
if ( this.options.helper ) {
@@ -107,6 +152,8 @@ $.widget( "ui.draggable", {
.appendTo( this.doc[0].body )
.offset( this.element.offset() );
}
+
+ this.cssPosition = this.dragEl.css( "position" );
// Cache starting absolute and relative positions
this.startPosition = this._getPosition();
@@ -121,16 +168,31 @@ $.widget( "ui.draggable", {
top: event.clientY
};
- // Cache the offset of scrollParent
- // TODO: store overflow height/width in a hash instead of separate properties
- this.overflowOffset = this.scrollParent.offset();
- this.overflowHeight = ( this.scrollParent[0] === this.doc[0] ) ?
+ // Cache the offset of scrollParent, if required for _handleScrolling
+ if ( this.scrollParent[0] != this.doc[0] && this.scrollParent[0].tagName != 'HTML') {
+ this.overflowOffset = this.scrollParent.offset();
+ }
+
+ this.overflow = {};
+
+ this.overflow.height = ( this.scrollParent[0] === this.doc[0] ) ?
this.win.height() : this.scrollParent.height();
- this.overflowWidth = ( this.scrollParent[0] === this.doc[0] ) ?
+
+ this.overflow.width = ( this.scrollParent[0] === this.doc[0] ) ?
this.win.width() : this.scrollParent.width();
- // TODO: allow modifying position, just like during drag
+ this._preparePosition( event );
+
this._trigger( "start", event, this._uiHash() );
+
+ // TODO: should user be able to change position of draggable, if event stopped?
+ // If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
+ if ( event.cancelBubble === true ) {
+ this.doc.unbind( "." + this.widgetName );
+ return;
+ }
+
+ this._setCss( event );
this._bind( this.doc, {
mousemove: "_mouseMove",
@@ -139,24 +201,76 @@ $.widget( "ui.draggable", {
},
_mouseMove: function( event ) {
+ var newLeft, newTop;
+
+ this._preparePosition( event );
+
+ this._trigger( "drag", event, this._uiHash() );
+
+ // TODO: should user be able to change position of draggable, if event stopped?
+ // If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
+ if ( event.cancelBubble === true ) {
+ this.doc.unbind( "." + this.widgetName );
+ return;
+ }
+
+ this._setCss( event );
+
+ // Scroll the scrollParent, if needed
+ this._handleScrolling( event );
+ },
+
+ _mouseUp: function( event ) {
+
+ this._preparePosition( event );
+
+ this._trigger( "stop", event, this._uiHash() );
+
+ // TODO: should user be able to change position of draggable, if event stopped?
+ // If user stops propagation, leave helper there, disallow any CSS changes
+ if ( event.cancelBubble !== true ) {
+
+ this._setCss( event );
+
+ if ( this.options.helper ) {
+ this.dragEl.remove();
+ }
+
+ }
+
+ this.doc.unbind( "." + this.widgetName );
+ },
+
+ // Uses event to determine new position of draggable, before any override from callbacks
+ _preparePosition: function( event ) {
var leftDiff = event.clientX - this.startCoords.left,
topDiff = event.clientY - this.startCoords.top,
newLeft = leftDiff + this.startPosition.left,
newTop = topDiff + this.startPosition.top;
+ // Save off new values for .css() in various callbacks using this function
this.position = {
left: newLeft,
top: newTop
};
+ // Save off values to compare user override against automatic coordinates
+ this.tempPosition = {
+ left: newLeft,
+ top: newTop
+ }
+
// Refresh offset cache with new positions
this.offset.left = this.startOffset.left + newLeft;
this.offset.top = this.startOffset.top + newTop;
+ },
- this._trigger( "drag", event, this._uiHash() );
+ // Places draggable where mouse or user from callback indicates
+ _setCss: function( event ) {
+ var newLeft, newTop;
// User overriding left/top so shortcut math is no longer valid
- if ( newLeft !== this.position.left || newTop !== this.position.top ) {
+ if ( this.tempPosition.left !== this.position.left || this.tempPosition.top !== this.position.top ) {
// TODO: can we just store the previous offset values
// and not go through .offset()?
// refresh offset using slower functions
@@ -176,34 +290,6 @@ $.widget( "ui.draggable", {
left: newLeft + "px",
top: newTop + "px"
});
-
- // Scroll the scrollParent, if needed
- this._handleScrolling( event );
- },
-
- _handleScrolling: function( event ) {
- var scrollTop = this.doc.scrollTop(),
- scrollLeft = this.doc.scrollLeft();
-
- // Handle vertical scrolling
- if ( ( ( this.overflowHeight + scrollTop ) - event.pageY ) < this.options.scrollSensitivity ) {
- this.doc.scrollTop( scrollTop + this.options.scrollSpeed );
- }
-
- // Handle horizontal scrolling
- if ( ( ( this.overflowWidth + scrollLeft ) - event.pageX ) < this.options.scrollSensitivity ) {
- this.doc.scrollLeft( scrollLeft + this.options.scrollSpeed );
- }
- },
-
- _mouseUp: function( event ) {
- this._trigger( "stop", event, this._uiHash() );
-
- if ( this.options.helper ) {
- this.dragEl.remove();
- }
-
- this.doc.unbind( "." + this.widgetName );
},
_uiHash: function( event ) {
diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js
index 31328a45564..5af56de040e 100644
--- a/ui/jquery.ui.widget.js
+++ b/ui/jquery.ui.widget.js
@@ -183,6 +183,9 @@ $.Widget.prototype = {
_createWidget: function( options, element ) {
element = $( element || this.defaultElement || this )[ 0 ];
this.element = $( element );
+ this.doc = $( this.element[0].ownerDocument );
+ this.win = $( this.doc[0].defaultView );
+ this.body = this.doc.body;
this.options = $.widget.extend( {},
this.options,
this._getCreateOptions(),
From e1e43e31091d5ea589a80c797c6e959a246f5337 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?=
Date: Thu, 27 Oct 2011 14:20:55 -0400
Subject: [PATCH 013/190] Draggable: Add ui-draggable class.
---
ui/jquery.ui.draggable.js | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 390c85a0522..f3842c9b553 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -41,6 +41,7 @@ $.widget( "ui.draggable", {
this.element.css( "position", "relative" );
}
+ this.element.addClass( "ui-draggable" );
this._bind({ mousedown: "_mouseDown" });
},
@@ -56,7 +57,7 @@ $.widget( "ui.draggable", {
// Take into account scrollbar
position.top -= scrollTop;
- position.left -= scrollLeft
+ position.left -= scrollLeft;
return position;
}
@@ -258,7 +259,7 @@ $.widget( "ui.draggable", {
this.tempPosition = {
left: newLeft,
top: newTop
- }
+ };
// Refresh offset cache with new positions
this.offset.left = this.startOffset.left + newLeft;
@@ -297,6 +298,10 @@ $.widget( "ui.draggable", {
position: this.position,
offset: this.offset
};
+ },
+
+ _destroy: function() {
+ this.element.removeClass( "ui-draggable" );
}
});
From 35e4ccae9129df1fc7f951ca40e2664b4b31acf4 Mon Sep 17 00:00:00 2001
From: Corey Frang
Date: Thu, 27 Oct 2011 21:34:48 -0500
Subject: [PATCH 014/190] Widget: Removing code to merge clean
---
ui/jquery.ui.widget.js | 3 ---
1 file changed, 3 deletions(-)
diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js
index 5af56de040e..31328a45564 100644
--- a/ui/jquery.ui.widget.js
+++ b/ui/jquery.ui.widget.js
@@ -183,9 +183,6 @@ $.Widget.prototype = {
_createWidget: function( options, element ) {
element = $( element || this.defaultElement || this )[ 0 ];
this.element = $( element );
- this.doc = $( this.element[0].ownerDocument );
- this.win = $( this.doc[0].defaultView );
- this.body = this.doc.body;
this.options = $.widget.extend( {},
this.options,
this._getCreateOptions(),
From f7ec5029922af49d0637d17758271bdb3c40f731 Mon Sep 17 00:00:00 2001
From: Corey Frang
Date: Thu, 27 Oct 2011 21:39:33 -0500
Subject: [PATCH 015/190] Draggable: Using this.document and this.window
instead of doc/win
---
ui/jquery.ui.draggable.js | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index f3842c9b553..f073fab5355 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -150,7 +150,7 @@ $.widget( "ui.draggable", {
this.dragEl
// TODO: should we move this to the stylesheet and use a class?
.css( "position", "absolute" )
- .appendTo( this.doc[0].body )
+ .appendTo( this.document[0].body )
.offset( this.element.offset() );
}
@@ -170,17 +170,17 @@ $.widget( "ui.draggable", {
};
// Cache the offset of scrollParent, if required for _handleScrolling
- if ( this.scrollParent[0] != this.doc[0] && this.scrollParent[0].tagName != 'HTML') {
+ if ( this.scrollParent[0] != this.document[0] && this.scrollParent[0].tagName != 'HTML') {
this.overflowOffset = this.scrollParent.offset();
}
this.overflow = {};
- this.overflow.height = ( this.scrollParent[0] === this.doc[0] ) ?
- this.win.height() : this.scrollParent.height();
+ this.overflow.height = ( this.scrollParent[0] === this.document[0] ) ?
+ this.window.height() : this.scrollParent.height();
- this.overflow.width = ( this.scrollParent[0] === this.doc[0] ) ?
- this.win.width() : this.scrollParent.width();
+ this.overflow.width = ( this.scrollParent[0] === this.document[0] ) ?
+ this.window.width() : this.scrollParent.width();
this._preparePosition( event );
@@ -189,13 +189,13 @@ $.widget( "ui.draggable", {
// TODO: should user be able to change position of draggable, if event stopped?
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
if ( event.cancelBubble === true ) {
- this.doc.unbind( "." + this.widgetName );
+ this.document.unbind( "." + this.widgetName );
return;
}
this._setCss( event );
- this._bind( this.doc, {
+ this._bind( this.document, {
mousemove: "_mouseMove",
mouseup: "_mouseUp"
});
@@ -211,7 +211,7 @@ $.widget( "ui.draggable", {
// TODO: should user be able to change position of draggable, if event stopped?
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
if ( event.cancelBubble === true ) {
- this.doc.unbind( "." + this.widgetName );
+ this.document.unbind( "." + this.widgetName );
return;
}
@@ -239,7 +239,7 @@ $.widget( "ui.draggable", {
}
- this.doc.unbind( "." + this.widgetName );
+ this.document.unbind( "." + this.widgetName );
},
// Uses event to determine new position of draggable, before any override from callbacks
From ec9c1cf6f42adbac695c1c142d28b6a8a53a8616 Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Sun, 6 Nov 2011 16:20:56 -0500
Subject: [PATCH 016/190] Draggable: Proper use of ._trigger for detecting
preventDefault. _uiHash now returns position and helper - removed offset.
---
ui/jquery.ui.draggable.js | 39 +++++++++++++++++++++++----------------
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 390c85a0522..4677eaf30ac 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -124,7 +124,7 @@ $.widget( "ui.draggable", {
},
_mouseDown: function( event ) {
- var newLeft, newTop;
+ var newLeft, newTop, allowed;
// Prevent text selection, among other things
event.preventDefault();
@@ -183,11 +183,10 @@ $.widget( "ui.draggable", {
this._preparePosition( event );
- this._trigger( "start", event, this._uiHash() );
+ allowed = this._trigger( "start", event, this._uiHash() );
- // TODO: should user be able to change position of draggable, if event stopped?
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
- if ( event.cancelBubble === true ) {
+ if ( allowed !== true ) {
this.doc.unbind( "." + this.widgetName );
return;
}
@@ -201,15 +200,15 @@ $.widget( "ui.draggable", {
},
_mouseMove: function( event ) {
- var newLeft, newTop;
-
+ var newLeft, newTop, allowed;
+
this._preparePosition( event );
- this._trigger( "drag", event, this._uiHash() );
-
- // TODO: should user be able to change position of draggable, if event stopped?
+ allowed = this._trigger( "drag", event, this._uiHash() );
+
+
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
- if ( event.cancelBubble === true ) {
+ if ( allowed !== true ) {
this.doc.unbind( "." + this.widgetName );
return;
}
@@ -221,14 +220,15 @@ $.widget( "ui.draggable", {
},
_mouseUp: function( event ) {
+
+ var allowed;
this._preparePosition( event );
- this._trigger( "stop", event, this._uiHash() );
+ allowed = this._trigger( "stop", event, this._uiHash() );
- // TODO: should user be able to change position of draggable, if event stopped?
// If user stops propagation, leave helper there, disallow any CSS changes
- if ( event.cancelBubble !== true ) {
+ if ( allowed === true ) {
this._setCss( event );
@@ -293,10 +293,17 @@ $.widget( "ui.draggable", {
},
_uiHash: function( event ) {
- return {
- position: this.position,
- offset: this.offset
+ var ret = {
+ position: this.position
+ // offset: this.offset
};
+
+ if ( this.options.helper ) {
+ ret.helper = this.dragEl;
+ }
+
+ return ret;
+
}
});
From 536a11893ad3cb6e2e480c83fc7662cd57877906 Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Sun, 6 Nov 2011 16:31:09 -0500
Subject: [PATCH 017/190] Draggable: Removed answered TODO
---
ui/jquery.ui.draggable.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 4677eaf30ac..b3fdd6f1440 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -76,7 +76,6 @@ $.widget( "ui.draggable", {
},
_handleScrolling: function( event ) {
- // TODO: what is expected behavior of absolute/fixed draggable inside a div having overflow:scroll?
var scrollTop = this.scrollParent.scrollTop(),
scrollLeft = this.scrollParent.scrollLeft();
From 7941f7c13f884ebe1e123fffd2ee2675db0c828b Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Sun, 6 Nov 2011 16:39:17 -0500
Subject: [PATCH 018/190] Draggable: Redid f7ec502992 after bad merge.
---
ui/jquery.ui.draggable.js | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index b3fdd6f1440..3b1b9f29d1e 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -46,7 +46,7 @@ $.widget( "ui.draggable", {
// TODO: why is relative handled differently than fixed/absolute?
_getPosition: function() {
- var left, top, position,
+ var left, top, position, offset,
scrollTop = this.scrollParent.scrollTop(),
scrollLeft = this.scrollParent.scrollLeft();
@@ -56,7 +56,7 @@ $.widget( "ui.draggable", {
// Take into account scrollbar
position.top -= scrollTop;
- position.left -= scrollLeft
+ position.left -= scrollLeft;
return position;
}
@@ -148,7 +148,7 @@ $.widget( "ui.draggable", {
this.dragEl
// TODO: should we move this to the stylesheet and use a class?
.css( "position", "absolute" )
- .appendTo( this.doc[0].body )
+ .appendTo( this.document[0].body )
.offset( this.element.offset() );
}
@@ -168,17 +168,17 @@ $.widget( "ui.draggable", {
};
// Cache the offset of scrollParent, if required for _handleScrolling
- if ( this.scrollParent[0] != this.doc[0] && this.scrollParent[0].tagName != 'HTML') {
+ if ( this.scrollParent[0] !== this.document[0] && this.scrollParent[0].tagName !== 'HTML') {
this.overflowOffset = this.scrollParent.offset();
}
this.overflow = {};
- this.overflow.height = ( this.scrollParent[0] === this.doc[0] ) ?
- this.win.height() : this.scrollParent.height();
+ this.overflow.height = ( this.scrollParent[0] === this.document[0] ) ?
+ this.window.height() : this.scrollParent.height();
- this.overflow.width = ( this.scrollParent[0] === this.doc[0] ) ?
- this.win.width() : this.scrollParent.width();
+ this.overflow.width = ( this.scrollParent[0] === this.document[0] ) ?
+ this.window.width() : this.scrollParent.width();
this._preparePosition( event );
@@ -186,13 +186,13 @@ $.widget( "ui.draggable", {
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
if ( allowed !== true ) {
- this.doc.unbind( "." + this.widgetName );
+ this.document.unbind( "." + this.widgetName );
return;
}
this._setCss( event );
- this._bind( this.doc, {
+ this._bind( this.document, {
mousemove: "_mouseMove",
mouseup: "_mouseUp"
});
@@ -208,7 +208,7 @@ $.widget( "ui.draggable", {
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
if ( allowed !== true ) {
- this.doc.unbind( "." + this.widgetName );
+ this.document.unbind( "." + this.widgetName );
return;
}
@@ -237,7 +237,7 @@ $.widget( "ui.draggable", {
}
- this.doc.unbind( "." + this.widgetName );
+ this.document.unbind( "." + this.widgetName );
},
// Uses event to determine new position of draggable, before any override from callbacks
@@ -257,7 +257,7 @@ $.widget( "ui.draggable", {
this.tempPosition = {
left: newLeft,
top: newTop
- }
+ };
// Refresh offset cache with new positions
this.offset.left = this.startOffset.left + newLeft;
From 1ca93b4a6c438928268179fd98872ba270ae5e49 Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Sun, 6 Nov 2011 17:42:35 -0500
Subject: [PATCH 019/190] Draggable: Added in iframeFix option
---
ui/jquery.ui.draggable.js | 92 +++++++++++++++++++++++++++++++--------
1 file changed, 73 insertions(+), 19 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 3b1b9f29d1e..21412cf9805 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -20,7 +20,8 @@ $.widget( "ui.draggable", {
options: {
helper: false,
scrollSensitivity: 20,
- scrollSpeed: 20
+ scrollSpeed: 20,
+ iframeFix: false
},
// dragEl: element being dragged (original or helper)
@@ -33,6 +34,36 @@ $.widget( "ui.draggable", {
// overflowOffset: offset of scroll parent
// overflow: object containing width and height keys of scroll parent
+ _blockFrames: function() {
+
+ var iframes = $('iframe'),
+ widget = this;
+
+ this.iframeBlocks = $('');
+
+ iframes.each( function() {
+
+ var iframe = $(this),
+ width = iframe.outerWidth(),
+ height = iframe.outerHeight(),
+ iframeOffset = iframe.offset(),
+ block = $('');
+
+ block.css({
+ position: 'absolute',
+ width: width+'px',
+ height: height+'px',
+ top: iframeOffset.top+'px',
+ left: iframeOffset.left+'px'
+ })
+ .appendTo( widget.document[0].body );
+
+ widget.iframeBlocks = widget.iframeBlocks.add( block );
+
+ });
+
+ },
+
_create: function() {
this.scrollParent = this.element.scrollParent();
@@ -78,10 +109,10 @@ $.widget( "ui.draggable", {
_handleScrolling: function( event ) {
var scrollTop = this.scrollParent.scrollTop(),
scrollLeft = this.scrollParent.scrollLeft();
-
+
// overflowOffset is only set when scrollParent is not doc/html
if ( !this.overflowOffset ) {
-
+
// Handle vertical scrolling
if ( ( ( this.overflow.height + scrollTop ) - event.pageY ) < this.options.scrollSensitivity ) {
this.scrollParent.scrollTop( scrollTop + this.options.scrollSpeed );
@@ -89,7 +120,7 @@ $.widget( "ui.draggable", {
else if ( event.pageY < ( scrollTop + this.options.scrollSensitivity ) ) {
this.scrollParent.scrollTop( scrollTop - this.options.scrollSpeed );
}
-
+
// Handle horizontal scrolling
if ( ( ( this.overflow.width + scrollLeft ) - event.pageX ) < this.options.scrollSensitivity ) {
this.scrollParent.scrollLeft( scrollLeft + this.options.scrollSpeed );
@@ -97,10 +128,10 @@ $.widget( "ui.draggable", {
else if ( event.pageX < ( scrollLeft + this.options.scrollSensitivity ) ) {
this.scrollParent.scrollLeft( scrollLeft - this.options.scrollSpeed );
}
-
+
} else {
-
-
+
+
// Handle vertical scrolling
if ( ( event.pageY + this.options.scrollSensitivity ) > ( this.overflow.height + this.overflowOffset.top ) ) {
this.scrollParent.scrollTop( scrollTop + this.options.scrollSpeed );
@@ -108,7 +139,7 @@ $.widget( "ui.draggable", {
else if ( ( event.pageY - this.options.scrollSensitivity ) < this.overflowOffset.top ) {
this.scrollParent.scrollTop( scrollTop - this.options.scrollSpeed );
}
-
+
// Handle horizontal scrolling
if ( ( event.pageX + this.options.scrollSensitivity ) > ( this.overflow.width + this.overflowOffset.left ) ) {
this.scrollParent.scrollLeft( scrollLeft + this.options.scrollSpeed );
@@ -116,10 +147,10 @@ $.widget( "ui.draggable", {
else if ( ( event.pageX - this.options.scrollSensitivity ) < this.overflowOffset.left ) {
this.scrollParent.scrollLeft( scrollLeft - this.options.scrollSpeed );
}
-
-
+
+
}
-
+
},
_mouseDown: function( event ) {
@@ -131,6 +162,10 @@ $.widget( "ui.draggable", {
// The actual dragging element, should always be a jQuery object
this.dragEl = this.element;
+ if ( this.options.iframeFix === true ) {
+ this._blockFrames();
+ }
+
// Helper required
if ( this.options.helper ) {
// clone
@@ -151,7 +186,7 @@ $.widget( "ui.draggable", {
.appendTo( this.document[0].body )
.offset( this.element.offset() );
}
-
+
this.cssPosition = this.dragEl.css( "position" );
// Cache starting absolute and relative positions
@@ -183,7 +218,7 @@ $.widget( "ui.draggable", {
this._preparePosition( event );
allowed = this._trigger( "start", event, this._uiHash() );
-
+
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
if ( allowed !== true ) {
this.document.unbind( "." + this.widgetName );
@@ -200,12 +235,12 @@ $.widget( "ui.draggable", {
_mouseMove: function( event ) {
var newLeft, newTop, allowed;
-
+
this._preparePosition( event );
allowed = this._trigger( "drag", event, this._uiHash() );
-
-
+
+
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
if ( allowed !== true ) {
this.document.unbind( "." + this.widgetName );
@@ -219,7 +254,7 @@ $.widget( "ui.draggable", {
},
_mouseUp: function( event ) {
-
+
var allowed;
this._preparePosition( event );
@@ -238,6 +273,11 @@ $.widget( "ui.draggable", {
}
this.document.unbind( "." + this.widgetName );
+
+ if ( this.options.iframeFix === true ) {
+ this._unblockFrames();
+ }
+
},
// Uses event to determine new position of draggable, before any override from callbacks
@@ -296,13 +336,27 @@ $.widget( "ui.draggable", {
position: this.position
// offset: this.offset
};
-
+
if ( this.options.helper ) {
ret.helper = this.dragEl;
}
-
+
return ret;
+
+ },
+
+ _unblockFrames: function() {
+
+ if ( !this.iframeBlocks || !this.iframeBlocks.length ) {
+ return;
+ }
+ this.iframeBlocks.each( function() {
+
+ $(this).remove();
+
+ });
+
}
});
From 38c06026a125aaeacb8dd73e0deb3a276b6836e9 Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Sun, 13 Nov 2011 17:14:19 -0500
Subject: [PATCH 020/190] Draggable: Fixed offset calculation. Offset now
passed back in uiHash.
---
ui/jquery.ui.draggable.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 21412cf9805..180f3038f57 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -298,10 +298,10 @@ $.widget( "ui.draggable", {
left: newLeft,
top: newTop
};
-
+
// Refresh offset cache with new positions
- this.offset.left = this.startOffset.left + newLeft;
- this.offset.top = this.startOffset.top + newTop;
+ this.offset.left = this.startOffset.left + leftDiff;
+ this.offset.top = this.startOffset.top + topDiff;
},
// Places draggable where mouse or user from callback indicates
@@ -333,8 +333,8 @@ $.widget( "ui.draggable", {
_uiHash: function( event ) {
var ret = {
- position: this.position
- // offset: this.offset
+ position: this.position,
+ offset: this.offset
};
if ( this.options.helper ) {
From 3c6455df0b5c405d7b1c9c2624ff2819c853313a Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Sun, 13 Nov 2011 17:28:56 -0500
Subject: [PATCH 021/190] Droppable: 2.0 initial commit
---
ui/jquery.ui.droppable.js | 302 +++++++-------------------------------
1 file changed, 51 insertions(+), 251 deletions(-)
diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js
index 3942c6b8f49..5cec18b6cc9 100644
--- a/ui/jquery.ui.droppable.js
+++ b/ui/jquery.ui.droppable.js
@@ -10,7 +10,6 @@
* Depends:
* jquery.ui.core.js
* jquery.ui.widget.js
- * jquery.ui.mouse.js
* jquery.ui.draggable.js
*/
(function( $, undefined ) {
@@ -18,276 +17,77 @@
$.widget("ui.droppable", {
version: "@VERSION",
widgetEventPrefix: "drop",
+ allowedTolerance: ['touch'],
options: {
- accept: '*',
- activeClass: false,
- addClasses: true,
- greedy: false,
- hoverClass: false,
- scope: 'default',
- tolerance: 'intersect'
+ // accept: '*',
+ // activeClass: false,
+ // addClasses: true,
+ // greedy: false,
+ // hoverClass: false,
+ // scope: 'default',
+ tolerance: 'touch' //'intersect'
},
+
+ // draggableProportions: width and height of currently dragging draggable
+ // proportions: width and height of droppable
+
_create: function() {
- var o = this.options, accept = o.accept;
- this.isover = 0; this.isout = 1;
-
- this.accept = $.isFunction(accept) ? accept : function(d) {
- return d.is(accept);
- };
+ // Store current location
+ this.offset = this.element.offset();
//Store the droppable's proportions
this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
- // Add the reference and positions to the manager
- $.ui.ddmanager.droppables[o.scope] = $.ui.ddmanager.droppables[o.scope] || [];
- $.ui.ddmanager.droppables[o.scope].push(this);
-
- (o.addClasses && this.element.addClass("ui-droppable"));
-
- },
-
- destroy: function() {
- var drop = $.ui.ddmanager.droppables[this.options.scope];
- for ( var i = 0; i < drop.length; i++ )
- if ( drop[i] == this )
- drop.splice(i, 1);
-
- this.element
- .removeClass("ui-droppable ui-droppable-disabled")
- .removeData("droppable")
- .unbind(".droppable");
-
- return this;
- },
-
- _setOption: function(key, value) {
-
- if(key == 'accept') {
- this.accept = $.isFunction(value) ? value : function(d) {
- return d.is(value);
- };
- }
- $.Widget.prototype._setOption.apply(this, arguments);
- },
-
- _activate: function(event) {
- var draggable = $.ui.ddmanager.current;
- if(this.options.activeClass) this.element.addClass(this.options.activeClass);
- (draggable && this._trigger('activate', event, this.ui(draggable)));
- },
-
- _deactivate: function(event) {
- var draggable = $.ui.ddmanager.current;
- if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
- (draggable && this._trigger('deactivate', event, this.ui(draggable)));
- },
-
- _over: function(event) {
-
- var draggable = $.ui.ddmanager.current;
- if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
-
- if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
- if(this.options.hoverClass) this.element.addClass(this.options.hoverClass);
- this._trigger('over', event, this.ui(draggable));
- }
+ // TODO: Use $.Callbacks or .on from 1.7
+ $('*').live( "drag", $.proxy( this._drag, this ) );
+ $('*').live( "dragstart", $.proxy( this._dragStart, this ) );
},
- _out: function(event) {
-
- var draggable = $.ui.ddmanager.current;
- if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
-
- if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
- if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
- this._trigger('out', event, this.ui(draggable));
- }
+ _drag: function( event, ui ) {
+
+ var rightEdge, bottomEdge, draggableRightEdge, draggableBottomEdge, xOverlap, yOverlap;
+
+ switch ( this.options.tolerance ) {
+
+ case 'touch':
+ rightEdge = ( this.offset.left + this.proportions.width ),
+ bottomEdge = ( this.offset.top + this.proportions.height ),
+ draggableRightEdge = ( ui.offset.left + this.draggableProportions.width ),
+ draggableBottomEdge = ( ui.offset.top + this.draggableProportions.height ),
+ xOverlap = ( draggableRightEdge >= this.offset.left && ui.offset.left <= rightEdge ),
+ yOverlap = ( draggableBottomEdge >= this.offset.top && ui.offset.top <= bottomEdge );
+
+ if ( xOverlap && yOverlap ) {
+ // TODO: properly fill out uiHash
+ this._trigger( "over", event, {} );
+ }
+
+ break;
+
+ default:
+ throw( "Invalid tolerance passed: " + this.options.tolerance + ". Allowed: " + this.allowedTolerance.join( ', ' ) );
+ break;
+ }
+
},
- _drop: function(event,custom) {
-
- var draggable = custom || $.ui.ddmanager.current;
- if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element
-
- var childrenIntersection = false;
- this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() {
- var inst = $.data(this, 'droppable');
- if(
- inst.options.greedy
- && !inst.options.disabled
- && inst.options.scope == draggable.options.scope
- && inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element))
- && $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)
- ) { childrenIntersection = true; return false; }
- });
- if(childrenIntersection) return false;
+ _dragStart: function( event, ui ) {
+
+ var draggable = $( event.target );
+
+ this.draggableProportions = { width: draggable[0].offsetWidth, height: draggable[0].offsetHeight };
+
- if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
- if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
- if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
- this._trigger('drop', event, this.ui(draggable));
- return this.element;
- }
- return false;
-
- },
-
- ui: function(c) {
- return {
- draggable: (c.currentItem || c.element),
- helper: c.helper,
- position: c.position,
- offset: c.positionAbs
- };
}
-});
-
-$.ui.intersect = function(draggable, droppable, toleranceMode) {
-
- if (!droppable.offset) return false;
-
- var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
- y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height;
- var l = droppable.offset.left, r = l + droppable.proportions.width,
- t = droppable.offset.top, b = t + droppable.proportions.height;
- switch (toleranceMode) {
- case 'fit':
- return (l <= x1 && x2 <= r
- && t <= y1 && y2 <= b);
- break;
- case 'intersect':
- return (l < x1 + (draggable.helperProportions.width / 2) // Right Half
- && x2 - (draggable.helperProportions.width / 2) < r // Left Half
- && t < y1 + (draggable.helperProportions.height / 2) // Bottom Half
- && y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
- break;
- case 'pointer':
- var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left),
- draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top),
- isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width);
- return isOver;
- break;
- case 'touch':
- return (
- (y1 >= t && y1 <= b) || // Top edge touching
- (y2 >= t && y2 <= b) || // Bottom edge touching
- (y1 < t && y2 > b) // Surrounded vertically
- ) && (
- (x1 >= l && x1 <= r) || // Left edge touching
- (x2 >= l && x2 <= r) || // Right edge touching
- (x1 < l && x2 > r) // Surrounded horizontally
- );
- break;
- default:
- return false;
- break;
- }
-};
-
-/*
- This manager tracks offsets of draggables and droppables
-*/
-$.ui.ddmanager = {
- current: null,
- droppables: { 'default': [] },
- prepareOffsets: function(t, event) {
-
- var m = $.ui.ddmanager.droppables[t.options.scope] || [];
- var type = event ? event.type : null; // workaround for #2317
- var list = (t.currentItem || t.element).find(":data(droppable)").andSelf();
-
- droppablesLoop: for (var i = 0; i < m.length; i++) {
-
- if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) continue; //No disabled and non-accepted
- for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item
- m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue
-
- if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables
-
- m[i].offset = m[i].element.offset();
- m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
-
- }
-
- },
- drop: function(draggable, event) {
-
- var dropped = false;
- $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
-
- if(!this.options) return;
- if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance))
- dropped = dropped || this._drop.call(this, event);
-
- if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
- this.isout = 1; this.isover = 0;
- this._deactivate.call(this, event);
- }
-
- });
- return dropped;
-
- },
- dragStart: function( draggable, event ) {
- //Listen for scrolling so that if the dragging causes scrolling the position of the droppables can be recalculated (see #5003)
- draggable.element.parentsUntil( "body" ).bind( "scroll.droppable", function() {
- if( !draggable.options.refreshPositions ) $.ui.ddmanager.prepareOffsets( draggable, event );
- });
- },
- drag: function(draggable, event) {
-
- //If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
- if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event);
-
- //Run through all droppables and check their positions based on specific tolerance options
- $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
-
- if(this.options.disabled || this.greedyChild || !this.visible) return;
- var intersects = $.ui.intersect(draggable, this, this.options.tolerance);
-
- var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null);
- if(!c) return;
-
- var parentInstance;
- if (this.options.greedy) {
- var parent = this.element.parents(':data(droppable):eq(0)');
- if (parent.length) {
- parentInstance = $.data(parent[0], 'droppable');
- parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
- }
- }
-
- // we just moved into a greedy child
- if (parentInstance && c == 'isover') {
- parentInstance['isover'] = 0;
- parentInstance['isout'] = 1;
- parentInstance._out.call(parentInstance, event);
- }
+});
- this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0;
- this[c == "isover" ? "_over" : "_out"].call(this, event);
+})(jQuery);
- // we just moved out of a greedy child
- if (parentInstance && c == 'isout') {
- parentInstance['isout'] = 0;
- parentInstance['isover'] = 1;
- parentInstance._over.call(parentInstance, event);
- }
- });
- },
- dragStop: function( draggable, event ) {
- draggable.element.parentsUntil( "body" ).unbind( "scroll.droppable" );
- //Call prepareOffsets one final time since IE does not fire return scroll events when overflow was caused by drag (see #5003)
- if( !draggable.options.refreshPositions ) $.ui.ddmanager.prepareOffsets( draggable, event );
- }
-};
-
-})(jQuery);
From e8e7847a4113b849f2dffa7f29b599d65db96094 Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Sun, 13 Nov 2011 17:42:05 -0500
Subject: [PATCH 022/190] Droppable: over, out, and drop callbacks working
---
ui/jquery.ui.droppable.js | 35 ++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js
index 5cec18b6cc9..5f72cdf0db3 100644
--- a/ui/jquery.ui.droppable.js
+++ b/ui/jquery.ui.droppable.js
@@ -29,6 +29,7 @@ $.widget("ui.droppable", {
},
// draggableProportions: width and height of currently dragging draggable
+ // over: whether or not a draggable is currently over droppable
// proportions: width and height of droppable
_create: function() {
@@ -42,6 +43,10 @@ $.widget("ui.droppable", {
// TODO: Use $.Callbacks or .on from 1.7
$('*').live( "drag", $.proxy( this._drag, this ) );
$('*').live( "dragstart", $.proxy( this._dragStart, this ) );
+
+ this._bind( this.document, {
+ mouseup: "_mouseUp"
+ });
},
@@ -59,9 +64,15 @@ $.widget("ui.droppable", {
xOverlap = ( draggableRightEdge >= this.offset.left && ui.offset.left <= rightEdge ),
yOverlap = ( draggableBottomEdge >= this.offset.top && ui.offset.top <= bottomEdge );
+
if ( xOverlap && yOverlap ) {
- // TODO: properly fill out uiHash
- this._trigger( "over", event, {} );
+ this._trigger( "over", event, this._uiHash() );
+ this.over = true;
+ }
+ else if ( this.over ) {
+ this.over = false;
+ this._trigger( "out", event, this._uiHash() );
+
}
break;
@@ -77,11 +88,29 @@ $.widget("ui.droppable", {
_dragStart: function( event, ui ) {
var draggable = $( event.target );
-
+
+ // TODO: Possibly move into draggable hash, so if there are multiple droppables, it's not recalculating all the time
this.draggableProportions = { width: draggable[0].offsetWidth, height: draggable[0].offsetHeight };
+ },
+
+ _mouseUp: function( event ) {
+
+ if ( this.over ) {
+ this._trigger( "drop", event, this._uiHash() );
+ }
+
+ this.over = false;
+
+ },
+
+ // TODO: fill me out
+ _uiHash: function() {
+
+ return {};
+
}
From 9ee7c90a594924beb7dc99ad961df36b7f76c1e0 Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Sun, 13 Nov 2011 17:49:37 -0500
Subject: [PATCH 023/190] Droppable: Added refreshPosition public method
---
ui/jquery.ui.droppable.js | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js
index 5f72cdf0db3..dbccbae2c46 100644
--- a/ui/jquery.ui.droppable.js
+++ b/ui/jquery.ui.droppable.js
@@ -32,13 +32,20 @@ $.widget("ui.droppable", {
// over: whether or not a draggable is currently over droppable
// proportions: width and height of droppable
- _create: function() {
-
+
+ refreshPosition: function() {
+
// Store current location
this.offset = this.element.offset();
//Store the droppable's proportions
this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
+
+ },
+
+ _create: function() {
+
+ this.refreshPosition();
// TODO: Use $.Callbacks or .on from 1.7
$('*').live( "drag", $.proxy( this._drag, this ) );
From 3914cebe66c71956c9067eb37ee2dabc7d7caae8 Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Sun, 13 Nov 2011 18:39:04 -0500
Subject: [PATCH 024/190] Droppable: Intersect tolerance added
---
ui/jquery.ui.droppable.js | 134 ++++++++++++++++++++++++++------------
1 file changed, 91 insertions(+), 43 deletions(-)
diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js
index dbccbae2c46..e2eabd2d9c1 100644
--- a/ui/jquery.ui.droppable.js
+++ b/ui/jquery.ui.droppable.js
@@ -25,24 +25,24 @@ $.widget("ui.droppable", {
// greedy: false,
// hoverClass: false,
// scope: 'default',
- tolerance: 'touch' //'intersect'
+ tolerance: 'intersect'
},
-
+
// draggableProportions: width and height of currently dragging draggable
// over: whether or not a draggable is currently over droppable
// proportions: width and height of droppable
-
-
+
+
refreshPosition: function() {
-
+
// Store current location
this.offset = this.element.offset();
//Store the droppable's proportions
this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
-
+
},
-
+
_create: function() {
this.refreshPosition();
@@ -50,7 +50,7 @@ $.widget("ui.droppable", {
// TODO: Use $.Callbacks or .on from 1.7
$('*').live( "drag", $.proxy( this._drag, this ) );
$('*').live( "dragstart", $.proxy( this._dragStart, this ) );
-
+
this._bind( this.document, {
mouseup: "_mouseUp"
});
@@ -58,66 +58,114 @@ $.widget("ui.droppable", {
},
_drag: function( event, ui ) {
-
- var rightEdge, bottomEdge, draggableRightEdge, draggableBottomEdge, xOverlap, yOverlap;
-
- switch ( this.options.tolerance ) {
-
- case 'touch':
- rightEdge = ( this.offset.left + this.proportions.width ),
- bottomEdge = ( this.offset.top + this.proportions.height ),
- draggableRightEdge = ( ui.offset.left + this.draggableProportions.width ),
- draggableBottomEdge = ( ui.offset.top + this.draggableProportions.height ),
- xOverlap = ( draggableRightEdge >= this.offset.left && ui.offset.left <= rightEdge ),
- yOverlap = ( draggableBottomEdge >= this.offset.top && ui.offset.top <= bottomEdge );
-
-
- if ( xOverlap && yOverlap ) {
- this._trigger( "over", event, this._uiHash() );
- this.over = true;
- }
- else if ( this.over ) {
- this.over = false;
- this._trigger( "out", event, this._uiHash() );
-
- }
+
+ var handleFunc, edges,
+ tolerance = this.options.tolerance,
+ over = false;
+
+ switch ( tolerance ) {
+
+ case "intersect":
+ case "touch":
+
+ edges = {
+ right: ( this.offset.left + this.proportions.width ),
+ bottom: ( this.offset.top + this.proportions.height ),
+ draggableRight: ( ui.offset.left + this.draggableProportions.width ),
+ draggableBottom: ( ui.offset.top + this.draggableProportions.height )
+ };
+
+
+ handleFunc = "_handle" + tolerance.substr(0, 1 ).toUpperCase() + tolerance.substr( 1 );
+ over = this[ handleFunc ]( edges, ui );
break;
-
+
default:
- throw( "Invalid tolerance passed: " + this.options.tolerance + ". Allowed: " + this.allowedTolerance.join( ', ' ) );
- break;
+ throw( "Invalid tolerance passed: " + this.options.tolerance + ". Allowed: " + this.allowedTolerance.join( ", " ) );
+
}
+ // If there is sufficient overlap as deemed by tolerance
+ if ( over === true ) {
+
+ this._trigger( "over", event, this._uiHash() );
+ this.over = true;
+
+ }
+
+ // If there isn't enough overlap and droppable was previously flagged as over
+ else if ( this.over === true ) {
+
+ this.over = false;
+ this._trigger( "out", event, this._uiHash() );
+
+ }
},
_dragStart: function( event, ui ) {
-
+
var draggable = $( event.target );
-
+
// TODO: Possibly move into draggable hash, so if there are multiple droppables, it's not recalculating all the time
this.draggableProportions = { width: draggable[0].offsetWidth, height: draggable[0].offsetHeight };
-
+
+ },
+
+ // Determines if draggable is over droppable based on intersect tolerance
+ _handleIntersect: function( edges, ui ) {
+
+ var xDiff = edges.draggableRight - this.offset.left,
+ yDiff = edges.draggableBottom - this.offset.top,
+ xHalfway = Math.round( this.proportions.width / 2 ),
+ yHalfway = Math.round( this.proportions.height / 2 ),
+ xHalfOverlap = false;
+ yHalfOverlap = false;
+
+
+ // If Coming from left or right
+ xHalfOverlap = ( ui.offset.left < this.offset.left ) ?
+ ( xDiff >= xHalfway ) :
+ ( xDiff <= xHalfway + this.proportions.width );
+
+ // If Coming from top or bottom
+ yHalfOverlap = ( ui.offset.top < this.offset.top ) ?
+ ( yDiff >= yHalfway ) :
+ ( yDiff <= yHalfway + this.proportions.height );
+
+ return ( xHalfOverlap && yHalfOverlap );
+
+
},
- _mouseUp: function( event ) {
+ // Determines if draggable is over droppable based on touch tolerance
+ _handleTouch: function( edges, ui ) {
+ var xOverlap = ( edges.draggableRight >= this.offset.left && ui.offset.left <= edges.right ),
+ yOverlap = ( edges.draggableBottom >= this.offset.top && ui.offset.top <= edges.bottom );
+
+ return ( xOverlap && yOverlap );
+
+ },
+
+ _mouseUp: function( event ) {
+
if ( this.over ) {
this._trigger( "drop", event, this._uiHash() );
}
-
+
this.over = false;
-
+
},
-
+
// TODO: fill me out
_uiHash: function() {
-
+
return {};
-
+
}
From dac3dddd9e33471da95d1f125489e9931437f5da Mon Sep 17 00:00:00 2001
From: Dave Stein
Date: Sun, 13 Nov 2011 18:41:29 -0500
Subject: [PATCH 025/190] Droppable: Put tolerance in allowed array
---
ui/jquery.ui.droppable.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js
index e2eabd2d9c1..a24bb14c26c 100644
--- a/ui/jquery.ui.droppable.js
+++ b/ui/jquery.ui.droppable.js
@@ -17,7 +17,7 @@
$.widget("ui.droppable", {
version: "@VERSION",
widgetEventPrefix: "drop",
- allowedTolerance: ['touch'],
+ allowedTolerance: ["touch","intersect"],
options: {
// accept: '*',
// activeClass: false,
From 4792d5b7afe163446b4ce2ed2e49f4d78f62f9c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?=
Date: Thu, 17 Nov 2011 19:48:04 -0500
Subject: [PATCH 026/190] Draggable: Cleanup.
---
ui/jquery.ui.draggable.js | 110 ++++++++++++--------------------------
1 file changed, 34 insertions(+), 76 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 180f3038f57..d4e98a6173a 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -18,10 +18,10 @@ $.widget( "ui.draggable", {
widgetEventPrefix: "drag",
options: {
- helper: false,
+ helper: null,
+ // TODO: remove scroll options
scrollSensitivity: 20,
- scrollSpeed: 20,
- iframeFix: false
+ scrollSpeed: 20
},
// dragEl: element being dragged (original or helper)
@@ -34,37 +34,28 @@ $.widget( "ui.draggable", {
// overflowOffset: offset of scroll parent
// overflow: object containing width and height keys of scroll parent
+ // TODO: move next to _unblockFrames()
_blockFrames: function() {
-
- var iframes = $('iframe'),
- widget = this;
-
- this.iframeBlocks = $('');
-
- iframes.each( function() {
-
- var iframe = $(this),
- width = iframe.outerWidth(),
- height = iframe.outerHeight(),
- iframeOffset = iframe.offset(),
- block = $('');
-
- block.css({
- position: 'absolute',
- width: width+'px',
- height: height+'px',
- top: iframeOffset.top+'px',
- left: iframeOffset.left+'px'
- })
- .appendTo( widget.document[0].body );
-
- widget.iframeBlocks = widget.iframeBlocks.add( block );
-
+ var body = this.document[0].body;
+
+ this.iframeBlocks = this.document.find( "iframe" ).map(function() {
+ var iframe = $( this ),
+ iframeOffset = iframe.offset();
+
+ return $( "" )
+ .css({
+ position: "absolute",
+ width: iframe.outerWidth(),
+ height: iframe.outerHeight(),
+ top: iframeOffset.top,
+ left: iframeOffset.left
+ })
+ .appendTo( body )[0];
});
-
},
_create: function() {
+ // TODO: move to drag start in case DOM changes
this.scrollParent = this.element.scrollParent();
// Static position elements can't be moved with top/left
@@ -128,10 +119,7 @@ $.widget( "ui.draggable", {
else if ( event.pageX < ( scrollLeft + this.options.scrollSensitivity ) ) {
this.scrollParent.scrollLeft( scrollLeft - this.options.scrollSpeed );
}
-
} else {
-
-
// Handle vertical scrolling
if ( ( event.pageY + this.options.scrollSensitivity ) > ( this.overflow.height + this.overflowOffset.top ) ) {
this.scrollParent.scrollTop( scrollTop + this.options.scrollSpeed );
@@ -147,14 +135,11 @@ $.widget( "ui.draggable", {
else if ( ( event.pageX - this.options.scrollSensitivity ) < this.overflowOffset.left ) {
this.scrollParent.scrollLeft( scrollLeft - this.options.scrollSpeed );
}
-
-
}
-
},
_mouseDown: function( event ) {
- var newLeft, newTop, allowed;
+ var newLeft, newTop;
// Prevent text selection, among other things
event.preventDefault();
@@ -162,10 +147,6 @@ $.widget( "ui.draggable", {
// The actual dragging element, should always be a jQuery object
this.dragEl = this.element;
- if ( this.options.iframeFix === true ) {
- this._blockFrames();
- }
-
// Helper required
if ( this.options.helper ) {
// clone
@@ -217,14 +198,13 @@ $.widget( "ui.draggable", {
this._preparePosition( event );
- allowed = this._trigger( "start", event, this._uiHash() );
-
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
- if ( allowed !== true ) {
+ if ( this._trigger( "start", event, this._uiHash() ) === false ) {
this.document.unbind( "." + this.widgetName );
return;
}
+ this._blockFrames();
this._setCss( event );
this._bind( this.document, {
@@ -234,15 +214,12 @@ $.widget( "ui.draggable", {
},
_mouseMove: function( event ) {
- var newLeft, newTop, allowed;
+ var newLeft, newTop;
this._preparePosition( event );
- allowed = this._trigger( "drag", event, this._uiHash() );
-
-
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
- if ( allowed !== true ) {
+ if ( this._trigger( "drag", event, this._uiHash() ) === false ) {
this.document.unbind( "." + this.widgetName );
return;
}
@@ -254,30 +231,18 @@ $.widget( "ui.draggable", {
},
_mouseUp: function( event ) {
-
- var allowed;
-
this._preparePosition( event );
- allowed = this._trigger( "stop", event, this._uiHash() );
-
// If user stops propagation, leave helper there, disallow any CSS changes
- if ( allowed === true ) {
-
+ if ( this._trigger( "stop", event, this._uiHash() ) === false ) {
this._setCss( event );
-
if ( this.options.helper ) {
this.dragEl.remove();
}
-
}
this.document.unbind( "." + this.widgetName );
-
- if ( this.options.iframeFix === true ) {
- this._unblockFrames();
- }
-
+ this._unblockFrames();
},
// Uses event to determine new position of draggable, before any override from callbacks
@@ -298,7 +263,7 @@ $.widget( "ui.draggable", {
left: newLeft,
top: newTop
};
-
+
// Refresh offset cache with new positions
this.offset.left = this.startOffset.left + leftDiff;
this.offset.top = this.startOffset.top + topDiff;
@@ -326,8 +291,8 @@ $.widget( "ui.draggable", {
}
this.dragEl.css({
- left: newLeft + "px",
- top: newTop + "px"
+ left: newLeft,
+ top: newTop
});
},
@@ -337,26 +302,19 @@ $.widget( "ui.draggable", {
offset: this.offset
};
+ // TODO: should we always set the helper?
if ( this.options.helper ) {
ret.helper = this.dragEl;
}
return ret;
-
},
_unblockFrames: function() {
-
- if ( !this.iframeBlocks || !this.iframeBlocks.length ) {
- return;
+ if ( this.iframeBlocks ) {
+ this.iframeBlocks.remove();
+ delete this.iframeBlocks;
}
-
- this.iframeBlocks.each( function() {
-
- $(this).remove();
-
- });
-
}
});
From e9f5c1857f9d70e69f08be158b2275736c02647f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?=
Date: Thu, 17 Nov 2011 19:48:09 -0500
Subject: [PATCH 027/190] Droppable: Cleanup.
---
ui/jquery.ui.droppable.js | 158 +++++++++++++++-----------------------
1 file changed, 60 insertions(+), 98 deletions(-)
diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js
index a24bb14c26c..3555cb83707 100644
--- a/ui/jquery.ui.droppable.js
+++ b/ui/jquery.ui.droppable.js
@@ -5,7 +5,7 @@
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
- * http://docs.jquery.com/UI/Droppables
+ * http://docs.jquery.com/UI/Droppable
*
* Depends:
* jquery.ui.core.js
@@ -14,164 +14,126 @@
*/
(function( $, undefined ) {
-$.widget("ui.droppable", {
+$.widget( "ui.droppable", {
version: "@VERSION",
widgetEventPrefix: "drop",
- allowedTolerance: ["touch","intersect"],
options: {
- // accept: '*',
- // activeClass: false,
- // addClasses: true,
+ // accept: null,
// greedy: false,
- // hoverClass: false,
- // scope: 'default',
- tolerance: 'intersect'
+ tolerance: "intersect"
},
// draggableProportions: width and height of currently dragging draggable
// over: whether or not a draggable is currently over droppable
// proportions: width and height of droppable
-
+ // TODO: move below _create()
+ // TODO: rename to refresh()?
refreshPosition: function() {
-
// Store current location
this.offset = this.element.offset();
- //Store the droppable's proportions
- this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
-
+ // Store the droppable's proportions
+ // TODO: should this delegate to core?
+ this.proportions = {
+ width: this.element[0].offsetWidth,
+ height: this.element[0].offsetHeight
+ };
},
_create: function() {
-
this.refreshPosition();
- // TODO: Use $.Callbacks or .on from 1.7
- $('*').live( "drag", $.proxy( this._drag, this ) );
- $('*').live( "dragstart", $.proxy( this._dragStart, this ) );
+ // TODO: make this much more efficient
+ // possibly just override draggable's methods
+ $( "*" ).live( "drag", $.proxy( this._drag, this ) );
+ $( "*" ).live( "dragstart", $.proxy( this._dragStart, this ) );
this._bind( this.document, {
mouseup: "_mouseUp"
});
-
},
_drag: function( event, ui ) {
+ var tolerance = this.options.tolerance,
+ handleFunc = "_handle" + tolerance.substr( 0, 1 ).toUpperCase() + tolerance.substr( 1 ),
+ edges = {
+ right: this.offset.left + this.proportions.width,
+ bottom: this.offset.top + this.proportions.height,
+ draggableRight: ui.offset.left + this.draggableProportions.width,
+ draggableBottom: ui.offset.top + this.draggableProportions.height
+ },
+ over = this[ handleFunc ]( edges, ui );
- var handleFunc, edges,
- tolerance = this.options.tolerance,
- over = false;
-
- switch ( tolerance ) {
-
- case "intersect":
- case "touch":
-
- edges = {
- right: ( this.offset.left + this.proportions.width ),
- bottom: ( this.offset.top + this.proportions.height ),
- draggableRight: ( ui.offset.left + this.draggableProportions.width ),
- draggableBottom: ( ui.offset.top + this.draggableProportions.height )
- };
-
-
- handleFunc = "_handle" + tolerance.substr(0, 1 ).toUpperCase() + tolerance.substr( 1 );
- over = this[ handleFunc ]( edges, ui );
-
- break;
-
- default:
- throw( "Invalid tolerance passed: " + this.options.tolerance + ". Allowed: " + this.allowedTolerance.join( ", " ) );
-
- }
-
// If there is sufficient overlap as deemed by tolerance
- if ( over === true ) {
-
+ if ( over ) {
this._trigger( "over", event, this._uiHash() );
this.over = true;
-
- }
-
// If there isn't enough overlap and droppable was previously flagged as over
- else if ( this.over === true ) {
-
+ } else if ( this.over ) {
this.over = false;
this._trigger( "out", event, this._uiHash() );
-
}
-
},
_dragStart: function( event, ui ) {
-
var draggable = $( event.target );
// TODO: Possibly move into draggable hash, so if there are multiple droppables, it's not recalculating all the time
- this.draggableProportions = { width: draggable[0].offsetWidth, height: draggable[0].offsetHeight };
-
-
-
+ this.draggableProportions = {
+ width: draggable[0].offsetWidth,
+ height: draggable[0].offsetHeight
+ };
},
// Determines if draggable is over droppable based on intersect tolerance
+ // TODO: move all tolerance methods into a hash
+ // $.ui.droppable.tolerance.intersect
_handleIntersect: function( edges, ui ) {
-
var xDiff = edges.draggableRight - this.offset.left,
yDiff = edges.draggableBottom - this.offset.top,
- xHalfway = Math.round( this.proportions.width / 2 ),
- yHalfway = Math.round( this.proportions.height / 2 ),
- xHalfOverlap = false;
- yHalfOverlap = false;
-
-
- // If Coming from left or right
- xHalfOverlap = ( ui.offset.left < this.offset.left ) ?
- ( xDiff >= xHalfway ) :
- ( xDiff <= xHalfway + this.proportions.width );
-
- // If Coming from top or bottom
- yHalfOverlap = ( ui.offset.top < this.offset.top ) ?
- ( yDiff >= yHalfway ) :
- ( yDiff <= yHalfway + this.proportions.height );
-
- return ( xHalfOverlap && yHalfOverlap );
-
-
+ // TODO: is there really any need to round here?
+ xHalfway = Math.round( this.proportions.width / 2 ),
+ yHalfway = Math.round( this.proportions.height / 2 ),
+ xOverlap = false,
+ yOverlap = false;
+
+ // If Coming from left or right
+ xOverlap = ui.offset.left < this.offset.left ?
+ xDiff >= xHalfway :
+ xDiff <= xHalfway + this.proportions.width;
+
+ // If Coming from top or bottom
+ yOverlap = ui.offset.top < this.offset.top ?
+ yDiff >= yHalfway :
+ yDiff <= yHalfway + this.proportions.height;
+
+ return xOverlap && yOverlap;
},
-
+
// Determines if draggable is over droppable based on touch tolerance
_handleTouch: function( edges, ui ) {
-
- var xOverlap = ( edges.draggableRight >= this.offset.left && ui.offset.left <= edges.right ),
- yOverlap = ( edges.draggableBottom >= this.offset.top && ui.offset.top <= edges.bottom );
-
- return ( xOverlap && yOverlap );
-
+ var xOverlap = edges.draggableRight >= this.offset.left &&
+ ui.offset.left <= edges.right,
+ yOverlap = edges.draggableBottom >= this.offset.top &&
+ ui.offset.top <= edges.bottom;
+
+ return xOverlap && yOverlap;
},
-
- _mouseUp: function( event ) {
+ // TODO: shouldn't this be dragStop?
+ _mouseUp: function( event ) {
if ( this.over ) {
this._trigger( "drop", event, this._uiHash() );
}
this.over = false;
-
},
// TODO: fill me out
_uiHash: function() {
-
return {};
-
}
-
-
-
});
-})(jQuery);
-
-
+})( jQuery );
From 51e1d576f61dd6e924c6120ded7446ab2903b7c5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?=
Date: Wed, 23 Nov 2011 09:03:02 -0500
Subject: [PATCH 028/190] Draggable: Cleanup.
---
ui/jquery.ui.draggable.js | 47 ++++++++++++++++++---------------------
1 file changed, 22 insertions(+), 25 deletions(-)
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index d4e98a6173a..15b5f873b90 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -34,30 +34,7 @@ $.widget( "ui.draggable", {
// overflowOffset: offset of scroll parent
// overflow: object containing width and height keys of scroll parent
- // TODO: move next to _unblockFrames()
- _blockFrames: function() {
- var body = this.document[0].body;
-
- this.iframeBlocks = this.document.find( "iframe" ).map(function() {
- var iframe = $( this ),
- iframeOffset = iframe.offset();
-
- return $( "" )
- .css({
- position: "absolute",
- width: iframe.outerWidth(),
- height: iframe.outerHeight(),
- top: iframeOffset.top,
- left: iframeOffset.left
- })
- .appendTo( body )[0];
- });
- },
-
_create: function() {
- // TODO: move to drag start in case DOM changes
- this.scrollParent = this.element.scrollParent();
-
// Static position elements can't be moved with top/left
if ( this.element.css( "position" ) === "static" ) {
this.element.css( "position", "relative" );
@@ -66,7 +43,6 @@ $.widget( "ui.draggable", {
this._bind({ mousedown: "_mouseDown" });
},
- // TODO: why is relative handled differently than fixed/absolute?
_getPosition: function() {
var left, top, position, offset,
scrollTop = this.scrollParent.scrollTop(),
@@ -84,10 +60,11 @@ $.widget( "ui.draggable", {
}
// When using relative, css values are checked
+ // Otherwise the position wouldn't account for padding on ancestors
left = this.dragEl.css( "left" );
top = this.dragEl.css( "top" );
- // Webkit will give back auto if there is nothing inline yet
+ // Webkit will give back auto if there is no explicit value
left = ( left === "auto" ) ? 0: parseInt( left, 10 );
top = ( top === "auto" ) ? 0: parseInt( top, 10 );
@@ -169,6 +146,7 @@ $.widget( "ui.draggable", {
}
this.cssPosition = this.dragEl.css( "position" );
+ this.scrollParent = this.element.scrollParent();
// Cache starting absolute and relative positions
this.startPosition = this._getPosition();
@@ -310,6 +288,25 @@ $.widget( "ui.draggable", {
return ret;
},
+ _blockFrames: function() {
+ var body = this.document[0].body;
+
+ this.iframeBlocks = this.document.find( "iframe" ).map(function() {
+ var iframe = $( this ),
+ iframeOffset = iframe.offset();
+
+ return $( "
" )
+ .css({
+ position: "absolute",
+ width: iframe.outerWidth(),
+ height: iframe.outerHeight(),
+ top: iframeOffset.top,
+ left: iframeOffset.left
+ })
+ .appendTo( body )[0];
+ });
+ },
+
_unblockFrames: function() {
if ( this.iframeBlocks ) {
this.iframeBlocks.remove();
From dbaa744f0c17f48336ca17259045b08ac11ef312 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?=
Date: Wed, 23 Nov 2011 12:03:09 -0500
Subject: [PATCH 029/190] Interaction: Initial implementation for base
interaction plugin.
---
demos/draggable/default.html | 2 +-
ui/jquery.ui.draggable.js | 24 ++++---------
ui/jquery.ui.interaction.js | 69 ++++++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+), 19 deletions(-)
create mode 100644 ui/jquery.ui.interaction.js
diff --git a/demos/draggable/default.html b/demos/draggable/default.html
index 3a334d4b692..6dff38d85ee 100644
--- a/demos/draggable/default.html
+++ b/demos/draggable/default.html
@@ -7,7 +7,7 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+ - Start:
+ - 0
+ - Move:
+ - 0
+ - Stop:
+ - 0
+
+
+
+
+
+
+
This demo shows a simple interaction built using the interaction utility (jquery.ui.interaction.js).
+
Make a down-move-up motion starting on the blue box above using the mouse or a touch input device to see the interaction events
+
+
+
+