Index: trunk/extensions/SideBarMenu/test/MenuParserTest.php |
— | — | @@ -15,16 +15,6 @@ |
16 | 16 | $this->assertTrue(MenuParser::isValidInput("+MenuItem")); |
17 | 17 | } |
18 | 18 | |
19 | | - public function testIsRoot(){ |
20 | | - $isRoot = MenuParser::isRoot("MenuItem"); |
21 | | - $this->assertTrue($isRoot); |
22 | | - } |
23 | | - |
24 | | - public function testIsNotRoot(){ |
25 | | - $isRoot = MenuParser::isRoot("*MenuItem"); |
26 | | - $this->assertFalse($isRoot); |
27 | | - } |
28 | | - |
29 | 19 | public function testGetLevelWhenNull(){ |
30 | 20 | $this->assertEquals(0,MenuParser::getLevel(null)); |
31 | 21 | } |
Index: trunk/extensions/SideBarMenu/test/MenuItemTest.php |
— | — | @@ -69,7 +69,7 @@ |
70 | 70 | $menuItemChild->setText("MenuItem1"); |
71 | 71 | $this->menuItem->addChild($menuItemChild); |
72 | 72 | $html = $this->menuItem->toHTML(); |
73 | | - $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1 sidebar-menu-item-collapsed"><div class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</div></li></ul>',$html); |
| 73 | + $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</span></div></li></ul>',$html); |
74 | 74 | } |
75 | 75 | |
76 | 76 | public function testToHTMLOnSeveralMenuItems(){ |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | $this->menuItem->addChild($menuItemChild2); |
84 | 84 | |
85 | 85 | $html = $this->menuItem->toHTML(); |
86 | | - $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1 sidebar-menu-item-collapsed"><div class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</div></li><li class="sidebar-menu-item sidebar-menu-item-1 sidebar-menu-item-collapsed"><div class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem2</div></li></ul>',$html); |
| 86 | + $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</span></div></li><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem2</span></div></li></ul>',$html); |
87 | 87 | } |
88 | 88 | |
89 | 89 | public function testToHTMLOnSeveralMenuItemsWithSublevels(){ |
— | — | @@ -99,6 +99,6 @@ |
100 | 100 | $subLevel1->setParent($menuItemChild2); |
101 | 101 | |
102 | 102 | $html = $this->menuItem->toHTML(); |
103 | | - $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1 sidebar-menu-item-collapsed"><div class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</div></li><li class="sidebar-menu-item sidebar-menu-item-1 sidebar-menu-item-collapsed"><div class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem2</div><ul class="sidebar-menu sidebar-menu-1"><li class="sidebar-menu-item sidebar-menu-item-2 sidebar-menu-item-collapsed"><div class="sidebar-menu-item-text sidebar-menu-item-text-2">SubMenuItem1</div></li></ul></li></ul>',$html); |
| 103 | + $this->assertEquals('<ul class="sidebar-menu sidebar-menu-0"><li class="sidebar-menu-item sidebar-menu-item-1"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem1</span></div></li><li class="sidebar-menu-item sidebar-menu-item-1 sidebar-menu-item-collapsed"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-1">MenuItem2</span><span class="sidebar-menu-item-controls"></span></div><ul class="sidebar-menu sidebar-menu-1"><li class="sidebar-menu-item sidebar-menu-item-2"><div class="sidebar-menu-item-text-container"><span class="sidebar-menu-item-text sidebar-menu-item-text-2">SubMenuItem1</span></div></li></ul></li></ul>',$html); |
104 | 104 | } |
105 | 105 | } |
Index: trunk/extensions/SideBarMenu/SideBarMenu.i18n.php |
— | — | @@ -0,0 +1,8 @@ |
| 2 | +<?php |
| 3 | +$messages = array(); |
| 4 | +$messages['en'] = array( |
| 5 | + 'controls.show' => '[show]', |
| 6 | + 'controls.hide' => '[hide]', |
| 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.' |
| 9 | +); |
\ No newline at end of file |
Index: trunk/extensions/SideBarMenu/SideBarMenu.php |
— | — | @@ -35,6 +35,9 @@ |
36 | 36 | $wgAutoloadClasses['MenuParser'] = $wgMyExtensionIncludes . '/MenuParser.php'; |
37 | 37 | $wgAutoloadClasses['MenuItem'] = $wgMyExtensionIncludes . '/MenuItem.php'; |
38 | 38 | |
| 39 | +//i18n |
| 40 | +$wgExtensionMessagesFiles['SideBarMenu'] = dirname( __FILE__ ) . '/SideBarMenu.i18n.php'; |
| 41 | + |
39 | 42 | //Resources |
40 | 43 | $wgResourceModules['ext.sidebarmenu.core'] = array( |
41 | 44 | 'scripts' => array( |
— | — | @@ -44,7 +47,9 @@ |
45 | 48 | 'css/ext.sidebarmenu.css' |
46 | 49 | ), |
47 | 50 | 'dependencies' => array ( |
48 | | - 'jquery.ui.core' |
| 51 | + 'jquery.ui.core', |
| 52 | + 'jquery.effects.core', |
| 53 | + |
49 | 54 | ), |
50 | 55 | 'group' => 'ext.sidebarmenu', |
51 | 56 | 'localBasePath' => dirname( __FILE__ ), |
— | — | @@ -52,5 +57,5 @@ |
53 | 58 | ); |
54 | 59 | |
55 | 60 | //default settings |
56 | | -$wgSideBarMenuConfigShowHTML = '[show]'; |
57 | | -$wgSideBarMenuConfigHideHTML = '[hide]'; |
\ No newline at end of file |
| 61 | +$wgSideBarMenuConfigShowHTML = null; |
| 62 | +$wgSideBarMenuConfigHideHTML = null; |
\ No newline at end of file |
Index: trunk/extensions/SideBarMenu/SideBarMenu.hooks.php |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | return $parser->recursiveTagParse($menuHTML,$frame); |
19 | 19 | }catch(Exception $x){ |
20 | 20 | wfDebug("An error occured during parsing of: '$input' caught exception: $x"); |
21 | | - return "FATAL ERROR: Could not parse the following input:</br><pre>$input</pre>"; |
| 21 | + return wfMsg('parser.input-error',$x->getMessage()); |
22 | 22 | } |
23 | 23 | } |
24 | 24 | |
— | — | @@ -40,8 +40,8 @@ |
41 | 41 | |
42 | 42 | public static function javascriptConfigVars(&$vars){ |
43 | 43 | global $wgSideBarMenuConfigShowHTML,$wgSideBarMenuConfigHideHTML; |
44 | | - $vars['wgSideBarMenuConfigShowHTML'] = $wgSideBarMenuConfigShowHTML; |
45 | | - $vars['wgSideBarMenuConfigHideHTML'] = $wgSideBarMenuConfigHideHTML; |
| 44 | + $vars['wgSideBarMenuConfigShowHTML'] = isset($wgSideBarMenuConfigShowHTML) ? $wgSideBarMenuConfigShowHTML : wfMsg('controls.show'); |
| 45 | + $vars['wgSideBarMenuConfigHideHTML'] = isset($wgSideBarMenuConfigHideHTML) ? $wgSideBarMenuConfigHideHTML : wfMsg('controls.hide'); |
46 | 46 | return true; |
47 | 47 | } |
48 | 48 | |
Index: trunk/extensions/SideBarMenu/includes/MenuParser.php |
— | — | @@ -1,11 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | class MenuParser { |
4 | 4 | |
5 | | - public static function isRoot($line) |
6 | | - { |
7 | | - return !self::startsWith($line, '*'); |
8 | | - } |
9 | | - |
10 | 5 | public static function isValidInput($data) |
11 | 6 | { |
12 | 7 | return !(is_null($data) || strlen($data) == 0); |
— | — | @@ -77,7 +72,7 @@ |
78 | 73 | $levelArray[$level][] = $line; |
79 | 74 | }else{ |
80 | 75 | //syntax error |
81 | | - throw new InvalidArgumentException(); |
| 76 | + throw new InvalidArgumentException(wfMsg('parser.syntax-error',$line)); |
82 | 77 | } |
83 | 78 | $prevLevel = $level; |
84 | 79 | } |
Index: trunk/extensions/SideBarMenu/css/ext.sidebarmenu.css |
— | — | @@ -4,11 +4,15 @@ |
5 | 5 | padding: 5px; |
6 | 6 | float: left; |
7 | 7 | clear: left; |
| 8 | + margin: 5px; |
8 | 9 | } |
9 | 10 | |
10 | 11 | .sidebar-menu-item-collapsed .sidebar-menu{ |
11 | 12 | display: none; |
12 | 13 | } |
| 14 | +.sidebar-menu-item-expanded { |
| 15 | + display: block; |
| 16 | +} |
13 | 17 | |
14 | 18 | .sidebar-menu-0,.sidebar-menu-1{ |
15 | 19 | margin: 0px !important; |
— | — | @@ -42,9 +46,13 @@ |
43 | 47 | |
44 | 48 | .sidebar-menu-item-controls{ |
45 | 49 | float: right; |
46 | | - margin-left: 5px; |
47 | 50 | color: #0645AD; |
48 | 51 | cursor: pointer; |
| 52 | + min-width: 45px; |
| 53 | + text-align: right; |
| 54 | + -moz-user-select: none; |
| 55 | + -khtml-user-select: none; |
| 56 | + user-select: none; |
49 | 57 | } |
50 | 58 | |
51 | 59 | .sidebar-menu-item-1{ |
Index: trunk/extensions/SideBarMenu/js/ext.sidebarmenu.js |
— | — | @@ -1,6 +1,30 @@ |
2 | 2 | $(document).ready(function(){ |
3 | | - $('.sidebar-menu-item-controls').append(mw.config.get('wgSideBarMenuConfigShowHTML')); |
| 3 | + |
| 4 | + var showText = mw.config.get('wgSideBarMenuConfigShowHTML'); |
| 5 | + var hideText = mw.config.get('wgSideBarMenuConfigHideHTML'); |
| 6 | + |
| 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 | + } |
| 11 | + |
| 12 | + initControls(); |
4 | 13 | $('.sidebar-menu-item-controls').click(function(){ |
5 | | - $(this).parents('.sidebar-menu-item:first').toggleClass('sidebar-menu-item-collapsed',1500); |
| 14 | + var currentText = $(this).text(); |
| 15 | + |
| 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 | + }); |
6 | 30 | }); |
7 | 31 | }); |
\ No newline at end of file |