diff options
author | Mike Sherov <mike.sherov@gmail.com> | 2014-02-17 16:08:41 -0500 |
---|---|---|
committer | Mike Sherov <mike.sherov@gmail.com> | 2014-02-18 12:48:06 -0500 |
commit | 7017805745873e61b32769354a13dc697cdf3ae0 (patch) | |
tree | 1a80a1804e9eac15cac62cfc720c22941a4b0ef2 /ui/draggable.js | |
parent | 39ef4afb3c2aef251c9cab91ef62e63aa64db9c1 (diff) | |
download | jquery-ui-7017805745873e61b32769354a13dc697cdf3ae0.tar.gz jquery-ui-7017805745873e61b32769354a13dc697cdf3ae0.zip |
Draggable: fix current JSCS violations.
Diffstat (limited to 'ui/draggable.js')
-rw-r--r-- | ui/draggable.js | 141 |
1 files changed, 69 insertions, 72 deletions
diff --git a/ui/draggable.js b/ui/draggable.js index 13f898c8c..c27fc8733 100644 --- a/ui/draggable.js +++ b/ui/draggable.js @@ -122,7 +122,7 @@ $.widget("ui.draggable", $.ui.mouse, { $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() { $("<div class='ui-draggable-iframeFix' style='background: #fff;'></div>") .css({ - width: this.offsetWidth+"px", height: this.offsetHeight+"px", + width: this.offsetWidth + "px", height: this.offsetHeight + "px", position: "absolute", opacity: "0.001", zIndex: 1000 }) .css($(this).offset()) @@ -146,7 +146,7 @@ $.widget("ui.draggable", $.ui.mouse, { this._cacheHelperProportions(); //If ddmanager is used for droppables, set the global draggable - if($.ui.ddmanager) { + if ($.ui.ddmanager) { $.ui.ddmanager.current = this; } @@ -195,7 +195,7 @@ $.widget("ui.draggable", $.ui.mouse, { this._setContainment(); //Trigger event + callbacks - if(this._trigger("start", event) === false) { + if (this._trigger("start", event) === false) { this._clear(); return false; } @@ -208,7 +208,6 @@ $.widget("ui.draggable", $.ui.mouse, { $.ui.ddmanager.prepareOffsets(this, event); } - 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) @@ -232,7 +231,7 @@ $.widget("ui.draggable", $.ui.mouse, { //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) { + if (this._trigger("drag", event, ui) === false) { this._mouseUp({}); return false; } @@ -242,7 +241,7 @@ $.widget("ui.draggable", $.ui.mouse, { this.helper[ 0 ].style.left = this.position.left + "px"; this.helper[ 0 ].style.top = this.position.top + "px"; - if($.ui.ddmanager) { + if ($.ui.ddmanager) { $.ui.ddmanager.drag(this, event); } @@ -259,19 +258,19 @@ $.widget("ui.draggable", $.ui.mouse, { } //if a drop comes from outside (a sortable) - if(this.dropped) { + if (this.dropped) { dropped = this.dropped; this.dropped = false; } - if((this.options.revert === "invalid" && !dropped) || (this.options.revert === "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) { + 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))) { $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() { - if(that._trigger("stop", event) !== false) { + if (that._trigger("stop", event) !== false) { that._clear(); } }); } else { - if(this._trigger("stop", event) !== false) { + if (this._trigger("stop", event) !== false) { this._clear(); } } @@ -286,7 +285,7 @@ $.widget("ui.draggable", $.ui.mouse, { }); //If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003) - if( $.ui.ddmanager ) { + if ( $.ui.ddmanager ) { $.ui.ddmanager.dragStop(this, event); } @@ -298,7 +297,7 @@ $.widget("ui.draggable", $.ui.mouse, { cancel: function() { - if(this.helper.is(".ui-draggable-dragging")) { + if (this.helper.is(".ui-draggable-dragging")) { this._mouseUp({}); } else { this._clear(); @@ -328,13 +327,13 @@ $.widget("ui.draggable", $.ui.mouse, { _createHelper: function(event) { var o = this.options, - helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper === "clone" ? this.element.clone().removeAttr("id") : this.element); + 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) { + 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"))) { + if (helper[0] !== this.element[0] && !(/(fixed|absolute)/).test(helper.css("position"))) { helper.css("position", "absolute"); } @@ -347,7 +346,7 @@ $.widget("ui.draggable", $.ui.mouse, { obj = obj.split(" "); } if ($.isArray(obj)) { - obj = {left: +obj[0], top: +obj[1] || 0}; + obj = { left: +obj[0], top: +obj[1] || 0 }; } if ("left" in obj) { this.offset.click.left = obj.left + this.margins.left; @@ -377,7 +376,7 @@ $.widget("ui.draggable", $.ui.mouse, { // 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])) { + 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(); } @@ -469,7 +468,7 @@ $.widget("ui.draggable", $.ui.mouse, { c = $( o.containment ); ce = c[ 0 ]; - if( !ce ) { + if ( !ce ) { return; } @@ -477,7 +476,7 @@ $.widget("ui.draggable", $.ui.mouse, { this.containment = [ ( parseInt( c.css( "borderLeftWidth" ), 10 ) || 0 ) + ( parseInt( c.css( "paddingLeft" ), 10 ) || 0 ), - ( parseInt( c.css( "borderTopWidth" ), 10 ) || 0 ) + ( parseInt( c.css( "paddingTop" ), 10 ) || 0 ) , + ( parseInt( c.css( "borderTopWidth" ), 10 ) || 0 ) + ( parseInt( c.css( "paddingTop" ), 10 ) || 0 ), ( over ? Math.max( ce.scrollWidth, ce.offsetWidth ) : ce.offsetWidth ) - ( parseInt( c.css( "borderRightWidth" ), 10 ) || 0 ) - ( parseInt( c.css( "paddingRight" ), 10 ) || 0 ) - this.helperProportions.width - this.margins.left - this.margins.right, ( over ? Math.max( ce.scrollHeight, ce.offsetHeight ) : ce.offsetHeight ) - ( parseInt( c.css( "borderBottomWidth" ), 10 ) || 0 ) - ( parseInt( c.css( "paddingBottom" ), 10 ) || 0 ) - this.helperProportions.height - this.margins.top - this.margins.bottom ]; @@ -486,7 +485,7 @@ $.widget("ui.draggable", $.ui.mouse, { _convertPositionTo: function(d, pos) { - if(!pos) { + if (!pos) { pos = this.position; } @@ -542,26 +541,25 @@ $.widget("ui.draggable", $.ui.mouse, { this.containment[ 2 ] + co.left, this.containment[ 3 ] + co.top ]; - } - else { + } else { containment = this.containment; } - if(event.pageX - this.offset.click.left < containment[0]) { + 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]) { + 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]) { + 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]) { + if (event.pageY - this.offset.click.top > containment[3]) { pageY = containment[3] + this.offset.click.top; } } - if(o.grid) { + 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) 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; @@ -600,7 +598,7 @@ $.widget("ui.draggable", $.ui.mouse, { _clear: function() { this.helper.removeClass("ui-draggable-dragging"); - if(this.helper[0] !== this.element[0] && !this.cancelHelperRemoval) { + if (this.helper[0] !== this.element[0] && !this.cancelHelperRemoval) { this.helper.remove(); } this.helper = null; @@ -616,7 +614,7 @@ $.widget("ui.draggable", $.ui.mouse, { ui = ui || this._uiHash(); $.ui.plugin.call( this, type, [ event, ui, this ], true ); //The absolute position has to be recalculated after plugins - if(type === "drag") { + if (type === "drag") { this.positionAbs = this._convertPositionTo("absolute"); } return $.Widget.prototype._trigger.call(this, type, event, ui); @@ -662,7 +660,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { }); $.each(inst.sortables, function() { - if(this.instance.isOver) { + if (this.instance.isOver) { this.instance.isOver = 0; @@ -670,7 +668,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work) //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) { + if (this.shouldRevert) { this.instance.options.revert = this.shouldRevert; } @@ -680,7 +678,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { this.instance.options.helper = this.instance.options._helper; //If the helper has been the original item, restore properties in the sortable - if(inst.options.helper === "original") { + if (inst.options.helper === "original") { this.instance.currentItem.css({ top: "auto", left: "auto" }); } @@ -706,9 +704,9 @@ $.ui.plugin.add("draggable", "connectToSortable", { this.instance.helperProportions = inst.helperProportions; this.instance.offset.click = inst.offset.click; - if(this.instance._intersectsWith(this.instance.containerCache)) { + if (this.instance._intersectsWith(this.instance.containerCache)) { innermostIntersecting = true; - $.each(inst.sortables, function () { + $.each(inst.sortables, function() { this.instance.positionAbs = inst.positionAbs; this.instance.helperProportions = inst.helperProportions; this.instance.offset.click = inst.offset.click; @@ -722,10 +720,9 @@ $.ui.plugin.add("draggable", "connectToSortable", { }); } - - if(innermostIntersecting) { + if (innermostIntersecting) { //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) { + if (!this.instance.isOver) { this.instance.isOver = 1; //Now we fake the start of dragging for the sortable instance, @@ -754,7 +751,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { } //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) { + if (this.instance.currentItem) { this.instance._mouseDrag(event); } @@ -762,7 +759,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { //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) { + if (this.instance.isOver) { this.instance.isOver = 0; this.instance.cancelHelperRemoval = true; @@ -778,7 +775,7 @@ $.ui.plugin.add("draggable", "connectToSortable", { //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) { + if (this.instance.placeholder) { this.instance.placeholder.remove(); } @@ -815,14 +812,14 @@ $.ui.plugin.add("draggable", "opacity", { start: function( event, ui, instance ) { var t = $( ui.helper ), o = instance.options; - if(t.css("opacity")) { + if (t.css("opacity")) { o._opacity = t.css("opacity"); } t.css("opacity", o.opacity); }, stop: function( event, ui, instance ) { var o = instance.options; - if(o._opacity) { + if (o._opacity) { $(ui.helper).css("opacity", o._opacity); } } @@ -830,7 +827,7 @@ $.ui.plugin.add("draggable", "opacity", { $.ui.plugin.add("draggable", "scroll", { start: function( event, ui, i ) { - if( i.scrollParent[ 0 ] !== i.document[ 0 ] && i.scrollParent[ 0 ].tagName !== "HTML" ) { + if ( i.scrollParent[ 0 ] !== i.document[ 0 ] && i.scrollParent[ 0 ].tagName !== "HTML" ) { i.overflowOffset = i.scrollParent.offset(); } }, @@ -840,44 +837,44 @@ $.ui.plugin.add("draggable", "scroll", { scrolled = false, document = i.document[ 0 ]; - if( i.scrollParent[ 0 ] !== document && i.scrollParent[ 0 ].tagName !== "HTML" ) { - if(!o.axis || o.axis !== "x") { - if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) { + if ( i.scrollParent[ 0 ] !== document && i.scrollParent[ 0 ].tagName !== "HTML" ) { + 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) { + } else if (event.pageY - i.overflowOffset.top < o.scrollSensitivity) { i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed; } } - if(!o.axis || o.axis !== "y") { - if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) { + 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) { + } else if (event.pageX - i.overflowOffset.left < o.scrollSensitivity) { i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed; } } } else { - if(!o.axis || o.axis !== "x") { - if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) { + 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) { + } else if ($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) { scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); } } - if(!o.axis || o.axis !== "y") { - if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) { + 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) { + } else if ($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) { scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); } } } - if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) { + if (scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) { $.ui.ddmanager.prepareOffsets(i, event); } @@ -894,7 +891,7 @@ $.ui.plugin.add("draggable", "snap", { $(o.snap.constructor !== String ? ( o.snap.items || ":data(ui-draggable)" ) : o.snap).each(function() { var $t = $(this), $o = $t.offset(); - if(this !== i.element[0]) { + if (this !== i.element[0]) { i.snapElements.push({ item: this, width: $t.outerWidth(), height: $t.outerHeight(), @@ -920,54 +917,54 @@ $.ui.plugin.add("draggable", "snap", { b = t + inst.snapElements[i].height; if ( x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d || !$.contains( inst.snapElements[ i ].item.ownerDocument, inst.snapElements[ i ].item ) ) { - if(inst.snapElements[i].snapping) { + 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") { + if (o.snapMode !== "inner") { ts = Math.abs(t - y2) <= d; bs = Math.abs(b - y1) <= d; ls = Math.abs(l - x2) <= d; rs = Math.abs(r - x1) <= d; - if(ts) { + if (ts) { ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top; } - if(bs) { + if (bs) { ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top; } - if(ls) { + if (ls) { ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left; } - if(rs) { + if (rs) { ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left; } } first = (ts || bs || ls || rs); - if(o.snapMode !== "outer") { + if (o.snapMode !== "outer") { ts = Math.abs(t - y1) <= d; bs = Math.abs(b - y2) <= d; ls = Math.abs(l - x1) <= d; rs = Math.abs(r - x2) <= d; - if(ts) { + if (ts) { ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top; } - if(bs) { + if (bs) { ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top; } - if(ls) { + if (ls) { ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left; } - if(rs) { + 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)) { + 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); @@ -1000,7 +997,7 @@ $.ui.plugin.add("draggable", "zIndex", { var t = $( ui.helper ), o = instance.options; - if(t.css("zIndex")) { + if (t.css("zIndex")) { o._zIndex = t.css("zIndex"); } t.css("zIndex", o.zIndex); @@ -1008,7 +1005,7 @@ $.ui.plugin.add("draggable", "zIndex", { stop: function( event, ui, instance ) { var o = instance.options; - if(o._zIndex) { + if (o._zIndex) { $(ui.helper).css("zIndex", o._zIndex); } } |