Index: trunk/extensions/CodeEditor/CodeEditor.php |
— | — | @@ -24,10 +24,25 @@ |
25 | 25 | |
26 | 26 | $wgHooks['EditPage::showEditForm:initial'][] = 'CodeEditorHooks::editPageShowEditFormInitial'; |
27 | 27 | |
28 | | -$wgResourceModules['ext.codeEditor'] = array( |
| 28 | +$tpl = array( |
29 | 29 | 'localBasePath' => dirname( __FILE__ ) . '/modules', |
30 | 30 | 'remoteExtPath' => 'CodeEditor/modules', |
31 | 31 | 'group' => 'ext.codeEditor', |
| 32 | +); |
| 33 | + |
| 34 | +$wgResourceModules['ext.codeEditor'] = array( |
32 | 35 | 'scripts' => 'ext.codeEditor.js', |
33 | | - 'dependencies' => array( 'ext.wikiEditor' ) |
34 | | -); |
| 36 | + 'dependencies' => array( |
| 37 | + 'ext.wikiEditor', |
| 38 | + 'ext.codeEditor.ace', |
| 39 | + ), |
| 40 | +) + $tpl; |
| 41 | + |
| 42 | +// Minimal bundling of a couple bits of Ace |
| 43 | +$wgResourceModules['ext.codeEditor.ace'] = array( |
| 44 | + 'scripts' => array( |
| 45 | + 'ace/ace-uncompressed.js', |
| 46 | + 'ace/mode-javascript.js', |
| 47 | + 'ace/mode-css.js', |
| 48 | + ), |
| 49 | +) + $tpl; |
Index: trunk/extensions/CodeEditor/modules/ext.codeEditor.js |
— | — | @@ -47,50 +47,42 @@ |
48 | 48 | var ext = matches[1]; |
49 | 49 | var map = {js: 'javascript', css: 'css'}; |
50 | 50 | var lang = map[ext]; |
51 | | - var modules = {}; |
52 | | - var load = function(path, callback) { |
53 | | - var url = editorBase + path; |
54 | | - $.getScript(url, callback); |
55 | | - }; |
56 | | - load('ace-uncompressed.js', function() { |
57 | | - load('mode-' + lang + '.js', function() { |
58 | | - // Ace doesn't like replacing a textarea directly. |
59 | | - // We'll stub this out to sit on top of it... |
60 | | - // line-height is needed to compensate for oddity in WikiEditor extension, which zeroes the line-height on a parent container |
61 | | - var container = $('<div style="position: relative"><div class="editor" style="line-height: 1.5em; top: 0px; left: 0px; right: 0px; bottom: 0px; border: 1px solid gray"></div></div>').insertAfter(box); |
62 | | - var editdiv = container.find('.editor'); |
63 | 51 | |
64 | | - box.css('display', 'none'); |
65 | | - container.width(box.width()) |
66 | | - .height(box.height()); |
| 52 | + // Ace doesn't like replacing a textarea directly. |
| 53 | + // We'll stub this out to sit on top of it... |
| 54 | + // line-height is needed to compensate for oddity in WikiEditor extension, which zeroes the line-height on a parent container |
| 55 | + var container = $('<div style="position: relative"><div class="editor" style="line-height: 1.5em; top: 0px; left: 0px; right: 0px; bottom: 0px; border: 1px solid gray"></div></div>').insertAfter(box); |
| 56 | + var editdiv = container.find('.editor'); |
67 | 57 | |
68 | | - editdiv.text(box.val()); |
69 | | - var editor = ace.edit(editdiv[0]); |
70 | | - box.closest('form').submit(function(event) { |
71 | | - box.val(editor.getSession().getValue()); |
72 | | - }); |
73 | | - editor.getSession().setMode(new (require("ace/mode/" + lang).Mode)); |
| 58 | + box.css('display', 'none'); |
| 59 | + container.width(box.width()) |
| 60 | + .height(box.height()); |
74 | 61 | |
75 | | - // Force the box to resize horizontally to match in future :D |
76 | | - var resize = function() { |
77 | | - container.width(box.width()); |
78 | | - }; |
79 | | - $(window).resize(resize); |
80 | | - // Use jquery.ui.resizable so user can make the box taller too |
81 | | - container.resizable({ |
82 | | - handles: 's', |
83 | | - minHeight: box.height(), |
84 | | - resize: function() { |
85 | | - editor.resize(); |
86 | | - } |
87 | | - }); |
| 62 | + editdiv.text(box.val()); |
| 63 | + var editor = ace.edit(editdiv[0]); |
| 64 | + box.closest('form').submit(function(event) { |
| 65 | + box.val(editor.getSession().getValue()); |
| 66 | + }); |
| 67 | + editor.getSession().setMode(new (require("ace/mode/" + lang).Mode)); |
88 | 68 | |
89 | | - var summary = $('#wpSummary'); |
90 | | - if (summary.val() == '') { |
91 | | - summary.val('/* using [[mw:CodeEditor|CodeEditor]] */ '); |
92 | | - } |
93 | | - }); |
94 | | - }); |
| 69 | + // Force the box to resize horizontally to match in future :D |
| 70 | + var resize = function() { |
| 71 | + container.width(box.width()); |
| 72 | + }; |
| 73 | + $(window).resize(resize); |
| 74 | + // Use jquery.ui.resizable so user can make the box taller too |
| 75 | + container.resizable({ |
| 76 | + handles: 's', |
| 77 | + minHeight: box.height(), |
| 78 | + resize: function() { |
| 79 | + editor.resize(); |
| 80 | + } |
| 81 | + }); |
| 82 | + |
| 83 | + var summary = $('#wpSummary'); |
| 84 | + if (summary.val() == '') { |
| 85 | + summary.val('/* using [[mw:CodeEditor|CodeEditor]] */ '); |
| 86 | + } |
95 | 87 | } |
96 | 88 | } |
97 | 89 | }); |