[MediaWiki-commits] [Gerrit] Combine var statements - change (mediawiki...CodeEditor)
Siebrand has uploaded a new change for review. https://gerrit.wikimedia.org/r/104734 Change subject: Combine var statements .. Combine var statements Change-Id: If005690ab8ecf21e64399781acbecd1ec3b02172 --- M modules/ext.codeEditor.geshi.js M modules/jquery.codeEditor.js 2 files changed, 87 insertions(+), 53 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CodeEditor refs/changes/34/104734/1 diff --git a/modules/ext.codeEditor.geshi.js b/modules/ext.codeEditor.geshi.js index 6a6e6bd..771f80a 100644 --- a/modules/ext.codeEditor.geshi.js +++ b/modules/ext.codeEditor.geshi.js @@ -5,10 +5,15 @@ */ $( function () { - var $sources = $( '.mw-geshi' ); + var $sources, setupEditor, openEditor; + + $sources = $( '.mw-geshi' ); + if ( $sources.length 0 ) { - var setupEditor = function ( $div ) { - var $link = $( 'a' ) + setupEditor = function ( $div ) { + var $link, $edit; + + $link = $( 'a' ) .text( mediaWiki.msg( 'editsection' ) ) .attr( 'href', '#' ) .attr( 'title', 'Edit this code section' ) @@ -16,23 +21,29 @@ openEditor( $div ); event.preventDefault(); } ); - var $edit = $( 'span' ) + $edit = $( 'span' ) .addClass( 'mw-editsection' ) .append( 'span class=mw-editsection-bracket[/span' ) .append( $link ) .append( 'span class=mw-editsection-bracket]/span' ); $div.prepend( $edit ); }; - var openEditor = function ( $div ) { - var $main = $div.find( 'div' ), - geshiLang = null, - matches = /(?:^| )source-([a-z0-9_-]+)/.exec( $main.attr( 'class' ) ); + + 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 - var map = { + map = { c: 'c_cpp', cpp: 'c_cpp', clojure: 'clojure', @@ -57,17 +68,17 @@ }; // Disable some annoying commands - var canon = require( 'pilot/canon' ); + canon = require( 'pilot/canon' ); canon.removeCommand( 'replace' ); // ctrl+R canon.removeCommand( 'transposeletters' ); // ctrl+T canon.removeCommand( 'gotoline' ); // ctrl+L - var $container = $( 'div' ) + $container = $( 'div' ) .attr( 'style', 'top: 32px; left: 0px; right: 0px; bottom: 0px; border: 1px solid gray' ) .text( $main.text() ); // quick hack :D - var $label = $( 'label' ).text( 'Source language: ' ); - var $langDropDown = $( 'select' ); + $label = $( 'label' ).text( 'Source language: ' ); + $langDropDown = $( 'select' ); $.each( map, function ( geshiLang, aceLang ) { var $opt = $( 'option' ) .text( geshiLang ) @@ -80,12 +91,14 @@ .change( function ( event ) { setLanguage( $( this ).val() ); } ); - var $save = $( 'button' ) + $save = $( 'button' ) .text( mediaWiki.msg( 'savearticle' ) )
[MediaWiki-commits] [Gerrit] Combine var statements - change (mediawiki...CodeEditor)
jenkins-bot has submitted this change and it was merged. Change subject: Combine var statements .. Combine var statements Change-Id: If005690ab8ecf21e64399781acbecd1ec3b02172 --- M modules/ext.codeEditor.geshi.js M modules/jquery.codeEditor.js 2 files changed, 89 insertions(+), 53 deletions(-) Approvals: TheDJ: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/ext.codeEditor.geshi.js b/modules/ext.codeEditor.geshi.js index 6a6e6bd..771f80a 100644 --- a/modules/ext.codeEditor.geshi.js +++ b/modules/ext.codeEditor.geshi.js @@ -5,10 +5,15 @@ */ $( function () { - var $sources = $( '.mw-geshi' ); + var $sources, setupEditor, openEditor; + + $sources = $( '.mw-geshi' ); + if ( $sources.length 0 ) { - var setupEditor = function ( $div ) { - var $link = $( 'a' ) + setupEditor = function ( $div ) { + var $link, $edit; + + $link = $( 'a' ) .text( mediaWiki.msg( 'editsection' ) ) .attr( 'href', '#' ) .attr( 'title', 'Edit this code section' ) @@ -16,23 +21,29 @@ openEditor( $div ); event.preventDefault(); } ); - var $edit = $( 'span' ) + $edit = $( 'span' ) .addClass( 'mw-editsection' ) .append( 'span class=mw-editsection-bracket[/span' ) .append( $link ) .append( 'span class=mw-editsection-bracket]/span' ); $div.prepend( $edit ); }; - var openEditor = function ( $div ) { - var $main = $div.find( 'div' ), - geshiLang = null, - matches = /(?:^| )source-([a-z0-9_-]+)/.exec( $main.attr( 'class' ) ); + + 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 - var map = { + map = { c: 'c_cpp', cpp: 'c_cpp', clojure: 'clojure', @@ -57,17 +68,17 @@ }; // Disable some annoying commands - var canon = require( 'pilot/canon' ); + canon = require( 'pilot/canon' ); canon.removeCommand( 'replace' ); // ctrl+R canon.removeCommand( 'transposeletters' ); // ctrl+T canon.removeCommand( 'gotoline' ); // ctrl+L - var $container = $( 'div' ) + $container = $( 'div' ) .attr( 'style', 'top: 32px; left: 0px; right: 0px; bottom: 0px; border: 1px solid gray' ) .text( $main.text() ); // quick hack :D - var $label = $( 'label' ).text( 'Source language: ' ); - var $langDropDown = $( 'select' ); + $label = $( 'label' ).text( 'Source language: ' ); + $langDropDown = $( 'select' ); $.each( map, function ( geshiLang, aceLang ) { var $opt = $( 'option' ) .text( geshiLang ) @@ -80,12 +91,14 @@ .change( function ( event ) { setLanguage( $( this ).val() ); } ); - var $save = $( 'button' ) + $save = $( 'button' ) .text( mediaWiki.msg( 'savearticle' ) ) .click( function ( event ) {