Index: trunk/extensions/MobileFrontend/MobileFormatter.php |
— | — | @@ -19,6 +19,7 @@ |
20 | 20 | */ |
21 | 21 | protected $title; |
22 | 22 | |
| 23 | + protected $expandableSections = false; |
23 | 24 | protected $mainPage = false; |
24 | 25 | |
25 | 26 | private $headings = 0; |
— | — | @@ -134,6 +135,14 @@ |
135 | 136 | return $this->format; |
136 | 137 | } |
137 | 138 | |
| 139 | + /** |
| 140 | + * @todo: kill with fire when there will be minimum of pre-1.1 app users remaining |
| 141 | + * @param bool $flag |
| 142 | + */ |
| 143 | + public function enableExpandableSections( $flag = true ) { |
| 144 | + $this->expandableSections = $flag; |
| 145 | + } |
| 146 | + |
138 | 147 | public function setIsMainPage( $value = true ) { |
139 | 148 | $this->mainPage = $value; |
140 | 149 | } |
— | — | @@ -283,7 +292,7 @@ |
284 | 293 | |
285 | 294 | switch ( $this->format ) { |
286 | 295 | case 'XHTML': |
287 | | - if ( !$this->mainPage && strlen( $html ) > 4000 ) { |
| 296 | + if ( $this->expandableSections && !$this->mainPage && strlen( $html ) > 4000 ) { |
288 | 297 | $html = $this->headingTransform( $html ); |
289 | 298 | } |
290 | 299 | break; |
— | — | @@ -348,13 +357,27 @@ |
349 | 358 | '↑' . $backToTop ) . |
350 | 359 | Html::closeElement( 'div' ); |
351 | 360 | // generate the HTML we are going to inject |
352 | | - $base .= Html::openElement( 'h2', |
353 | | - array( |
354 | | - 'class' => 'section_heading', |
355 | | - 'id' => 'section_' . $this->headings |
356 | | - ) |
357 | | - ); |
358 | | - $base .= |
| 361 | + // TODO: remove legacy code for Wikipedia Mobile app < 1.3 which is not using the api |
| 362 | + // when usage of said apps is low |
| 363 | + $buttons = Html::element( 'button', |
| 364 | + array( 'class' => 'section_heading show', |
| 365 | + 'section_id' => $this->headings ), |
| 366 | + $show ) . |
| 367 | + Html::element( 'button', |
| 368 | + array( 'class' => 'section_heading hide', |
| 369 | + 'section_id' => $this->headings ), |
| 370 | + $hide ); |
| 371 | + if ( $this->expandableSections ) { |
| 372 | + $h2OnClick = 'javascript:wm_toggle_section(' . $this->headings . ');'; |
| 373 | + $base .= Html::openElement( 'h2', |
| 374 | + array( 'class' => 'section_heading', |
| 375 | + 'id' => 'section_' . $this->headings, 'onclick' => $h2OnClick ) ); |
| 376 | + } else { |
| 377 | + $base .= Html::openElement( 'h2', |
| 378 | + array( 'class' => 'section_heading', |
| 379 | + 'id' => 'section_' . $this->headings ) ); |
| 380 | + } |
| 381 | + $base .= $buttons . |
359 | 382 | Html::rawElement( 'span', |
360 | 383 | array( 'id' => $headlineId ), |
361 | 384 | $matches[2] ) . |
Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -18,6 +18,7 @@ |
19 | 19 | public static $mainPageUrl; |
20 | 20 | public static $randomPageUrl; |
21 | 21 | public static $format; |
| 22 | + public static $search; |
22 | 23 | public static $callback; |
23 | 24 | public static $useFormat; |
24 | 25 | public static $disableImages; |
— | — | @@ -417,6 +418,7 @@ |
418 | 419 | self::$format = $wgRequest->getText( 'format' ); |
419 | 420 | self::$callback = $wgRequest->getText( 'callback' ); |
420 | 421 | $this->wmlContext->setRequestedSegment( $wgRequest->getInt( 'seg', 0 ) ); |
| 422 | + self::$search = $wgRequest->getText( 'search' ); |
421 | 423 | self::$searchField = $wgRequest->getText( 'search', '' ); |
422 | 424 | |
423 | 425 | $device = new DeviceDetection(); |
— | — | @@ -1059,6 +1061,11 @@ |
1060 | 1062 | $prepend = '<p><input emptyok="true" format="*M" type="text" name="search" value="" size="16" />' . |
1061 | 1063 | '<do type="accept" label="' . self::$messages['mobile-frontend-search-submit'] . '">' . |
1062 | 1064 | '<go href="' . $wgScript . '?title=Special%3ASearch&search=$(search)"></go></do></p>'; |
| 1065 | + } elseif ( $this->contentFormat == 'XHTML' |
| 1066 | + && self::$device['supports_javascript'] === true |
| 1067 | + && empty( self::$search ) ) |
| 1068 | + { |
| 1069 | + $formatter->enableExpandableSections(); |
1063 | 1070 | } |
1064 | 1071 | $contentHtml = $formatter->getText( 'content', $prepend ); |
1065 | 1072 | |
Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js |
— | — | @@ -11,6 +11,11 @@ |
12 | 12 | var i, search, clearSearch, results, languageSelection, a, heading, |
13 | 13 | sectionHeadings = utilities( '.section_heading' ); |
14 | 14 | utilities( document.body ).addClass( 'jsEnabled' ); |
| 15 | + |
| 16 | + // TODO: remove in future - currently enables toggling in Wikipedia Mobile App v < 1.3 |
| 17 | + window.wm_toggle_section = wm_toggle_section; |
| 18 | + utilities( '.section_heading button' ).remove(); |
| 19 | + |
15 | 20 | function openSectionHandler() { |
16 | 21 | var sectionNumber = this.id ? this.id.split( '_' )[1] : -1; |
17 | 22 | if( sectionNumber > -1 ) { |
— | — | @@ -33,6 +38,7 @@ |
34 | 39 | } |
35 | 40 | for( i = 0; i < sectionHeadings.length; i++ ) { |
36 | 41 | heading = sectionHeadings[i]; |
| 42 | + heading.removeAttribute( 'onclick' ); // TODO: remove any legacy onclick handlers |
37 | 43 | heading.insertBefore( createButton( true ), heading.firstChild ); |
38 | 44 | heading.insertBefore( createButton( false ), heading.firstChild ); |
39 | 45 | utilities( heading ).bind( 'click', openSectionHandler ); |
— | — | @@ -132,9 +138,20 @@ |
133 | 139 | function bind( type, handler ) { |
134 | 140 | el.addEventListener( type, handler, false ); |
135 | 141 | } |
| 142 | + |
| 143 | + // TODO: support single elements |
| 144 | + function remove(els) { |
| 145 | + var i, el; |
| 146 | + for( i = 0; i < els.length; i++ ) { |
| 147 | + el = els[i]; |
| 148 | + el.parentNode.removeChild(el); |
| 149 | + } |
| 150 | + } |
| 151 | + |
136 | 152 | return { |
137 | 153 | addClass: addClass, |
138 | 154 | bind: bind, |
| 155 | + remove: remove, |
139 | 156 | removeClass: removeClass |
140 | 157 | }; |
141 | 158 | } |
Index: trunk/extensions/MobileFrontend/javascripts/application.js |
— | — | @@ -7,6 +7,11 @@ |
8 | 8 | var i, results, languageSelection, a, heading, |
9 | 9 | sectionHeadings = utilities( '.section_heading' ); |
10 | 10 | utilities( document.body ).addClass( 'jsEnabled' ); |
| 11 | + |
| 12 | + // TODO: remove in future - currently enables toggling in Wikipedia Mobile App v < 1.3 |
| 13 | + window.wm_toggle_section = wm_toggle_section; |
| 14 | + utilities( '.section_heading button' ).remove(); |
| 15 | + |
11 | 16 | function openSectionHandler() { |
12 | 17 | var sectionNumber = this.id ? this.id.split( '_' )[1] : -1; |
13 | 18 | if( sectionNumber > -1 ) { |
— | — | @@ -29,6 +34,7 @@ |
30 | 35 | } |
31 | 36 | for( i = 0; i < sectionHeadings.length; i++ ) { |
32 | 37 | heading = sectionHeadings[i]; |
| 38 | + heading.removeAttribute( 'onclick' ); // TODO: remove any legacy onclick handlers |
33 | 39 | heading.insertBefore( createButton( true ), heading.firstChild ); |
34 | 40 | heading.insertBefore( createButton( false ), heading.firstChild ); |
35 | 41 | utilities( heading ).bind( 'click', openSectionHandler ); |
— | — | @@ -127,9 +133,20 @@ |
128 | 134 | function bind( type, handler ) { |
129 | 135 | el.addEventListener( type, handler, false ); |
130 | 136 | } |
| 137 | + |
| 138 | + // TODO: support single elements |
| 139 | + function remove(els) { |
| 140 | + var i, el; |
| 141 | + for( i = 0; i < els.length; i++ ) { |
| 142 | + el = els[i]; |
| 143 | + el.parentNode.removeChild(el); |
| 144 | + } |
| 145 | + } |
| 146 | + |
131 | 147 | return { |
132 | 148 | addClass: addClass, |
133 | 149 | bind: bind, |
| 150 | + remove: remove, |
134 | 151 | removeClass: removeClass |
135 | 152 | }; |
136 | 153 | } |