Skip to content

Commit

Permalink
Merge branch 'release-2.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
gvas committed Dec 23, 2014
2 parents d918e4f + 9330e99 commit cbe3cab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "knockout-jqueryui",
"description": "knockout binding handlers for jQuery UI",
"homepage": "https://github.com/gvas/knockout-jqueryui",
"version": "2.2.0",
"version": "2.2.1",
"author": {
"name": "Vas Gabor <[email protected]>"
},
Expand Down
44 changes: 29 additions & 15 deletions src/selectmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ define(

'use strict';

var Selectmenu = function () {
var domDataKey, Selectmenu;

domDataKey = '__kojqui_selectmenu_value';

Selectmenu = function () {
/// <summary>Constructor.</summary>

BindingHandler.call(this, 'selectmenu');
Expand All @@ -27,13 +31,11 @@ define(
Selectmenu.prototype = utils.createObject(BindingHandler.prototype);
Selectmenu.prototype.constructor = Selectmenu;

Selectmenu.prototype.init = function (element, valueAccessor,
allBindingsAccessor) {
Selectmenu.prototype.init = function (element, valueAccessor) {
/// <summary>Connects the view model and the widget via the isOpen property.
// </summary>
/// <param name='element' type='DOMNode'></param>
/// <param name='valueAccessor' type='Function'></param>
/// <param name='allBindingsAccessor' type='Object'></param>
/// <returns type='Object'></returns>

var value, result;
Expand Down Expand Up @@ -66,17 +68,6 @@ define(
});
}

// synchronize the selected option with knockout's standard value binding
if (allBindingsAccessor().hasOwnProperty('value')) {
ko.computed({
read: function () {
ko.utils.unwrapObservable(allBindingsAccessor().value);
$(element).selectmenu('refresh');
},
disposeWhenNodeIsRemoved: element
});
}

// Notify knockout's value- and selectedOptions bindings that the selected
// option has been changed.
this.on(element, 'change', function () {
Expand All @@ -86,6 +77,29 @@ define(
return result;
};

/*jslint unparam:true*/
Selectmenu.prototype.update = function (element, valueAccessor,
allBindingsAccessor) {
/// <summary>Refreshes the widget if the value binding changes.</summary>
/// <param name='element' type='DOMNode'></param>
/// <param name='valueAccessor' type='Function'></param>
/// <param name='allBindingsAccessor' type='Object'></param>

var oldValue, newValue;

BindingHandler.prototype.update.apply(this, arguments);

// synchronize the selected option with knockout's standard value binding
if (allBindingsAccessor().hasOwnProperty('value')) {
oldValue = ko.utils.domData.get(element, domDataKey);
newValue = ko.utils.unwrapObservable(allBindingsAccessor().value);
if (oldValue !== newValue) {
$(element).selectmenu('refresh');
}
}
};
/*jslint unparam:false*/

utils.register(Selectmenu);

return Selectmenu;
Expand Down

0 comments on commit cbe3cab

Please sign in to comment.