1
0
Fork 0
fgdata/Phi/3rdparty/knockout-jqueryui/tooltip.js

72 lines
2.1 KiB
JavaScript
Raw Normal View History

2015-01-25 12:02:20 +00:00
/*global define*/
define(
[
'jquery',
'knockout',
'./bindingHandler',
'./utils',
'jquery-ui/tooltip'
],
function ($, ko, BindingHandler, utils) {
'use strict';
var Tooltip = function () {
/// <summary>Constructor.</summary>
BindingHandler.call(this, 'tooltip');
this.options = ['content', 'disabled', 'hide', 'items', 'position', 'show',
'tooltipClass', 'track'];
this.events = ['create', 'open', 'close'];
};
Tooltip.prototype = utils.createObject(BindingHandler.prototype);
Tooltip.prototype.constructor = Tooltip;
Tooltip.prototype.init = function (element, valueAccessor) {
/// <summary>Keeps the isOpen binding property in sync with the tooltip's
/// state.
/// </summary>
/// <param name='element' type='DOMNode'></param>
/// <param name='valueAccessor' type='Function'></param>
var value, result;
value = valueAccessor();
result = 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);
});
}
return result;
};
utils.register(Tooltip);
return Tooltip;
}
);