Index: trunk/extensions/MobileFrontend/javascripts/opensearch.js |
— | — | @@ -5,7 +5,8 @@ |
6 | 6 | numResults = 5, pixels = 'px', |
7 | 7 | results = document.getElementById( 'results' ), |
8 | 8 | search = document.getElementById( 'search' ), |
9 | | - sb = document.getElementById( 'searchbox' ); |
| 9 | + sb = document.getElementById( 'searchbox' ), |
| 10 | + u = MobileFrontend.utils; |
10 | 11 | |
11 | 12 | if ( scriptPath ) { |
12 | 13 | apiUrl = scriptPath + apiUrl; |
— | — | @@ -43,7 +44,7 @@ |
44 | 45 | } |
45 | 46 | |
46 | 47 | window.onload = function () { |
47 | | - search.addEventListener( 'keyup', |
| 48 | + u( search ).bind( 'keyup', |
48 | 49 | function() { |
49 | 50 | clearTimeout( timer ); |
50 | 51 | var term = this.value; |
— | — | @@ -131,7 +132,7 @@ |
132 | 133 | label = document.createTextNode( '+' ); |
133 | 134 | link.appendChild(label); |
134 | 135 | link.className = 'sq-val-update'; |
135 | | - link.addEventListener( 'click', suggestionListener ); |
| 136 | + u( link ).bind( 'click', suggestionListener ); |
136 | 137 | suggestionsResult.appendChild( link ); |
137 | 138 | |
138 | 139 | link = document.createElement( 'a' ); |
Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js |
— | — | @@ -1,5 +1,9 @@ |
2 | 2 | /*global document, window */ |
3 | 3 | /*jslint sloppy: true, white:true, maxerr: 50, indent: 4, plusplus: true*/ |
| 4 | +/* |
| 5 | +TODO: getElementsByClassName not supported by IE < 9 |
| 6 | +TODO: addEventListener not supported by IE < 9 |
| 7 | +*/ |
4 | 8 | MobileFrontend = (function() { |
5 | 9 | |
6 | 10 | function init() { |
— | — | @@ -14,7 +18,7 @@ |
15 | 19 | } |
16 | 20 | } |
17 | 21 | for( i = 0; i < sectionHeadings.length; i++ ) { |
18 | | - sectionHeadings[i].addEventListener( 'click', openSectionHandler, false ); |
| 22 | + utilities( sectionHeadings[i] ).bind( 'click', openSectionHandler, false ); |
19 | 23 | } |
20 | 24 | search = document.getElementById( 'search' ); |
21 | 25 | clearSearch = document.getElementById( 'clearsearch' ); |
— | — | @@ -29,10 +33,10 @@ |
30 | 34 | search.select(); |
31 | 35 | } |
32 | 36 | clearSearch.setAttribute( 'title', 'Clear' ); |
33 | | - clearSearch.addEventListener( 'mousedown', clearSearchBox, true ); |
34 | | - search.addEventListener( 'keyup', handleClearSearchLink, false ); |
35 | | - search.addEventListener( 'keydown', handleDefaultText, false ); |
36 | | - search.addEventListener( 'click', onFocusHandler, true ); |
| 37 | + utilities( clearSearch ).bind( 'mousedown', clearSearchBox, true ); |
| 38 | + utilities( search ).bind( 'keyup', handleClearSearchLink, false ); |
| 39 | + utilities( search ).bind( 'keydown', handleDefaultText, false ); |
| 40 | + utilities( search ).bind( 'click', onFocusHandler, true ); |
37 | 41 | } |
38 | 42 | |
39 | 43 | function navigateToLanguageSelection() { |
— | — | @@ -44,7 +48,7 @@ |
45 | 49 | } |
46 | 50 | } |
47 | 51 | } |
48 | | - languageSelection.addEventListener( 'change', navigateToLanguageSelection ); |
| 52 | + utilities( languageSelection ).bind( 'change', navigateToLanguageSelection ); |
49 | 53 | |
50 | 54 | function handleDefaultText() { |
51 | 55 | var pE = document.getElementById( 'placeholder' ); |
— | — | @@ -87,7 +91,7 @@ |
88 | 92 | search.onpaste = function() { |
89 | 93 | handleDefaultText(); |
90 | 94 | }; |
91 | | - document.getElementById( 'logo' ).addEventListener( 'click', logoClick ); |
| 95 | + utilities( document.getElementById( 'logo' ) ).bind( 'click', logoClick ); |
92 | 96 | dismissNotification = document.getElementById( 'dismiss-notification' ); |
93 | 97 | |
94 | 98 | if ( dismissNotification ) { |
— | — | @@ -115,7 +119,7 @@ |
116 | 120 | } |
117 | 121 | checkHash(); |
118 | 122 | for ( a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) { |
119 | | - a[i].addEventListener( 'click', checkHash ); |
| 123 | + utilities( a[i] ).bind( 'click', checkHash ); |
120 | 124 | } |
121 | 125 | |
122 | 126 | // Try to scroll and hide URL bar |
— | — | @@ -207,8 +211,16 @@ |
208 | 212 | el.className = newClasses.join( ' ' ); |
209 | 213 | } |
210 | 214 | |
| 215 | + function bind( type, handler ) { |
| 216 | + if ( el.addEventListener ) { // standardised browser |
| 217 | + el.addEventListener( type, handler, false ); |
| 218 | + } else if( el.attachEvent ) { |
| 219 | + el.attachEvent( 'on' + type, handler ); |
| 220 | + } |
| 221 | + } |
211 | 222 | return { |
212 | 223 | addClass: addClass, |
| 224 | + bind: bind, |
213 | 225 | removeClass: removeClass |
214 | 226 | }; |
215 | 227 | } |
Index: trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js |
— | — | @@ -14,7 +14,8 @@ |
15 | 15 | zeroRatedBanner = document.getElementById( 'zero-rated-banner' ) || |
16 | 16 | document.getElementById( 'zero-rated-banner-red' ), |
17 | 17 | clearSearch = document.getElementById( 'clearsearch' ), |
18 | | - focused = false, ol = {}; |
| 18 | + focused = false, ol = {}, |
| 19 | + u = MobileFrontend.utils; |
19 | 20 | |
20 | 21 | if ( scriptPath ) { |
21 | 22 | apiUrl = scriptPath + apiUrl; |
— | — | @@ -28,7 +29,7 @@ |
29 | 30 | var viewportmeta = document.querySelector( 'meta[name="viewport"]' ); |
30 | 31 | if ( viewportmeta ) { |
31 | 32 | viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0'; |
32 | | - document.body.addEventListener( 'gesturestart', function () { |
| 33 | + u( document.body ).bind( 'gesturestart', function () { |
33 | 34 | viewportmeta.content = 'width=device-width, initial-scale=1.0'; |
34 | 35 | }, false ); |
35 | 36 | } |
— | — | @@ -72,7 +73,7 @@ |
73 | 74 | rrd = document.createElement( 'a' ); |
74 | 75 | rrd.setAttribute( 'href', '#' ); |
75 | 76 | rrd.setAttribute( 'id', 'remove-results' ); |
76 | | - rrd.addEventListener( 'click', removeResults ); |
| 77 | + u( rrd ).bind( 'click', removeResults ); |
77 | 78 | rrdD = document.createElement( 'div' ); |
78 | 79 | rrdD.setAttribute( 'id', 'left-arrow' ); |
79 | 80 | rrd.appendChild( rrdD ); |
— | — | @@ -135,7 +136,7 @@ |
136 | 137 | } |
137 | 138 | |
138 | 139 | window.onload = function () { |
139 | | - search.addEventListener( 'keyup', |
| 140 | + u( search ).bind( 'keyup', |
140 | 141 | function() { |
141 | 142 | clearTimeout( timer ); |
142 | 143 | term = this.value; |
— | — | @@ -233,7 +234,7 @@ |
234 | 235 | label = document.createTextNode( '+' ); |
235 | 236 | link.appendChild(label); |
236 | 237 | link.className = 'sq-val-update'; |
237 | | - link.addEventListener( 'click', suggestionListener ); |
| 238 | + u( link ).bind( 'click', suggestionListener ); |
238 | 239 | suggestionsResult.appendChild( link ); |
239 | 240 | |
240 | 241 | link = document.createElement( 'a' ); |
Index: trunk/extensions/MobileFrontend/javascripts/application.js |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | } |
16 | 16 | } |
17 | 17 | for( i = 0; i < sectionHeadings.length; i++ ) { |
18 | | - sectionHeadings[i].addEventListener( 'click', openSectionHandler, false ); |
| 18 | + utilities( sectionHeadings[i] ).bind( 'click', openSectionHandler, false ); |
19 | 19 | } |
20 | 20 | search = document.getElementById( 'search' ); |
21 | 21 | clearSearch = document.getElementById( 'clearsearch' ); |
— | — | @@ -26,9 +26,9 @@ |
27 | 27 | search.select(); |
28 | 28 | } |
29 | 29 | clearSearch.setAttribute( 'title', 'Clear' ); |
30 | | - clearSearch.addEventListener( 'mousedown', clearSearchBox, true ); |
31 | | - search.addEventListener( 'keyup', handleClearSearchLink, false ); |
32 | | - search.addEventListener( 'click', onFocusHandler, true ); |
| 30 | + utilities( clearSearch ).bind( 'mousedown', clearSearchBox, true ); |
| 31 | + utilities( search ).bind( 'keyup', handleClearSearchLink, false ); |
| 32 | + utilities( search ).bind( 'click', onFocusHandler, true ); |
33 | 33 | } |
34 | 34 | |
35 | 35 | function navigateToLanguageSelection() { |
— | — | @@ -40,7 +40,7 @@ |
41 | 41 | } |
42 | 42 | } |
43 | 43 | } |
44 | | - languageSelection.addEventListener( 'change', navigateToLanguageSelection ); |
| 44 | + utilities( languageSelection ).bind( 'change', navigateToLanguageSelection ); |
45 | 45 | |
46 | 46 | function handleClearSearchLink() { |
47 | 47 | if ( clearSearch ) { |
— | — | @@ -79,7 +79,7 @@ |
80 | 80 | } |
81 | 81 | } |
82 | 82 | initClearSearchLink(); |
83 | | - document.getElementById( 'logo' ).addEventListener( 'click', logoClick ); |
| 83 | + utilities( document.getElementById( 'logo' ) ).bind( 'click', logoClick ); |
84 | 84 | dismissNotification = document.getElementById( 'dismiss-notification' ); |
85 | 85 | |
86 | 86 | if ( dismissNotification ) { |
— | — | @@ -107,7 +107,7 @@ |
108 | 108 | } |
109 | 109 | checkHash(); |
110 | 110 | for ( a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) { |
111 | | - a[i].addEventListener( 'click', checkHash ); |
| 111 | + utilities( a[i] ).bind( 'click', checkHash ); |
112 | 112 | } |
113 | 113 | |
114 | 114 | // Try to scroll and hide URL bar |
— | — | @@ -199,8 +199,16 @@ |
200 | 200 | el.className = newClasses.join( ' ' ); |
201 | 201 | } |
202 | 202 | |
| 203 | + function bind( type, handler ) { |
| 204 | + if ( el.addEventListener ) { // standardised browser |
| 205 | + el.addEventListener( type, handler, false ); |
| 206 | + } else if( el.attachEvent ) { |
| 207 | + el.attachEvent( 'on' + type, handler ); |
| 208 | + } |
| 209 | + } |
203 | 210 | return { |
204 | 211 | addClass: addClass, |
| 212 | + bind: bind, |
205 | 213 | removeClass: removeClass |
206 | 214 | }; |
207 | 215 | } |