Skip to content
Browse files

Fire change event focused inputs when sorting starts to ensure update…

… in Firefox (#13)
  • Loading branch information...
1 parent 84cfd4c commit e19ff0d62172c55358deca28dae696d66c08eace @rniemeyer committed
Showing with 6 additions and 6 deletions.
  1. +3 −3 build/knockout-sortable.js
  2. +1 −1 build/knockout-sortable.min.js
  3. +2 −2 src/knockout-sortable.js
View
6 build/knockout-sortable.js
@@ -8,7 +8,7 @@ var prepareTemplateOptions = function(valueAccessor) {
if (options.data) {
result.foreach = options.data;
result.name = options.template;
- ko.utils.arrayForEach(["afterAdd", "beforeRemove", "afterRender", "includeDestroyed", "templateEngine", "templateOptions"], function (option) {
+ ko.utils.arrayForEach(["afterAdd", "beforeRemove", "includeDestroyed", "templateEngine", "templateOptions"], function (option) {
result[option] = options[option];
});
} else {
@@ -78,8 +78,8 @@ ko.bindingHandlers.sortable = {
setTimeout(function() {
$element.sortable(ko.utils.extend(sortable.options, {
start: function(event, ui) {
- //make sure that fields have a chance to lose focus to update model
- ui.item.filter(':visible').focus();
+ //make sure that fields have a chance to update model
+ ui.item.find("input:focus").change();
if (startActual) {
startActual.apply(this, arguments);
}
View
2 build/knockout-sortable.min.js
@@ -1,2 +1,2 @@
//knockout-sortable | (c) 2012 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
-(function(a,b,c){var d=function(b){var c={},d=a.utils.unwrapObservable(b());return d.data?(c.foreach=d.data,c.name=d.template,a.utils.arrayForEach(["afterAdd","beforeRemove","afterRender","includeDestroyed","templateEngine","templateOptions"],function(a){c[a]=d[a]})):c.foreach=b(),d.afterRender?c.afterRender=function(b,c){a.bindingHandlers.sortable.afterRender.call(c,b,c),d.afterRender.call(c,b,c)}:c.afterRender=a.bindingHandlers.sortable.afterRender,c},e="ko_sortItem",f="ko_sortList",g="ko_parentList";a.bindingHandlers.sortable={init:function(h,i,j,k,l){var m=b(h),n=a.utils.unwrapObservable(i()),o=d(i),p={};a.utils.arrayForEach(h.childNodes,function(a){a&&a.nodeType===3&&a.parentNode.removeChild(a)}),a.utils.extend(p,a.bindingHandlers.sortable),a.utils.extend(p,n||{}),p.connectClass&&(a.isObservable(p.allowDrop)||typeof p.allowDrop=="function")?a.computed({read:function(){var b=a.utils.unwrapObservable(p.allowDrop),c=typeof b=="function"?b.call(this,o.foreach):b;a.utils.toggleDomNodeCssClass(h,p.connectClass,c)},disposeWhenNodeIsRemoved:h},this):a.utils.toggleDomNodeCssClass(h,p.connectClass,p.allowDrop),a.bindingHandlers.template.init(h,function(){return o},j,k,l);var q=p.options.start,r=p.options.update;return setTimeout(function(){m.sortable(a.utils.extend(p.options,{start:function(a,b){b.item.filter(":visible").focus(),q&&q.apply(this,arguments)},update:function(c,d){var h,i,j,k,l=d.item[0],m=a.utils.domData.get(l,e);if(m){h=a.utils.domData.get(l,g),i=a.utils.domData.get(l.parentNode,f),j=a.utils.arrayIndexOf(d.item.parent().children(),l);if(p.beforeMove||p.afterMove)k={item:m,sourceParent:h,sourceParentNode:l.parentNode,sourceIndex:h.indexOf(m),targetParent:i,targetIndex:j,cancelDrop:!1};if(p.beforeMove){p.beforeMove.call(this,k,c,d);if(k.cancelDrop){b(k.sourceParent===k.targetParent?this:d.sender).sortable("cancel");return}}j>=0&&(h.remove(m),i.splice(j,0,m)),a.utils.domData.set(l,e,null),d.item.remove(),p.afterMove&&p.afterMove.call(this,k,c,d)}r&&r.apply(this,arguments)},connectWith:p.connectClass?"."+p.connectClass:!1})),p.isEnabled!==c&&a.computed({read:function(){m.sortable(a.utils.unwrapObservable(p.isEnabled)?"enable":"disable")},disposeWhenNodeIsRemoved:h})},0),a.utils.domNodeDisposal.addDisposeCallback(h,function(){m.sortable("destroy")}),{controlsDescendantBindings:!0}},update:function(b,c,e,g,h){var i=d(c);a.utils.domData.set(b,f,i.foreach),a.bindingHandlers.template.update(b,function(){return i},e,g,h)},afterRender:function(b,c){a.utils.arrayForEach(b,function(b){b.nodeType===1&&(a.utils.domData.set(b,e,c),a.utils.domData.set(b,g,a.utils.domData.get(b.parentNode,f)))})},connectClass:"ko_container",allowDrop:!0,afterMove:null,beforeMove:null,options:{}}})(ko,jQuery)
+(function(a,b,c){var d=function(b){var c={},d=a.utils.unwrapObservable(b());return d.data?(c.foreach=d.data,c.name=d.template,a.utils.arrayForEach(["afterAdd","beforeRemove","includeDestroyed","templateEngine","templateOptions"],function(a){c[a]=d[a]})):c.foreach=b(),d.afterRender?c.afterRender=function(b,c){a.bindingHandlers.sortable.afterRender.call(c,b,c),d.afterRender.call(c,b,c)}:c.afterRender=a.bindingHandlers.sortable.afterRender,c},e="ko_sortItem",f="ko_sortList",g="ko_parentList";a.bindingHandlers.sortable={init:function(h,i,j,k,l){var m=b(h),n=a.utils.unwrapObservable(i()),o=d(i),p={};a.utils.arrayForEach(h.childNodes,function(a){a&&a.nodeType===3&&a.parentNode.removeChild(a)}),a.utils.extend(p,a.bindingHandlers.sortable),a.utils.extend(p,n||{}),p.connectClass&&(a.isObservable(p.allowDrop)||typeof p.allowDrop=="function")?a.computed({read:function(){var b=a.utils.unwrapObservable(p.allowDrop),c=typeof b=="function"?b.call(this,o.foreach):b;a.utils.toggleDomNodeCssClass(h,p.connectClass,c)},disposeWhenNodeIsRemoved:h},this):a.utils.toggleDomNodeCssClass(h,p.connectClass,p.allowDrop),a.bindingHandlers.template.init(h,function(){return o},j,k,l);var q=p.options.start,r=p.options.update;return setTimeout(function(){m.sortable(a.utils.extend(p.options,{start:function(a,b){b.item.find("input:focus").change(),q&&q.apply(this,arguments)},update:function(c,d){var h,i,j,k,l=d.item[0],m=a.utils.domData.get(l,e);if(m){h=a.utils.domData.get(l,g),i=a.utils.domData.get(l.parentNode,f),j=a.utils.arrayIndexOf(d.item.parent().children(),l);if(p.beforeMove||p.afterMove)k={item:m,sourceParent:h,sourceParentNode:l.parentNode,sourceIndex:h.indexOf(m),targetParent:i,targetIndex:j,cancelDrop:!1};if(p.beforeMove){p.beforeMove.call(this,k,c,d);if(k.cancelDrop){b(k.sourceParent===k.targetParent?this:d.sender).sortable("cancel");return}}j>=0&&(h.remove(m),i.splice(j,0,m)),a.utils.domData.set(l,e,null),d.item.remove(),p.afterMove&&p.afterMove.call(this,k,c,d)}r&&r.apply(this,arguments)},connectWith:p.connectClass?"."+p.connectClass:!1})),p.isEnabled!==c&&a.computed({read:function(){m.sortable(a.utils.unwrapObservable(p.isEnabled)?"enable":"disable")},disposeWhenNodeIsRemoved:h})},0),a.utils.domNodeDisposal.addDisposeCallback(h,function(){m.sortable("destroy")}),{controlsDescendantBindings:!0}},update:function(b,c,e,g,h){var i=d(c);a.utils.domData.set(b,f,i.foreach),a.bindingHandlers.template.update(b,function(){return i},e,g,h)},afterRender:function(b,c){a.utils.arrayForEach(b,function(b){b.nodeType===1&&(a.utils.domData.set(b,e,c),a.utils.domData.set(b,g,a.utils.domData.get(b.parentNode,f)))})},connectClass:"ko_container",allowDrop:!0,afterMove:null,beforeMove:null,options:{}}})(ko,jQuery)
View
4 src/knockout-sortable.js
@@ -78,8 +78,8 @@ ko.bindingHandlers.sortable = {
setTimeout(function() {
$element.sortable(ko.utils.extend(sortable.options, {
start: function(event, ui) {
- //make sure that fields have a chance to lose focus to update model
- ui.item.filter(':visible').focus();
+ //make sure that fields have a chance to update model
+ ui.item.find("input:focus").change();
if (startActual) {
startActual.apply(this, arguments);
}

0 comments on commit e19ff0d

Please sign in to comment.
Something went wrong with that request. Please try again.