##// END OF EJS Templates
Register widget models and views that have the right inheritance, rather than the right name....
Jason Grout -
Show More
@@ -1,49 +1,34 b''
1 // Copyright (c) IPython Development Team.
1 // Copyright (c) IPython Development Team.
2 // Distributed under the terms of the Modified BSD License.
2 // Distributed under the terms of the Modified BSD License.
3
3
4 define([
4 define([
5 "widgets/js/manager",
5 "widgets/js/manager",
6 "widgets/js/widget",
6 "widgets/js/widget_link",
7 "widgets/js/widget_link",
7 "widgets/js/widget_bool",
8 "widgets/js/widget_bool",
8 "widgets/js/widget_button",
9 "widgets/js/widget_button",
9 "widgets/js/widget_box",
10 "widgets/js/widget_box",
10 "widgets/js/widget_float",
11 "widgets/js/widget_float",
11 "widgets/js/widget_image",
12 "widgets/js/widget_image",
12 "widgets/js/widget_int",
13 "widgets/js/widget_int",
13 "widgets/js/widget_output",
14 "widgets/js/widget_output",
14 "widgets/js/widget_selection",
15 "widgets/js/widget_selection",
15 "widgets/js/widget_selectioncontainer",
16 "widgets/js/widget_selectioncontainer",
16 "widgets/js/widget_string",
17 "widgets/js/widget_string",
17 ], function(widgetmanager) {
18 ], function(widgetmanager, widget) {
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
34 // Register all of the loaded models and views with the widget manager.
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 var module = arguments[i];
21 var module = arguments[i];
37 for (var target_name in module) {
22 for (var target_name in module) {
38 if (module.hasOwnProperty(target_name)) {
23 if (module.hasOwnProperty(target_name)) {
39 if (endsWith(target_name, "View")) {
24 var target = module[target_name];
40 widgetmanager.WidgetManager.register_widget_view(target_name, module[target_name]);
25 if (target.prototype instanceof widget.WidgetModel) {
41 } else if (endsWith(target_name, "Model")) {
26 widgetmanager.WidgetManager.register_widget_model(target_name, target);
42 widgetmanager.WidgetManager.register_widget_model(target_name, module[target_name]);
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 return {'WidgetManager': widgetmanager.WidgetManager};
33 return {'WidgetManager': widgetmanager.WidgetManager};
49 });
34 });
General Comments 0
You need to be logged in to leave comments. Login now