Cache selectors

This commit is contained in:
Pete Richards
2018-01-25 13:58:09 -08:00
parent 5e3ca00b2a
commit 9f640c24fb
4 changed files with 29 additions and 17 deletions

View File

@@ -37,6 +37,9 @@ define([
this.deleteButton = $('.t-delete', this.domElement);
this.duplicateButton = $('.t-duplicate', this.domElement);
this.conditionContents = $('.t-condition-context', this.domElement)
this.selectContainer = $('.t-configuration', this.domElement)
this.inputArea = $('.t-value-inputs', this.domElement)
this.selects = {};
this.valueInputs = [];
@@ -106,10 +109,10 @@ define([
});
Object.values(this.selects).forEach(function (select) {
$('.t-configuration', self.domElement).append(select.getDOM());
self.selectContainer.append(select.getDOM());
});
this.listenTo($(this.domElement), 'input', onValueInput);
this.listenTo(this.domElement, 'input', onValueInput);
}
Condition.prototype.getDOM = function (container) {
@@ -172,13 +175,12 @@ define([
*/
Condition.prototype.generateValueInputs = function (operation) {
var evaluator = this.conditionManager.getEvaluator(),
inputArea = $('.t-value-inputs', this.domElement),
inputCount,
inputType,
newInput,
index = 0;
inputArea.html('');
this.inputArea.html('');
this.valueInputs = [];
if (evaluator.getInputCount(operation)) {
@@ -190,7 +192,7 @@ define([
}
newInput = $('<input class="sm" type = "' + inputType + '" value = "' + this.config.values[index] + '"> </input>');
this.valueInputs.push(newInput.get(0));
inputArea.append(newInput);
this.inputArea.append(newInput);
index += 1;
}
}

View File

@@ -62,6 +62,7 @@ define([
this.deleteButton = $('.t-delete', this.domElement);
this.duplicateButton = $('.t-duplicate', this.domElement);
this.addConditionButton = $('.add-condition', this.domElement);
this.insertBefore = $('li:last-of-type', this.conditionArea);
/**
* The text inputs for this rule: any input included in this object will
@@ -414,9 +415,9 @@ define([
this.addConditionButton.show();
self.conditions.forEach(function (condition) {
$condition = condition.getDOM();
$('li:last-of-type', self.conditionArea).before($condition);
self.insertBefore.before($condition);
if (loopCnt > 0) {
$('.t-condition-context', $condition).html(triggerContextStr + ' when');
condition.conditionContents.html(triggerContextStr + ' when');
}
loopCnt++;
});
@@ -447,6 +448,7 @@ define([
this.eventEmitter.emit('conditionChange');
};
/**
* Build a human-readable description from this rule's conditions
*/

View File

@@ -37,6 +37,8 @@ define([
this.deleteButton = $('.t-delete', this.domElement);
this.duplicateButton = $('.t-duplicate', this.domElement);
this.equalTo = $('.equal-to', this.domElement);
this.selects = {};
this.valueInputs = [];
@@ -57,6 +59,13 @@ define([
if (property === 'key') {
self.generateValueInput(value);
}
if (property === 'object') {
if (!value) {
self.equalTo.hide();
} else {
self.equalTo.show();
}
}
self.eventEmitter.emit('change', {
value: value,
property: property,

View File

@@ -21,6 +21,7 @@ define([
var self = this;
this.domElement = $(selectTemplate);
this.$select = $('select', this.domElement);
this.options = [];
this.eventEmitter = new EventEmitter();
this.supportedCallbacks = ['change'];
@@ -40,7 +41,7 @@ define([
self.eventEmitter.emit('change', value[0]);
}
this.listenTo($('select', this.domElement), 'change', onChange, this);
this.listenTo(this.$select, 'change', onChange, this);
}
/**
@@ -74,16 +75,16 @@ define([
var self = this,
selectedIndex = 0;
selectedIndex = $('select', this.domElement).prop('selectedIndex');
selectedIndex = this.$select.prop('selectedIndex');
$('option', this.domElement).remove();
self.options.forEach(function (option, index) {
$('select', self.domElement)
self.$select
.append('<option value = "' + option[0] + '"' + ' >' +
option[1] + '</option>');
});
$('select', this.domElement).prop('selectedIndex', selectedIndex);
this.$select.prop('selectedIndex', selectedIndex);
};
/**
@@ -120,7 +121,7 @@ define([
selectedIndex = index;
}
});
$('select', this.domElement).prop('selectedIndex', selectedIndex);
this.$select.prop('selectedIndex', selectedIndex);
selectedOption = this.options[selectedIndex];
this.eventEmitter.emit('change', selectedOption[0]);
@@ -131,17 +132,15 @@ define([
* @return {string}
*/
Select.prototype.getSelected = function () {
return $('select', this.domElement).prop('value');
return this.$select.prop('value');
};
Select.prototype.hide = function () {
$(this.domElement).addClass('hidden');
$('.equal-to').addClass('hidden');
this.domElement.addClass('hidden');
};
Select.prototype.show = function () {
$(this.domElement).removeClass('hidden');
$('.equal-to').removeClass('hidden');
this.domElement.removeClass('hidden');
};
Select.prototype.destroy = function () {