r113255 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113254‎ | r113255 | r113256 >
Date:17:31, 7 March 2012
Author:netbrain
Status:deferred
Tags:
Comment:
did some final polishing
Modified paths:
  • /trunk/extensions/SideBarMenu/SideBarMenu.hooks.php (modified) (history)
  • /trunk/extensions/SideBarMenu/SideBarMenu.i18n.php (modified) (history)
  • /trunk/extensions/SideBarMenu/SideBarMenu.php (modified) (history)
  • /trunk/extensions/SideBarMenu/css/ext.sidebarmenu.css (modified) (history)
  • /trunk/extensions/SideBarMenu/js/ext.sidebarmenu.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SideBarMenu/SideBarMenu.i18n.php
@@ -4,5 +4,6 @@
55 'controls.show' => '[show]',
66 'controls.hide' => '[hide]',
77 'parser.input-error' => 'FATAL ERROR: parser returned with error: $1',
8 - 'parser.syntax-error' => 'Could not parse "$1", make sure the syntax is correct.'
 8+ 'parser.syntax-error' => 'Could not parse "$1", make sure the syntax is correct.',
 9+ 'js.init-error' => 'Error loading javascript resources'
910 );
\ No newline at end of file
Index: trunk/extensions/SideBarMenu/SideBarMenu.php
@@ -20,9 +20,6 @@
2121 // Specify the function that will register the magic words for the parser function.
2222 $wgHooks['LanguageGetMagic'][] = 'SideBarMenuHooks::registerMagicWords';
2323
24 -// Javascript variables
25 -$wgHooks['ResourceLoaderGetConfigVars'][] = 'SideBarMenuHooks::javascriptConfigVars';
26 -
2724 // Sepcify phpunit tests
2825 $wgHooks['UnitTestsList'][] = 'SideBarMenuHooks::registerUnitTests';
2926
@@ -51,11 +48,15 @@
5249 'jquery.effects.core',
5350
5451 ),
 52+ 'messages' => array(
 53+ 'js.init-error'
 54+ ),
5555 'group' => 'ext.sidebarmenu',
5656 'localBasePath' => dirname( __FILE__ ),
5757 'remoteExtPath' => 'SideBarMenu'
5858 );
5959
6060 //default settings
61 -$wgSideBarMenuConfigShowHTML = null;
62 -$wgSideBarMenuConfigHideHTML = null;
\ No newline at end of file
 61+$wgSideBarMenuConfig['controls.show'] = null;
 62+$wgSideBarMenuConfig['controls.hide']= null;
 63+$wgSideBarMenuConfig['js.animate'] = true;
