2015-02-05 10:37:34 +00:00
|
|
|
var cm_loaded = 0;
|
2014-04-07 16:07:58 +00:00
|
|
|
|
2015-02-03 19:14:44 +00:00
|
|
|
$(document).ready(function(){
|
|
|
|
var els = document.getElementsByTagName("textarea");
|
|
|
|
if(els.length == 0)
|
|
|
|
return;
|
2014-04-07 16:07:58 +00:00
|
|
|
|
2015-02-03 19:14:44 +00:00
|
|
|
if($(els[0]).closest("div#edit").css("display")=="none") { // DEF special
|
|
|
|
$("table.internals a").each(function(){
|
|
|
|
var oc = $(this).attr("onclick");
|
|
|
|
if(oc) {
|
|
|
|
$(this).attr("onclick", oc+
|
|
|
|
's=document.getElementById("edit").getElementsByTagName("textarea");'+
|
2015-02-05 10:37:34 +00:00
|
|
|
'if(!s[0].editor) { s[0].editor=true; AddCodeMirror(s[0]);}');
|
2015-02-03 19:14:44 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
AddCodeMirror(els[0]);
|
|
|
|
}
|
2014-04-07 16:07:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function
|
2015-02-05 10:37:34 +00:00
|
|
|
AddCodeMirror(e, cb)
|
2014-04-07 16:07:58 +00:00
|
|
|
{
|
2015-02-05 10:37:34 +00:00
|
|
|
if(cm_loaded == 4)
|
|
|
|
return cm_wait(e, cb);
|
2014-04-07 16:07:58 +00:00
|
|
|
loadLink("codemirror/codemirror.css");
|
|
|
|
loadLink("codemirror/show-hint.css");
|
2015-02-05 10:37:34 +00:00
|
|
|
loadScript("codemirror/codemirror.js", function(){ cm_loaded++;} );
|
|
|
|
loadScript("codemirror/closebrackets.js",function(){ cm_loaded++;} );
|
|
|
|
loadScript("codemirror/matchbrackets.js",function(){ cm_loaded++;} );
|
|
|
|
loadScript("codemirror/show-hint.js", function(){
|
|
|
|
cm_loaded++;
|
|
|
|
cm_wait(e, cb);
|
|
|
|
});
|
2014-04-07 16:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function
|
2015-02-05 10:37:34 +00:00
|
|
|
cm_wait(cm_editor, callback)
|
2014-04-07 16:07:58 +00:00
|
|
|
{
|
|
|
|
if(cm_loaded != 4) {
|
|
|
|
setTimeout(cm_wait, 10);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ltype,type="fhem"; // get the type from the hidden filename extension
|
|
|
|
$("input[name=save]").each(function(){
|
|
|
|
ltype = $(this).attr("value");
|
|
|
|
ltype = ltype.substr(ltype.lastIndexOf(".")+1);
|
|
|
|
if(ltype=="css") type = "css";
|
|
|
|
if(ltype=="svg") type = "xml";
|
|
|
|
});
|
|
|
|
var attr = {
|
|
|
|
theme: "blackboard",
|
|
|
|
lineNumbers: true,
|
|
|
|
matchBrackets: true,
|
|
|
|
autoCloseBrackets: true,
|
|
|
|
extraKeys:{'Ctrl-Space':'autocomplete'}
|
|
|
|
};
|
|
|
|
var userAttr = scriptAttribute("fhem_codemirror.js");
|
|
|
|
for(var a in userAttr)
|
|
|
|
attr[a] = userAttr[a];
|
|
|
|
|
|
|
|
loadLink("codemirror/"+attr.theme+".css");
|
2014-04-30 10:15:37 +00:00
|
|
|
$("head").append(
|
|
|
|
'<style type="text/css">'+
|
|
|
|
(ltype ?
|
|
|
|
'.CodeMirror {height: ' + (window.innerHeight - 150) + 'px;}':
|
|
|
|
'.CodeMirror {width: ' + (window.innerWidth - 300) + 'px;}')+
|
|
|
|
'</style>');
|
2014-04-07 16:07:58 +00:00
|
|
|
|
|
|
|
loadScript("codemirror/"+type+".js", function(){
|
|
|
|
log("Calling CodeMirror");
|
2015-02-05 10:37:34 +00:00
|
|
|
var cm = CodeMirror.fromTextArea(cm_editor, attr);
|
|
|
|
if(callback)
|
|
|
|
callback(cm);
|
2014-04-07 16:07:58 +00:00
|
|
|
});
|
|
|
|
}
|