http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89806

Revision: 89806
Author:   brion
Date:     2011-06-09 22:17:00 +0000 (Thu, 09 Jun 2011)
Log Message:
-----------
Update CodeEditor extension to load Ace editor via RL instead of manually

Modified Paths:
--------------
    trunk/extensions/CodeEditor/CodeEditor.php
    trunk/extensions/CodeEditor/modules/ext.codeEditor.js

Modified: trunk/extensions/CodeEditor/CodeEditor.php
===================================================================
--- trunk/extensions/CodeEditor/CodeEditor.php  2011-06-09 21:59:09 UTC (rev 
89805)
+++ trunk/extensions/CodeEditor/CodeEditor.php  2011-06-09 22:17:00 UTC (rev 
89806)
@@ -24,10 +24,25 @@
 
 $wgHooks['EditPage::showEditForm:initial'][] = 
'CodeEditorHooks::editPageShowEditFormInitial';
 
-$wgResourceModules['ext.codeEditor'] = array(
+$tpl = array(
        'localBasePath' => dirname( __FILE__ ) . '/modules',
        'remoteExtPath' => 'CodeEditor/modules',
        'group' => 'ext.codeEditor',
+);
+
+$wgResourceModules['ext.codeEditor'] = array(
        'scripts' => 'ext.codeEditor.js',
-       'dependencies' => array( 'ext.wikiEditor' )
-);
+       'dependencies' => array(
+               'ext.wikiEditor',
+               'ext.codeEditor.ace',
+       ),
+) + $tpl;
+
+// Minimal bundling of a couple bits of Ace
+$wgResourceModules['ext.codeEditor.ace'] = array(
+       'scripts' => array(
+               'ace/ace-uncompressed.js',
+               'ace/mode-javascript.js',
+               'ace/mode-css.js',
+       ),
+) + $tpl;

Modified: trunk/extensions/CodeEditor/modules/ext.codeEditor.js
===================================================================
--- trunk/extensions/CodeEditor/modules/ext.codeEditor.js       2011-06-09 
21:59:09 UTC (rev 89805)
+++ trunk/extensions/CodeEditor/modules/ext.codeEditor.js       2011-06-09 
22:17:00 UTC (rev 89806)
@@ -47,50 +47,42 @@
                 var ext = matches[1];
                 var map = {js: 'javascript', css: 'css'};
                 var lang = map[ext];
-                var modules = {};
-                var load = function(path, callback) {
-                    var url = editorBase + path;
-                    $.getScript(url, callback);
-                };
-                load('ace-uncompressed.js', function() {
-                    load('mode-' + lang + '.js', function() {
-                        // Ace doesn't like replacing a textarea directly.
-                        // We'll stub this out to sit on top of it...
-                        // line-height is needed to compensate for oddity in 
WikiEditor extension, which zeroes the line-height on a parent container
-                        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);
-                        var editdiv = container.find('.editor');
 
-                        box.css('display', 'none');
-                        container.width(box.width())
-                                 .height(box.height());
+                               // Ace doesn't like replacing a textarea 
directly.
+                               // We'll stub this out to sit on top of it...
+                               // line-height is needed to compensate for 
oddity in WikiEditor extension, which zeroes the line-height on a parent 
container
+                               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);
+                               var editdiv = container.find('.editor');
 
-                        editdiv.text(box.val());
-                        var editor = ace.edit(editdiv[0]);
-                        box.closest('form').submit(function(event) {
-                            box.val(editor.getSession().getValue());
-                        });
-                        editor.getSession().setMode(new (require("ace/mode/" + 
lang).Mode));
+                               box.css('display', 'none');
+                               container.width(box.width())
+                                                .height(box.height());
 
-                        // Force the box to resize horizontally to match in 
future :D
-                        var resize = function() {
-                            container.width(box.width());
-                        };
-                        $(window).resize(resize);
-                        // Use jquery.ui.resizable so user can make the box 
taller too
-                        container.resizable({
-                            handles: 's',
-                            minHeight: box.height(),
-                            resize: function() {
-                                editor.resize();
-                            }
-                        });
+                               editdiv.text(box.val());
+                               var editor = ace.edit(editdiv[0]);
+                               box.closest('form').submit(function(event) {
+                                       box.val(editor.getSession().getValue());
+                               });
+                               editor.getSession().setMode(new 
(require("ace/mode/" + lang).Mode));
 
-                        var summary = $('#wpSummary');
-                        if (summary.val() == '') {
-                            summary.val('/* using [[mw:CodeEditor|CodeEditor]] 
*/ ');
-                        }
-                    });
-                });
+                               // Force the box to resize horizontally to 
match in future :D
+                               var resize = function() {
+                                       container.width(box.width());
+                               };
+                               $(window).resize(resize);
+                               // Use jquery.ui.resizable so user can make the 
box taller too
+                               container.resizable({
+                                       handles: 's',
+                                       minHeight: box.height(),
+                                       resize: function() {
+                                               editor.resize();
+                                       }
+                               });
+
+                               var summary = $('#wpSummary');
+                               if (summary.val() == '') {
+                                       summary.val('/* using 
[[mw:CodeEditor|CodeEditor]] */ ');
+                               }
             }
         }
     });


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to