1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

TypedInput: preload type icons to ensure width calc correct

This commit is contained in:
Nick O'Leary 2016-04-13 18:10:04 -07:00
parent e92241bf97
commit cf69dbe1dc

View File

@ -235,12 +235,17 @@
if (!arguments.length) { if (!arguments.length) {
return this.propertyType; return this.propertyType;
} else { } else {
var that = this;
var opt = this.typeMap[type]; var opt = this.typeMap[type];
if (opt && this.propertyType !== type) { if (opt && this.propertyType !== type) {
this.propertyType = type; this.propertyType = type;
this.typeField.val(type); this.typeField.val(type);
this.selectLabel.empty(); this.selectLabel.empty();
var image;
if (opt.icon) { if (opt.icon) {
image = new Image();
image.name = opt.icon;
image.src = opt.icon;
$('<img>',{src:opt.icon,style:"margin-right: 4px;height: 18px;"}).prependTo(this.selectLabel); $('<img>',{src:opt.icon,style:"margin-right: 4px;height: 18px;"}).prependTo(this.selectLabel);
} else { } else {
this.selectLabel.text(opt.label); this.selectLabel.text(opt.label);
@ -249,7 +254,6 @@
if (this.optionSelectTrigger) { if (this.optionSelectTrigger) {
this.optionSelectTrigger.show(); this.optionSelectTrigger.show();
this.element.hide(); this.element.hide();
var that = this;
this.optionMenu = this._createMenu(opt.options,function(v){ this.optionMenu = this._createMenu(opt.options,function(v){
that.optionSelectLabel.text(v); that.optionSelectLabel.text(v);
that.value(v); that.value(v);
@ -277,9 +281,14 @@
} }
this.element.trigger('change'); this.element.trigger('change');
} }
if (image) {
image.onload = function() { that._resize(); }
image.onerror = function() { that._resize(); }
} else {
this._resize(); this._resize();
} }
} }
}
}, },
validate: function() { validate: function() {
var result; var result;