-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathknockout.x-editable.min.js
1 lines (1 loc) · 1.57 KB
/
knockout.x-editable.min.js
1
!function(e){"function"==typeof define&&define.amd?define(["knockout","jquery"],e):e(window.ko,window.jQuery)}(function(e,n){e.bindingHandlers.editable={init:function(i,t,a,o,s){function u(e,n,i){var t=typeof n;return"function"==t?n(e):"string"==t?e[n]:i}var r=n(i),l=t(),d=a(),p=d.editableOptions||{};p.value=e.utils.unwrapObservable(l),p.name||n.each(s.$data,function(e,n){return n==l?(p.name=e,!1):void 0}),!p.validate&&l.isValid&&(p.validate=function(n){var i=l();l(n);var t=l.isValid()?null:e.utils.unwrapObservable(l.error);return l(i),t}),"select"!==p.type&&"select2"!==p.type&&"checklist"!==p.type&&"typeahead"!==p.type||p.source||!p.options||(p.optionsCaption&&(p.prepend=p.optionsCaption),p.source=function(){return e.utils.arrayMap(e.utils.unwrapObservable(p.options),function(n){var i=u(n,p.optionsValue,n),t=u(n,p.optionsText,i);return{value:e.utils.unwrapObservable(i),text:e.utils.unwrapObservable(t)}})}),p.visible&&e.isObservable(p.visible)&&(p.toggle="manual");var v=r.editable(p);p.bindTextInput&&p.bindTextInput===!0?v.on("shown.ko",function(n,i){2==arguments.length&&e.applyBindingsToNode(i.input.$input[0],{textInput:l},l)}):e.isObservable(l)&&v.on("save.ko",function(e,n){l(n.newValue)}),p.save&&v.on("save",p.save),e.computed({read:function(){var n=e.utils.unwrapObservable(t());null===n&&(n=""),v.editable("setValue",n,!0)},owner:this,disposeWhenNodeIsRemoved:i}),p.visible&&e.isObservable(p.visible)&&(e.computed({read:function(){var n=e.utils.unwrapObservable(p.visible());n&&v.editable("show")},owner:this,disposeWhenNodeIsRemoved:i}),v.on("hidden.ko",function(){p.visible(!1)}))}}});