r97214 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97213‎ | r97214 | r97215 >
Date:22:10, 15 September 2011
Author:preilly
Status:deferred
Tags:
Comment:
fix for bug 30650 - remove jQuery from mobile site
Modified paths:
  • /trunk/extensions/MobileFrontend/javascripts/application.js (modified) (history)
  • /trunk/extensions/MobileFrontend/views/layout/application.html.php (modified) (history)

Diff [purge]

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+ };
412
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+ };
922
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+ }
1929 }
20 - });
 30+ };
2131
22 - if( document.location.hash.indexOf( '#' ) == 0 ) {
 32+ if ( document.location.hash.indexOf( '#' ) == 0 ) {
2333 wm_reveal_for_hash( document.location.hash );
2434 }
2535
@@ -27,11 +37,12 @@
2838 // Try to scroll and hide URL bar
2939 window.scrollTo( 0, 1 );
3040
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+};
3647
3748 /**
3849 * updateOrientation checks the current orientation, sets the body's class
@@ -53,26 +64,27 @@
5465 window.onorientationchange = updateOrientation;
5566
5667 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] );
6275 wm_toggle_section( section_idx );
6376 }
6477 }
6578 }
6679
6780 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 @@
3535 }
3636 //]]>
3737 </script>
38 - <script type="text/javascript" language="javascript" src="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/jquery.js"></script>
3938 <script type="text/javascript" language="javascript" src="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/application.js"></script>
4039 </head>
4140 <body>

Follow-up revisions

RevisionCommit summaryAuthorDate
r97215mft r97214 and r97076preilly22:14, 15 September 2011

Status & tagging log