diff --git a/beakerx/js/src/comboBox/jQueryComboBox.js b/beakerx/js/src/comboBox/jQueryComboBox.js index 7806367b31..1bbf01cc80 100644 --- a/beakerx/js/src/comboBox/jQueryComboBox.js +++ b/beakerx/js/src/comboBox/jQueryComboBox.js @@ -14,140 +14,147 @@ * limitations under the License. */ -$( function() { - $.widget('custom.combobox', { - options: { - change: null, - disabled: false - }, - - _create: function () { - this.editable = this.element.attr('easyform-editable') === 'true'; - this.wrapper = $('') - .addClass('easyform-combobox') - .insertAfter(this.element); - - this.element.hide(); - this._createAutocomplete(); - this._createShowAllButton(); - }, - - _createAutocomplete: function () { - var selected = this.element.children(':selected'); - var value = selected.val() ? selected.text() : ''; - - this.input = $('') - .appendTo(this.wrapper) - .val(value) - .attr('title', '') - .addClass('easyform-combobox-input ui-widget ui-widget-content ui-corner-left') - .autocomplete({ - delay: 150, - minLength: 0, - source: $.proxy(this, '_source') - }) - .tooltip({ - tooltipClass: 'ui-state-highlight' +define([ + 'jquery', + 'jquery-ui', + 'jquery-ui/ui/widget' +], function($, jqui, jquiWidget) { + + $( function() { + $.widget('custom.combobox', { + options: { + change: null, + disabled: false + }, + + _create: function () { + this.editable = this.element.attr('easyform-editable') === 'true'; + this.wrapper = $('') + .addClass('easyform-combobox') + .insertAfter(this.element); + + this.element.hide(); + this._createAutocomplete(); + this._createShowAllButton(); + }, + + _createAutocomplete: function () { + var selected = this.element.children(':selected'); + var value = selected.val() ? selected.text() : ''; + + this.input = $('') + .appendTo(this.wrapper) + .val(value) + .attr('title', '') + .addClass('easyform-combobox-input ui-widget ui-widget-content ui-corner-left') + .autocomplete({ + delay: 150, + minLength: 0, + source: $.proxy(this, '_source') + }) + .tooltip({ + tooltipClass: 'ui-state-highlight' + }); + + if (!this.editable) { + var input = this.input; + var wasOpen = false; + + this.input + .attr('readonly', 'true') + .mousedown(function () { + wasOpen = input.autocomplete('widget').is(':visible'); + }) + .click(function () { + input.focus(); + if (wasOpen) { + return; + } + input.autocomplete('search', ''); + }); + } + + if(this.options.disabled){ + this.input.attr('disabled', 'disabled'); + } + + this._on(this.input, { + autocompleteselect: function (event, ui) { + ui.item.option.selected = true; + this._trigger('select', event, { + item: ui.item.option + }); + if ($.isFunction(this.options.change)) { + this.options.change(ui.item.option.value); + } + }, + autocompletesearch: function () { + if ($.isFunction(this.options.change) && this.editable) { + this.options.change(this.input[0].value); + } + } }); + }, - if (!this.editable) { + _createShowAllButton: function () { var input = this.input; var wasOpen = false; - this.input - .attr('readonly', 'true') + //use jquery button fn instead of bootstrap + //reverts to jquery button fn + var self = this; + var $showAllButton = $('', { + tabIndex: -1, + title: 'Show All Items' + }) + .appendTo(this.wrapper) + .button({ + icons: { + primary: 'ui-icon-triangle-1-s' + }, + text: false + }) + .removeClass('ui-corner-all') + .addClass('easyform-combobox-toggle ui-corner-right') .mousedown(function () { - wasOpen = input.autocomplete('widget').is(':visible'); + if (!self.options.disabled) { + wasOpen = input.autocomplete('widget').is(':visible'); + } }) .click(function () { - input.focus(); - if (wasOpen) { - return; - } - input.autocomplete('search', ''); - }); - } - - if(this.options.disabled){ - this.input.attr('disabled', 'disabled'); - } + if (!self.options.disabled) { + input.focus(); - this._on(this.input, { - autocompleteselect: function (event, ui) { - ui.item.option.selected = true; - this._trigger('select', event, { - item: ui.item.option - }); - if ($.isFunction(this.options.change)) { - this.options.change(ui.item.option.value); - } - }, - autocompletesearch: function () { - if ($.isFunction(this.options.change) && this.editable) { - this.options.change(this.input[0].value); - } - } - }); - }, - - _createShowAllButton: function () { - var input = this.input; - var wasOpen = false; - - //use jquery button fn instead of bootstrap - //reverts to jquery button fn - var self = this; - var $showAllButton = $('', { - tabIndex: -1, - title: 'Show All Items' - }) - .appendTo(this.wrapper) - .button({ - icons: { - primary: 'ui-icon-triangle-1-s' - }, - text: false - }) - .removeClass('ui-corner-all') - .addClass('easyform-combobox-toggle ui-corner-right') - .mousedown(function () { - if (!self.options.disabled) { - wasOpen = input.autocomplete('widget').is(':visible'); - } - }) - .click(function () { - if (!self.options.disabled) { - input.focus(); + if (wasOpen) { + return; + } - if (wasOpen) { - return; + input.autocomplete('search', ''); } + }); - input.autocomplete('search', ''); - } - }); - - $showAllButton.prop('disabled', self.options.disabled); - }, + $showAllButton.prop('disabled', self.options.disabled); + }, - _source: function (request, response) { - var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), 'i'); + _source: function (request, response) { + var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), 'i'); - response(this.element.children('option').map(function () { - var text = $(this).text(); + response(this.element.children('option').map(function () { + var text = $(this).text(); - if (this.value && ( !request.term || matcher.test(text) )) - return { - label: text, - value: text, - option: this - }; - })); - }, + if (this.value && ( !request.term || matcher.test(text) )) + return { + label: text, + value: text, + option: this + }; + })); + }, - _destroy: function () { - this.wrapper.remove(); - this.element.show(); - } + _destroy: function () { + this.wrapper.remove(); + this.element.show(); + } + }); }); }); diff --git a/beakerx/js/src/embed.js b/beakerx/js/src/embed.js index b9ad9a7d4e..a17e70a2fc 100644 --- a/beakerx/js/src/embed.js +++ b/beakerx/js/src/embed.js @@ -5,10 +5,26 @@ // already be loaded by the notebook otherwise. // Export widget models and views, and the npm package version number. -module.exports = require('./Plot.js'); -module.exports = require('./TableDisplay.js'); -module.exports = require('./EasyForm.js'); -module.exports = require('./TabView.js'); -module.exports = require('./GridView.js'); -module.exports = require('./CyclingDisplayBox.js'); +module.exports = {}; + +var loadedModules = [ + require("./Plot"), + require("./TableDisplay"), + require("./EasyForm"), + require("./TabView"), + require("./GridView"), + require("./CyclingDisplayBox") +]; + +for (var i in loadedModules) { + if (loadedModules.hasOwnProperty(i)) { + var loadedModule = loadedModules[i]; + for (var target_name in loadedModule) { + if (loadedModule.hasOwnProperty(target_name)) { + module.exports[target_name] = loadedModule[target_name]; + } + } + } +} + module.exports['version'] = require('../package.json').version; diff --git a/beakerx/js/webpack.config.js b/beakerx/js/webpack.config.js index 520147ccc1..1d25a15ef0 100644 --- a/beakerx/js/webpack.config.js +++ b/beakerx/js/webpack.config.js @@ -126,6 +126,7 @@ module.exports = [ output: { filename: 'index.js', path: path.resolve(__dirname, './dist/'), + library: 'beakerx', libraryTarget: 'amd', publicPath: 'https://unpkg.com/beakerx@' + version + '/dist/' },