From 7fec8480e5ab7c52de6a29c86b49c290c4d664e1 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 5 Feb 2015 09:42:47 -0700 Subject: [PATCH] fix(ionItem): properly hide option buttons on scroll in collection-repeat Closes #1811. Closes #2804. --- js/angular/directive/item.js | 45 ++++++++++++++++++++++++------------ js/angular/directive/list.js | 4 ++-- js/views/listView.js | 9 ++++++-- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/js/angular/directive/item.js b/js/angular/directive/item.js index c5fd9b8f0e..5486c0dc8b 100644 --- a/js/angular/directive/item.js +++ b/js/angular/directive/item.js @@ -44,24 +44,39 @@ IonicModule //Lame way of testing, but we have to know at compile what to do with the element /ion-(delete|option|reorder)-button/i.test($element.html()); - if (isComplexItem) { - var innerElement = jqLite(isAnchor ? ITEM_TPL_CONTENT_ANCHOR : ITEM_TPL_CONTENT); - innerElement.append($element.contents()); + if (isComplexItem) { + var innerElement = jqLite(isAnchor ? ITEM_TPL_CONTENT_ANCHOR : ITEM_TPL_CONTENT); + innerElement.append($element.contents()); - $element.append(innerElement); - $element.addClass('item item-complex'); - } else { - $element.addClass('item'); - } + $element.append(innerElement); + $element.addClass('item item-complex'); + } else { + $element.addClass('item'); + } - return function link($scope, $element, $attrs) { - $scope.$href = function() { - return $attrs.href || $attrs.ngHref; - }; - $scope.$target = function() { - return $attrs.target || '_self'; - }; + return function link($scope, $element, $attrs) { + var listCtrl; + $scope.$href = function() { + return $attrs.href || $attrs.ngHref; }; + $scope.$target = function() { + return $attrs.target || '_self'; + }; + + $scope.$on('$ionic.disconnectScope', cleanupDragOp); + + function cleanupDragOp() { + // lazily fetch list parent controller + listCtrl || (listCtrl = $element.controller('ionList')); + if (!listCtrl || !listCtrl.listView) return; + + if (listCtrl.listView._lastDragOp) { + listCtrl.listView.clearDragEffects(); + } + + } + }; + } }; }); diff --git a/js/angular/directive/list.js b/js/angular/directive/list.js index 5ef5413bf7..ca0a0752f9 100644 --- a/js/angular/directive/list.js +++ b/js/angular/directive/list.js @@ -91,8 +91,8 @@ function($timeout) { controller: '$ionicList', compile: function($element, $attr) { var listEl = jqLite('
') - .append( $element.contents() ) - .addClass($attr.type); + .append( $element.contents() ) + .addClass($attr.type); $element.append(listEl); return function($scope, $element, $attrs, ctrls) { diff --git a/js/views/listView.js b/js/views/listView.js index f147d8b51e..d082d16583 100644 --- a/js/views/listView.js +++ b/js/views/listView.js @@ -25,6 +25,7 @@ var SlideDrag = function(opts) { this.dragThresholdX = opts.dragThresholdX || 10; this.el = opts.el; + this.item = opts.item; this.canSwipe = opts.canSwipe; }; @@ -189,7 +190,7 @@ this.dragThresholdY = opts.dragThresholdY || 0; this.onReorder = opts.onReorder; this.listEl = opts.listEl; - this.el = opts.el; + this.el = this.item = opts.el; this.scrollEl = opts.scrollEl; this.scrollView = opts.scrollView; // Get the True Top of the list el http://www.quirksmode.org/js/findpos.html @@ -546,7 +547,11 @@ // Make sure this is an item with buttons item = this._getItem(e.target); if (item && item.querySelector('.item-options')) { - this._dragOp = new SlideDrag({ el: this.el, canSwipe: this.canSwipe }); + this._dragOp = new SlideDrag({ + el: this.el, + item: item, + canSwipe: this.canSwipe + }); this._dragOp.start(e); e.preventDefault(); }