Created
April 7, 2017 10:22
-
-
Save mrfratello/bcf9aedb20eec4651a4261162b035b54 to your computer and use it in GitHub Desktop.
CodeMirror example of dynamic change mode and text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Code mirror test</title> | |
<link rel="stylesheet" type="text/css" href="lib/lib/codemirror.css"> | |
<script type="text/javascript" src="lib/lib/codemirror.js"></script> | |
<script src="lib/mode/javascript/javascript.js"></script> | |
<script src="lib/mode/python/python.js"></script> | |
<script src="lib/mode/htmlembedded/htmlembedded.js"></script> | |
<script src="lib/mode/htmlmixed/htmlmixed.js"></script> | |
<script src="lib/mode/xml/xml.js"></script> | |
<script src="lib/mode/css/css.js"></script> | |
<script src="lib/mode/clike/clike.js"></script> | |
<script src="lib/mode/php/php.js"></script> | |
</head> | |
<body style="background: #ccc"> | |
<div id="code" style="width: 70%;height: 300px;"></div> | |
<script type="text/javascript"> | |
var myCodeMirror = CodeMirror(document.getElementById('code'), { | |
value: "print u\"Hello\"", | |
mode: "python" | |
}); | |
setTimeout(function() { | |
myCodeMirror.doc.setValue('function hi()\n{\n echo "hello";\n}\n'); | |
myCodeMirror.setOption('mode', 'text/x-php'); | |
setTimeout(function(){ | |
myCodeMirror.doc.setValue('function myScript(){return 100;}\n'); | |
myCodeMirror.setOption('mode', 'javascript'); | |
}, 3000); | |
}, 3000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment