Created
September 26, 2011 13:02
-
-
Save hallgren/1242184 to your computer and use it in GitHub Desktop.
KnockoutJS jqeury UI Accordion depending on RXJS
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
//KnockoutJS - Jquery UI binding depending on RXJS library | |
// | |
//Example of usage | |
//<div data-bind='template: { name: "tmpl", foreach: items, afterAdd: function(elem){ $(elem).trigger("valueChanged");} }, jqAccordion: {}'/> | |
ko.bindingHandlers.jqAccordion = { | |
init: function(element, valueAccessor) { | |
var options = valueAccessor(); | |
var jqElement = $(element); | |
jqElement.accordion(options); | |
jqElement.toObservable("valueChanged") | |
.Select(function() {return Rx.Observable.Return().Delay(1);} ) | |
.Switch() | |
.Subscribe(function(x) { | |
ko.bindingHandlers.jqAccordion.update(element,valueAccessor); | |
}) | |
}, | |
update: function(element,valueAccessor) { | |
var options = valueAccessor(); | |
var activeoptions = $(element).accordion("option"); | |
$(element).accordion('destroy').accordion(activeoptions); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment