/usr/share/games/flightgear/Phi/3rdparty/knockout-jqueryui/bindingHandler.js is in flightgear-phi 2016.4.2+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | /*global define*/
define(
[
'jquery',
'knockout',
'./utils',
'jquery-ui/widget'
],
function ($, ko, utils) {
'use strict';
var domDataKey, filterAndUnwrapProperties, subscribeToRefreshOn, BindingHandler;
domDataKey = '__kojqui_options';
filterAndUnwrapProperties = function (source, properties) {
/// <summary>Filters and unwraps the properties of an object.</summary>
/// <param name='source' type='Object'></param>
/// <param name='properties' type='Array' elementType='String'></param>
/// <returns type='Object'>A new object with the specified properties copied
/// and unwrapped from source.</returns>
var result = {};
ko.utils.arrayForEach(properties, function (property) {
if (source[property] !== undefined) {
result[property] = ko.utils.unwrapObservable(source[property]);
}
});
return result;
};
subscribeToRefreshOn = function (widgetName, element, bindingValue) {
/// <summary>Creates a subscription to the refreshOn observable.</summary>
/// <param name='widgetName' type='String'>The widget's name.</param>
/// <param name='element' type='DOMNode'></param>
/// <param name='bindingValue' type='Object'></param>
if (ko.isObservable(bindingValue.refreshOn)) {
ko.computed({
read: function () {
bindingValue.refreshOn();
$(element)[widgetName]('refresh');
},
disposeWhenNodeIsRemoved: element
});
}
};
BindingHandler = function (widgetName) {
/// <summary>Constructor.</summary>
/// <param name='widgetName' type='String'>The jQuery UI widget's
/// name.</param>
this.widgetName = widgetName;
this.widgetEventPrefix = widgetName;
this.options = [];
this.events = [];
this.after = [];
this.hasRefresh = false;
};
/*jslint unparam:true*/
BindingHandler.prototype.init = function (element, valueAccessor,
allBindingsAccessor, viewModel, bindingContext) {
var widgetName, value, unwrappedOptions, unwrappedEvents,
shouldApplyBindingsToDescendants;
widgetName = this.widgetName;
value = valueAccessor();
unwrappedOptions = filterAndUnwrapProperties(value, this.options);
unwrappedEvents = filterAndUnwrapProperties(value, this.events);
// There can be control flow- or other bindings on some of the descendant
// elements which affect the shape of the element-rooted DOM subtree. These
// should be processed before instantiating the jQuery UI widget, because they
// can add pages to the tabs widget, menu items to the menu widget, etc.
shouldApplyBindingsToDescendants = !ko.utils.arrayFirst(
utils.descendantControllingBindings,
function (bindingName) {
return this.hasOwnProperty(bindingName);
},
allBindingsAccessor()
);
if (shouldApplyBindingsToDescendants) {
// process descendant bindings
ko.applyBindingsToDescendants(bindingContext, element);
}
// store the options' values so they can be checked for changes in the
// update() method
ko.utils.domData.set(element, domDataKey, unwrappedOptions);
// bind the widget events to the viewmodel
$.each(unwrappedEvents, function (key, value) {
unwrappedEvents[key] = value.bind(viewModel);
});
// initialize the widget
$(element)[widgetName](ko.utils.extend(unwrappedOptions, unwrappedEvents));
if (this.hasRefresh) {
subscribeToRefreshOn(widgetName, element, value);
}
// store the element in the widget observable
if (ko.isWriteableObservable(value.widget)) {
value.widget($(element));
}
// handle disposal
ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
$(element)[widgetName]('destroy');
});
return { controlsDescendantBindings: shouldApplyBindingsToDescendants };
};
/*jslint unparam:false*/
BindingHandler.prototype.update = function (element, valueAccessor) {
var widgetName, value, oldOptions, newOptions;
widgetName = this.widgetName;
value = valueAccessor();
oldOptions = ko.utils.domData.get(element, domDataKey);
newOptions = filterAndUnwrapProperties(value, this.options);
// set only the changed options
$.each(newOptions, function (prop, val) {
if (val !== oldOptions[prop]) {
$(element)[widgetName]('option', prop, newOptions[prop]);
}
});
// store the options' values so they can be checked for changes in the next
// update() method
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;
}
);
|