// Kendo-Backbone // -------------- // v0.0.6 // // Copyright (c)2013 Telerik. All Rights Reserved. // Distributed under Apache 2.0 license // // http://kendoui.com (function(t,e){"use strict";e.Backbone=e.Backbone||{},function(){function t(t,e){return o.define({fields:e,init:function(e){e instanceof t||(e=new t(e)),o.fn.init.call(this,e.toJSON()),this.backbone=e},set:function(t,e){o.fn.set.call(this,t,e),this.backbone.set(t,e)}})}var o=e.data.Model;e.backboneModel=t}(),function(){function t(t){return o.extend({init:function(e){o.fn.init.call(this,e.models,t),this.collection=e},splice:function(){var t,o,n;t=Array.prototype.slice.call(arguments,2);var a=e.data.ObservableArray.fn.splice.apply(this,arguments);if(a.length)for(o=0,n=a.length;n>o;o++)this.collection.remove(a[o].backbone);if(t.length)for(o=0,n=t.length;n>o;o++)this.collection.unshift(t[o].backbone);return a}})}var o=(e.data.Model,e.data.ObservableArray);e.backboneCollection=t}(),e.Backbone.BackboneTransport=function(){function t(t){this.colWrap=t}return _.extend(t.prototype,{create:function(t){var e=t.data;this.colWrap.create(e,function(e){t.success(e)})},read:function(t){t.success(this.colWrap.collection.toJSON())},update:function(t){var e=this.colWrap.collection.get(t.data.id);e.set(t.data),t.success(t.data)},destroy:function(t){var e=this.colWrap.collection.get(t.data.id);this.colWrap.collection.remove(e),t.success(t.data)}}),t}(),e.Backbone.CollectionAdapter=function(){function t(t,e){this.collection=t,this.dataSource=e,this.listenTo(this.collection,"add",this._addToDataSource),this.listenTo(this.collection,"remove",this._removeFromDataSource),this.listenTo(this.collection,"reset",this._resetDataSource)}return _.extend(t.prototype,Backbone.Events,{create:function(t,e){this.addFromCol?e(t):(this.addFromDS=!0,t.id||(t.id=null),this.collection.create(t,{wait:!0,success:function(t){e(t.toJSON())}}),this.addFromDS=!1)},_addToDataSource:function(t){if(!this.addFromDS){this.addFromCol=!0;var e=t.toJSON();this.dataSource.add(e),this.addFromCol=!1}},_removeFromDataSource:function(t){var e=this.dataSource.get(t.id);e&&this.dataSource.remove(e)},_resetDataSource:function(){this.dataSource.read()}}),t}(),e.Backbone.DataSource=function(t,e,o){function n(t,e){return o.defaults(t,{schema:{}}),o.defaults(t.schema,{model:{}}),o.defaults(t.schema.model,{id:a(e).model.prototype.idAttribute||"id"}),t}function a(t){return Object.getPrototypeOf?Object.getPrototypeOf(t):t.__proto__||t.constructor.prototype}var i=e.data.DataSource.extend({init:function(t){var a=t.collection,i=new e.Backbone.CollectionAdapter(a,this),c=new e.Backbone.BackboneTransport(i);o.defaults(t,{transport:c}),t=n(t,a),e.data.DataSource.prototype.init.call(this,t)}});return i}($,e,_),e.Backbone.ViewEvents=function(t,e,o,n){var a,i=/^(\S+)\s*(.*)$/,c="kendoUIEvents",r={delegate:function(t){this._processEvents(t,function(t,e,o){a=o,t.bind(e,o)})},undelegate:function(t){this._processEvents(t,function(t,e){t.unbind(e)})},_processEvents:function(t,o){var a=n.result(t,c);if(a)for(var r in a){var s=a[r];if(n.isFunction(s)||(s=t[s]),s){var l=r.match(i),u=l[1],d=l[2];s=n.bind(s,t);var f=t.$(d),h=e.widgetInstance(f,e.ui)||e.widgetInstance(f,e.mobile.ui)||e.widgetInstance(f,e.dataviz.ui);o.call(this,h,u,s)}}}};return r}(jQuery,e,Backbone,_)})(this,kendo); //@ sourceMappingURL=kendo.backbone.map