|
@@ -83,6 +83,7 @@ module INSPECTOR {
|
|
private _escapeInputHandler: EventListener;
|
|
private _escapeInputHandler: EventListener;
|
|
/** Handler used on focus out */
|
|
/** Handler used on focus out */
|
|
private _focusOutInputHandler: EventListener;
|
|
private _focusOutInputHandler: EventListener;
|
|
|
|
+ private _input_checkbox: HTMLInputElement;
|
|
/** Handler used to get mouse position */
|
|
/** Handler used to get mouse position */
|
|
private _onMouseDownHandler: EventListener;
|
|
private _onMouseDownHandler: EventListener;
|
|
private _onMouseDragHandler: EventListener;
|
|
private _onMouseDragHandler: EventListener;
|
|
@@ -106,7 +107,10 @@ module INSPECTOR {
|
|
|
|
|
|
// Value
|
|
// Value
|
|
this._valueDiv = Helpers.CreateDiv('prop-value', this._div);
|
|
this._valueDiv = Helpers.CreateDiv('prop-value', this._div);
|
|
- this._valueDiv.textContent = this._displayValueContent() || '-'; // Init value text node
|
|
|
|
|
|
+
|
|
|
|
+ if (typeof this.value !== 'boolean') {
|
|
|
|
+ this._valueDiv.textContent = this._displayValueContent() || '-'; // Init value text node
|
|
|
|
+ }
|
|
|
|
|
|
this._createElements();
|
|
this._createElements();
|
|
|
|
|
|
@@ -117,17 +121,18 @@ module INSPECTOR {
|
|
this._updateValue();
|
|
this._updateValue();
|
|
|
|
|
|
// If the property type is not simple, add click event to unfold its children
|
|
// If the property type is not simple, add click event to unfold its children
|
|
- if (!this._isSimple()) {
|
|
|
|
|
|
+ if (typeof this.value === 'boolean') {
|
|
|
|
+ this._checkboxInput();
|
|
|
|
+ } else if (!this._isSimple()) {
|
|
this._valueDiv.classList.add('clickable');
|
|
this._valueDiv.classList.add('clickable');
|
|
this._valueDiv.addEventListener('click', this._addDetails.bind(this));
|
|
this._valueDiv.addEventListener('click', this._addDetails.bind(this));
|
|
} else {
|
|
} else {
|
|
this._initInput();
|
|
this._initInput();
|
|
this._valueDiv.addEventListener('click', this._displayInputHandler);
|
|
this._valueDiv.addEventListener('click', this._displayInputHandler);
|
|
- this._input.addEventListener('keypress', this._validateInputHandler);
|
|
|
|
- this._input.addEventListener('keydown', this._escapeInputHandler);
|
|
|
|
this._input.addEventListener('focusout', this._focusOutInputHandler);
|
|
this._input.addEventListener('focusout', this._focusOutInputHandler);
|
|
|
|
+ this._input.addEventListener('keydown', this._validateInputHandler);
|
|
|
|
+ this._input.addEventListener('keydown', this._escapeInputHandler);
|
|
}
|
|
}
|
|
-
|
|
|
|
// Add this property to the scheduler
|
|
// Add this property to the scheduler
|
|
Scheduler.getInstance().add(this);
|
|
Scheduler.getInstance().add(this);
|
|
}
|
|
}
|
|
@@ -158,7 +163,11 @@ module INSPECTOR {
|
|
* On escape : removes the input
|
|
* On escape : removes the input
|
|
*/
|
|
*/
|
|
private _validateInput(e: KeyboardEvent) {
|
|
private _validateInput(e: KeyboardEvent) {
|
|
- if (e.keyCode == 13) {
|
|
|
|
|
|
+ this._input.removeEventListener('focusout', this._focusOutInputHandler);
|
|
|
|
+ if (e.keyCode == 13) { // Enter
|
|
|
|
+ this.validateInput(this._input.value);
|
|
|
|
+ } else if (e.keyCode == 9) { // Tab
|
|
|
|
+ e.preventDefault();
|
|
this.validateInput(this._input.value);
|
|
this.validateInput(this._input.value);
|
|
} else if (e.keyCode == 27) {
|
|
} else if (e.keyCode == 27) {
|
|
// Esc : remove input
|
|
// Esc : remove input
|
|
@@ -169,9 +178,9 @@ module INSPECTOR {
|
|
public validateInput(value: any): void {
|
|
public validateInput(value: any): void {
|
|
this.updateObject();
|
|
this.updateObject();
|
|
|
|
|
|
- if(typeof this._property.value === 'number'){
|
|
|
|
|
|
+ if (typeof this._property.value === 'number') {
|
|
this._property.value = parseFloat(value);
|
|
this._property.value = parseFloat(value);
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
this._property.value = value;
|
|
this._property.value = value;
|
|
}
|
|
}
|
|
// Remove input
|
|
// Remove input
|
|
@@ -195,7 +204,9 @@ module INSPECTOR {
|
|
/** Removes the input without validating the new value */
|
|
/** Removes the input without validating the new value */
|
|
private _removeInputWithoutValidating() {
|
|
private _removeInputWithoutValidating() {
|
|
Helpers.CleanDiv(this._valueDiv);
|
|
Helpers.CleanDiv(this._valueDiv);
|
|
- this._valueDiv.textContent = "-";
|
|
|
|
|
|
+ if (typeof this.value !== 'boolean') {
|
|
|
|
+ this._valueDiv.textContent = "-";
|
|
|
|
+ }
|
|
// restore elements
|
|
// restore elements
|
|
for (let elem of this._elements) {
|
|
for (let elem of this._elements) {
|
|
this._valueDiv.appendChild(elem.toHtml());
|
|
this._valueDiv.appendChild(elem.toHtml());
|
|
@@ -208,6 +219,8 @@ module INSPECTOR {
|
|
// Remove the displayInput event listener
|
|
// Remove the displayInput event listener
|
|
this._valueDiv.removeEventListener('click', this._displayInputHandler);
|
|
this._valueDiv.removeEventListener('click', this._displayInputHandler);
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
// Set input value
|
|
// Set input value
|
|
let valueTxt = this._valueDiv.textContent;
|
|
let valueTxt = this._valueDiv.textContent;
|
|
this._valueDiv.textContent = "";
|
|
this._valueDiv.textContent = "";
|
|
@@ -215,10 +228,16 @@ module INSPECTOR {
|
|
this._valueDiv.appendChild(this._input);
|
|
this._valueDiv.appendChild(this._input);
|
|
this._input.focus();
|
|
this._input.focus();
|
|
|
|
|
|
- if(typeof this.value === 'number') {
|
|
|
|
|
|
+ if (typeof this.value === 'number') {
|
|
|
|
+ // Slider
|
|
|
|
+ // let slider = Helpers.CreateDiv('slider-number', this._valueDiv);
|
|
|
|
+ // slider.style.background = '#303030';
|
|
|
|
+ // slider.style.cursor = 'ew-resize';
|
|
|
|
+ // slider.innerHTML = 'HELLO'
|
|
this._input.addEventListener('mousedown', this._onMouseDownHandler);
|
|
this._input.addEventListener('mousedown', this._onMouseDownHandler);
|
|
}
|
|
}
|
|
this._input.addEventListener('focusout', this._focusOutInputHandler);
|
|
this._input.addEventListener('focusout', this._focusOutInputHandler);
|
|
|
|
+
|
|
// Pause the scheduler
|
|
// Pause the scheduler
|
|
Scheduler.getInstance().pause = true;
|
|
Scheduler.getInstance().pause = true;
|
|
}
|
|
}
|
|
@@ -283,12 +302,12 @@ module INSPECTOR {
|
|
if (typeof value === 'number') {
|
|
if (typeof value === 'number') {
|
|
return Helpers.Trunc(value);
|
|
return Helpers.Trunc(value);
|
|
}
|
|
}
|
|
|
|
+
|
|
// If it's a string or a boolean, display its value
|
|
// If it's a string or a boolean, display its value
|
|
if (typeof value === 'string' || typeof value === 'boolean') {
|
|
if (typeof value === 'string' || typeof value === 'boolean') {
|
|
return value;
|
|
return value;
|
|
}
|
|
}
|
|
return PROPERTIES.format(value);
|
|
return PROPERTIES.format(value);
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/** Delete properly this property line.
|
|
/** Delete properly this property line.
|
|
@@ -317,7 +336,11 @@ module INSPECTOR {
|
|
this.updateObject();
|
|
this.updateObject();
|
|
// Then update its value
|
|
// Then update its value
|
|
// this._valueDiv.textContent = " "; // TOFIX this removes the elements after
|
|
// this._valueDiv.textContent = " "; // TOFIX this removes the elements after
|
|
- this._valueDiv.childNodes[0].nodeValue = this._displayValueContent();
|
|
|
|
|
|
+ if (typeof this.value === 'boolean') {
|
|
|
|
+ this._checkboxInput();
|
|
|
|
+ } else {
|
|
|
|
+ this._valueDiv.childNodes[0].nodeValue = this._displayValueContent();
|
|
|
|
+ }
|
|
for (let elem of this._elements) {
|
|
for (let elem of this._elements) {
|
|
elem.update(this.value);
|
|
elem.update(this.value);
|
|
}
|
|
}
|
|
@@ -394,12 +417,11 @@ module INSPECTOR {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Refresh mouse position on y axis
|
|
* Refresh mouse position on y axis
|
|
* @param e
|
|
* @param e
|
|
*/
|
|
*/
|
|
- private _onMouseDrag(e: MouseEvent): void {
|
|
|
|
|
|
+ private _onMouseDrag(e: MouseEvent): void {
|
|
const diff = this._prevY - e.clientY;
|
|
const diff = this._prevY - e.clientY;
|
|
this._input.value = (this._preValue + diff).toString();
|
|
this._input.value = (this._preValue + diff).toString();
|
|
}
|
|
}
|
|
@@ -413,7 +435,7 @@ module INSPECTOR {
|
|
window.removeEventListener('mouseup', this._onMouseUpHandler);
|
|
window.removeEventListener('mouseup', this._onMouseUpHandler);
|
|
this._prevY = e.clientY;
|
|
this._prevY = e.clientY;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Start record mouse position
|
|
* Start record mouse position
|
|
* @param e
|
|
* @param e
|
|
@@ -424,5 +446,20 @@ module INSPECTOR {
|
|
window.addEventListener('mousemove', this._onMouseDragHandler);
|
|
window.addEventListener('mousemove', this._onMouseDragHandler);
|
|
window.addEventListener('mouseup', this._onMouseUpHandler);
|
|
window.addEventListener('mouseup', this._onMouseUpHandler);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Create input entry
|
|
|
|
+ */
|
|
|
|
+ private _checkboxInput() {
|
|
|
|
+ if(this._valueDiv.childElementCount < 1) { // Prevent display two checkbox
|
|
|
|
+ this._input_checkbox = Helpers.CreateInput('checkbox-element', this._valueDiv);
|
|
|
|
+ this._input_checkbox.type = 'checkbox'
|
|
|
|
+ this._input_checkbox.checked = this.value;
|
|
|
|
+ this._input_checkbox.addEventListener('change', () => {
|
|
|
|
+ Scheduler.getInstance().pause = true;
|
|
|
|
+ this.validateInput(!this.value)
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|