\ No newline at end of file
Index: trunk/extensions/SideBarMenu/SideBarMenu.hooks.php
@@ -2,23 +2,26 @@
33
44 class SideBarMenuHooks
55 {
6 -
7 - public static function init(&$parser){
 6+ public static function init(Parser &$parser){
87 $parser->setHook('sidebarmenu','SideBarMenuHooks::renderFromTag');
98 return true;
109 }
1110
1211 public static function renderFromTag( $input, array $args, Parser $parser, PPFrame $frame ){
1312 $parser->getOutput()->addModules('ext.sidebarmenu.core');
 13+
 14+ $output = '<div class="sidebar-menu-container">';
1415 try{
15 - $menuHTML = '<div class="sidebar-menu-container">';
16 - $menuHTML .= MenuParser::getMenuTree($input)->toHTML();
17 - $menuHTML .= '</div>';
18 - return $parser->recursiveTagParse($menuHTML,$frame);
 16+ $output .= MenuParser::getMenuTree($input)->toHTML();
1917 }catch(Exception $x){
2018 wfDebug("An error occured during parsing of: '$input' caught exception: $x");
2119 return wfMsg('parser.input-error',$x->getMessage());
2220 }
 21+ $output .= '</div>';
 22+
 23+ $jsOutput = self::getJSConfig($args);
 24+
 25+ return array( $jsOutput.$parser->recursiveTagParse($output,$frame), 'noparse' => true, 'isHTML' => true );
2326 }
2427
2528 public static function registerUnitTests( &$files ) {
@@ -38,11 +41,40 @@
3942 return true;
4043 }
4144
42 - public static function javascriptConfigVars(&$vars){
43 - global $wgSideBarMenuConfigShowHTML,$wgSideBarMenuConfigHideHTML;
44 - $vars['wgSideBarMenuConfigShowHTML'] = isset($wgSideBarMenuConfigShowHTML) ? $wgSideBarMenuConfigShowHTML : wfMsg('controls.show');
45 - $vars['wgSideBarMenuConfigHideHTML'] = isset($wgSideBarMenuConfigHideHTML) ? $wgSideBarMenuConfigHideHTML : wfMsg('controls.hide');
46 - return true;
 45+ private static function minifyJavascript(&$js)
 46+ {
 47+ $js = preg_replace("/[\n\r]/", "", $js); //remove newlines
 48+ $js = preg_replace("/[\s]{2,}/", " ", $js); //remove spaces
4749 }
4850
 51+ private static function getAsJSEncodedString($s)
 52+ {
 53+ return "'" . $s . "'";
 54+ }
 55+
 56+ private static function getJSConfig(&$args){
 57+ global $wgSideBarMenuConfig;
 58+ //default settings
 59+ $defaults['controls.show'] = isset($wgSideBarMenuConfig['controls.show']) ? $wgSideBarMenuConfig['controls.show'] : wfMsg('controls.show');
 60+ $defaults['controls.hide'] = isset($wgSideBarMenuConfig['controls.hide']) ? $wgSideBarMenuConfig['controls.hide'] : wfMsg('controls.hide');
 61+ $defaults['js.animate'] = $wgSideBarMenuConfig['js.animate'];
 62+
 63+ //javascript config output
 64+ $jsOutput = Html::inlineScript("
 65+ var sidebarmenu = {
 66+ config: {
 67+ controls: {
 68+ show: " . (array_key_exists('controls.show', $args) ? self::getAsJSEncodedString($args['controls.show']) : self::getAsJSEncodedString($defaults['controls.show'])) . ",
 69+ hide: " . (array_key_exists('controls.hide', $args) ? self::getAsJSEncodedString($args['controls.hide']) : self::getAsJSEncodedString($defaults['controls.hide'])) . "
 70+ },
 71+ js: {
 72+ animate: " . (array_key_exists('js.animate', $args) ? is_bool($args['js.animate']) ? 'true' : 'false' : $defaults['js.animate']) . "
 73+ }
 74+ }
 75+ };
 76+ ");
 77+ //minify js to prevent <p> tags to be rendered
 78+ self::minifyJavascript($jsOutput);
 79+ return $jsOutput;
 80+ }
4981 }
Index: trunk/extensions/SideBarMenu/css/ext.sidebarmenu.css
@@ -11,7 +11,7 @@
1212 display: none;
1313 }
1414 .sidebar-menu-item-expanded {
15 - display: block;
 15+ display: list-item;
1616 }
1717
1818 .sidebar-menu-0,.sidebar-menu-1{
Index: trunk/extensions/SideBarMenu/js/ext.sidebarmenu.js
@@ -1,30 +1,37 @@
22 $(document).ready(function(){
 3+ if(sidebarmenu != undefined){
 4+ var showText = sidebarmenu.config.controls.show;
 5+ var hideText = sidebarmenu.config.controls.hide;
 6+ var useAnimations = sidebarmenu.config.js.animate;
37
4 - var showText = mw.config.get('wgSideBarMenuConfigShowHTML');
5 - var hideText = mw.config.get('wgSideBarMenuConfigHideHTML');
 8+ function initControls() {
 9+ $('.sidebar-menu-item-collapsed').children('.sidebar-menu-item-text-container').children('.sidebar-menu-item-controls').append(showText);
 10+ $('.sidebar-menu-item-expanded').children('.sidebar-menu-item-text-container').children('.sidebar-menu-item-controls').append(hideText);
 11+ }
612
7 - function initControls() {
8 - $('.sidebar-menu-item-collapsed').children('.sidebar-menu-item-text-container').children('.sidebar-menu-item-controls').append(showText);
9 - $('.sidebar-menu-item-expanded').children('.sidebar-menu-item-text-container').children('.sidebar-menu-item-controls').append(hideText);
10 - }
 13+ initControls();
 14+ $('.sidebar-menu-item-controls').click(function(){
 15+ var currentText = $(this).text();
1116
12 - initControls();
13 - $('.sidebar-menu-item-controls').click(function(){
14 - var currentText = $(this).text();
 17+ if(currentText == showText){
 18+ $(this).text(hideText);
 19+ }else if(currentText == hideText){
 20+ $(this).text(showText);
 21+ }
1522
16 - if(currentText == showText){
17 - $(this).text(hideText);
18 - }else if(currentText == hideText){
19 - $(this).text(showText);
20 - }
21 -
22 - //A little "ugly" hack to prevent some gui glitches.
23 - $(this).parents('.sidebar-menu-item:first').
24 - toggleClass('sidebar-menu-item-collapsed sidebar-menu-item-expanded',250).children('.sidebar-menu').show(0,function(){
25 - var _this = $(this);
26 - setTimeout(function(){
27 - _this.css('display','')
28 - },250);
29 - });
30 - });
 23+ if(useAnimations){
 24+ //A little "ugly" hack to prevent some gui glitches.
 25+ $(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed sidebar-menu-item-expanded',250).children('.sidebar-menu').show(0,function(){
 26+ var _this = $(this);
 27+ setTimeout(function(){
 28+ _this.css('display','')
 29+ },250);
 30+ });
 31+ }else{
 32+ $(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed sidebar-menu-item-expanded');
 33+ }
 34+ });
 35+ }else{
 36+ $('.sidebar-menu-container').prepend(mw.msg('js.init-error'));
 37+ }
3138 });
\ No newline at end of file

Status & tagging log