From 8e829a46483166a0a4aabef4ff6f141549f93b89 Mon Sep 17 00:00:00 2001 From: Alex Key Date: Sun, 6 Nov 2016 16:50:05 +0000 Subject: [PATCH 1/2] deprecated sort property in favour of disableSort for polymer markup compatibility --- polymer-sortablejs.html | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/polymer-sortablejs.html b/polymer-sortablejs.html index c26d881..6554f99 100644 --- a/polymer-sortablejs.html +++ b/polymer-sortablejs.html @@ -13,6 +13,8 @@ properties: { group : { type: Object, value: () => {return {name: Math.random()};}, observer: "groupChanged" }, + disableSort : { type: Boolean, value: false, observer: "disableSortChanged" }, + //sort has been deprecated in favour of disableSort see https://github.com/SortableJS/polymer-sortablejs/issues/22 sort : { type: Boolean, value: true, observer: "sortChanged" }, disabled : { type: Boolean, value: false, observer: "disabledChanged" }, store : { type: Object, value: null, observer: "storeChanged" }, @@ -73,6 +75,9 @@ Object.keys(this.properties).forEach(function(key) { options[key] = this[key]; }.bind(this)); + + //override sort with disableSort as sort doesn't work as expected anyway during config via markup. See https://github.com/SortableJS/polymer-sortablejs/issues/22 + options.sort = !this.disableSort; var _this = this; var eventCallbacks = { @@ -161,14 +166,22 @@ } this.sortable && this.sortable.option("group", value ); }, - sortChanged : function(value) { this.sortable && this.sortable.option("sort", value); }, + disableSortChanged : function(value) { this.sortable && this.sortable.option("sort", !value); }, + sortChanged : function(value) { + + this.sortable && this.sortable.option("sort", value); + + if(this.sortable && typeof window.console !== "undefined" && typeof window.console.log !== "undefined") { + console.log("The sort proprty has been deprecated as it cannot be used with with polymer via markup due to boolean's not supporting the default true, please use the disableSort property instead. See https://github.com/SortableJS/polymer-sortablejs/issues/22 for more information."); + } + }, disabledChanged : function(value) { this.sortable && this.sortable.option("disabled", value); }, storeChanged : function(value) { this.sortable && this.sortable.option("store", value); }, handleChanged : function(value) { this.sortable && this.sortable.option("handle", value); }, - scrollChanged : function(value) { this.sortable && this.sortable.option("scroll", value); }, + scrollChanged : function(value) { this.sortable && this.sortable.option("scroll", value); }, scrollSensitivityChanged : function(value) { this.sortable && this.sortable.option("scrollSensitivity", value); }, scrollSpeedChanged : function(value) { this.sortable && this.sortable.option("scrollSpeed", value); }, - draggableChanged : function(value) { this.sortable && this.sortable.option("draggable", value); }, + draggableChanged : function(value) { this.sortable && this.sortable.option("draggable", value); }, ghostClassChanged : function(value) { this.sortable && this.sortable.option("ghostClass", value); }, chosenClassChanged : function(value) { this.sortable && this.sortable.option("chosenClass", value); }, ignoreChanged : function(value) { this.sortable && this.sortable.option("ignore", value); }, From aa6045be395b5b1093ef21645546e7182eb55daa Mon Sep 17 00:00:00 2001 From: Alex Key Date: Sun, 6 Nov 2016 20:12:06 +0000 Subject: [PATCH 2/2] syncronising sort and disabledSort properties --- polymer-sortablejs.html | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/polymer-sortablejs.html b/polymer-sortablejs.html index 6554f99..57c9f16 100644 --- a/polymer-sortablejs.html +++ b/polymer-sortablejs.html @@ -166,14 +166,27 @@ } this.sortable && this.sortable.option("group", value ); }, - disableSortChanged : function(value) { this.sortable && this.sortable.option("sort", !value); }, + disableSortChanged : function(value) { + this.sortable && this.sortable.option("sort", !value); + this.sort = !value; + }, sortChanged : function(value) { + + if(this.sortable) { + //Whilst the sort property is deprecated, keep disablesort and sort in sync for backwards compatibility. + var alreadyChanged = this.sortable.option("sort") == value; + + if(!alreadyChanged) { + this.sortable.option("sort", value); + + if(this.sortable && typeof window.console !== "undefined" && typeof window.console.log !== "undefined") { + console.log("The sort property has been deprecated as it cannot be used with with polymer via markup due to boolean's not supporting the default true, please use the disableSort property instead. See https://github.com/SortableJS/polymer-sortablejs/issues/22 for more information."); + } + + this.disableSort = !value; + } + } - this.sortable && this.sortable.option("sort", value); - - if(this.sortable && typeof window.console !== "undefined" && typeof window.console.log !== "undefined") { - console.log("The sort proprty has been deprecated as it cannot be used with with polymer via markup due to boolean's not supporting the default true, please use the disableSort property instead. See https://github.com/SortableJS/polymer-sortablejs/issues/22 for more information."); - } }, disabledChanged : function(value) { this.sortable && this.sortable.option("disabled", value); }, storeChanged : function(value) { this.sortable && this.sortable.option("store", value); },