knockout-sortable - simple list

https://github.com/rniemeyer/knockout-sortable

by Asle Gundersby

HTML

<script src="http://knockoutjs.com/downloads/knockout-2.2.1.js"></script>
<script src="https://rawgithub.com/rniemeyer/knockout-sortable/master/build/knockout-sortable.js"></script>
<div id="allocationable-texts" class="menupanel">
    <h4 class="select">Text(s) to allocate:</h4>
    <div class="tb-table">
        <div class="tb-list" data-bind="sortable:{template:'textbatchTmpl1',data:$root.allocationableTextbatches,allowDrop:true}"></div> 
    </div>
    <span>Add text by dragging onto accordion or by pushing the button.</span>
</div>

<hr />
<div id="chosen-texts" class="menupanel">
    <h4 class="select">Text(s) allocated:</h4>
    <div class="tb-table">
        <div class="tb-list" data-bind="sortable:{template:'textbatchTmpl2',data:$root.thisScenesTextbatches,allowDrop:true}"></div> 
    </div>
</div>

<hr />
<hr />
Scenes:
<div id="wys-ss-accordion" data-bind="jqAccordion: { target: '#wys-ss-paccordion' },template: { name: 'scene-template', foreach: Scenes,  afterAdd: function(elem){$(elem).trigger('valueChanged');} }" class="group ui-widget ui-helper-clearfix"></div>


<script id="textbatchTmpl1" type="text/html"><div class="textbatch" data-bind="click: $root.selectedText">
        <span class="tb-title" data-bind="text: title"></span>
        <button class="btn btn-success btn-xs wysTextbatchAddButton right" title="Add text to selected scene" data-bind="click: $root.addTextbatchToScene" >Add</button>
</div></script>

<script id="textbatchTmpl2" type="text/html"><div class="textbatch" data-bind="click: $root.selectedText">
        <span class="tb-title" data-bind="text: title"></span>
        <a class="undo-textallocation" data-bind="click: function(){$root.undoTextAllocation($data)}"><span>x</span></a>
</div></script>

<script type="text/html" id="scene-template"><div data-bind="attr: {'id': 'scene' + sceneID}">
    <div class="accordion-header" data-bind="click:$root.selectedScene">
        <span class="title form-control"...

CSS

body {
    font-family: arial;
    background: lightgrey;
}
p, a, input {
    font-size: .8em;
}

#allocationable-texts, #chosen-texts{
  width: 300px;
}

span.title {
    font-size: 10px;
    vertical-align: text-top;
    line-height: 9px;
    display: block;
    margin-bottom: 1px;
    word-break:normal;    /* when showing group description we want this - also with long email-adresses. breaks on words and hyphen*/
}
span.title {
    margin-top: 1px;
    margin-bottom: 0px;
}
.tb-table {
    float: left;
    margin-right: 5px;
    width: 100%;
}
.tb-table span {
    font-size: 0.75em;
    padding: 2px;
}
.tb-list {
    border: 3px solid #666;
    height: 100px;
    background-color: #777;
    margin: 2px 0px 3px;
    padding: 1px;
    border-radius: 3px;
    box-shadow: 0px 0px 0px #999;
    /*overflow-y: auto;*/    /* perfectScrollbar applied */
}
.textbatch {
    background-color: #333;
    color: #FFF;
    border-radius: 3px;
    margin: 1px;
    padding: 1px 0px 1px 8px;
    cursor: move;
    min-height: 20px;
    display: inline-flex;
}
.textbatch.tb-title {
    padding-left: 0px;
}
.undo-textallocation {
    float: right;
    width: 12px;
    height: 12px;
    cursor: pointer;
    text-align: center;
    margin: 0px 6px;
}
.undo-textallocation span {
    vertical-align: text-top;
    color: #F00;
    font-size: 11px;
    font-weight: 600;
}

JavaScript

ko.bindingHandlers.jqAccordion = {
    init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
        //init: function (element, valueAccessor) {
        var options = valueAccessor();
        var $element = $(element),
             value = ko.utils.unwrapObservable(valueAccessor()) || {};

        $(element).accordion(options);
        $(element).bind("valueChanged", function () {
            ko.bindingHandlers.jqAccordion.update(element, valueAccessor);
        });

        //handle disposal (if KO removes by the template binding)
        ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
            $(element).accordion("destroy");
        });
    },
    //update: function (element, valueAccessor) {
    update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
        var options = valueAccessor() || {};
        //var options = valueAccessor();

        if (!bindingContext) {
            bindingContext = ko.contextFor(this);
        }
        $(element).accordion("destroy").accordion({
            header: ".accordion-header",
            collapsible: true,
            navigation: true,
            heightStyle: "content",
            active: false,
            beforeActivate: function (event, ui) {
                active = $(this).accordion("option", "active");
            },
            activate: function (event, ui) {
                if (!$.isEmptyObject(ui.newHeader.offset())) {
                    var topOffset = 150;
                    // $('html:not(:animated), body:not(:animated)').animate({ scrollTop: ui.newHeader.offset().top - topOffset }, 'slow');
                    event.stopPropagation();
                }
            }
        })
        .sortable({
            axis: "x,y",
            handle: ".accordion-header",
            placeholder: "ui-state-highlight",
            allowDrop: true,
            start: function (event, ui) {
                //change bool to...