##// END OF EJS Templates
Register widget models and views that have the right inheritance, rather than the right name....
Jason Grout -
Show More
@@ -3,6 +3,7 b''
3 3
4 4 define([
5 5 "widgets/js/manager",
6 "widgets/js/widget",
6 7 "widgets/js/widget_link",
7 8 "widgets/js/widget_bool",
8 9 "widgets/js/widget_button",
@@ -14,36 +15,20 b' define(['
14 15 "widgets/js/widget_selection",
15 16 "widgets/js/widget_selectioncontainer",
16 17 "widgets/js/widget_string",
17 ], function(widgetmanager) {
18
19
20 /**
21 * From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
22 * Can be removed with the string endsWith function is implemented in major browsers
23 */
24 var endsWith = function(target, searchString, position) {
25 var subjectString = target.toString();
26 if (position === undefined || position > subjectString.length) {
27 position = subjectString.length;
28 }
29 position -= searchString.length;
30 var lastIndex = subjectString.indexOf(searchString, position);
31 return lastIndex !== -1 && lastIndex === position;
32 };
33
18 ], function(widgetmanager, widget) {
34 19 // Register all of the loaded models and views with the widget manager.
35 for (var i = 1; i < arguments.length; i++) {
20 for (var i = 2; i < arguments.length; i++) {
36 21 var module = arguments[i];
37 22 for (var target_name in module) {
38 23 if (module.hasOwnProperty(target_name)) {
39 if (endsWith(target_name, "View")) {
40 widgetmanager.WidgetManager.register_widget_view(target_name, module[target_name]);
41 } else if (endsWith(target_name, "Model")) {
42 widgetmanager.WidgetManager.register_widget_model(target_name, module[target_name]);
24 var target = module[target_name];
25 if (target.prototype instanceof widget.WidgetModel) {
26 widgetmanager.WidgetManager.register_widget_model(target_name, target);
27 } else if (target.prototype instanceof widget.WidgetView) {
28 widgetmanager.WidgetManager.register_widget_view(target_name, target);
43 29 }
44 30 }
45 31 }
46 32 }
47
48 33 return {'WidgetManager': widgetmanager.WidgetManager};
49 34 });
General Comments 0
You need to be logged in to leave comments. Login now