Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace sort property with polmyer compatible property #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions polymer-sortablejs.html
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -161,14 +166,35 @@
}
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);
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;
}
}

},
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); },
Expand Down