/** * This is experimental and does not yet actually save anything back. * Has to be manually enabled. * Needs some code de-dup with the full-page JS/CSS page editing. */ $( function () { var $sources, setupEditor, openEditor; $sources = $( '.mw-geshi' ); if ( $sources.length > 0 ) { setupEditor = function ( $div ) { var $link, $edit; $link = $( '' ) .text( mediaWiki.msg( 'editsection' ) ) .attr( 'href', '#' ) .attr( 'title', 'Edit this code section' ) .click( function ( event ) { openEditor( $div ); event.preventDefault(); } ); $edit = $( '' ) .addClass( 'mw-editsection' ) .append( '[' ) .append( $link ) .append( ']' ); $div.prepend( $edit ); }; openEditor = function ( $div ) { var $main, geshiLang, matches, $label, $langDropDown, $xcontainer, codeEditor; $main = $div.find( 'div' ); geshiLang = null; matches = /(?:^| )source-([a-z0-9_-]+)/.exec( $main.attr( 'class' ) ); if ( matches ) { geshiLang = matches[1]; } mediaWiki.loader.using( 'ext.codeEditor.ace.modes', function () { var map, canon, $container, $save, $cancel, $controls, setLanguage, closeEditor; // @fixme de-duplicate map = { c: 'c_cpp', cpp: 'c_cpp', clojure: 'clojure', csharp: 'csharp', css: 'css', coffeescript: 'coffee', groovy: 'groovy', html4strict: 'html', html5: 'html', java: 'java', java5: 'java', javascript: 'javascript', jquery: 'javascript', json: 'json', ocaml: 'ocaml', perl: 'perl', php: 'php', python: 'python', ruby: 'ruby', scala: 'scala', xml: 'xml' }; // Disable some annoying commands canon = require( 'pilot/canon' ); canon.removeCommand( 'replace' ); // ctrl+R canon.removeCommand( 'transposeletters' ); // ctrl+T canon.removeCommand( 'gotoline' ); // ctrl+L $container = $( '
' ) .attr( 'style', 'top: 32px; left: 0px; right: 0px; bottom: 0px; border: 1px solid gray; position: absolute;' ) .text( $main.text() ); // quick hack :D $label = $( '