diff --git a/IPython/html/static/widgets/js/init.js b/IPython/html/static/widgets/js/init.js index 0ea0a25..da09f54 100644 --- a/IPython/html/static/widgets/js/init.js +++ b/IPython/html/static/widgets/js/init.js @@ -3,6 +3,7 @@ define([ "widgets/js/manager", + "widgets/js/widget", "widgets/js/widget_link", "widgets/js/widget_bool", "widgets/js/widget_button", @@ -14,36 +15,20 @@ define([ "widgets/js/widget_selection", "widgets/js/widget_selectioncontainer", "widgets/js/widget_string", -], function(widgetmanager) { - - - /** - * From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith - * Can be removed with the string endsWith function is implemented in major browsers - */ - var endsWith = function(target, searchString, position) { - var subjectString = target.toString(); - if (position === undefined || position > subjectString.length) { - position = subjectString.length; - } - position -= searchString.length; - var lastIndex = subjectString.indexOf(searchString, position); - return lastIndex !== -1 && lastIndex === position; - }; - +], function(widgetmanager, widget) { // Register all of the loaded models and views with the widget manager. - for (var i = 1; i < arguments.length; i++) { + for (var i = 2; i < arguments.length; i++) { var module = arguments[i]; for (var target_name in module) { if (module.hasOwnProperty(target_name)) { - if (endsWith(target_name, "View")) { - widgetmanager.WidgetManager.register_widget_view(target_name, module[target_name]); - } else if (endsWith(target_name, "Model")) { - widgetmanager.WidgetManager.register_widget_model(target_name, module[target_name]); + var target = module[target_name]; + if (target.prototype instanceof widget.WidgetModel) { + widgetmanager.WidgetManager.register_widget_model(target_name, target); + } else if (target.prototype instanceof widget.WidgetView) { + widgetmanager.WidgetManager.register_widget_view(target_name, target); } } } } - return {'WidgetManager': widgetmanager.WidgetManager}; });