fhem_codemirror.js/fhemweb.js: enable codemirror in rawdefinition (Forum #81595)

git-svn-id: https://svn.fhem.de/fhem/trunk@15695 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2017-12-26 13:47:50 +00:00
parent a1352f6c33
commit c807bd5ef0
2 changed files with 36 additions and 15 deletions

View File

@ -57,6 +57,16 @@ var cm_attr = {
}; };
function AddCodeMirror(e, cb) { function AddCodeMirror(e, cb) {
if(e instanceof jQuery) {
AddCodeMirror(e.get(0), cb);
return;
}
if(e == undefined || e.editor) {
return;
}
e.editor = true;
if(cm_active && cm_loaded == cm_active) if(cm_active && cm_loaded == cm_active)
return cm_wait(e, cb); return cm_wait(e, cb);

View File

@ -644,10 +644,7 @@ FW_inlineModify() // Do not generate a new HTML page upon pressing modify
if( typeof AddCodeMirror == 'function' ) { if( typeof AddCodeMirror == 'function' ) {
// init codemirror for FW_style edit textarea // init codemirror for FW_style edit textarea
var s = $('textarea[name="data"]'); AddCodeMirror($('textarea[name="data"]'));
if( s.length && !s[0].editor ) {
s[0].editor = true; AddCodeMirror( s[0] );
}
} }
$('#DEFa').click(function(){ $('#DEFa').click(function(){
@ -656,9 +653,7 @@ FW_inlineModify() // Do not generate a new HTML page upon pressing modify
$('#disp').css('display', old=='none' ? 'none' : 'block'); $('#disp').css('display', old=='none' ? 'none' : 'block');
if( typeof AddCodeMirror == 'function' ) { if( typeof AddCodeMirror == 'function' ) {
var s=document.getElementById("edit").getElementsByTagName("textarea"); var s=document.getElementById("edit").getElementsByTagName("textarea");
if(!s[0].editor) { AddCodeMirror(s[0], function(pcm) {cm = pcm;});
s[0].editor=true; AddCodeMirror(s[0], function(pcm) {cm = pcm;});
}
} }
}); });
@ -722,31 +717,48 @@ FW_rawDef()
$("#rawDef").remove(); $("#rawDef").remove();
return; return;
} }
var textAreaStyle = typeof AddCodeMirror == 'function'?'opacity:0':'';
$("#content").append('<div id="rawDef">'+ $("#content").append('<div id="rawDef">'+
'<textarea id="td_rawDef" rows="25" cols="60" style="width:99%"/>'+ '<textarea id="td_rawDef" rows="25" cols="60" style="width:99%; '+textAreaStyle+'"/>'+
'<button>Execute commands</button>'+ '<button>Execute commands</button>'+
' Dump "Probably associated with" too <input type="checkbox">'+ ' Dump "Probably associated with" too <input type="checkbox">'+
'</div></br>'); '<br><br></div>');
function function
fillData(opt) fillData(opt)
{ {
var s = $('#rawDef textarea');
FW_cmd(FW_root+"?cmd=list "+opt+" "+dev+"&XHR=1", function(data) { FW_cmd(FW_root+"?cmd=list "+opt+" "+dev+"&XHR=1", function(data) {
var re = new RegExp("^define", "gm"); var re = new RegExp("^define", "gm");
data = data.replace(re, "defmod"); data = data.replace(re, "defmod");
$("#rawDef textarea").val(data); s.val(data);
var off = $("#rawDef").position().top-20; var off = $("#rawDef").position().top-20;
$('body, html').animate({scrollTop:off}, 500); $('body, html').animate({scrollTop:off}, 500);
$("#rawDef button").hide(); $("#rawDef button").hide();
$('#rawDef textarea').bind('input propertychange', function() { var propertychange = function() {
var nData = $("#rawDef textarea").val(); var nData = $("#rawDef textarea").val();
if(nData != data) if(nData != data)
$("#rawDef button").show(); $("#rawDef button").show();
else else
$("#rawDef button").hide(); $("#rawDef button").hide();
}); };
s.bind('input propertychange', propertychange);
if( typeof AddCodeMirror == 'function') {
$('#rawDef textarea + .CodeMirror').remove();
AddCodeMirror(s, function(cm) {
cm.on("change", function() {
s.val(cm.getValue());
propertychange();
})
});
}
}); });
} }
fillData("-r"); fillData("-r");
@ -1196,9 +1208,8 @@ FW_createTextField(elName, devName, vArr, currVal, set, params, cmd)
$("#td_longText").val(txt); $("#td_longText").val(txt);
var cm; var cm;
if(typeof AddCodeMirror == 'function' && !$("#td_longText").get(0).editor) { if(typeof AddCodeMirror == 'function') {
$("#td_longText").get(0).editor = true; AddCodeMirror($("#td_longText"), function(pcm) {cm = pcm;});
AddCodeMirror($("#td_longText").get(0), function(pcm) {cm = pcm;});
} }
$('#editdlg').dialog( $('#editdlg').dialog(