binding for chosen

binding for https://github.com/harvesthq/chosen

HTML

<link rel="stylesheet" href="https://raw.github.com/harvesthq/chosen/master/chosen/chosen.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.jquery.min.js"></script>
<script src="http://knockoutjs.com/downloads/knockout-3.0.0.js"></script>
<p>
<select data-bind="singleChosen : ListOfPlaces, value: selectedPlace, optionsCaption:'Choose...', optionsText:'name'" style="width:350px;"  class="chzn-select" >
</select>
</p>
<hr/>

CSS

body {
    font-family: Helvetica, Sans, Arial;
}

/* @group Base */
.chzn-container {
  font-size: 13px;
  position: relative;
  display: inline-block;
  zoom: 1;
  *display: inline;
}
.chzn-container .chzn-drop {
  background: #fff;
  border: 1px solid #aaa;
  border-top: 0;
  position: absolute;
  top: 29px;
  left: 0;
  -webkit-box-shadow: 0 4px 5px rgba(0,0,0,.15);
  -moz-box-shadow   : 0 4px 5px rgba(0,0,0,.15);
  box-shadow        : 0 4px 5px rgba(0,0,0,.15);
  z-index: 1010;
}
/* @end */

/* @group Single Chosen */
.chzn-container-single .chzn-single {
  background-color: #ffffff;
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#eeeeee', GradientType=0 );   
  background-image: -webkit-gradient(linear, 0 0, 0 100%, color-stop(20%, #ffffff), color-stop(50%, #f6f6f6), color-stop(52%, #eeeeee), color-stop(100%, #f4f4f4));
  background-image: -webkit-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
  background-image: -moz-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
  background-image: -o-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%);
  background-image: linear-gradient(#ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); 
  -webkit-border-radius: 5px;
  -moz-border-radius   : 5px;
  border-radius        : 5px;
  -moz-background-clip   : padding;
  -webkit-background-clip: padding-box;
  background-clip        : padding-box;
  border: 1px solid #aaaaaa;
  -webkit-box-shadow: 0 0 3px #ffffff inset, 0 1px 1px rgba(0,0,0,0.1);
  -moz-box-shadow   : 0 0 3px #ffffff inset, 0 1px 1px rgba(0,0,0,0.1);
  box-shadow        : 0 0 3px #ffffff inset, 0 1px 1px rgba(0,0,0,0.1);
  display: block;
  overflow: hidden;
  white-space: nowrap;
  position: relative;
  height: 23px;
  line-height: 24px;
  padding: 0 0 0 8px;
  color: #444444;
  text-decoration: none;
}
.chzn-container-single .chzn-default {
  color: #999;
}
.chzn-container-single...

JavaScript

ko.bindingHandlers.singleChosen = {

    init: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
        // This will be called when the binding is first applied to an element
        // Set up any initial state, event handlers, etc. here
        $(element).chosen();

        ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
            // blah
        });

    },
    update: function(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
        // This will be called once when the binding is first applied to an element,
        // and again whenever the associated observable changes value.
        // Update the DOM element based on the supplied values here.
        var value = ko.utils.unwrapObservable(valueAccessor());

        ko.bindingHandlers.options.update(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);

        setTimeout(function() {
            $(element).trigger("liszt:updated");
        }, 0);

    }

};

var my = my || {};
my.vm = (function() {
    var listofPlaces = ko.observableArray([]),
        selectedPlace = ko.observable();

    listofPlaces([
        {
        name: 'Timbuktu',
        planet: 'Mars'},
    {
        name: 'Foo',
        planet: 'Saturn'},
    {
        name: 'Bar',
        planet: 'Jupiter'}
    ]);

/*
    $.ajax({
        url: "http://ws.geonames.org/searchJSON",
        dataType: "jsonp",
        data: {
            featureClass: "P",
            countryBias: "CA",
            style: "full",
            maxRows: 12,
            name_startsWith: 'Alt'
        },
        success: function(data) {

            listofPlaces(data.geonames);
        }
    });
*/
    return {
        ListOfPlaces: listofPlaces,
        selectedPlace: selectedPlace
    }
})();
$(document).ready(function() {

    ko.applyBindings(my.vm);

}); //ready