Skip to content

Commit

Permalink
Merge branch 'release-2.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
gvas committed Jul 10, 2014
2 parents a4ea7e5 + e9ac707 commit 482ed44
Show file tree
Hide file tree
Showing 22 changed files with 203 additions and 158 deletions.
24 changes: 10 additions & 14 deletions examples/amd/lib/knockout-jqueryui/accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,28 @@ define(
'jquery-ui/accordion'
],

function ($, ko, utils, BindingHandler, accordion) {
function ($, ko, utils, BindingHandler) {

'use strict';

var Accordion = function () {
/// <summary>Constructor.</summary>

var version = utils.parseVersionString(accordion.version);

BindingHandler.call(this, 'accordion');

if (version.major === 1 && version.minor === 8) {
if (utils.uiVersion.major === 1 && utils.uiVersion.minor === 8) {
this.options = ['active', 'animated', 'autoHeight', 'clearStyle',
'collapsible', 'disabled', 'event', 'fillSpace', 'header', 'icons',
'navigation', 'navigationFilter'];
this.events = ['change', 'changestart', 'create'];
this.hasRefresh = false;
this.eventToWatch = 'accordionchange.accordion';
this.eventToWatch = 'change';
} else {
this.options = ['active', 'animate', 'collapsible', 'disabled', 'event',
'header', 'heightStyle', 'icons'];
this.events = ['activate', 'beforeActivate', 'create'];
this.hasRefresh = true;
this.eventToWatch = 'accordionactivate.accordion';
this.eventToWatch = 'activate';
}
};

Expand All @@ -46,21 +44,19 @@ define(
/// <param name='valueAccessor' type='Function'></param>
/// <returns type='Object'></returns>

var value = valueAccessor();
var widgetName, value;

widgetName = this.widgetName;
value = valueAccessor();

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

if (ko.isWriteableObservable(value.active)) {
$(element).on(this.eventToWatch, function () {
value.active($(element).accordion('option', 'active'));
this.on(element, this.eventToWatch, function () {
value.active($(element)[widgetName]('option', 'active'));
});
}

// handle disposal
ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
$(element).off('.accordion');
});

// the inner elements have already been taken care of
return { controlsDescendantBindings: true };
};
Expand Down
6 changes: 2 additions & 4 deletions examples/amd/lib/knockout-jqueryui/autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ define(
'jquery-ui/autocomplete'
],

function (BindingHandler, utils, autocomplete) {
function (BindingHandler, utils) {

'use strict';

var Autocomplete = function () {
/// <summary>Constructor.</summary>

var version = utils.parseVersionString(autocomplete.version);

BindingHandler.call(this, 'autocomplete');

this.options = ['appendTo', 'autoFocus', 'delay', 'disabled', 'minLength',
'position', 'source'];

if (version.major === 1 && version.minor === 8) {
if (utils.uiVersion.major === 1 && utils.uiVersion.minor === 8) {
this.events = ['change', 'close', 'create', 'focus', 'open', 'search',
'select'];
} else {
Expand Down
31 changes: 28 additions & 3 deletions examples/amd/lib/knockout-jqueryui/bindingHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ define(

BindingHandler = function (widgetName) {
/// <summary>Constructor.</summary>
/// <param name='widgetName' type='String'>Name of the jQuery UI widget.
/// </param>
/// <param name='widgetName' type='String'>The jQuery UI widget's
/// name.</param>

this.widgetName = widgetName;
this.widgetEventPrefix = widgetName;
this.options = [];
this.events = [];
this.hasRefresh = false;
Expand Down Expand Up @@ -88,7 +89,7 @@ define(
$(element)[widgetName](ko.utils.extend(unwrappedOptions, unwrappedEvents));

if (this.hasRefresh) {
subscribeToRefreshOn(this.widgetName, element, value);
subscribeToRefreshOn(widgetName, element, value);
}

// store the element in the widget observable
Expand Down Expand Up @@ -127,6 +128,30 @@ define(
ko.utils.domData.set(element, domDataKey, newOptions);
};

BindingHandler.prototype.on = function (element, type, callback) {
/// <summary>Attaches callback to a widget event.</summary>
/// <param name='element' type='DOMElement'></param>
/// <param name='type' type='String'></param>
/// <param name='callback' type='Function'></param>

var eventName;

// the same algorithm as in widget._trigger()
if (type === this.widgetEventPrefix) {
eventName = type;
} else {
eventName = this.widgetEventPrefix + type;
}
eventName = [eventName.toLowerCase(), '.', this.widgetName].join('');

$(element).on(eventName, callback);

// handle disposal
ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
$(element).off(eventName);
});
};

return BindingHandler;
}
);
14 changes: 8 additions & 6 deletions examples/amd/lib/knockout-jqueryui/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ define(
'showOtherMonths', 'showWeek', 'stepMonths', 'weekHeader', 'yearRange',
'yearSuffix', 'beforeShow', 'beforeShowDay', 'onChangeMonthYear',
'onClose', 'onSelect'];
this.hasRefresh = true;
};

Datepicker.prototype = utils.createObject(BindingHandler.prototype);
Expand All @@ -42,20 +43,21 @@ define(
/// <param name='valueAccessor' type='Function'></param>
/// <returns type='Object'></returns>

var options, value, subscription, origOnSelect;
var widgetName, options, value, subscription, origOnSelect;

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

widgetName = this.widgetName;
options = valueAccessor();
value = ko.utils.unwrapObservable(options.value);

if (value) {
$(element).datepicker('setDate', value);
$(element)[widgetName]('setDate', value);
}

if (ko.isObservable(options.value)) {
subscription = options.value.subscribe(function (newValue) {
$(element).datepicker('setDate', newValue);
$(element)[widgetName]('setDate', newValue);
});

ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
Expand All @@ -64,11 +66,11 @@ define(
}

if (ko.isWriteableObservable(options.value)) {
origOnSelect = $(element).datepicker('option', 'onSelect');
$(element).datepicker('option', 'onSelect', function (selectedText) {
origOnSelect = $(element)[widgetName]('option', 'onSelect');
$(element)[widgetName]('option', 'onSelect', function (selectedText) {
var format, date;

format = $(element).datepicker('option', 'dateFormat');
format = $(element)[widgetName]('option', 'dateFormat');
date = $.datepicker.parseDate(format, selectedText);
options.value(date);

Expand Down
28 changes: 11 additions & 17 deletions examples/amd/lib/knockout-jqueryui/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@ define(
'jquery-ui/dialog'
],

function ($, ko, BindingHandler, utils, dialog) {
function ($, ko, BindingHandler, utils) {

'use strict';

var Dialog = function () {
/// <summary>Constructor.</summary>

var version = utils.parseVersionString(dialog.version);

BindingHandler.call(this, 'dialog');

if (version.major === 1 && version.minor === 8) {
if (utils.uiVersion.major === 1 && utils.uiVersion.minor === 8) {
this.options = ['autoOpen', 'buttons', 'closeOnEscape', 'closeText',
'dialogClass', 'disabled', 'draggable', 'height', 'maxHeight',
'maxWidth', 'minHeight', 'minWidth', 'modal', 'position', 'resizable',
'show', 'stack', 'title', 'width', 'zIndex'];
this.events = ['beforeClose', 'create', 'open', 'focus', 'dragStart',
'drag', 'dragStop', 'resizeStart', 'resize', 'resizeStop', 'close'];
} else if (version.major === 1 && version.minor === 9) {
} else if (utils.uiVersion.major === 1 && utils.uiVersion.minor === 9) {
this.options = ['autoOpen', 'buttons', 'closeOnEscape', 'closeText',
'dialogClass', 'draggable', 'height', 'hide', 'maxHeight', 'maxWidth',
'minHeight', 'minWidth', 'modal', 'position', 'resizable', 'show',
Expand Down Expand Up @@ -78,27 +76,28 @@ define(
ko.computed({
read: function () {
if (ko.utils.unwrapObservable(value.isOpen)) {
$(element).dialog('open');
$(element)[this.widgetName]('open');
} else {
$(element).dialog('close');
$(element)[this.widgetName]('close');
}
},
disposeWhenNodeIsRemoved: element
disposeWhenNodeIsRemoved: element,
owner: this
});
}
if (ko.isWriteableObservable(value.isOpen)) {
$(element).on('dialogopen.dialog', function () {
this.on(element, 'open', function () {
value.isOpen(true);
});
$(element).on('dialogclose.dialog', function () {
this.on(element, 'close', function () {
value.isOpen(false);
});
}

// make the width option two-way
if (ko.isWriteableObservable(value.width)) {
/*jslint unparam:true*/
$(element).on('dialogresizestop.dialog', function (ev, ui) {
this.on(element, 'resizestop', function (ev, ui) {
value.width(Math.round(ui.size.width));
});
/*jslint unparam:false*/
Expand All @@ -107,17 +106,12 @@ define(
// make the height option two-way
if (ko.isWriteableObservable(value.height)) {
/*jslint unparam:true*/
$(element).on('dialogresizestop.dialog', function (ev, ui) {
this.on(element, 'resizestop', function (ev, ui) {
value.height(Math.round(ui.size.height));
});
/*jslint unparam:false*/
}

// handle disposal
ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
$(element).off('.dialog');
});

// the inner elements have already been taken care of
return { controlsDescendantBindings: true };
};
Expand Down
8 changes: 7 additions & 1 deletion examples/amd/lib/knockout-jqueryui/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ define(

BindingHandler.call(this, 'menu');

this.options = ['disabled', 'icons', 'menus', 'position', 'role'];
if (utils.uiVersion.major === 1 && utils.uiVersion.minor < 11) {
this.options = ['disabled', 'icons', 'menus', 'position', 'role'];
} else {
this.options = ['disabled', 'icons', 'items', 'menus', 'position',
'role'];
}

this.events = ['blur', 'create', 'focus', 'select'];
this.hasRefresh = true;
};
Expand Down
6 changes: 2 additions & 4 deletions examples/amd/lib/knockout-jqueryui/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ define(
'jquery-ui/progressbar'
],

function (BindingHandler, utils, progressbar) {
function (BindingHandler, utils) {

'use strict';

var Progressbar = function () {
/// <summary>Constructor.</summary>

var version = utils.parseVersionString(progressbar.version);

BindingHandler.call(this, 'progressbar');

this.events = ['change', 'create', 'complete'];
this.hasRefresh = true;

if (version.major === 1 && version.minor === 8) {
if (utils.uiVersion.major === 1 && utils.uiVersion.minor === 8) {
this.options = ['disabled', 'value'];
} else {
this.options = ['disabled', 'max', 'value'];
Expand Down
71 changes: 71 additions & 0 deletions examples/amd/lib/knockout-jqueryui/selectmenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*global define*/
define(

[
'jquery',
'knockout',
'./bindingHandler',
'./utils',
'jquery-ui/selectmenu'
],

function ($, ko, BindingHandler, utils) {

'use strict';

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

BindingHandler.call(this, 'selectmenu');

this.options = ['appendTo', 'disabled', 'icons', 'position', 'width'];
this.events = ['change', 'close', 'create', 'focus', 'open', 'select'];
this.hasRefresh = true;
};

Selectmenu.prototype = utils.createObject(BindingHandler.prototype);
Selectmenu.prototype.constructor = Selectmenu;

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>
/// <returns type='Object'></returns>

var value = valueAccessor();

/// invokes the prototype's init() method
BindingHandler.prototype.init.apply(this, arguments);

if (value.isOpen) {
ko.computed({
read: function () {
if (ko.utils.unwrapObservable(value.isOpen)) {
$(element)[this.widgetName]('open');
} else {
$(element)[this.widgetName]('close');
}
},
disposeWhenNodeIsRemoved: element,
owner: this
});
}
if (ko.isWriteableObservable(value.isOpen)) {
this.on(element, 'open', function () {
value.isOpen(true);
});
this.on(element, 'close', function () {
value.isOpen(false);
});
}

// the inner elements have already been taken care of
return { controlsDescendantBindings: true };
};

utils.register(Selectmenu);

return Selectmenu;
}
);
Loading

0 comments on commit 482ed44

Please sign in to comment.