diff --git a/js/views/listView.js b/js/views/listView.js index fa41febe59..1477345a30 100644 --- a/js/views/listView.js +++ b/js/views/listView.js @@ -37,16 +37,16 @@ return; } - if(e.target.classList.contains(ITEM_CONTENT_CLASS)) { + if (e.target.classList.contains(ITEM_CONTENT_CLASS)) { content = e.target; - } else if(e.target.classList.contains(ITEM_CLASS)) { + } else if (e.target.classList.contains(ITEM_CLASS)) { content = e.target.querySelector('.' + ITEM_CONTENT_CLASS); } else { content = ionic.DomUtil.getParentWithClass(e.target, ITEM_CONTENT_CLASS); } // If we don't have a content area as one of our children (or ourselves), skip - if(!content) { + if (!content) { return; } @@ -58,7 +58,7 @@ // Grab the buttons buttons = content.parentNode.querySelector('.' + ITEM_OPTIONS_CLASS); - if(!buttons) { + if (!buttons) { return; } buttons.classList.remove('invisible'); @@ -77,7 +77,7 @@ * Check if this is the same item that was previously dragged. */ SlideDrag.prototype.isSameItem = function(op) { - if(op._lastDrag && this._currentDrag) { + if (op._lastDrag && this._currentDrag) { return this._currentDrag.content == op._lastDrag.content; } return false; @@ -86,7 +86,7 @@ SlideDrag.prototype.clean = function(e) { var lastDrag = this._lastDrag; - if(!lastDrag) return; + if (!lastDrag || !lastDrag.content) return; lastDrag.content.style[ionic.CSS.TRANSITION] = ''; lastDrag.content.style[ionic.CSS.TRANSFORM] = ''; @@ -101,27 +101,26 @@ var buttonsWidth; // We really aren't dragging - if(!this._currentDrag) { + if (!this._currentDrag) { return; } // Check if we should start dragging. Check if we've dragged past the threshold, // or we are starting from the open state. - if(!this._isDragging && + if (!this._isDragging && ((Math.abs(e.gesture.deltaX) > this.dragThresholdX) || - (Math.abs(this._currentDrag.startOffsetX) > 0))) - { + (Math.abs(this._currentDrag.startOffsetX) > 0))) { this._isDragging = true; } - if(this._isDragging) { + if (this._isDragging) { buttonsWidth = this._currentDrag.buttonsWidth; // Grab the new X point, capping it at zero var newX = Math.min(0, this._currentDrag.startOffsetX + e.gesture.deltaX); // If the new X position is past the buttons, we need to slow down the drag (rubber band style) - if(newX < -buttonsWidth) { + if (newX < -buttonsWidth) { // Calculate the new X position, capped at the top of the buttons newX = Math.min(-buttonsWidth, -buttonsWidth + (((e.gesture.deltaX + buttonsWidth) * 0.4))); } @@ -135,7 +134,7 @@ var _this = this; // There is no drag, just end immediately - if(!this._currentDrag) { + if (!this._currentDrag) { doneCallback && doneCallback(); return; } @@ -146,19 +145,19 @@ // Check if the drag didn't clear the buttons mid-point // and we aren't moving fast enough to swipe open - if(e.gesture.deltaX > -(this._currentDrag.buttonsWidth/2)) { + if (e.gesture.deltaX > -(this._currentDrag.buttonsWidth / 2)) { // If we are going left but too slow, or going right, go back to resting - if(e.gesture.direction == "left" && Math.abs(e.gesture.velocityX) < 0.3) { + if (e.gesture.direction == "left" && Math.abs(e.gesture.velocityX) < 0.3) { restingPoint = 0; - } else if(e.gesture.direction == "right") { + } else if (e.gesture.direction == "right") { restingPoint = 0; } } ionic.requestAnimationFrame(function() { - if(restingPoint === 0) { + if (restingPoint === 0) { _this._currentDrag.content.style[ionic.CSS.TRANSFORM] = ''; var buttons = _this._currentDrag.buttons; setTimeout(function() { @@ -171,12 +170,12 @@ // Kill the current drag - if(_this._lastDrag) { + if (_this._lastDrag) { _this._lastDrag.buttons = null; _this._lastDrag.content = null; } _this._lastDrag = _this._currentDrag; - if(_this._currentDrag) { + if (_this._currentDrag) { _this._currentDrag.buttons = null; _this._currentDrag.content = null; } @@ -212,7 +211,7 @@ this.scrollView.getValues().top - (this._currentDrag.elementHeight / 2) - this.listElTrueTop; - this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(0, '+y+'px, 0)'; + this.el.style[ionic.CSS.TRANSFORM] = 'translate3d(0, ' + y + 'px, 0)'; }; ReorderDrag.prototype.deregister = function() { @@ -248,7 +247,7 @@ ReorderDrag.prototype.drag = ionic.animationFrameThrottle(function(e) { // We really aren't dragging var self = this; - if(!this._currentDrag) { + if (!this._currentDrag) { return; } @@ -263,8 +262,8 @@ scrollY = this.scrollView.getValues().top; var containerTop = container.offsetTop; - var pixelsPastTop = containerTop - pageY + this._currentDrag.elementHeight/2; - var pixelsPastBottom = pageY + this._currentDrag.elementHeight/2 - containerTop - container.offsetHeight; + var pixelsPastTop = containerTop - pageY + this._currentDrag.elementHeight / 2; + var pixelsPastBottom = pageY + this._currentDrag.elementHeight / 2 - containerTop - container.offsetHeight; if (e.gesture.deltaY < 0 && pixelsPastTop > 0 && scrollY > 0) { this.scrollView.scrollBy(null, -pixelsPastTop); @@ -286,11 +285,11 @@ // Check if we should start dragging. Check if we've dragged past the threshold, // or we are starting from the open state. - if(!this._isDragging && Math.abs(e.gesture.deltaY) > this.dragThresholdY) { + if (!this._isDragging && Math.abs(e.gesture.deltaY) > this.dragThresholdY) { this._isDragging = true; } - if(this._isDragging) { + if (this._isDragging) { this._moveElement(e); this._currentDrag.currentY = scrollY + pageY - offset; @@ -329,7 +328,7 @@ }; ReorderDrag.prototype.end = function(e, doneCallback) { - if(!this._currentDrag) { + if (!this._currentDrag) { doneCallback && doneCallback(); return; } @@ -375,7 +374,7 @@ ionic.extend(this, opts); - if(!this.itemHeight && this.listEl) { + if (!this.itemHeight && this.listEl) { this.itemHeight = this.listEl.children[0] && parseInt(this.listEl.children[0].style.height, 10); } @@ -420,7 +419,7 @@ * of active elements in order to figure out the viewport to render. */ didScroll: function(e) { - if(this.isVirtual) { + if (this.isVirtual) { var itemHeight = this.itemHeight; // TODO: This would be inaccurate if we are windowed @@ -462,8 +461,8 @@ }, didStopScrolling: function(e) { - if(this.isVirtual) { - for(var i = 0; i < this._virtualItemsToRemove.length; i++) { + if (this.isVirtual) { + for (var i = 0; i < this._virtualItemsToRemove.length; i++) { var el = this._virtualItemsToRemove[i]; //el.parentNode.removeChild(el); this.didHideItem && this.didHideItem(i); @@ -477,7 +476,7 @@ * Clear any active drag effects on the list. */ clearDragEffects: function() { - if(this._lastDragOp) { + if (this._lastDragOp) { this._lastDragOp.clean && this._lastDragOp.clean(); this._lastDragOp.deregister && this._lastDragOp.deregister(); this._lastDragOp = null; @@ -488,7 +487,7 @@ //ionic.views.ListView.__super__._initDrag.call(this); // Store the last one - if(this._lastDragOp) { + if (this._lastDragOp) { this._lastDragOp.deregister && this._lastDragOp.deregister(); } this._lastDragOp = this._dragOp; @@ -498,8 +497,8 @@ // Return the list item from the given target _getItem: function(target) { - while(target) { - if(target.classList && target.classList.contains(ITEM_CLASS)) { + while (target) { + if (target.classList && target.classList.contains(ITEM_CLASS)) { return target; } target = target.parentNode; @@ -519,10 +518,10 @@ var item; // Check if this is a reorder drag - if(ionic.DomUtil.getParentOrSelfWithClass(e.target, ITEM_REORDER_BTN_CLASS) && (e.gesture.direction == 'up' || e.gesture.direction == 'down')) { + if (ionic.DomUtil.getParentOrSelfWithClass(e.target, ITEM_REORDER_BTN_CLASS) && (e.gesture.direction == 'up' || e.gesture.direction == 'down')) { item = this._getItem(e.target); - if(item) { + if (item) { this._dragOp = new ReorderDrag({ listEl: this.el, el: item, @@ -538,11 +537,11 @@ } // Or check if this is a swipe to the side drag - else if(!this._didDragUpOrDown && (e.gesture.direction == 'left' || e.gesture.direction == 'right') && Math.abs(e.gesture.deltaX) > 5) { + else if (!this._didDragUpOrDown && (e.gesture.direction == 'left' || e.gesture.direction == 'right') && Math.abs(e.gesture.deltaX) > 5) { // Make sure this is an item with buttons item = this._getItem(e.target); - if(item && item.querySelector('.item-options')) { + if (item && item.querySelector('.item-options')) { this._dragOp = new SlideDrag({ el: this.el, canSwipe: this.canSwipe }); this._dragOp.start(e); e.preventDefault(); @@ -550,7 +549,7 @@ } // If we had a last drag operation and this is a new one on a different item, clean that last one - if(lastDragOp && this._dragOp && !this._dragOp.isSameItem(lastDragOp) && e.defaultPrevented) { + if (lastDragOp && this._dragOp && !this._dragOp.isSameItem(lastDragOp) && e.defaultPrevented) { lastDragOp.clean && lastDragOp.clean(); } }, @@ -561,7 +560,7 @@ this._didDragUpOrDown = false; - if(!this._dragOp) { + if (!this._dragOp) { //ionic.views.ListView.__super__._handleEndDrag.call(this, e); return; } @@ -577,18 +576,18 @@ _handleDrag: function(e) { var _this = this, content, buttons; - if(Math.abs(e.gesture.deltaY) > 5) { + if (Math.abs(e.gesture.deltaY) > 5) { this._didDragUpOrDown = true; } // If we get a drag event, make sure we aren't in another drag, then check if we should // start one - if(!this.isDragging && !this._dragOp) { + if (!this.isDragging && !this._dragOp) { this._startDrag(e); } // No drag still, pass it up - if(!this._dragOp) { + if (!this._dragOp) { //ionic.views.ListView.__super__._handleDrag.call(this, e); return; }