Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/javascripts/application.js |
— | — | @@ -1,24 +1,34 @@ |
2 | | -/* Super gross hack implemented where MOST of the JS is repeated in lib/native_app_hack.rb |
3 | | -If you make significant changes here, make sure to update that version too!*/ |
| 2 | +// Ideally, this would be loaded in the head and activated by a script at the bottom, |
| 3 | +// I think, rather than attached to an onload... |
| 4 | +window.onload = function() { |
| 5 | + // I don't think this makes sense. Loading this here means that this button |
| 6 | + // won't function until the page is loaded. It would probably be an |
| 7 | + // improvement to just attach an onclick straight into the html. |
| 8 | + document.getElementById( 'logo' ).onclick = function() { |
| 9 | + var n = document.getElementById( 'nav' ).style; |
| 10 | + n.display = n.display == 'block' ? 'none' : 'block'; |
| 11 | + }; |
4 | 12 | |
5 | | -$( document ).ready( function() { |
6 | | - $( '#logo' ).click( function() { |
7 | | - $( '#nav' ).toggle(); |
8 | | - }); |
| 13 | + // Also problematic, not working until the page loads... |
| 14 | + for( var h = document.getElementsByTagName( 'h2' ), i = 0; i < h.length; i++ ) { |
| 15 | + if ( h[i].className == 'section_heading' ) { |
| 16 | + h[i].onclick = function() { |
| 17 | + var section_idx = parseInt( this.id.replace( /section_(\d+)/, '$1' ) ); |
| 18 | + wm_toggle_section( section_idx ); |
| 19 | + } |
| 20 | + } |
| 21 | + }; |
9 | 22 | |
10 | | - $( 'h2.section_heading' ).click( function() { |
11 | | - var section_idx = parseInt( $( this ).get( 0 ).id.replace( /section_(\d+)/, '$1' ) ); |
12 | | - wm_toggle_section( section_idx ); |
13 | | - }); |
14 | | - |
15 | | - $( 'a' ).click( function() { |
16 | | - var link = $( this ).get( 0 ); |
17 | | - if( link.hash.indexOf( '#' ) == 0 ) { |
18 | | - wm_reveal_for_hash( link.hash ); |
| 23 | + // And this... |
| 24 | + for ( var a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) { |
| 25 | + a[i].onclick = function() { |
| 26 | + if ( this.hash.indexOf( '#' ) == 0 ) { |
| 27 | + wm_reveal_for_hash( this.hash ); |
| 28 | + } |
19 | 29 | } |
20 | | - }); |
| 30 | + }; |
21 | 31 | |
22 | | - if( document.location.hash.indexOf( '#' ) == 0 ) { |
| 32 | + if ( document.location.hash.indexOf( '#' ) == 0 ) { |
23 | 33 | wm_reveal_for_hash( document.location.hash ); |
24 | 34 | } |
25 | 35 | |
— | — | @@ -27,11 +37,12 @@ |
28 | 38 | // Try to scroll and hide URL bar |
29 | 39 | window.scrollTo( 0, 1 ); |
30 | 40 | |
31 | | - decode = $( '#searchField' ); |
32 | | - decode.val( unescape( decode.val() ) ); |
33 | | - decode = $( 'title' ); |
34 | | - decode.html( unescape( decode.html() ) ); |
35 | | -}); |
| 41 | + // This is a global. I don't know why. |
| 42 | + decode = document.getElementById( 'searchField' ); |
| 43 | + decode.value = unescape( decode.value ); |
| 44 | + decode = document.getElementsByTagName( 'title' )[0]; |
| 45 | + decode.innerHTML = unescape( decode.innerHTML ); |
| 46 | +}; |
36 | 47 | |
37 | 48 | /** |
38 | 49 | * updateOrientation checks the current orientation, sets the body's class |
— | — | @@ -53,26 +64,27 @@ |
54 | 65 | window.onorientationchange = updateOrientation; |
55 | 66 | |
56 | 67 | function wm_reveal_for_hash( hash ) { |
57 | | - var targetel = $( hash ); |
58 | | - if( targetel ) { |
59 | | - var parentdiv = targetel.parents( 'div.content_block' ); |
60 | | - if( parentdiv.length > 0 && ! parentdiv.is( ':visible' ) ) { |
61 | | - var section_idx = parseInt( parentdiv.get( 0 ).id.replace( /content_(\d+)/, '$1' ) ); |
| 68 | + var targetel = document.getElementById( hash.substr(1) ); |
| 69 | + if ( targetel ) { |
| 70 | + for (var p = targetel.parentNode; p && p.className != 'content_block' && p.className != 'section_heading'; ) { |
| 71 | + p = p.parentNode; |
| 72 | + } |
| 73 | + if ( p && p.style.display != 'block' ) { |
| 74 | + var section_idx = parseInt( p.id.split( '_' )[1] ); |
62 | 75 | wm_toggle_section( section_idx ); |
63 | 76 | } |
64 | 77 | } |
65 | 78 | } |
66 | 79 | |
67 | 80 | function wm_toggle_section( section_id ) { |
68 | | - $( 'h2#section_' + section_id ).children( 'button.show' ).toggle(); |
69 | | - $( 'h2#section_' + section_id ).children( 'button.hide' ).toggle(); |
70 | | - |
71 | | - $( 'div#content_' + section_id ).toggle(); |
72 | | - $( 'div#anchor_' + section_id ).toggle(); |
73 | | -} |
74 | | - |
75 | | -var wm_clearText = function() { |
76 | | - document.getElementById( 'searchField' ).value = ''; |
77 | | - $( '#searchField' ).val( '' ).focus(); |
78 | | -} |
79 | | - |
| 81 | + var b = document.getElementById( 'section_' + section_id ), |
| 82 | + bb = b.getElementsByTagName( 'button' ); |
| 83 | + for ( var i = 0; i <= 1; i++ ) { |
| 84 | + var s = bb[i].style; |
| 85 | + s.display = s.display == 'none' || ( i && !s.display ) ? 'inline-block' : 'none'; |
| 86 | + } |
| 87 | + for ( var i = 0, d = ['content_','anchor_']; i<=1; i++ ) { |
| 88 | + var s = document.getElementById( d[i] + section_id ).style; |
| 89 | + s.display = s.display == 'block' ? 'none' : 'block'; |
| 90 | + } |
| 91 | +} |
\ No newline at end of file |
Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/MobileFrontend.php |
— | — | @@ -707,13 +707,8 @@ |
708 | 708 | return $s; |
709 | 709 | } |
710 | 710 | |
711 | | - private function removeQuerystringVar( $url, $key ) { |
712 | | - $url = preg_replace( '/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&' ); |
713 | | - $url = substr( $url, 0, -1 ); |
714 | | - return ( $url ); |
715 | | - } |
716 | | - |
717 | 711 | private function createWMLCard( $s ) { |
| 712 | + global $wgRequest; |
718 | 713 | wfProfileIn( __METHOD__ ); |
719 | 714 | $segments = explode( $this->WMLSectionSeperator, $s ); |
720 | 715 | $card = ''; |
— | — | @@ -727,20 +722,28 @@ |
728 | 723 | $card .= "<p>" . $idx . "/" . $segmentsCount . "</p>"; |
729 | 724 | |
730 | 725 | $useFormatParam = ( isset( self::$useFormat ) ) ? '&' . 'useformat=' . self::$useFormat : ''; |
731 | | - |
732 | | - $basePage = self::$currentURL; |
733 | | - |
734 | | - $basePage = $this->removeQuerystringVar( $this->removeQuerystringVar( $basePage, 'useformat' ), 'seg' ); |
735 | | - |
736 | | - $delimiter = ( strpos( $basePage, '?' ) === false ) ? '?' : '&'; |
737 | 726 | |
| 727 | + // Title::getLocalUrl doesn't work at this point since PHP 5.1.x, all objects have their destructors called |
| 728 | + // before the output buffer callback function executes. |
| 729 | + // Thus, globalized objects will not be available as expected in the function. |
| 730 | + // This is stated to be intended behavior, as per the following: [http://bugs.php.net/bug.php?id=40104] |
| 731 | + $mDefaultQuery = $wgRequest->getQueryValues(); |
| 732 | + unset( $mDefaultQuery['seg'] ); |
| 733 | + unset( $mDefaultQuery['useformat'] ); |
| 734 | + |
| 735 | + $qs = wfArrayToCGI( $mDefaultQuery ); |
| 736 | + $delimiter = ( !empty( $qs ) ) ? '?' : ''; |
| 737 | + $basePageParts = wfParseUrl( self::$currentURL ); |
| 738 | + $basePage = $basePageParts['scheme'] . $basePageParts['delimiter'] . $basePageParts['host'] . $basePageParts['path'] . $delimiter . $qs; |
| 739 | + $appendDelimiter = ( $delimiter === '?' ) ? '&' : '?'; |
| 740 | + |
738 | 741 | if ( $idx < $segmentsCount ) { |
739 | | - $card .= "<p><a href=\"{$basePage}{$delimiter}seg={$idx}{$useFormatParam}\">" . self::$messages['mobile-frontend-wml-continue'] . "</a></p>"; |
| 742 | + $card .= "<p><a href=\"{$basePage}{$appendDelimiter}seg={$idx}{$useFormatParam}\">" . self::$messages['mobile-frontend-wml-continue'] . "</a></p>"; |
740 | 743 | } |
741 | 744 | |
742 | 745 | if ( $idx > 1 ) { |
743 | 746 | $back_idx = $requestedSegment - 1; |
744 | | - $card .= "<p><a href=\"{$basePage}{$delimiter}seg={$back_idx}{$useFormatParam}\">" . self::$messages['mobile-frontend-wml-back'] . "</a></p>"; |
| 747 | + $card .= "<p><a href=\"{$basePage}{$appendDelimiter}seg={$back_idx}{$useFormatParam}\">" . self::$messages['mobile-frontend-wml-back'] . "</a></p>"; |
745 | 748 | } |
746 | 749 | |
747 | 750 | $card .= '</card>'; |
— | — | @@ -931,6 +934,8 @@ |
932 | 935 | && empty( self::$search ) && !self::$isMainPage ) { |
933 | 936 | $contentHtml = $this->headingTransform( $contentHtml ); |
934 | 937 | } elseif ( $this->contentFormat == 'WML' ) { |
| 938 | + $homeButton = self::$messages['mobile-frontend-home-button']; |
| 939 | + $randomButton = self::$messages['mobile-frontend-random-button']; |
935 | 940 | //header( 'Content-Type: text/vnd.wap.wml' ); |
936 | 941 | |
937 | 942 | // TODO: Content transformations required |
Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/views/layout/application.html.php |
— | — | @@ -34,7 +34,6 @@ |
35 | 35 | } |
36 | 36 | //]]> |
37 | 37 | </script> |
38 | | - <script type="text/javascript" language="javascript" src="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/jquery.js"></script> |
39 | 38 | <script type="text/javascript" language="javascript" src="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/application.js"></script> |
40 | 39 | </head> |
41 | 40 | <body> |