r112481 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112480‎ | r112481 | r112482 >
Date:13:14, 27 February 2012
Author:jdlrobson
Status:ok
Tags:
Comment:
abstract document.querySelectorAll

some browsers do not support querySelectorAll or getElementsByClassName
therefore am abstracting this so javascript doesn't break on these browsers
libraries such as zepto or jquery should be substitute in where necessary to make
these browsers work
Modified paths:
  • /trunk/extensions/MobileFrontend/javascripts/application.js (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/beta_application.js (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js
@@ -5,10 +5,11 @@
66 TODO: addEventListener not supported by IE < 9
77 */
88 MobileFrontend = (function() {
 9+ var utilities;
910
1011 function init() {
1112 var i, search, clearSearch, results, languageSelection, a, heading,
12 - sectionHeadings = document.getElementsByClassName( 'section_heading' );
 13+ sectionHeadings = utilities( '.section_heading' );
1314 utilities( document.body ).addClass( 'jsEnabled' );
1415 function openSectionHandler() {
1516 var sectionNumber = this.id ? this.id.split( '_' )[1] : -1;
@@ -65,7 +66,6 @@
6667 // Try to scroll and hide URL bar
6768 window.scrollTo( 0, 1 );
6869 }
69 - init();
7070
7171 function wm_reveal_for_hash( hash ) {
7272 var targetel = document.getElementById( hash.substr(1) ),
@@ -99,6 +99,12 @@
100100 }
101101
102102 function utilities( el ) {
 103+ if( typeof(el) === 'string' ) {
 104+ if( document.querySelectorAll ) {
 105+ return document.querySelectorAll( el );
 106+ }
 107+ }
 108+
103109 function addClass( name ) {
104110 var className = el.className,
105111 classNames = className.split( ' ' );
@@ -144,6 +150,7 @@
145151 xmlHttp.send();
146152 };
147153
 154+ init();
148155 return {
149156 wm_reveal_for_hash: wm_reveal_for_hash,
150157 wm_toggle_section: wm_toggle_section,
Index: trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js
@@ -26,7 +26,7 @@
2727 }
2828 function resetViewPort() {
2929 if ( navigator.userAgent.match( /iPhone/i ) || navigator.userAgent.match( /iPad/i ) ) {
30 - var viewportmeta = document.querySelector( 'meta[name="viewport"]' );
 30+ var viewportmeta = utilities( 'meta[name="viewport"]' );
3131 if ( viewportmeta ) {
3232 viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
3333 u( document.body ).bind( 'gesturestart', function () {
Index: trunk/extensions/MobileFrontend/javascripts/application.js
@@ -1,10 +1,11 @@
22 /*global document, window */
33 /*jslint sloppy: true, white:true, maxerr: 50, indent: 4, plusplus: true*/
44 MobileFrontend = (function() {
 5+ var utilities;
56
67 function init() {
78 var i, results, languageSelection, a, heading,
8 - sectionHeadings = document.getElementsByClassName( 'section_heading' );
 9+ sectionHeadings = utilities( '.section_heading' );
910 utilities( document.body ).addClass( 'jsEnabled' );
1011 function openSectionHandler() {
1112 var sectionNumber = this.id ? this.id.split( '_' )[1] : -1;
@@ -61,7 +62,6 @@
6263 // Try to scroll and hide URL bar
6364 window.scrollTo( 0, 1 );
6465 }
65 - init();
6666
6767 function wm_reveal_for_hash( hash ) {
6868 var targetel = document.getElementById( hash.substr(1) ),
@@ -94,7 +94,12 @@
9595 }
9696 }
9797
98 - function utilities( el ) {
 98+ utilities = function( el ) {
 99+ if( typeof(el) === 'string' ) {
 100+ if( document.querySelectorAll ) {
 101+ return document.querySelectorAll( el );
 102+ }
 103+ }
99104 function addClass( name ) {
100105 var className = el.className,
101106 classNames = className.split( ' ' );
@@ -140,6 +145,7 @@
141146 xmlHttp.send();
142147 };
143148
 149+ init();
144150 return {
145151 wm_reveal_for_hash: wm_reveal_for_hash,
146152 wm_toggle_section: wm_toggle_section,

Status & tagging log