Created
December 6, 2013 20:40
-
-
Save seiyria/7831726 to your computer and use it in GitHub Desktop.
add a defaultText option to knockout-sortable (https://github.com/rniemeyer/knockout-sortable). the defaultText must be contained in a span.injected element or else it will not be removed properly. thanks to @mbest for the help, and a related stackoverflow question can be found here: http://stackoverflow.com/questions/20407640/knockout-js-knocko…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var origForeachUpdate = ko.bindingHandlers.sortable.update; | |
ko.bindingHandlers.sortable.update = function(element, valueAccessor, allBindingsAccessor, data, context) { | |
var options = valueAccessor(); | |
if (options.defaultText) { | |
var hasDefaultText = $(element).find('span.injected').length > 0; | |
var array = ko.unwrap(options.data); | |
if (!array || !array.length) { | |
element.innerHTML = options.defaultText; | |
} else if(hasDefaultText){ | |
$(element).find('span.injected').remove(); | |
} | |
} | |
origForeachUpdate.apply(this, arguments); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment