r89806 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89805‎ | r89806 | r89807 >
Date:22:17, 9 June 2011
Author:brion
Status:deferred
Tags:
Comment:
Update CodeEditor extension to load Ace editor via RL instead of manually
Modified paths:
  • /trunk/extensions/CodeEditor/CodeEditor.php (modified) (history)
  • /trunk/extensions/CodeEditor/modules/ext.codeEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeEditor/CodeEditor.php
@@ -24,10 +24,25 @@
2525
2626 $wgHooks['EditPage::showEditForm:initial'][] = 'CodeEditorHooks::editPageShowEditFormInitial';
2727
28 -$wgResourceModules['ext.codeEditor'] = array(
 28+$tpl = array(
2929 'localBasePath' => dirname( __FILE__ ) . '/modules',
3030 'remoteExtPath' => 'CodeEditor/modules',
3131 'group' => 'ext.codeEditor',
 32+);
 33+
 34+$wgResourceModules['ext.codeEditor'] = array(
3235 '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 @@
4848 var ext = matches[1];
4949 var map = {js: 'javascript', css: 'css'};
5050 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');
6351
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');
6757
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());
7461
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));
8868
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+ }
9587 }
9688 }
9789 });

Status & tagging log