Index: trunk/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.closest( '.section_heading' ).next( '.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: trunk/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> |