Index: trunk/extensions/SideBarMenu/SideBarMenu.i18n.php |
— | — | @@ -4,5 +4,6 @@ |
5 | 5 | 'controls.show' => '[show]', |
6 | 6 | 'controls.hide' => '[hide]', |
7 | 7 | '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' |
9 | 10 | ); |
\ No newline at end of file |
Index: trunk/extensions/SideBarMenu/SideBarMenu.php |
— | — | @@ -20,9 +20,6 @@ |
21 | 21 | // Specify the function that will register the magic words for the parser function. |
22 | 22 | $wgHooks['LanguageGetMagic'][] = 'SideBarMenuHooks::registerMagicWords'; |
23 | 23 | |
24 | | -// Javascript variables |
25 | | -$wgHooks['ResourceLoaderGetConfigVars'][] = 'SideBarMenuHooks::javascriptConfigVars'; |
26 | | - |
27 | 24 | // Sepcify phpunit tests |
28 | 25 | $wgHooks['UnitTestsList'][] = 'SideBarMenuHooks::registerUnitTests'; |
29 | 26 | |
— | — | @@ -51,11 +48,15 @@ |
52 | 49 | 'jquery.effects.core', |
53 | 50 | |
54 | 51 | ), |
| 52 | + 'messages' => array( |
| 53 | + 'js.init-error' |
| 54 | + ), |
55 | 55 | 'group' => 'ext.sidebarmenu', |
56 | 56 | 'localBasePath' => dirname( __FILE__ ), |
57 | 57 | 'remoteExtPath' => 'SideBarMenu' |
58 | 58 | ); |
59 | 59 | |
60 | 60 | //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 @@ |
3 | 3 | |
4 | 4 | class SideBarMenuHooks |
5 | 5 | { |
6 | | - |
7 | | - public static function init(&$parser){ |
| 6 | + public static function init(Parser &$parser){ |
8 | 7 | $parser->setHook('sidebarmenu','SideBarMenuHooks::renderFromTag'); |
9 | 8 | return true; |
10 | 9 | } |
11 | 10 | |
12 | 11 | public static function renderFromTag( $input, array $args, Parser $parser, PPFrame $frame ){ |
13 | 12 | $parser->getOutput()->addModules('ext.sidebarmenu.core'); |
| 13 | + |
| 14 | + $output = '<div class="sidebar-menu-container">'; |
14 | 15 | 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(); |
19 | 17 | }catch(Exception $x){ |
20 | 18 | wfDebug("An error occured during parsing of: '$input' caught exception: $x"); |
21 | 19 | return wfMsg('parser.input-error',$x->getMessage()); |
22 | 20 | } |
| 21 | + $output .= '</div>'; |
| 22 | + |
| 23 | + $jsOutput = self::getJSConfig($args); |
| 24 | + |
| 25 | + return array( $jsOutput.$parser->recursiveTagParse($output,$frame), 'noparse' => true, 'isHTML' => true ); |
23 | 26 | } |
24 | 27 | |
25 | 28 | public static function registerUnitTests( &$files ) { |
— | — | @@ -38,11 +41,40 @@ |
39 | 42 | return true; |
40 | 43 | } |
41 | 44 | |
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 |
47 | 49 | } |
48 | 50 | |
| 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 | + } |
49 | 81 | } |
Index: trunk/extensions/SideBarMenu/css/ext.sidebarmenu.css |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | display: none; |
13 | 13 | } |
14 | 14 | .sidebar-menu-item-expanded { |
15 | | - display: block; |
| 15 | + display: list-item; |
16 | 16 | } |
17 | 17 | |
18 | 18 | .sidebar-menu-0,.sidebar-menu-1{ |
Index: trunk/extensions/SideBarMenu/js/ext.sidebarmenu.js |
— | — | @@ -1,30 +1,37 @@ |
2 | 2 | $(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; |
3 | 7 | |
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 | + } |
6 | 12 | |
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(); |
11 | 16 | |
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 | + } |
15 | 22 | |
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 | + } |
31 | 38 | }); |
\ No newline at end of file |