Skip to content

Commit

Permalink
#5597 fix beakerx embed bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
jszalek committed Jul 20, 2017
1 parent 97a6e0e commit e48fa5d
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 125 deletions.
245 changes: 126 additions & 119 deletions beakerx/js/src/comboBox/jQueryComboBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<span>')
.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 = $('<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 = $('<span>')
.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 = $('<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 = $('<a>', {
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 = $('<a>', {
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();
}
});
});
});
28 changes: 22 additions & 6 deletions beakerx/js/src/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 1 addition & 0 deletions beakerx/js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
},
Expand Down

0 comments on commit e48fa5d

Please sign in to comment.