-
Notifications
You must be signed in to change notification settings - Fork 22
/
knockout-extended.js
38 lines (33 loc) · 1.88 KB
/
knockout-extended.js
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
define(['knockout', 'knockout-amd-helpers', 'knockout-es5-option4', 'lib-ext/knockout-custom-bindings'], function (ko) {
//TODO: turn off if it breaks your existing code, see http://knockoutjs.com/documentation/deferred-updates.html
ko.options.deferUpdates = true;
//TODO: change to your template folder path and suffix if needed
ko.amdTemplateEngine.defaultPath = '';
ko.amdTemplateEngine.defaultSuffix = '.html';
//TODO: change the following ko component convention as needed
//this allows the usage of custom elements (http://knockoutjs.com/documentation/component-custom-elements.html)
//without having to explicitly register them beforehand
//the catch is that if unrecognized HTML tags are found, and they are not custom elements, error will be thrown
ko.components.getComponentNameForNode = function (node) {
var tagNameLower = node.tagName && node.tagName.toLowerCase(node);
// Try to determine that this node can be considered a *custom* element; see
// https://github.com/knockout/knockout/issues/1603
if (!node.hasAttribute('data-bind')) {
if ((tagNameLower.indexOf('-') != -1) || (String(node) == '[object HTMLUnknownElement]') ||
((ko.utils.ieVersion <= 8) && (node.tagName === tagNameLower))) {
return tagNameLower;
}
}
};
//TODO: change the following ko component convention as needed
//establish a component AMD path convention for the configuration of component/custom elements
//each component should be a file with the corresponding filename under /component/ folder
//http://knockoutjs.com/documentation/component-loaders.html#getconfigname-callback
//http://knockoutjs.com/documentation/component-registration.html#a-recommended-amd-module-pattern
ko.components.loaders.push({
getConfig: function (name, callback) {
callback({ require: 'component/' + name + '/' + name });
}
});
return ko;
});