Sync: Adding shamap and documentation to enable easier sync next time OHM is updated.
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this
5 file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 Copyright (C) 2012 Prince Samuel <prince.samuel@gmail.com>
11 ko.bindingHandlers.treeTable = {
12 update: function(element, valueAccessor, allBindingsAccessor) {
13 var dependency = ko.utils.unwrapObservable(valueAccessor()),
14 options = ko.toJS(allBindingsAccessor().treeOptions || {});
16 setTimeout(function() { $(element).treeTable(options); }, 0);
20 var node = function(config, parent) {
24 var mappingOptions = {
26 create: function(args) {
27 return new node(args.data, _this);
31 return ko.utils.unwrapObservable(data.id);
36 ko.mapping.fromJS(config, mappingOptions, this);
40 $.getJSON('data.json', function(data) {
41 viewModel = new node(data, undefined);
44 function flattenChildren(children, result) {
45 ko.utils.arrayForEach(children(), function(child) {
48 flattenChildren(child.Children, result);
53 viewModel.flattened = ko.dependentObservable(function() {
54 var result = []; //root node
56 if (viewModel.Children) {
57 flattenChildren(viewModel.Children, result);
63 viewModel.update = function() {
64 $.getJSON('data.json', function(data) {
65 ko.mapping.fromJS(data, {}, viewModel);
69 viewModel.rate = 3000; //milliseconds
72 viewModel.startAuto = function (){
73 viewModel.timer = setInterval(viewModel.update, viewModel.rate);
76 viewModel.stopAuto = function (){
77 clearInterval(viewModel.timer);
80 viewModel.auto_refresh = ko.observable(false);
81 viewModel.toggleAuto = ko.dependentObservable(function() {
82 if (viewModel.auto_refresh())
83 viewModel.startAuto();
90 ko.applyBindings(viewModel);
91 $("#tree").treeTable({
92 initialState: "expanded",
93 clickableNodeNames: true
96 $( "#refresh" ).button();
97 $( "#auto_refresh" ).button();
98 $( "#slider" ).slider({
102 slide: function( event, ui ) {
103 viewModel.rate = ui.value * 1000;
104 if (viewModel.auto_refresh()) {
106 viewModel.stopAuto();
107 viewModel.startAuto();
109 $( "#lbl" ).text( ui.value + "s");
112 $( "#lbl" ).text( $( "#slider" ).slider( "value" ) + "s");