User:Vadim/common.js
From CruisersWiki
(Difference between revisions)
Line 14: | Line 14: | ||
// load code editor if required | // load code editor if required | ||
addOnloadHook(function () { // https://ace.c9.io/#nav=embedding | addOnloadHook(function () { // https://ace.c9.io/#nav=embedding | ||
- | if ((wgAction == 'edit' || wgAction == 'submit') && /\.js$/.test(wgPageName)) { | + | if ((wgAction == 'edit' || wgAction == 'submit') && (/\.js$/.test(wgPageName) || /\.css$/.test(wgPageName))) { |
loadScript('https://cdn.jsdelivr.net/ace/1.2.3/min/ace.js', initCodeEditor); //function () {}); | loadScript('https://cdn.jsdelivr.net/ace/1.2.3/min/ace.js', initCodeEditor); //function () {}); | ||
} | } | ||
Line 20: | Line 20: | ||
function initCodeEditor() { | function initCodeEditor() { | ||
+ | // https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts< | ||
$wpTextbox1 = $( '#wpTextbox1' ); | $wpTextbox1 = $( '#wpTextbox1' ); | ||
$aceEditor = $( "<div></div>" ).insertAfter( "#wpTextbox1" ); | $aceEditor = $( "<div></div>" ).insertAfter( "#wpTextbox1" ); | ||
Line 35: | Line 36: | ||
}); | }); | ||
- | // editor.setTheme("ace/theme/monokai"); | + | // editor.setTheme("ace/theme/monokai"); |
- | editor.getSession().setMode("ace/mode/javascript"); | + | editor.getSession().setUseSoftTabs(true); |
+ | |||
+ | if (/\.js$/.test(wgPageName)) { | ||
+ | editor.getSession().setMode("ace/mode/javascript"); | ||
+ | } else if (/\.css$/.test(wgPageName)) { | ||
+ | editor.getSession().setMode("ace/mode/css"); | ||
+ | } | ||
} | } |
Revision as of 09:12, 22 January 2016
function addCustomEditButton (imageFile, speedTip, tagOpen, tagClose, sampleText, imageId) { mwCustomEditButtons[mwEditButtons.length] = {"imageId": imageId, "imageFile": imageFile, "speedTip": speedTip, "tagOpen": tagOpen, "tagClose": tagClose, "sampleText": sampleText}; } addCustomEditButton("/images/7/70/Button_POI.png","Add POI","{{poi | lat= | lon=\n| type=\n| name=","\n| text=\n}}\n","","mw-editbutton-poi"); // load code editor if required addOnloadHook(function () { // https://ace.c9.io/#nav=embedding if ((wgAction == 'edit' || wgAction == 'submit') && (/\.js$/.test(wgPageName) || /\.css$/.test(wgPageName))) { loadScript('https://cdn.jsdelivr.net/ace/1.2.3/min/ace.js', initCodeEditor); //function () {}); } }); function initCodeEditor() { // https://github.com/ajaxorg/ace/wiki/Default-Keyboard-Shortcuts< $wpTextbox1 = $( '#wpTextbox1' ); $aceEditor = $( "<div></div>" ).insertAfter( "#wpTextbox1" ); $aceEditor.height($wpTextbox1.height()); $aceEditor.text($wpTextbox1.text()); $wpTextbox1.hide(); editor = ace.edit($aceEditor[0]); editor.getSession().on( 'change', function(e) { // e.type, etc $wpTextbox1.text(editor.getValue()); }); // editor.setTheme("ace/theme/monokai"); editor.getSession().setUseSoftTabs(true); if (/\.js$/.test(wgPageName)) { editor.getSession().setMode("ace/mode/javascript"); } else if (/\.css$/.test(wgPageName)) { editor.getSession().setMode("ace/mode/css"); } }