From df8d6c9cd6b557fdcc9bd8a0c431d84aecc5dc36 Mon Sep 17 00:00:00 2001 From: laszlojakab Date: Wed, 18 Dec 2013 13:24:34 +0100 Subject: [PATCH 1/7] Update knockout-kendoNumericTextBox.js --- src/knockout-kendoNumericTextBox.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/knockout-kendoNumericTextBox.js b/src/knockout-kendoNumericTextBox.js index ab105ca..5e6507c 100644 --- a/src/knockout-kendoNumericTextBox.js +++ b/src/knockout-kendoNumericTextBox.js @@ -10,16 +10,18 @@ createBinding({ max: function(newMax) { this.options.max = newMax; //make sure current value is still valid - if (this.value() > newMax) { + var value = this.value(); + if ((value || value === 0) && value > newMax) { this.value(newMax); } }, min: function(newMin) { this.options.min = newMin; //make sure that current value is still valid - if (this.value() < newMin) { + var value = this.value(); + if ((value || value === 0) && value < newMin ) { this.value(newMin); } } } -}); \ No newline at end of file +}); From 2e7a321d6bdbf76f34580764b54d44ef361b1028 Mon Sep 17 00:00:00 2001 From: Brian McCord Date: Thu, 27 Mar 2014 09:25:12 -0500 Subject: [PATCH 2/7] Added "selected" binding to kendoPanelBar --- build/knockout-kendo.js | 7 ++++++- build/knockout-kendo.min.js | 2 +- src/knockout-kendoPanelBar.js | 7 ++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/build/knockout-kendo.js b/build/knockout-kendo.js index 1ca0b49..62ec12f 100644 --- a/build/knockout-kendo.js +++ b/build/knockout-kendo.js @@ -601,7 +601,8 @@ createBinding({ parent: "kendoPanelBar", watch: { enabled: ENABLE, - expanded: [EXPAND, COLLAPSE] + expanded: [EXPAND, COLLAPSE], + selected: [SELECT] }, childProp: "item", events: { @@ -612,6 +613,10 @@ createBinding({ collapse: { writeTo: EXPANDED, value: false + }, + select: { + writeTo: SELECTED, + value: VALUE } }, async: true diff --git a/build/knockout-kendo.min.js b/build/knockout-kendo.min.js index ce76b82..effbacc 100644 --- a/build/knockout-kendo.min.js +++ b/build/knockout-kendo.min.js @@ -14,4 +14,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -!function(a){"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?a(require("knockout"),require("jquery"),require("kendo")):"function"==typeof define&&define.amd?define(["knockout","jquery","kendo"],a):a(window.ko,window.jQuery,window.kendo)}(function(a,b,c,d){c=c||window.kendo,a.kendo=a.kendo||{},a.kendo.BindingFactory=function(){var e=this;this.createBinding=function(c){if(b()[c.parent||c.name]){var d={};d.init=function(a,b,f,g,h){var i=e.buildOptions(c,b);return i.async===!0||c.async===!0&&i.async!==!1?(setTimeout(function(){d.setup(a,i,h)},0),void 0):(d.setup(a,i,h),i&&i.useKOTemplates?{controlsDescendantBindings:!0}:void 0)},d.setup=function(d,f,g){var h,i=b(d);e.setupTemplates(c.templates,f,d,g),h=e.getWidget(c,f,i),e.handleEvents(f,c,d,h),e.watchValues(h,f,c,d),h.destroy&&a.utils.domNodeDisposal.addDisposeCallback(d,function(){h.destroy()})},d.options={},d.widgetConfig=c,a.bindingHandlers[c.bindingName||c.name]=d}},this.buildOptions=function(b,d){var e=b.defaultOption,f=a.utils.extend({},a.bindingHandlers[b.name].options),g=a.utils.unwrapObservable(d());return g instanceof c.data.DataSource||"object"!=typeof g||null===g||e&&!(e in g)?f[e]=d():a.utils.extend(f,g),f};var f=function(b,c){return function(d){return a.renderTemplate(b,c.createChildContext(d._raw&&d._raw()||d))}};this.setupTemplates=function(b,c,d,e){var g,h,i,j;if(b&&c&&c.useKOTemplates){for(g=0,h=b.length;h>g;g++)i=b[g],c[i]&&(c[i]=f(c[i],e));j=c.dataBound,c.dataBound=function(){a.memoization.unmemoizeDomNodeAndDescendants(d),j&&j.apply(this,arguments)}}},this.unwrapOneLevel=function(b){var d,e={};if(b)if(b instanceof c.data.DataSource)e=b;else if("object"==typeof b)for(d in b)e[d]=a.utils.unwrapObservable(b[d]);return e},this.getWidget=function(b,c,d){var e;if(b.parent){var f=d.closest("[data-bind*='"+b.parent+":']");e=f.length?f.data(b.parent):null}else e=d[b.name](this.unwrapOneLevel(c)).data(b.name);return a.isObservable(c.widget)&&c.widget(e),e},this.watchValues=function(a,b,c,d){var f,g=c.watch;if(g)for(f in g)g.hasOwnProperty(f)&&e.watchOneValue(f,a,b,c,d)},this.watchOneValue=function(c,e,f,g,h){var i=a.computed({read:function(){var i,j,k=g.watch[c],l=a.utils.unwrapObservable(f[c]),m=g.parent?[h]:[];b.isArray(k)?k=e[l?k[0]:k[1]]:"string"==typeof k?k=e[k]:j=!0,k&&f[c]!==d&&(j?m.push(l,f):(i=k.apply(e,m),m.push(l)),(j||i!==l)&&k.apply(e,m))},disposeWhenNodeIsRemoved:h}).extend({throttle:1});a.isObservable(f[c])||i.dispose()},this.handleEvents=function(b,c,d,f){var g,h,i=c.events;if(i)for(g in i)i.hasOwnProperty(g)&&(h=i[g],"string"==typeof h&&(h={value:h,writeTo:h}),a.isObservable(b[h.writeTo])&&e.handleOneEvent(g,h,b,d,f,c.childProp))},this.handleOneEvent=function(a,b,c,d,e,f){e.bind(a,function(a){var e,g;f&&a[f]&&a[f]!==d||(e=b.value,g="string"==typeof e&&this[e]?this[e](f&&d):e,c[b.writeTo](g))})}},a.kendo.bindingFactory=new a.kendo.BindingFactory,a.kendo.setDataSource=function(b,d,e){var f,g;return d instanceof c.data.DataSource?(b.setDataSource(d),void 0):(e&&e.useKOTemplates||(f=a.mapping&&d&&d.__ko_mapping__,g=d&&f?a.mapping.toJS(d):a.toJS(d)),b.dataSource.data(g||d),void 0)},function(){var a=c.data.ObservableArray.fn.wrap;c.data.ObservableArray.fn.wrap=function(b){var c=a.apply(this,arguments);return c._raw=function(){return b},c}}();var e=function(b){return function(c){c&&(a.utils.extend(this.options[b],c),this.redraw(),this.value(.001+this.value()))}},f=a.kendo.bindingFactory.createBinding.bind(a.kendo.bindingFactory),g="close",h="collapse",i="content",j="data",k="enable",l="expand",m="expanded",n="filter",o="isOpen",p="max",q="min",r="open",s="palette",t="search",u="selected",v="size",w="title",x="value",y="values";f({name:"kendoAutoComplete",events:{change:x,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,search:[t,g],data:function(b){a.kendo.setDataSource(this,b)},value:x}}),f({name:"kendoCalendar",defaultOption:x,events:{change:x},watch:{max:p,min:q,value:x}}),f({name:"kendoColorPicker",events:{change:x,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,value:x,color:x,palette:s}}),f({name:"kendoComboBox",events:{change:x,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,isOpen:[r,g],data:function(b){a.kendo.setDataSource(this,b)},value:x}}),f({name:"kendoDatePicker",defaultOption:x,events:{change:x,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,max:p,min:q,value:x,isOpen:[r,g]}}),f({name:"kendoDateTimePicker",defaultOption:x,events:{change:x,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,max:p,min:q,value:x,isOpen:[r,g]}}),f({name:"kendoDropDownList",events:{change:x,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,isOpen:[r,g],data:function(b){a.kendo.setDataSource(this,b),b.length&&this.options.optionLabel&&this.select()<0&&this.select(0)},value:x}}),f({name:"kendoEditor",defaultOption:x,events:{change:x},watch:{enabled:k,value:x}}),f({name:"kendoGrid",defaultOption:j,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["rowTemplate","altRowTemplate"]}),f({name:"kendoListView",defaultOption:j,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["template"]}),f({name:"kendoMenu",async:!0}),f({name:"kendoMenuItem",parent:"kendoMenu",watch:{enabled:k,isOpen:[r,g]},async:!0}),f({name:"kendoMultiSelect",events:{change:x,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,search:[t,g],data:function(b){a.kendo.setDataSource(this,b)},value:x}}),f({name:"kendoNumericTextBox",defaultOption:x,events:{change:x},watch:{enabled:k,value:x,max:function(a){this.options.max=a,this.value()>a&&this.value(a)},min:function(a){this.options.min=a,this.value()g;g++)i=b[g],c[i]&&(c[i]=f(c[i],e));j=c.dataBound,c.dataBound=function(){a.memoization.unmemoizeDomNodeAndDescendants(d),j&&j.apply(this,arguments)}}},this.unwrapOneLevel=function(b){var d,e={};if(b)if(b instanceof c.data.DataSource)e=b;else if("object"==typeof b)for(d in b)e[d]=a.utils.unwrapObservable(b[d]);return e},this.getWidget=function(b,c,d){var e;if(b.parent){var f=d.closest("[data-bind*='"+b.parent+":']");e=f.length?f.data(b.parent):null}else e=d[b.name](this.unwrapOneLevel(c)).data(b.name);return a.isObservable(c.widget)&&c.widget(e),e},this.watchValues=function(a,b,c,d){var f,g=c.watch;if(g)for(f in g)g.hasOwnProperty(f)&&e.watchOneValue(f,a,b,c,d)},this.watchOneValue=function(c,e,f,g,h){var i=a.computed({read:function(){var i,j,k=g.watch[c],l=a.utils.unwrapObservable(f[c]),m=g.parent?[h]:[];b.isArray(k)?k=e[l?k[0]:k[1]]:"string"==typeof k?k=e[k]:j=!0,k&&f[c]!==d&&(j?m.push(l,f):(i=k.apply(e,m),m.push(l)),(j||i!==l)&&k.apply(e,m))},disposeWhenNodeIsRemoved:h}).extend({throttle:1});a.isObservable(f[c])||i.dispose()},this.handleEvents=function(b,c,d,f){var g,h,i=c.events;if(i)for(g in i)i.hasOwnProperty(g)&&(h=i[g],"string"==typeof h&&(h={value:h,writeTo:h}),a.isObservable(b[h.writeTo])&&e.handleOneEvent(g,h,b,d,f,c.childProp))},this.handleOneEvent=function(a,b,c,d,e,f){e.bind(a,function(a){var e,g;f&&a[f]&&a[f]!==d||(e=b.value,g="string"==typeof e&&this[e]?this[e](f&&d):e,c[b.writeTo](g))})}},a.kendo.bindingFactory=new a.kendo.BindingFactory,a.kendo.setDataSource=function(b,d,e){var f,g;return d instanceof c.data.DataSource?void b.setDataSource(d):(e&&e.useKOTemplates||(f=a.mapping&&d&&d.__ko_mapping__,g=d&&f?a.mapping.toJS(d):a.toJS(d)),void b.dataSource.data(g||d))},function(){var a=c.data.ObservableArray.fn.wrap;c.data.ObservableArray.fn.wrap=function(b){var c=a.apply(this,arguments);return c._raw=function(){return b},c}}();var e=function(b){return function(c){c&&(a.utils.extend(this.options[b],c),this.redraw(),this.value(.001+this.value()))}},f=a.kendo.bindingFactory.createBinding.bind(a.kendo.bindingFactory),g="close",h="collapse",i="content",j="data",k="enable",l="expand",m="expanded",n="filter",o="isOpen",p="max",q="min",r="open",s="palette",t="search",u="select",v="selected",w="size",x="title",y="value",z="values";f({name:"kendoAutoComplete",events:{change:y,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,search:[t,g],data:function(b){a.kendo.setDataSource(this,b)},value:y}}),f({name:"kendoCalendar",defaultOption:y,events:{change:y},watch:{max:p,min:q,value:y}}),f({name:"kendoColorPicker",events:{change:y,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,value:y,color:y,palette:s}}),f({name:"kendoComboBox",events:{change:y,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,isOpen:[r,g],data:function(b){a.kendo.setDataSource(this,b)},value:y}}),f({name:"kendoDatePicker",defaultOption:y,events:{change:y,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,max:p,min:q,value:y,isOpen:[r,g]}}),f({name:"kendoDateTimePicker",defaultOption:y,events:{change:y,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,max:p,min:q,value:y,isOpen:[r,g]}}),f({name:"kendoDropDownList",events:{change:y,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,isOpen:[r,g],data:function(b){a.kendo.setDataSource(this,b),b.length&&this.options.optionLabel&&this.select()<0&&this.select(0)},value:y}}),f({name:"kendoEditor",defaultOption:y,events:{change:y},watch:{enabled:k,value:y}}),f({name:"kendoGrid",defaultOption:j,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["rowTemplate","altRowTemplate"]}),f({name:"kendoListView",defaultOption:j,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["template"]}),f({name:"kendoMenu",async:!0}),f({name:"kendoMenuItem",parent:"kendoMenu",watch:{enabled:k,isOpen:[r,g]},async:!0}),f({name:"kendoMultiSelect",events:{change:y,open:{writeTo:o,value:!0},close:{writeTo:o,value:!1}},watch:{enabled:k,search:[t,g],data:function(b){a.kendo.setDataSource(this,b)},value:y}}),f({name:"kendoNumericTextBox",defaultOption:y,events:{change:y},watch:{enabled:k,value:y,max:function(a){this.options.max=a,this.value()>a&&this.value(a)},min:function(a){this.options.min=a,this.value() Date: Sat, 19 Apr 2014 00:04:01 +0200 Subject: [PATCH 3/7] Update knockout-kendoNumericTextBox.js --- src/knockout-kendoNumericTextBox.js | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/knockout-kendoNumericTextBox.js b/src/knockout-kendoNumericTextBox.js index 5e6507c..3188012 100644 --- a/src/knockout-kendoNumericTextBox.js +++ b/src/knockout-kendoNumericTextBox.js @@ -7,21 +7,21 @@ createBinding({ watch: { enabled: ENABLE, value: VALUE, - max: function(newMax) { - this.options.max = newMax; - //make sure current value is still valid - var value = this.value(); - if ((value || value === 0) && value > newMax) { - this.value(newMax); - } - }, - min: function(newMin) { - this.options.min = newMin; - //make sure that current value is still valid - var value = this.value(); - if ((value || value === 0) && value < newMin ) { - this.value(newMin); - } + max: function(newMax) { + this.options.max = newMax; + //make sure current value is still valid + var value = this.value(); + if ((value || value === 0) && value > newMax) { + this.value(newMax); } + }, + min: function(newMin) { + this.options.min = newMin; + //make sure that current value is still valid + var value = this.value(); + if ((value || value === 0) && value < newMin ) { + this.value(newMin); + } + } } }); From 1eebf82836262e67122ae5e2dff1028715e219ee Mon Sep 17 00:00:00 2001 From: Ryan Niemeyer Date: Fri, 23 May 2014 00:08:18 -0500 Subject: [PATCH 4/7] add kendoSortable functionality --- build/knockout-kendo.js | 44 ++++++++++++++++++++--- build/knockout-kendo.min.js | 4 +-- spec/knockout-kendo-bindingSpecFactory.js | 43 ++++++++++++++++++++-- spec/knockout-kendoSortable.spec.js | 8 +++++ spec/runner.html | 1 + src/knockout-kendo-core.js | 10 ++++-- src/knockout-kendo.js | 2 ++ src/knockout-kendoSortable.js | 37 +++++++++++++++++++ 8 files changed, 138 insertions(+), 11 deletions(-) create mode 100644 spec/knockout-kendoSortable.spec.js create mode 100644 src/knockout-kendoSortable.js diff --git a/build/knockout-kendo.js b/build/knockout-kendo.js index 9a43d04..226a6de 100644 --- a/build/knockout-kendo.js +++ b/build/knockout-kendo.js @@ -1,5 +1,5 @@ /* - * knockout-kendo 0.8.0 + * knockout-kendo 0.8.1 * Copyright © 2013 Ryan Niemeyer & Telerik * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -249,10 +249,14 @@ ko.kendo.BindingFactory = function() { //bind to a single event this.handleOneEvent = function(eventName, eventConfig, options, element, widget, childProp, context) { - var handler; + var handler = typeof eventConfig === "function" ? eventConfig : options[eventConfig.call]; - //not an observable, use function as handler with normal KO args - if (eventConfig.call && typeof options[eventConfig.call] === "function") { + //call a function defined directly in the binding definition, supply options that were passed to the binding + if (typeof eventConfig === "function") { + handler = handler.bind(context.$data, options); + } + //use function passed in binding options as handler with normal KO args + else if (eventConfig.call && typeof options[eventConfig.call] === "function") { handler = options[eventConfig.call].bind(context.$data, context.$data); } //option is observable, determine what to write to it @@ -734,6 +738,38 @@ createBinding({ } }); +createBinding({ + name: "kendoSortable", + defaultOption: DATA, + events: { + end: function(options, e) { + var dataKey = "__ko_kendo_sortable_data__", + data = e.action !== "receive" ? ko.dataFor(e.item[0]) : e.draggableEvent[dataKey], + items = options.data, + underlyingArray = options.data; + + if (e.action === "sort" || e.action === "remove") { + underlyingArray.splice(e.oldIndex, 1); + + if (e.action === "remove") { + e.draggableEvent[dataKey] = data; + } + } + + if (e.action === "sort" || e.action === "receive") { + underlyingArray.splice(e.newIndex, 0, data); + + delete e.draggableEvent[dataKey]; + + $(e.draggableEvent.target).hide(); + e.preventDefault(); + } + + items.valueHasMutated(); + } + } +}); + createBinding({ name: "kendoSplitter", async: true diff --git a/build/knockout-kendo.min.js b/build/knockout-kendo.min.js index e873eaf..1e18f87 100644 --- a/build/knockout-kendo.min.js +++ b/build/knockout-kendo.min.js @@ -1,5 +1,5 @@ /* - * knockout-kendo 0.8.0 + * knockout-kendo 0.8.1 * Copyright © 2013 Ryan Niemeyer & Telerik * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,4 +14,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -!function(a){"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?a(require("knockout"),require("jquery"),require("kendo")):"function"==typeof define&&define.amd?define(["knockout","jquery","kendo"],a):a(window.ko,window.jQuery,window.kendo)}(function(a,b,c,d){c=c||window.kendo,a.kendo=a.kendo||{},a.kendo.BindingFactory=function(){var e=this;this.createBinding=function(c){if(b()[c.parent||c.name]){var d={};d.init=function(a,b,f,g,h){var i=e.buildOptions(c,b);return i.async===!0||c.async===!0&&i.async!==!1?(setTimeout(function(){d.setup(a,i,h)},0),void 0):(d.setup(a,i,h),i&&i.useKOTemplates?{controlsDescendantBindings:!0}:void 0)},d.setup=function(d,f,g){var h,i=b(d);e.setupTemplates(c.templates,f,d,g),h=e.getWidget(c,f,i),e.handleEvents(f,c,d,h,g),e.watchValues(h,f,c,d),h.destroy&&a.utils.domNodeDisposal.addDisposeCallback(d,function(){h.destroy()})},d.options={},d.widgetConfig=c,a.bindingHandlers[c.bindingName||c.name]=d}},this.buildOptions=function(b,d){var e=b.defaultOption,f=a.utils.extend({},a.bindingHandlers[b.name].options),g=a.utils.unwrapObservable(d());return g instanceof c.data.DataSource||"object"!=typeof g||null===g||e&&!(e in g)?f[e]=d():a.utils.extend(f,g),f};var f=function(b,c){return function(d){return a.renderTemplate(b,c.createChildContext(d._raw&&d._raw()||d))}};this.setupTemplates=function(b,c,d,e){var g,h,i,j;if(b&&c&&c.useKOTemplates){for(g=0,h=b.length;h>g;g++)i=b[g],c[i]&&(c[i]=f(c[i],e));j=c.dataBound,c.dataBound=function(){a.memoization.unmemoizeDomNodeAndDescendants(d),j&&j.apply(this,arguments)}}},this.unwrapOneLevel=function(b){var d,e={};if(b)if(b instanceof c.data.DataSource)e=b;else if("object"==typeof b)for(d in b)e[d]=a.utils.unwrapObservable(b[d]);return e},this.getWidget=function(b,c,d){var e;if(b.parent){var f=d.closest("[data-bind*='"+b.parent+":']");e=f.length?f.data(b.parent):null}else e=d[b.name](this.unwrapOneLevel(c)).data(b.name);return a.isObservable(c.widget)&&c.widget(e),e},this.watchValues=function(a,b,c,d){var f,g=c.watch;if(g)for(f in g)g.hasOwnProperty(f)&&e.watchOneValue(f,a,b,c,d)},this.watchOneValue=function(c,e,f,g,h){var i=a.computed({read:function(){var i,j,k=g.watch[c],l=a.utils.unwrapObservable(f[c]),m=g.parent?[h]:[];b.isArray(k)?k=e[l?k[0]:k[1]]:"string"==typeof k?k=e[k]:j=!0,k&&f[c]!==d&&(j?m.push(l,f):(i=k.apply(e,m),m.push(l)),(j||i!==l)&&k.apply(e,m))},disposeWhenNodeIsRemoved:h}).extend({throttle:1});a.isObservable(f[c])||i.dispose()},this.handleEvents=function(a,b,c,d,f){var g,h,i=b.events;if(i)for(g in i)i.hasOwnProperty(g)&&(h=i[g],"string"==typeof h&&(h={value:h,writeTo:h}),e.handleOneEvent(g,h,a,c,d,b.childProp,f))},this.handleOneEvent=function(b,c,d,e,f,g,h){var i;c.call&&"function"==typeof d[c.call]?i=d[c.call].bind(h.$data,h.$data):c.writeTo&&a.isWriteableObservable(d[c.writeTo])&&(i=function(a){var b,f;g&&a[g]&&a[g]!==e||(b=c.value,f="string"==typeof b&&this[b]?this[b](g&&e):b,d[c.writeTo](f))}),i&&f.bind(b,i)}},a.kendo.bindingFactory=new a.kendo.BindingFactory,a.kendo.setDataSource=function(b,d,e){var f,g;return d instanceof c.data.DataSource?(b.setDataSource(d),void 0):(e&&e.useKOTemplates||(f=a.mapping&&d&&d.__ko_mapping__,g=d&&f?a.mapping.toJS(d):a.toJS(d)),b.dataSource.data(g||d),void 0)},function(){var a=c.data.ObservableArray.fn.wrap;c.data.ObservableArray.fn.wrap=function(b){var c=a.apply(this,arguments);return c._raw=function(){return b},c}}();var e=function(b){return function(c){c&&(a.utils.extend(this.options[b],c),this.redraw(),this.value(.001+this.value()))}},f=a.kendo.bindingFactory.createBinding.bind(a.kendo.bindingFactory),g="clicked",h="close",i="collapse",j="content",k="data",l="enable",m="expand",n="expanded",o="error",p="filter",q="info",r="isOpen",s="max",t="min",u="open",v="palette",w="readonly",x="search",y="selected",z="success",A="size",B="title",C="value",D="values",E="warning";f({name:"kendoAutoComplete",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoButton",defaultOption:g,events:{click:{call:g}},watch:{enabled:l}}),f({name:"kendoCalendar",defaultOption:C,events:{change:C},watch:{max:s,min:t,value:C}}),f({name:"kendoColorPicker",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,value:C,color:C,palette:v}}),f({name:"kendoComboBox",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoDatePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDateTimePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDropDownList",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b),b.length&&this.options.optionLabel&&this.select()<0&&this.select(0)},value:C}}),f({name:"kendoEditor",defaultOption:C,events:{change:C},watch:{enabled:l,value:C}}),f({name:"kendoGrid",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["rowTemplate","altRowTemplate"]}),f({name:"kendoListView",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["template"]}),f({name:"kendoMaskedTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,isReadOnly:w,value:C}}),f({name:"kendoMenu",async:!0}),f({name:"kendoMenuItem",parent:"kendoMenu",watch:{enabled:l,isOpen:[u,h]},async:!0}),f({name:"kendoMultiSelect",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}});var F=function(a,b){b||0===b?this.show(b,a):this.hide()};f({name:"kendoNotification",watch:{error:function(a){F.call(this,o,a)},info:function(a){F.call(this,q,a)},success:function(a){F.call(this,z,a)},warning:function(a){F.call(this,E,a)}}}),f({name:"kendoNumericTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,value:C,max:function(a){this.options.max=a,this.value()>a&&this.value(a)},min:function(a){this.options.min=a,this.value()g;g++)i=b[g],c[i]&&(c[i]=f(c[i],e));j=c.dataBound,c.dataBound=function(){a.memoization.unmemoizeDomNodeAndDescendants(d),j&&j.apply(this,arguments)}}},this.unwrapOneLevel=function(b){var d,e={};if(b)if(b instanceof c.data.DataSource)e=b;else if("object"==typeof b)for(d in b)e[d]=a.utils.unwrapObservable(b[d]);return e},this.getWidget=function(b,c,d){var e;if(b.parent){var f=d.closest("[data-bind*='"+b.parent+":']");e=f.length?f.data(b.parent):null}else e=d[b.name](this.unwrapOneLevel(c)).data(b.name);return a.isObservable(c.widget)&&c.widget(e),e},this.watchValues=function(a,b,c,d){var f,g=c.watch;if(g)for(f in g)g.hasOwnProperty(f)&&e.watchOneValue(f,a,b,c,d)},this.watchOneValue=function(c,e,f,g,h){var i=a.computed({read:function(){var i,j,k=g.watch[c],l=a.utils.unwrapObservable(f[c]),m=g.parent?[h]:[];b.isArray(k)?k=e[l?k[0]:k[1]]:"string"==typeof k?k=e[k]:j=!0,k&&f[c]!==d&&(j?m.push(l,f):(i=k.apply(e,m),m.push(l)),(j||i!==l)&&k.apply(e,m))},disposeWhenNodeIsRemoved:h}).extend({throttle:1});a.isObservable(f[c])||i.dispose()},this.handleEvents=function(a,b,c,d,f){var g,h,i=b.events;if(i)for(g in i)i.hasOwnProperty(g)&&(h=i[g],"string"==typeof h&&(h={value:h,writeTo:h}),e.handleOneEvent(g,h,a,c,d,b.childProp,f))},this.handleOneEvent=function(b,c,d,e,f,g,h){var i="function"==typeof c?c:d[c.call];"function"==typeof c?i=i.bind(h.$data,d):c.call&&"function"==typeof d[c.call]?i=d[c.call].bind(h.$data,h.$data):c.writeTo&&a.isWriteableObservable(d[c.writeTo])&&(i=function(a){var b,f;g&&a[g]&&a[g]!==e||(b=c.value,f="string"==typeof b&&this[b]?this[b](g&&e):b,d[c.writeTo](f))}),i&&f.bind(b,i)}},a.kendo.bindingFactory=new a.kendo.BindingFactory,a.kendo.setDataSource=function(b,d,e){var f,g;return d instanceof c.data.DataSource?(b.setDataSource(d),void 0):(e&&e.useKOTemplates||(f=a.mapping&&d&&d.__ko_mapping__,g=d&&f?a.mapping.toJS(d):a.toJS(d)),b.dataSource.data(g||d),void 0)},function(){var a=c.data.ObservableArray.fn.wrap;c.data.ObservableArray.fn.wrap=function(b){var c=a.apply(this,arguments);return c._raw=function(){return b},c}}();var e=function(b){return function(c){c&&(a.utils.extend(this.options[b],c),this.redraw(),this.value(.001+this.value()))}},f=a.kendo.bindingFactory.createBinding.bind(a.kendo.bindingFactory),g="clicked",h="close",i="collapse",j="content",k="data",l="enable",m="expand",n="expanded",o="error",p="filter",q="info",r="isOpen",s="max",t="min",u="open",v="palette",w="readonly",x="search",y="selected",z="success",A="size",B="title",C="value",D="values",E="warning";f({name:"kendoAutoComplete",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoButton",defaultOption:g,events:{click:{call:g}},watch:{enabled:l}}),f({name:"kendoCalendar",defaultOption:C,events:{change:C},watch:{max:s,min:t,value:C}}),f({name:"kendoColorPicker",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,value:C,color:C,palette:v}}),f({name:"kendoComboBox",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoDatePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDateTimePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDropDownList",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b),b.length&&this.options.optionLabel&&this.select()<0&&this.select(0)},value:C}}),f({name:"kendoEditor",defaultOption:C,events:{change:C},watch:{enabled:l,value:C}}),f({name:"kendoGrid",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["rowTemplate","altRowTemplate"]}),f({name:"kendoListView",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["template"]}),f({name:"kendoMaskedTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,isReadOnly:w,value:C}}),f({name:"kendoMenu",async:!0}),f({name:"kendoMenuItem",parent:"kendoMenu",watch:{enabled:l,isOpen:[u,h]},async:!0}),f({name:"kendoMultiSelect",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}});var F=function(a,b){b||0===b?this.show(b,a):this.hide()};f({name:"kendoNotification",watch:{error:function(a){F.call(this,o,a)},info:function(a){F.call(this,q,a)},success:function(a){F.call(this,z,a)},warning:function(a){F.call(this,E,a)}}}),f({name:"kendoNumericTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,value:C,max:function(a){this.options.max=a,this.value()>a&&this.value(a)},min:function(a){this.options.min=a,this.value()" + }); + + //additional kendoSortable cases +}); \ No newline at end of file diff --git a/spec/runner.html b/spec/runner.html index 62d9f2d..5e1fa50 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -39,6 +39,7 @@ + diff --git a/src/knockout-kendo-core.js b/src/knockout-kendo-core.js index 8cfae4d..a3f3194 100644 --- a/src/knockout-kendo-core.js +++ b/src/knockout-kendo-core.js @@ -217,10 +217,14 @@ ko.kendo.BindingFactory = function() { //bind to a single event this.handleOneEvent = function(eventName, eventConfig, options, element, widget, childProp, context) { - var handler; + var handler = typeof eventConfig === "function" ? eventConfig : options[eventConfig.call]; - //not an observable, use function as handler with normal KO args - if (eventConfig.call && typeof options[eventConfig.call] === "function") { + //call a function defined directly in the binding definition, supply options that were passed to the binding + if (typeof eventConfig === "function") { + handler = handler.bind(context.$data, options); + } + //use function passed in binding options as handler with normal KO args + else if (eventConfig.call && typeof options[eventConfig.call] === "function") { handler = options[eventConfig.call].bind(context.$data, context.$data); } //option is observable, determine what to write to it diff --git a/src/knockout-kendo.js b/src/knockout-kendo.js index 4c049bb..cc0b510 100644 --- a/src/knockout-kendo.js +++ b/src/knockout-kendo.js @@ -60,6 +60,8 @@ kendo = kendo || window.kendo; //import "knockout-kendoSlider.js" +//import "knockout-kendoSortable.js" + //import "knockout-kendoSplitter.js" //import "knockout-kendoTabStrip.js" diff --git a/src/knockout-kendoSortable.js b/src/knockout-kendoSortable.js new file mode 100644 index 0000000..798cfea --- /dev/null +++ b/src/knockout-kendoSortable.js @@ -0,0 +1,37 @@ +createBinding({ + name: "kendoSortable", + defaultOption: DATA, + events: { + end: function(options, e) { + var dataKey = "__ko_kendo_sortable_data__", + data = e.action !== "receive" ? ko.dataFor(e.item[0]) : e.draggableEvent[dataKey], + items = options.data, + underlyingArray = options.data; + + //remove item from its original position + if (e.action === "sort" || e.action === "remove") { + underlyingArray.splice(e.oldIndex, 1); + + //keep track of the item between remove and receive + if (e.action === "remove") { + e.draggableEvent[dataKey] = data; + } + } + + //add the item to its new position + if (e.action === "sort" || e.action === "receive") { + underlyingArray.splice(e.newIndex, 0, data); + + //clear the data we passed + delete e.draggableEvent[dataKey]; + + //we are moving the item ourselves via the observableArray, cancel the draggable and hide the animation + $(e.draggableEvent.target).hide(); + e.preventDefault(); + } + + //signal that the observableArray has changed now that we are done changing the array + items.valueHasMutated(); + } + } +}); \ No newline at end of file From 9d1f0268a1984c55140307af4109c5b9c9696de4 Mon Sep 17 00:00:00 2001 From: Nadisan Bogdan Date: Mon, 14 Apr 2014 14:36:35 +0300 Subject: [PATCH 5/7] Update knockout-kendo-core.js Why should we always invoke async method calls if not wanted? With this approach, we can decide if the widget should use async events or not. e.g. kendoGrid: { throttle: -1 } If not specified, by default it will execute async calls. Hope this helps. --- src/knockout-kendo-core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/knockout-kendo-core.js b/src/knockout-kendo-core.js index a3f3194..2cd3eda 100644 --- a/src/knockout-kendo-core.js +++ b/src/knockout-kendo-core.js @@ -189,7 +189,7 @@ ko.kendo.BindingFactory = function() { } }, disposeWhenNodeIsRemoved: element - }).extend({ throttle: 1 }); + }).extend({ throttle: options.throttle ? options.throttle : 1 }); //if option is not observable, then dispose up front after executing the logic once if (!ko.isObservable(options[prop])) { @@ -287,4 +287,4 @@ var extendAndRedraw = function(prop) { this.value(0.001 + this.value()); } }; -}; \ No newline at end of file +}; From 67ddc4e527fde1033d2266ef99ba370b297bdcca Mon Sep 17 00:00:00 2001 From: Ryan Niemeyer Date: Fri, 23 May 2014 15:57:16 -0500 Subject: [PATCH 6/7] small style tweak --- build/knockout-kendo.js | 18 ++++++++++++++---- build/knockout-kendo.min.js | 4 ++-- src/knockout-kendo-core.js | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/build/knockout-kendo.js b/build/knockout-kendo.js index 226a6de..3706546 100644 --- a/build/knockout-kendo.js +++ b/build/knockout-kendo.js @@ -1,5 +1,5 @@ /* - * knockout-kendo 0.8.1 + * knockout-kendo 0.8.0 * Copyright © 2013 Ryan Niemeyer & Telerik * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -221,7 +221,7 @@ ko.kendo.BindingFactory = function() { } }, disposeWhenNodeIsRemoved: element - }).extend({ throttle: 1 }); + }).extend({ throttle: (options.throttle || options.throttle === 0) ? options.throttle : 1 }); //if option is not observable, then dispose up front after executing the logic once if (!ko.isObservable(options[prop])) { @@ -321,6 +321,7 @@ var extendAndRedraw = function(prop) { }; }; + //library is in a closure, use this private variable to reduce size of minified file var createBinding = ko.kendo.bindingFactory.createBinding.bind(ko.kendo.bindingFactory); @@ -652,20 +653,23 @@ createBinding({ max: function(newMax) { this.options.max = newMax; //make sure current value is still valid - if (this.value() > newMax) { + var value = this.value(); + if ((value || value === 0) && value > newMax) { this.value(newMax); } }, min: function(newMin) { this.options.min = newMin; //make sure that current value is still valid - if (this.value() < newMin) { + var value = this.value(); + if ((value || value === 0) && value < newMin ) { this.value(newMin); } } } }); + createBinding({ name: "kendoPanelBar", async: true @@ -748,23 +752,29 @@ createBinding({ items = options.data, underlyingArray = options.data; + //remove item from its original position if (e.action === "sort" || e.action === "remove") { underlyingArray.splice(e.oldIndex, 1); + //keep track of the item between remove and receive if (e.action === "remove") { e.draggableEvent[dataKey] = data; } } + //add the item to its new position if (e.action === "sort" || e.action === "receive") { underlyingArray.splice(e.newIndex, 0, data); + //clear the data we passed delete e.draggableEvent[dataKey]; + //we are moving the item ourselves via the observableArray, cancel the draggable and hide the animation $(e.draggableEvent.target).hide(); e.preventDefault(); } + //signal that the observableArray has changed now that we are done changing the array items.valueHasMutated(); } } diff --git a/build/knockout-kendo.min.js b/build/knockout-kendo.min.js index 1e18f87..34248ff 100644 --- a/build/knockout-kendo.min.js +++ b/build/knockout-kendo.min.js @@ -1,5 +1,5 @@ /* - * knockout-kendo 0.8.1 + * knockout-kendo 0.8.0 * Copyright © 2013 Ryan Niemeyer & Telerik * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,4 +14,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -!function(a){"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?a(require("knockout"),require("jquery"),require("kendo")):"function"==typeof define&&define.amd?define(["knockout","jquery","kendo"],a):a(window.ko,window.jQuery,window.kendo)}(function(a,b,c,d){c=c||window.kendo,a.kendo=a.kendo||{},a.kendo.BindingFactory=function(){var e=this;this.createBinding=function(c){if(b()[c.parent||c.name]){var d={};d.init=function(a,b,f,g,h){var i=e.buildOptions(c,b);return i.async===!0||c.async===!0&&i.async!==!1?(setTimeout(function(){d.setup(a,i,h)},0),void 0):(d.setup(a,i,h),i&&i.useKOTemplates?{controlsDescendantBindings:!0}:void 0)},d.setup=function(d,f,g){var h,i=b(d);e.setupTemplates(c.templates,f,d,g),h=e.getWidget(c,f,i),e.handleEvents(f,c,d,h,g),e.watchValues(h,f,c,d),h.destroy&&a.utils.domNodeDisposal.addDisposeCallback(d,function(){h.destroy()})},d.options={},d.widgetConfig=c,a.bindingHandlers[c.bindingName||c.name]=d}},this.buildOptions=function(b,d){var e=b.defaultOption,f=a.utils.extend({},a.bindingHandlers[b.name].options),g=a.utils.unwrapObservable(d());return g instanceof c.data.DataSource||"object"!=typeof g||null===g||e&&!(e in g)?f[e]=d():a.utils.extend(f,g),f};var f=function(b,c){return function(d){return a.renderTemplate(b,c.createChildContext(d._raw&&d._raw()||d))}};this.setupTemplates=function(b,c,d,e){var g,h,i,j;if(b&&c&&c.useKOTemplates){for(g=0,h=b.length;h>g;g++)i=b[g],c[i]&&(c[i]=f(c[i],e));j=c.dataBound,c.dataBound=function(){a.memoization.unmemoizeDomNodeAndDescendants(d),j&&j.apply(this,arguments)}}},this.unwrapOneLevel=function(b){var d,e={};if(b)if(b instanceof c.data.DataSource)e=b;else if("object"==typeof b)for(d in b)e[d]=a.utils.unwrapObservable(b[d]);return e},this.getWidget=function(b,c,d){var e;if(b.parent){var f=d.closest("[data-bind*='"+b.parent+":']");e=f.length?f.data(b.parent):null}else e=d[b.name](this.unwrapOneLevel(c)).data(b.name);return a.isObservable(c.widget)&&c.widget(e),e},this.watchValues=function(a,b,c,d){var f,g=c.watch;if(g)for(f in g)g.hasOwnProperty(f)&&e.watchOneValue(f,a,b,c,d)},this.watchOneValue=function(c,e,f,g,h){var i=a.computed({read:function(){var i,j,k=g.watch[c],l=a.utils.unwrapObservable(f[c]),m=g.parent?[h]:[];b.isArray(k)?k=e[l?k[0]:k[1]]:"string"==typeof k?k=e[k]:j=!0,k&&f[c]!==d&&(j?m.push(l,f):(i=k.apply(e,m),m.push(l)),(j||i!==l)&&k.apply(e,m))},disposeWhenNodeIsRemoved:h}).extend({throttle:1});a.isObservable(f[c])||i.dispose()},this.handleEvents=function(a,b,c,d,f){var g,h,i=b.events;if(i)for(g in i)i.hasOwnProperty(g)&&(h=i[g],"string"==typeof h&&(h={value:h,writeTo:h}),e.handleOneEvent(g,h,a,c,d,b.childProp,f))},this.handleOneEvent=function(b,c,d,e,f,g,h){var i="function"==typeof c?c:d[c.call];"function"==typeof c?i=i.bind(h.$data,d):c.call&&"function"==typeof d[c.call]?i=d[c.call].bind(h.$data,h.$data):c.writeTo&&a.isWriteableObservable(d[c.writeTo])&&(i=function(a){var b,f;g&&a[g]&&a[g]!==e||(b=c.value,f="string"==typeof b&&this[b]?this[b](g&&e):b,d[c.writeTo](f))}),i&&f.bind(b,i)}},a.kendo.bindingFactory=new a.kendo.BindingFactory,a.kendo.setDataSource=function(b,d,e){var f,g;return d instanceof c.data.DataSource?(b.setDataSource(d),void 0):(e&&e.useKOTemplates||(f=a.mapping&&d&&d.__ko_mapping__,g=d&&f?a.mapping.toJS(d):a.toJS(d)),b.dataSource.data(g||d),void 0)},function(){var a=c.data.ObservableArray.fn.wrap;c.data.ObservableArray.fn.wrap=function(b){var c=a.apply(this,arguments);return c._raw=function(){return b},c}}();var e=function(b){return function(c){c&&(a.utils.extend(this.options[b],c),this.redraw(),this.value(.001+this.value()))}},f=a.kendo.bindingFactory.createBinding.bind(a.kendo.bindingFactory),g="clicked",h="close",i="collapse",j="content",k="data",l="enable",m="expand",n="expanded",o="error",p="filter",q="info",r="isOpen",s="max",t="min",u="open",v="palette",w="readonly",x="search",y="selected",z="success",A="size",B="title",C="value",D="values",E="warning";f({name:"kendoAutoComplete",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoButton",defaultOption:g,events:{click:{call:g}},watch:{enabled:l}}),f({name:"kendoCalendar",defaultOption:C,events:{change:C},watch:{max:s,min:t,value:C}}),f({name:"kendoColorPicker",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,value:C,color:C,palette:v}}),f({name:"kendoComboBox",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoDatePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDateTimePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDropDownList",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b),b.length&&this.options.optionLabel&&this.select()<0&&this.select(0)},value:C}}),f({name:"kendoEditor",defaultOption:C,events:{change:C},watch:{enabled:l,value:C}}),f({name:"kendoGrid",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["rowTemplate","altRowTemplate"]}),f({name:"kendoListView",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["template"]}),f({name:"kendoMaskedTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,isReadOnly:w,value:C}}),f({name:"kendoMenu",async:!0}),f({name:"kendoMenuItem",parent:"kendoMenu",watch:{enabled:l,isOpen:[u,h]},async:!0}),f({name:"kendoMultiSelect",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}});var F=function(a,b){b||0===b?this.show(b,a):this.hide()};f({name:"kendoNotification",watch:{error:function(a){F.call(this,o,a)},info:function(a){F.call(this,q,a)},success:function(a){F.call(this,z,a)},warning:function(a){F.call(this,E,a)}}}),f({name:"kendoNumericTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,value:C,max:function(a){this.options.max=a,this.value()>a&&this.value(a)},min:function(a){this.options.min=a,this.value()g;g++)i=b[g],c[i]&&(c[i]=f(c[i],e));j=c.dataBound,c.dataBound=function(){a.memoization.unmemoizeDomNodeAndDescendants(d),j&&j.apply(this,arguments)}}},this.unwrapOneLevel=function(b){var d,e={};if(b)if(b instanceof c.data.DataSource)e=b;else if("object"==typeof b)for(d in b)e[d]=a.utils.unwrapObservable(b[d]);return e},this.getWidget=function(b,c,d){var e;if(b.parent){var f=d.closest("[data-bind*='"+b.parent+":']");e=f.length?f.data(b.parent):null}else e=d[b.name](this.unwrapOneLevel(c)).data(b.name);return a.isObservable(c.widget)&&c.widget(e),e},this.watchValues=function(a,b,c,d){var f,g=c.watch;if(g)for(f in g)g.hasOwnProperty(f)&&e.watchOneValue(f,a,b,c,d)},this.watchOneValue=function(c,e,f,g,h){var i=a.computed({read:function(){var i,j,k=g.watch[c],l=a.utils.unwrapObservable(f[c]),m=g.parent?[h]:[];b.isArray(k)?k=e[l?k[0]:k[1]]:"string"==typeof k?k=e[k]:j=!0,k&&f[c]!==d&&(j?m.push(l,f):(i=k.apply(e,m),m.push(l)),(j||i!==l)&&k.apply(e,m))},disposeWhenNodeIsRemoved:h}).extend({throttle:f.throttle||0===f.throttle?f.throttle:1});a.isObservable(f[c])||i.dispose()},this.handleEvents=function(a,b,c,d,f){var g,h,i=b.events;if(i)for(g in i)i.hasOwnProperty(g)&&(h=i[g],"string"==typeof h&&(h={value:h,writeTo:h}),e.handleOneEvent(g,h,a,c,d,b.childProp,f))},this.handleOneEvent=function(b,c,d,e,f,g,h){var i="function"==typeof c?c:d[c.call];"function"==typeof c?i=i.bind(h.$data,d):c.call&&"function"==typeof d[c.call]?i=d[c.call].bind(h.$data,h.$data):c.writeTo&&a.isWriteableObservable(d[c.writeTo])&&(i=function(a){var b,f;g&&a[g]&&a[g]!==e||(b=c.value,f="string"==typeof b&&this[b]?this[b](g&&e):b,d[c.writeTo](f))}),i&&f.bind(b,i)}},a.kendo.bindingFactory=new a.kendo.BindingFactory,a.kendo.setDataSource=function(b,d,e){var f,g;return d instanceof c.data.DataSource?(b.setDataSource(d),void 0):(e&&e.useKOTemplates||(f=a.mapping&&d&&d.__ko_mapping__,g=d&&f?a.mapping.toJS(d):a.toJS(d)),b.dataSource.data(g||d),void 0)},function(){var a=c.data.ObservableArray.fn.wrap;c.data.ObservableArray.fn.wrap=function(b){var c=a.apply(this,arguments);return c._raw=function(){return b},c}}();var e=function(b){return function(c){c&&(a.utils.extend(this.options[b],c),this.redraw(),this.value(.001+this.value()))}},f=a.kendo.bindingFactory.createBinding.bind(a.kendo.bindingFactory),g="clicked",h="close",i="collapse",j="content",k="data",l="enable",m="expand",n="expanded",o="error",p="filter",q="info",r="isOpen",s="max",t="min",u="open",v="palette",w="readonly",x="search",y="selected",z="success",A="size",B="title",C="value",D="values",E="warning";f({name:"kendoAutoComplete",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoButton",defaultOption:g,events:{click:{call:g}},watch:{enabled:l}}),f({name:"kendoCalendar",defaultOption:C,events:{change:C},watch:{max:s,min:t,value:C}}),f({name:"kendoColorPicker",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,value:C,color:C,palette:v}}),f({name:"kendoComboBox",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoDatePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDateTimePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDropDownList",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b),b.length&&this.options.optionLabel&&this.select()<0&&this.select(0)},value:C}}),f({name:"kendoEditor",defaultOption:C,events:{change:C},watch:{enabled:l,value:C}}),f({name:"kendoGrid",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["rowTemplate","altRowTemplate"]}),f({name:"kendoListView",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["template"]}),f({name:"kendoMaskedTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,isReadOnly:w,value:C}}),f({name:"kendoMenu",async:!0}),f({name:"kendoMenuItem",parent:"kendoMenu",watch:{enabled:l,isOpen:[u,h]},async:!0}),f({name:"kendoMultiSelect",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}});var F=function(a,b){b||0===b?this.show(b,a):this.hide()};f({name:"kendoNotification",watch:{error:function(a){F.call(this,o,a)},info:function(a){F.call(this,q,a)},success:function(a){F.call(this,z,a)},warning:function(a){F.call(this,E,a)}}}),f({name:"kendoNumericTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,value:C,max:function(a){this.options.max=a;var b=this.value();(b||0===b)&&b>a&&this.value(a)},min:function(a){this.options.min=a;var b=this.value();(b||0===b)&&a>b&&this.value(a)}}}),f({name:"kendoPanelBar",async:!0}),f({name:"kendoPanelItem",parent:"kendoPanelBar",watch:{enabled:l,expanded:[m,i]},childProp:"item",events:{expand:{writeTo:n,value:!0},collapse:{writeTo:n,value:!1}},async:!0}),f({name:"kendoProgressBar",defaultOption:C,events:{change:C},watch:{enabled:l,value:C}}),f({name:"kendoRangeSlider",defaultOption:D,events:{change:D},watch:{values:D,enabled:l}}),f({async:!0,name:"kendoScheduler",watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}}}),f({name:"kendoSlider",defaultOption:C,events:{change:C},watch:{value:C,enabled:l}}),f({name:"kendoSortable",defaultOption:k,events:{end:function(c,d){var e="__ko_kendo_sortable_data__",f="receive"!==d.action?a.dataFor(d.item[0]):d.draggableEvent[e],g=c.data,h=c.data;("sort"===d.action||"remove"===d.action)&&(h.splice(d.oldIndex,1),"remove"===d.action&&(d.draggableEvent[e]=f)),("sort"===d.action||"receive"===d.action)&&(h.splice(d.newIndex,0,f),delete d.draggableEvent[e],b(d.draggableEvent.target).hide(),d.preventDefault()),g.valueHasMutated()}}}),f({name:"kendoSplitter",async:!0}),f({name:"kendoSplitterPane",parent:"kendoSplitter",watch:{max:s,min:t,size:A,expanded:[m,i]},childProp:"pane",events:{collapse:{writeTo:n,value:!1},expand:{writeTo:n,value:!0},resize:A},async:!0}),f({name:"kendoTabStrip",async:!0}),f({name:"kendoTab",parent:"kendoTabStrip",watch:{enabled:l},childProp:"item",async:!0}),f({name:"kendoTooltip",events:{},watch:{content:j,filter:p}}),f({name:"kendoTimePicker",defaultOption:C,events:{change:C},watch:{max:s,min:t,value:C,enabled:l,isOpen:[u,h]}}),f({name:"kendoTreeView",async:!0}),f({name:"kendoTreeItem",parent:"kendoTreeView",watch:{enabled:l,expanded:[m,i],selected:function(a,b){b?this.select(a):this.select()[0]==a&&this.select(null)}},childProp:"node",events:{collapse:{writeTo:n,value:!1},expand:{writeTo:n,value:!0},select:{writeTo:y,value:!0}},async:!0}),f({name:"kendoUpload",watch:{enabled:l}}),f({async:!0,name:"kendoWindow",events:{open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{content:j,title:B,isOpen:[u,h]}}),f({name:"kendoChart",watch:{data:function(b){a.kendo.setDataSource(this,b)}}}),f({name:"kendoLinearGauge",defaultOption:C,watch:{value:C,gaugeArea:e("gaugeArea"),pointer:e("pointer"),scale:e("scale")}}),f({name:"kendoRadialGauge",defaultOption:C,watch:{value:C,gaugeArea:e("gaugeArea"),pointer:e("pointer"),scale:e("scale")}})}); \ No newline at end of file diff --git a/src/knockout-kendo-core.js b/src/knockout-kendo-core.js index 2cd3eda..dc5bba6 100644 --- a/src/knockout-kendo-core.js +++ b/src/knockout-kendo-core.js @@ -189,7 +189,7 @@ ko.kendo.BindingFactory = function() { } }, disposeWhenNodeIsRemoved: element - }).extend({ throttle: options.throttle ? options.throttle : 1 }); + }).extend({ throttle: (options.throttle || options.throttle === 0) ? options.throttle : 1 }); //if option is not observable, then dispose up front after executing the logic once if (!ko.isObservable(options[prop])) { From d42e0488adb29423776780fb74c0d7b7def9a16d Mon Sep 17 00:00:00 2001 From: Ryan Niemeyer Date: Fri, 23 May 2014 16:09:56 -0500 Subject: [PATCH 7/7] update version to 0.8.1 --- bower.json | 2 +- build/knockout-kendo.js | 9 +++++++-- build/knockout-kendo.min.js | 4 ++-- package.json | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index f7c3f0f..f632163 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "knockout-kendo", - "version": "0.8.0", + "version": "0.8.1", "main": "build/knockout-kendo.min.js", "dependencies": { "knockout": ">= 2.0" diff --git a/build/knockout-kendo.js b/build/knockout-kendo.js index 3706546..9a3666d 100644 --- a/build/knockout-kendo.js +++ b/build/knockout-kendo.js @@ -1,5 +1,5 @@ /* - * knockout-kendo 0.8.0 + * knockout-kendo 0.8.1 * Copyright © 2013 Ryan Niemeyer & Telerik * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -680,7 +680,8 @@ createBinding({ parent: "kendoPanelBar", watch: { enabled: ENABLE, - expanded: [EXPAND, COLLAPSE] + expanded: [EXPAND, COLLAPSE], + selected: [SELECT] }, childProp: "item", events: { @@ -691,6 +692,10 @@ createBinding({ collapse: { writeTo: EXPANDED, value: false + }, + select: { + writeTo: SELECTED, + value: VALUE } }, async: true diff --git a/build/knockout-kendo.min.js b/build/knockout-kendo.min.js index 34248ff..236788d 100644 --- a/build/knockout-kendo.min.js +++ b/build/knockout-kendo.min.js @@ -1,5 +1,5 @@ /* - * knockout-kendo 0.8.0 + * knockout-kendo 0.8.1 * Copyright © 2013 Ryan Niemeyer & Telerik * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,4 +14,4 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -!function(a){"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?a(require("knockout"),require("jquery"),require("kendo")):"function"==typeof define&&define.amd?define(["knockout","jquery","kendo"],a):a(window.ko,window.jQuery,window.kendo)}(function(a,b,c,d){c=c||window.kendo,a.kendo=a.kendo||{},a.kendo.BindingFactory=function(){var e=this;this.createBinding=function(c){if(b()[c.parent||c.name]){var d={};d.init=function(a,b,f,g,h){var i=e.buildOptions(c,b);return i.async===!0||c.async===!0&&i.async!==!1?(setTimeout(function(){d.setup(a,i,h)},0),void 0):(d.setup(a,i,h),i&&i.useKOTemplates?{controlsDescendantBindings:!0}:void 0)},d.setup=function(d,f,g){var h,i=b(d);e.setupTemplates(c.templates,f,d,g),h=e.getWidget(c,f,i),e.handleEvents(f,c,d,h,g),e.watchValues(h,f,c,d),h.destroy&&a.utils.domNodeDisposal.addDisposeCallback(d,function(){h.destroy()})},d.options={},d.widgetConfig=c,a.bindingHandlers[c.bindingName||c.name]=d}},this.buildOptions=function(b,d){var e=b.defaultOption,f=a.utils.extend({},a.bindingHandlers[b.name].options),g=a.utils.unwrapObservable(d());return g instanceof c.data.DataSource||"object"!=typeof g||null===g||e&&!(e in g)?f[e]=d():a.utils.extend(f,g),f};var f=function(b,c){return function(d){return a.renderTemplate(b,c.createChildContext(d._raw&&d._raw()||d))}};this.setupTemplates=function(b,c,d,e){var g,h,i,j;if(b&&c&&c.useKOTemplates){for(g=0,h=b.length;h>g;g++)i=b[g],c[i]&&(c[i]=f(c[i],e));j=c.dataBound,c.dataBound=function(){a.memoization.unmemoizeDomNodeAndDescendants(d),j&&j.apply(this,arguments)}}},this.unwrapOneLevel=function(b){var d,e={};if(b)if(b instanceof c.data.DataSource)e=b;else if("object"==typeof b)for(d in b)e[d]=a.utils.unwrapObservable(b[d]);return e},this.getWidget=function(b,c,d){var e;if(b.parent){var f=d.closest("[data-bind*='"+b.parent+":']");e=f.length?f.data(b.parent):null}else e=d[b.name](this.unwrapOneLevel(c)).data(b.name);return a.isObservable(c.widget)&&c.widget(e),e},this.watchValues=function(a,b,c,d){var f,g=c.watch;if(g)for(f in g)g.hasOwnProperty(f)&&e.watchOneValue(f,a,b,c,d)},this.watchOneValue=function(c,e,f,g,h){var i=a.computed({read:function(){var i,j,k=g.watch[c],l=a.utils.unwrapObservable(f[c]),m=g.parent?[h]:[];b.isArray(k)?k=e[l?k[0]:k[1]]:"string"==typeof k?k=e[k]:j=!0,k&&f[c]!==d&&(j?m.push(l,f):(i=k.apply(e,m),m.push(l)),(j||i!==l)&&k.apply(e,m))},disposeWhenNodeIsRemoved:h}).extend({throttle:f.throttle||0===f.throttle?f.throttle:1});a.isObservable(f[c])||i.dispose()},this.handleEvents=function(a,b,c,d,f){var g,h,i=b.events;if(i)for(g in i)i.hasOwnProperty(g)&&(h=i[g],"string"==typeof h&&(h={value:h,writeTo:h}),e.handleOneEvent(g,h,a,c,d,b.childProp,f))},this.handleOneEvent=function(b,c,d,e,f,g,h){var i="function"==typeof c?c:d[c.call];"function"==typeof c?i=i.bind(h.$data,d):c.call&&"function"==typeof d[c.call]?i=d[c.call].bind(h.$data,h.$data):c.writeTo&&a.isWriteableObservable(d[c.writeTo])&&(i=function(a){var b,f;g&&a[g]&&a[g]!==e||(b=c.value,f="string"==typeof b&&this[b]?this[b](g&&e):b,d[c.writeTo](f))}),i&&f.bind(b,i)}},a.kendo.bindingFactory=new a.kendo.BindingFactory,a.kendo.setDataSource=function(b,d,e){var f,g;return d instanceof c.data.DataSource?(b.setDataSource(d),void 0):(e&&e.useKOTemplates||(f=a.mapping&&d&&d.__ko_mapping__,g=d&&f?a.mapping.toJS(d):a.toJS(d)),b.dataSource.data(g||d),void 0)},function(){var a=c.data.ObservableArray.fn.wrap;c.data.ObservableArray.fn.wrap=function(b){var c=a.apply(this,arguments);return c._raw=function(){return b},c}}();var e=function(b){return function(c){c&&(a.utils.extend(this.options[b],c),this.redraw(),this.value(.001+this.value()))}},f=a.kendo.bindingFactory.createBinding.bind(a.kendo.bindingFactory),g="clicked",h="close",i="collapse",j="content",k="data",l="enable",m="expand",n="expanded",o="error",p="filter",q="info",r="isOpen",s="max",t="min",u="open",v="palette",w="readonly",x="search",y="selected",z="success",A="size",B="title",C="value",D="values",E="warning";f({name:"kendoAutoComplete",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoButton",defaultOption:g,events:{click:{call:g}},watch:{enabled:l}}),f({name:"kendoCalendar",defaultOption:C,events:{change:C},watch:{max:s,min:t,value:C}}),f({name:"kendoColorPicker",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,value:C,color:C,palette:v}}),f({name:"kendoComboBox",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}}),f({name:"kendoDatePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDateTimePicker",defaultOption:C,events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:C,isOpen:[u,h]}}),f({name:"kendoDropDownList",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b),b.length&&this.options.optionLabel&&this.select()<0&&this.select(0)},value:C}}),f({name:"kendoEditor",defaultOption:C,events:{change:C},watch:{enabled:l,value:C}}),f({name:"kendoGrid",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["rowTemplate","altRowTemplate"]}),f({name:"kendoListView",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["template"]}),f({name:"kendoMaskedTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,isReadOnly:w,value:C}}),f({name:"kendoMenu",async:!0}),f({name:"kendoMenuItem",parent:"kendoMenu",watch:{enabled:l,isOpen:[u,h]},async:!0}),f({name:"kendoMultiSelect",events:{change:C,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:C}});var F=function(a,b){b||0===b?this.show(b,a):this.hide()};f({name:"kendoNotification",watch:{error:function(a){F.call(this,o,a)},info:function(a){F.call(this,q,a)},success:function(a){F.call(this,z,a)},warning:function(a){F.call(this,E,a)}}}),f({name:"kendoNumericTextBox",defaultOption:C,events:{change:C},watch:{enabled:l,value:C,max:function(a){this.options.max=a;var b=this.value();(b||0===b)&&b>a&&this.value(a)},min:function(a){this.options.min=a;var b=this.value();(b||0===b)&&a>b&&this.value(a)}}}),f({name:"kendoPanelBar",async:!0}),f({name:"kendoPanelItem",parent:"kendoPanelBar",watch:{enabled:l,expanded:[m,i]},childProp:"item",events:{expand:{writeTo:n,value:!0},collapse:{writeTo:n,value:!1}},async:!0}),f({name:"kendoProgressBar",defaultOption:C,events:{change:C},watch:{enabled:l,value:C}}),f({name:"kendoRangeSlider",defaultOption:D,events:{change:D},watch:{values:D,enabled:l}}),f({async:!0,name:"kendoScheduler",watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}}}),f({name:"kendoSlider",defaultOption:C,events:{change:C},watch:{value:C,enabled:l}}),f({name:"kendoSortable",defaultOption:k,events:{end:function(c,d){var e="__ko_kendo_sortable_data__",f="receive"!==d.action?a.dataFor(d.item[0]):d.draggableEvent[e],g=c.data,h=c.data;("sort"===d.action||"remove"===d.action)&&(h.splice(d.oldIndex,1),"remove"===d.action&&(d.draggableEvent[e]=f)),("sort"===d.action||"receive"===d.action)&&(h.splice(d.newIndex,0,f),delete d.draggableEvent[e],b(d.draggableEvent.target).hide(),d.preventDefault()),g.valueHasMutated()}}}),f({name:"kendoSplitter",async:!0}),f({name:"kendoSplitterPane",parent:"kendoSplitter",watch:{max:s,min:t,size:A,expanded:[m,i]},childProp:"pane",events:{collapse:{writeTo:n,value:!1},expand:{writeTo:n,value:!0},resize:A},async:!0}),f({name:"kendoTabStrip",async:!0}),f({name:"kendoTab",parent:"kendoTabStrip",watch:{enabled:l},childProp:"item",async:!0}),f({name:"kendoTooltip",events:{},watch:{content:j,filter:p}}),f({name:"kendoTimePicker",defaultOption:C,events:{change:C},watch:{max:s,min:t,value:C,enabled:l,isOpen:[u,h]}}),f({name:"kendoTreeView",async:!0}),f({name:"kendoTreeItem",parent:"kendoTreeView",watch:{enabled:l,expanded:[m,i],selected:function(a,b){b?this.select(a):this.select()[0]==a&&this.select(null)}},childProp:"node",events:{collapse:{writeTo:n,value:!1},expand:{writeTo:n,value:!0},select:{writeTo:y,value:!0}},async:!0}),f({name:"kendoUpload",watch:{enabled:l}}),f({async:!0,name:"kendoWindow",events:{open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{content:j,title:B,isOpen:[u,h]}}),f({name:"kendoChart",watch:{data:function(b){a.kendo.setDataSource(this,b)}}}),f({name:"kendoLinearGauge",defaultOption:C,watch:{value:C,gaugeArea:e("gaugeArea"),pointer:e("pointer"),scale:e("scale")}}),f({name:"kendoRadialGauge",defaultOption:C,watch:{value:C,gaugeArea:e("gaugeArea"),pointer:e("pointer"),scale:e("scale")}})}); \ No newline at end of file +!function(a){"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?a(require("knockout"),require("jquery"),require("kendo")):"function"==typeof define&&define.amd?define(["knockout","jquery","kendo"],a):a(window.ko,window.jQuery,window.kendo)}(function(a,b,c,d){c=c||window.kendo,a.kendo=a.kendo||{},a.kendo.BindingFactory=function(){var e=this;this.createBinding=function(c){if(b()[c.parent||c.name]){var d={};d.init=function(a,b,f,g,h){var i=e.buildOptions(c,b);return i.async===!0||c.async===!0&&i.async!==!1?(setTimeout(function(){d.setup(a,i,h)},0),void 0):(d.setup(a,i,h),i&&i.useKOTemplates?{controlsDescendantBindings:!0}:void 0)},d.setup=function(d,f,g){var h,i=b(d);e.setupTemplates(c.templates,f,d,g),h=e.getWidget(c,f,i),e.handleEvents(f,c,d,h,g),e.watchValues(h,f,c,d),h.destroy&&a.utils.domNodeDisposal.addDisposeCallback(d,function(){h.destroy()})},d.options={},d.widgetConfig=c,a.bindingHandlers[c.bindingName||c.name]=d}},this.buildOptions=function(b,d){var e=b.defaultOption,f=a.utils.extend({},a.bindingHandlers[b.name].options),g=a.utils.unwrapObservable(d());return g instanceof c.data.DataSource||"object"!=typeof g||null===g||e&&!(e in g)?f[e]=d():a.utils.extend(f,g),f};var f=function(b,c){return function(d){return a.renderTemplate(b,c.createChildContext(d._raw&&d._raw()||d))}};this.setupTemplates=function(b,c,d,e){var g,h,i,j;if(b&&c&&c.useKOTemplates){for(g=0,h=b.length;h>g;g++)i=b[g],c[i]&&(c[i]=f(c[i],e));j=c.dataBound,c.dataBound=function(){a.memoization.unmemoizeDomNodeAndDescendants(d),j&&j.apply(this,arguments)}}},this.unwrapOneLevel=function(b){var d,e={};if(b)if(b instanceof c.data.DataSource)e=b;else if("object"==typeof b)for(d in b)e[d]=a.utils.unwrapObservable(b[d]);return e},this.getWidget=function(b,c,d){var e;if(b.parent){var f=d.closest("[data-bind*='"+b.parent+":']");e=f.length?f.data(b.parent):null}else e=d[b.name](this.unwrapOneLevel(c)).data(b.name);return a.isObservable(c.widget)&&c.widget(e),e},this.watchValues=function(a,b,c,d){var f,g=c.watch;if(g)for(f in g)g.hasOwnProperty(f)&&e.watchOneValue(f,a,b,c,d)},this.watchOneValue=function(c,e,f,g,h){var i=a.computed({read:function(){var i,j,k=g.watch[c],l=a.utils.unwrapObservable(f[c]),m=g.parent?[h]:[];b.isArray(k)?k=e[l?k[0]:k[1]]:"string"==typeof k?k=e[k]:j=!0,k&&f[c]!==d&&(j?m.push(l,f):(i=k.apply(e,m),m.push(l)),(j||i!==l)&&k.apply(e,m))},disposeWhenNodeIsRemoved:h}).extend({throttle:f.throttle||0===f.throttle?f.throttle:1});a.isObservable(f[c])||i.dispose()},this.handleEvents=function(a,b,c,d,f){var g,h,i=b.events;if(i)for(g in i)i.hasOwnProperty(g)&&(h=i[g],"string"==typeof h&&(h={value:h,writeTo:h}),e.handleOneEvent(g,h,a,c,d,b.childProp,f))},this.handleOneEvent=function(b,c,d,e,f,g,h){var i="function"==typeof c?c:d[c.call];"function"==typeof c?i=i.bind(h.$data,d):c.call&&"function"==typeof d[c.call]?i=d[c.call].bind(h.$data,h.$data):c.writeTo&&a.isWriteableObservable(d[c.writeTo])&&(i=function(a){var b,f;g&&a[g]&&a[g]!==e||(b=c.value,f="string"==typeof b&&this[b]?this[b](g&&e):b,d[c.writeTo](f))}),i&&f.bind(b,i)}},a.kendo.bindingFactory=new a.kendo.BindingFactory,a.kendo.setDataSource=function(b,d,e){var f,g;return d instanceof c.data.DataSource?(b.setDataSource(d),void 0):(e&&e.useKOTemplates||(f=a.mapping&&d&&d.__ko_mapping__,g=d&&f?a.mapping.toJS(d):a.toJS(d)),b.dataSource.data(g||d),void 0)},function(){var a=c.data.ObservableArray.fn.wrap;c.data.ObservableArray.fn.wrap=function(b){var c=a.apply(this,arguments);return c._raw=function(){return b},c}}();var e=function(b){return function(c){c&&(a.utils.extend(this.options[b],c),this.redraw(),this.value(.001+this.value()))}},f=a.kendo.bindingFactory.createBinding.bind(a.kendo.bindingFactory),g="clicked",h="close",i="collapse",j="content",k="data",l="enable",m="expand",n="expanded",o="error",p="filter",q="info",r="isOpen",s="max",t="min",u="open",v="palette",w="readonly",x="search",y="select",z="selected",A="success",B="size",C="title",D="value",E="values",F="warning";f({name:"kendoAutoComplete",events:{change:D,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:D}}),f({name:"kendoButton",defaultOption:g,events:{click:{call:g}},watch:{enabled:l}}),f({name:"kendoCalendar",defaultOption:D,events:{change:D},watch:{max:s,min:t,value:D}}),f({name:"kendoColorPicker",events:{change:D,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,value:D,color:D,palette:v}}),f({name:"kendoComboBox",events:{change:D,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b)},value:D}}),f({name:"kendoDatePicker",defaultOption:D,events:{change:D,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:D,isOpen:[u,h]}}),f({name:"kendoDateTimePicker",defaultOption:D,events:{change:D,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,max:s,min:t,value:D,isOpen:[u,h]}}),f({name:"kendoDropDownList",events:{change:D,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,isOpen:[u,h],data:function(b){a.kendo.setDataSource(this,b),b.length&&this.options.optionLabel&&this.select()<0&&this.select(0)},value:D}}),f({name:"kendoEditor",defaultOption:D,events:{change:D},watch:{enabled:l,value:D}}),f({name:"kendoGrid",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["rowTemplate","altRowTemplate"]}),f({name:"kendoListView",defaultOption:k,watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}},templates:["template"]}),f({name:"kendoMaskedTextBox",defaultOption:D,events:{change:D},watch:{enabled:l,isReadOnly:w,value:D}}),f({name:"kendoMenu",async:!0}),f({name:"kendoMenuItem",parent:"kendoMenu",watch:{enabled:l,isOpen:[u,h]},async:!0}),f({name:"kendoMultiSelect",events:{change:D,open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{enabled:l,search:[x,h],data:function(b){a.kendo.setDataSource(this,b)},value:D}});var G=function(a,b){b||0===b?this.show(b,a):this.hide()};f({name:"kendoNotification",watch:{error:function(a){G.call(this,o,a)},info:function(a){G.call(this,q,a)},success:function(a){G.call(this,A,a)},warning:function(a){G.call(this,F,a)}}}),f({name:"kendoNumericTextBox",defaultOption:D,events:{change:D},watch:{enabled:l,value:D,max:function(a){this.options.max=a;var b=this.value();(b||0===b)&&b>a&&this.value(a)},min:function(a){this.options.min=a;var b=this.value();(b||0===b)&&a>b&&this.value(a)}}}),f({name:"kendoPanelBar",async:!0}),f({name:"kendoPanelItem",parent:"kendoPanelBar",watch:{enabled:l,expanded:[m,i],selected:[y]},childProp:"item",events:{expand:{writeTo:n,value:!0},collapse:{writeTo:n,value:!1},select:{writeTo:z,value:D}},async:!0}),f({name:"kendoProgressBar",defaultOption:D,events:{change:D},watch:{enabled:l,value:D}}),f({name:"kendoRangeSlider",defaultOption:E,events:{change:E},watch:{values:E,enabled:l}}),f({async:!0,name:"kendoScheduler",watch:{data:function(b,c){a.kendo.setDataSource(this,b,c)}}}),f({name:"kendoSlider",defaultOption:D,events:{change:D},watch:{value:D,enabled:l}}),f({name:"kendoSortable",defaultOption:k,events:{end:function(c,d){var e="__ko_kendo_sortable_data__",f="receive"!==d.action?a.dataFor(d.item[0]):d.draggableEvent[e],g=c.data,h=c.data;("sort"===d.action||"remove"===d.action)&&(h.splice(d.oldIndex,1),"remove"===d.action&&(d.draggableEvent[e]=f)),("sort"===d.action||"receive"===d.action)&&(h.splice(d.newIndex,0,f),delete d.draggableEvent[e],b(d.draggableEvent.target).hide(),d.preventDefault()),g.valueHasMutated()}}}),f({name:"kendoSplitter",async:!0}),f({name:"kendoSplitterPane",parent:"kendoSplitter",watch:{max:s,min:t,size:B,expanded:[m,i]},childProp:"pane",events:{collapse:{writeTo:n,value:!1},expand:{writeTo:n,value:!0},resize:B},async:!0}),f({name:"kendoTabStrip",async:!0}),f({name:"kendoTab",parent:"kendoTabStrip",watch:{enabled:l},childProp:"item",async:!0}),f({name:"kendoTooltip",events:{},watch:{content:j,filter:p}}),f({name:"kendoTimePicker",defaultOption:D,events:{change:D},watch:{max:s,min:t,value:D,enabled:l,isOpen:[u,h]}}),f({name:"kendoTreeView",async:!0}),f({name:"kendoTreeItem",parent:"kendoTreeView",watch:{enabled:l,expanded:[m,i],selected:function(a,b){b?this.select(a):this.select()[0]==a&&this.select(null)}},childProp:"node",events:{collapse:{writeTo:n,value:!1},expand:{writeTo:n,value:!0},select:{writeTo:z,value:!0}},async:!0}),f({name:"kendoUpload",watch:{enabled:l}}),f({async:!0,name:"kendoWindow",events:{open:{writeTo:r,value:!0},close:{writeTo:r,value:!1}},watch:{content:j,title:C,isOpen:[u,h]}}),f({name:"kendoChart",watch:{data:function(b){a.kendo.setDataSource(this,b)}}}),f({name:"kendoLinearGauge",defaultOption:D,watch:{value:D,gaugeArea:e("gaugeArea"),pointer:e("pointer"),scale:e("scale")}}),f({name:"kendoRadialGauge",defaultOption:D,watch:{value:D,gaugeArea:e("gaugeArea"),pointer:e("pointer"),scale:e("scale")}})}); \ No newline at end of file diff --git a/package.json b/package.json index 3b052d7..5828e51 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "knockout-kendo", - "version": "0.8.0", + "version": "0.8.1", "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-uglify": "0.x.x",