From 8ad265d83b1b79e86b316a726942acdcaa55bd8b Mon Sep 17 00:00:00 2001 From: christophe-g Date: Fri, 9 Dec 2016 17:21:44 +0100 Subject: [PATCH] add delegateAdd and delegateRemove propeties so as to be able to delate template adding/removing items to other parts of the application (e.g. listening to the add event -> pushing a key to a firebase -> the template reacting to firebase added-item event) --- polymer-sortablejs.html | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/polymer-sortablejs.html b/polymer-sortablejs.html index b86302b..363959e 100644 --- a/polymer-sortablejs.html +++ b/polymer-sortablejs.html @@ -32,7 +32,23 @@ fallbackClass : { type: String, value: "sortable-fallback", observer: "fallbackClassChanged" }, fallbackOnBody : { type: Boolean, value: false, observer: "fallbackOnBodyChanged" }, draggable : {}, - scroll : {} + scroll : {}, + + /** + * `delegateAdd` set true to delegate adding item to the template to other part of the application + */ + delegateAdd: { + type: Boolean, + value: false + }, + + /** + * `delegateAdd` set true to delegate removing item to the template to other part of the application + */ + delegateRemove: { + type: Boolean, + value: false + } }, created: function() { @@ -79,19 +95,19 @@ onUpdate: function (e) { if (template) { template.splice("items", e.newIndex, 0, template.splice("items", e.oldIndex, 1)[0]); - /* + /* if (manuallyHandleUpdateEvents) { template.items.splice(e.newIndex, 0, template.items.splice(e.oldIndex, 1)[0]); } else { template.splice("items", e.newIndex, 0, template.splice("items", e.oldIndex, 1)[0]); } - */ + */ } _this.fire("update", e); }, onAdd: function(e) { - if (template) { + if (template && !_this.delegateAdd) { var froms = e.from.querySelectorAll("template[is='dom-repeat']"); var from = froms[froms.length-1]; var item = from.items[e.oldIndex]; @@ -105,7 +121,7 @@ if (e.target.group.pull === 'clone') { return false; } - if (template) { + if (template && !_this.delegateRemove) { template.splice("items", e.oldIndex, 1)[0]; } _this.fire("remove", e);