mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 21:36:47 +02:00
save when focus on inputs
This commit is contained in:
parent
477ed88284
commit
3abbc98857
1 changed files with 24 additions and 15 deletions
|
@ -352,7 +352,7 @@ function setTextareaScrolling(element) {
|
||||||
|
|
||||||
var editor = null;
|
var editor = null;
|
||||||
var editorTimeout = null;
|
var editorTimeout = null;
|
||||||
var lastJSONString=null;
|
var lastJSONString = null;
|
||||||
|
|
||||||
function createJSONEditor() {
|
function createJSONEditor() {
|
||||||
var container = document.getElementById("userdata-editor");
|
var container = document.getElementById("userdata-editor");
|
||||||
|
@ -368,12 +368,10 @@ function createJSONEditor() {
|
||||||
alert('JSON editor:' + e)
|
alert('JSON editor:' + e)
|
||||||
},
|
},
|
||||||
onChange: function() {
|
onChange: function() {
|
||||||
console.log('changed')
|
if (currentJSONString === '{"":""}') {
|
||||||
if(currentJSONString==='{"":""}'){
|
|
||||||
console.log('its empty')
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$('#userdata-save').attr('disabled',false)
|
$('#userdata-save').attr('disabled', false)
|
||||||
var currentJSONString = editor.getText();
|
var currentJSONString = editor.getText();
|
||||||
|
|
||||||
|
|
||||||
|
@ -440,6 +438,7 @@ function getEditorJSON() {
|
||||||
function deleteJSONEditor() {
|
function deleteJSONEditor() {
|
||||||
if (editor !== null) {
|
if (editor !== null) {
|
||||||
editor.destroy();
|
editor.destroy();
|
||||||
|
editor = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -448,20 +447,29 @@ var savedJSONTimer = null;
|
||||||
function saveJSONUserData() {
|
function saveJSONUserData() {
|
||||||
setUserDataFromEditor();
|
setUserDataFromEditor();
|
||||||
$('#userdata-saved').show();
|
$('#userdata-saved').show();
|
||||||
|
$('#userdata-save').attr('disabled', true)
|
||||||
if (savedJSONTimer !== null) {
|
if (savedJSONTimer !== null) {
|
||||||
clearTimeout(savedJSONTimer);
|
clearTimeout(savedJSONTimer);
|
||||||
}
|
}
|
||||||
savedJSONTimer = setTimeout(function() {
|
savedJSONTimer = setTimeout(function() {
|
||||||
$('#userdata-saved').hide();
|
$('#userdata-saved').hide();
|
||||||
$('#userdata-save').attr('disabled',true)
|
|
||||||
}, 1500)
|
}, 1500)
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindAllNonJSONEditorElements(){
|
function bindAllNonJSONEditorElements() {
|
||||||
var inputs = $('input');
|
var inputs = $('input');
|
||||||
var i;
|
var i;
|
||||||
for(i=0;i<inputs.length;i++){
|
for (i = 0; i < inputs.length; i++) {
|
||||||
var input = inputs[i];
|
var input = inputs[i];
|
||||||
|
var field = $(input);
|
||||||
|
field.on('focus', function(e) {
|
||||||
|
if (e.target.id === "userdata-new-editor" || e.target.id === "userdata-clear") {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
saveJSONUserData();
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -657,12 +665,17 @@ function loaded() {
|
||||||
EventBridge.scriptEventReceived.connect(function(data) {
|
EventBridge.scriptEventReceived.connect(function(data) {
|
||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
if (data.type == "update") {
|
if (data.type == "update") {
|
||||||
|
|
||||||
if (data.selections.length == 0) {
|
if (data.selections.length == 0) {
|
||||||
|
if (editor !== null) {
|
||||||
|
deleteJSONEditor();
|
||||||
|
}
|
||||||
elTypeIcon.style.display = "none";
|
elTypeIcon.style.display = "none";
|
||||||
elType.innerHTML = "<i>No selection</i>";
|
elType.innerHTML = "<i>No selection</i>";
|
||||||
elID.innerHTML = "";
|
elID.innerHTML = "";
|
||||||
disableProperties();
|
disableProperties();
|
||||||
} else if (data.selections.length > 1) {
|
} else if (data.selections.length > 1) {
|
||||||
|
deleteJSONEditor();
|
||||||
var selections = data.selections;
|
var selections = data.selections;
|
||||||
|
|
||||||
var ids = [];
|
var ids = [];
|
||||||
|
@ -787,7 +800,6 @@ function loaded() {
|
||||||
FIXME: See FIXME for property-script-url.
|
FIXME: See FIXME for property-script-url.
|
||||||
elScriptTimestamp.value = properties.scriptTimestamp;
|
elScriptTimestamp.value = properties.scriptTimestamp;
|
||||||
*/
|
*/
|
||||||
//deleteJSONEditor();
|
|
||||||
hideUserDataTextArea();
|
hideUserDataTextArea();
|
||||||
var json = null;
|
var json = null;
|
||||||
try {
|
try {
|
||||||
|
@ -798,7 +810,6 @@ function loaded() {
|
||||||
}
|
}
|
||||||
if (editor === null) {
|
if (editor === null) {
|
||||||
createJSONEditor();
|
createJSONEditor();
|
||||||
console.log('CREATING NEW EDITOR')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setEditorJSON(json);
|
setEditorJSON(json);
|
||||||
|
@ -974,7 +985,7 @@ function loaded() {
|
||||||
elLocked.removeAttribute('disabled');
|
elLocked.removeAttribute('disabled');
|
||||||
} else {
|
} else {
|
||||||
enableProperties();
|
enableProperties();
|
||||||
elSaveUserData.disabled=true;
|
elSaveUserData.disabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var activeElement = document.activeElement;
|
var activeElement = document.activeElement;
|
||||||
|
@ -1115,9 +1126,7 @@ function loaded() {
|
||||||
});
|
});
|
||||||
|
|
||||||
elUserData.addEventListener('change', createEmitTextPropertyUpdateFunction('userData'));
|
elUserData.addEventListener('change', createEmitTextPropertyUpdateFunction('userData'));
|
||||||
// elJSONEditor.addEventListener('mouseleave',function(){
|
|
||||||
// saveJSONUserData();
|
|
||||||
// });
|
|
||||||
elNewJSONEditor.addEventListener('click', function() {
|
elNewJSONEditor.addEventListener('click', function() {
|
||||||
deleteJSONEditor();
|
deleteJSONEditor();
|
||||||
createJSONEditor();
|
createJSONEditor();
|
||||||
|
@ -1387,7 +1396,7 @@ function loaded() {
|
||||||
clicked = true;
|
clicked = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
bindMouseLeaveForJSONEditor();
|
bindAllNonJSONEditorElements();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Collapsible sections
|
// Collapsible sections
|
||||||
|
|
Loading…
Reference in a new issue