Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js |
— | — | @@ -1,29 +1,31 @@ |
2 | | -MobileFrontend = function() { |
| 2 | +/*global document, window */ |
| 3 | +/*jslint sloppy: true, white:true, maxerr: 50, indent: 4, plusplus: true*/ |
| 4 | +MobileFrontend = (function() { |
3 | 5 | |
4 | 6 | function init() { |
| 7 | + var i, search, clearSearch, results, languageSelection, a, |
| 8 | + sectionHeadings = document.getElementsByClassName( 'section_heading' ), |
| 9 | + dismissNotification, cookieNameZeroVisibility, zeroRatedBanner, zeroRatedBannerVisibility; |
5 | 10 | document.body.className = "jsEnabled"; |
6 | | - var sectionHeadings = document.getElementsByClassName( 'section_heading' ); |
7 | | - for( var i = 0; i < sectionHeadings.length; i++ ) { |
8 | | - sectionHeadings[i].addEventListener( 'click', function() { |
9 | | - var sectionNumber = this.id ? this.id.split( '_' )[1] : -1; |
10 | | - if(sectionNumber > -1) { |
11 | | - wm_toggle_section( sectionNumber ); |
12 | | - } |
13 | | - }, false ); |
| 11 | + function openSectionHandler() { |
| 12 | + var sectionNumber = this.id ? this.id.split( '_' )[1] : -1; |
| 13 | + if( sectionNumber > -1 ) { |
| 14 | + wm_toggle_section( sectionNumber ); |
| 15 | + } |
14 | 16 | } |
15 | | - var search = document.getElementById( 'search' ); |
16 | | - var clearSearch = document.getElementById( 'clearsearch' ); |
17 | | - var results = document.getElementById( 'results' ); |
18 | | - var languageSelection = document.getElementById( 'languageselection' ); |
| 17 | + for( i = 0; i < sectionHeadings.length; i++ ) { |
| 18 | + sectionHeadings[i].addEventListener( 'click', openSectionHandler, false ); |
| 19 | + } |
| 20 | + search = document.getElementById( 'search' ); |
| 21 | + clearSearch = document.getElementById( 'clearsearch' ); |
| 22 | + results = document.getElementById( 'results' ); |
| 23 | + languageSelection = document.getElementById( 'languageselection' ); |
19 | 24 | |
20 | | - var zeroRatedBanner = document.getElementById( 'zero-rated-banner' ); |
| 25 | + zeroRatedBanner = document.getElementById( 'zero-rated-banner' ) || |
| 26 | + document.getElementById( 'zero-rated-banner-red' ); |
21 | 27 | |
22 | | - if ( !zeroRatedBanner ) { |
23 | | - var zeroRatedBanner = document.getElementById( 'zero-rated-banner-red' ); |
24 | | - } |
25 | | - |
26 | 28 | function initClearSearchLink() { |
27 | | - clearSearch.setAttribute( 'title','Clear' ); |
| 29 | + clearSearch.setAttribute( 'title', 'Clear' ); |
28 | 30 | clearSearch.addEventListener( 'mousedown', clearSearchBox, true ); |
29 | 31 | search.addEventListener( 'keyup', handleClearSearchLink, false ); |
30 | 32 | search.addEventListener( 'keydown', handleDefaultText, false ); |
— | — | @@ -38,7 +40,7 @@ |
39 | 41 | } |
40 | 42 | } |
41 | 43 | } |
42 | | - document.getElementById( 'languageselection' ).addEventListener( 'change', navigateToLanguageSelection ); |
| 44 | + languageSelection.addEventListener( 'change', navigateToLanguageSelection ); |
43 | 45 | |
44 | 46 | function handleDefaultText() { |
45 | 47 | var pE = document.getElementById( 'placeholder' ); |
— | — | @@ -66,28 +68,28 @@ |
67 | 69 | } |
68 | 70 | |
69 | 71 | function logoClick() { |
70 | | - var n = document.getElementById( 'nav' ).style; |
71 | | - n.display = n.display == 'block' ? 'none' : 'block'; |
72 | | - if (n.display == 'block') { |
| 72 | + var n = document.getElementById( 'nav' ).style, newWidth; |
| 73 | + n.display = n.display === 'block' ? 'none' : 'block'; |
| 74 | + if (n.display === 'block') { |
73 | 75 | if ( languageSelection ) { |
74 | 76 | if ( languageSelection.offsetWidth > 175 ) { |
75 | | - var newWidth = languageSelection.offsetWidth + 30; |
| 77 | + newWidth = languageSelection.offsetWidth + 30; |
76 | 78 | n.width = newWidth + 'px'; |
77 | 79 | } |
78 | 80 | } |
79 | 81 | } |
80 | | - }; |
| 82 | + } |
81 | 83 | initClearSearchLink(); |
82 | 84 | search.onpaste = function() { |
83 | 85 | handleDefaultText(); |
84 | 86 | }; |
85 | 87 | document.getElementById( 'logo' ).addEventListener( 'click', logoClick ); |
86 | | - var dismissNotification = document.getElementById( 'dismiss-notification' ); |
| 88 | + dismissNotification = document.getElementById( 'dismiss-notification' ); |
87 | 89 | |
88 | 90 | if ( dismissNotification ) { |
89 | | - var cookieNameZeroVisibility = 'zeroRatedBannerVisibility'; |
90 | | - var zeroRatedBanner = document.getElementById( 'zero-rated-banner' ); |
91 | | - var zeroRatedBannerVisibility = readCookie( cookieNameZeroVisibility ); |
| 91 | + cookieNameZeroVisibility = 'zeroRatedBannerVisibility'; |
| 92 | + zeroRatedBanner = document.getElementById( 'zero-rated-banner' ); |
| 93 | + zeroRatedBannerVisibility = readCookie( cookieNameZeroVisibility ); |
92 | 94 | |
93 | 95 | if ( zeroRatedBannerVisibility === 'off' ) { |
94 | 96 | zeroRatedBanner.style.display = 'none'; |
— | — | @@ -100,17 +102,17 @@ |
101 | 103 | } |
102 | 104 | }; |
103 | 105 | } |
104 | | - if ( document.location.hash.indexOf( '#' ) == 0 ) { |
105 | | - wm_reveal_for_hash( document.location.hash ); |
106 | | - } |
107 | 106 | |
108 | | - for ( var a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) { |
109 | | - a[i].addEventListener( 'click', function() { |
110 | | - if ( this.hash.indexOf( '#' ) == 0 ) { |
111 | | - wm_reveal_for_hash( this.hash ); |
112 | | - } |
113 | | - }); |
| 107 | + function checkHash() { |
| 108 | + var hash = this.hash || document.location.hash; |
| 109 | + if ( hash.indexOf( '#' ) === 0 ) { |
| 110 | + wm_reveal_for_hash( hash ); |
| 111 | + } |
114 | 112 | } |
| 113 | + checkHash(); |
| 114 | + for ( a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) { |
| 115 | + a[i].addEventListener( 'click', checkHash ); |
| 116 | + } |
115 | 117 | |
116 | 118 | // Try to scroll and hide URL bar |
117 | 119 | window.scrollTo( 0, 1 ); |
— | — | @@ -118,13 +120,16 @@ |
119 | 121 | init(); |
120 | 122 | |
121 | 123 | function wm_reveal_for_hash( hash ) { |
122 | | - var targetel = document.getElementById( hash.substr(1) ); |
| 124 | + var targetel = document.getElementById( hash.substr(1) ), |
| 125 | + p, section_idx; |
123 | 126 | if ( targetel ) { |
124 | | - for (var p = targetel.parentNode; p && p.className != 'content_block' && p.className != 'section_heading'; ) { |
| 127 | + p = targetel; |
| 128 | + while ( p && p.className !== 'content_block' && |
| 129 | + p.className !== 'section_heading' ) { |
125 | 130 | p = p.parentNode; |
126 | 131 | } |
127 | | - if ( p && p.style.display != 'block' ) { |
128 | | - var section_idx = parseInt( p.id.split( '_' )[1] ); |
| 132 | + if ( p && p.style.display !== 'block' ) { |
| 133 | + section_idx = parseInt( p.id.split( '_' )[1], 10 ); |
129 | 134 | wm_toggle_section( section_idx ); |
130 | 135 | } |
131 | 136 | } |
— | — | @@ -132,40 +137,41 @@ |
133 | 138 | |
134 | 139 | function wm_toggle_section( section_id ) { |
135 | 140 | var b = document.getElementById( 'section_' + section_id ), |
136 | | - bb = b.getElementsByTagName( 'button' ); |
137 | | - for ( var i = 0; i <= 1; i++ ) { |
138 | | - var s = bb[i].style; |
139 | | - s.display = s.display == 'none' || ( i && !s.display ) ? 'inline-block' : 'none'; |
| 141 | + bb = b.getElementsByTagName( 'button' ), i, s, e; |
| 142 | + for ( i = 0; i <= 1; i++ ) { |
| 143 | + s = bb[i].style; |
| 144 | + s.display = s.display === 'none' || ( i && !s.display ) ? 'inline-block' : 'none'; |
140 | 145 | } |
141 | | - for ( var i = 0, d = ['content_','anchor_']; i<=1; i++ ) { |
142 | | - var e = document.getElementById( d[i] + section_id ); |
143 | | - |
| 146 | + for ( i = 0, d = ['content_','anchor_']; i<=1; i++ ) { |
| 147 | + e = document.getElementById( d[i] + section_id ); |
144 | 148 | if ( e ) { |
145 | | - e.style.display = e.style.display == 'block' ? 'none' : 'block'; |
| 149 | + e.style.display = e.style.display === 'block' ? 'none' : 'block'; |
146 | 150 | } |
147 | 151 | } |
148 | 152 | } |
149 | 153 | |
150 | 154 | function writeCookie( name, value, days ) { |
| 155 | + var date, expires; |
151 | 156 | if ( days ) { |
152 | | - var date = new Date(); |
| 157 | + date = new Date(); |
153 | 158 | date.setTime( date.getTime() + ( days * 24 * 60 * 60 *1000 ) ); |
154 | | - var expires = '; expires=' + date.toGMTString(); |
| 159 | + expires = '; expires=' + date.toGMTString(); |
155 | 160 | } else { |
156 | | - var expires = ''; |
| 161 | + expires = ''; |
157 | 162 | } |
158 | 163 | document.cookie = name + '=' + value + expires + '; path=/'; |
159 | 164 | } |
160 | 165 | |
161 | 166 | function readCookie( name ) { |
162 | | - var nameVA = name + '='; |
163 | | - var ca = document.cookie.split( ';' ); |
164 | | - for( var i=0; i < ca.length; i++ ) { |
165 | | - var c = ca[i]; |
| 167 | + var nameVA = name + '=', |
| 168 | + ca = document.cookie.split( ';' ), |
| 169 | + c, i; |
| 170 | + for( i=0; i < ca.length; i++ ) { |
| 171 | + c = ca[i]; |
166 | 172 | while ( c.charAt(0) === ' ' ) { |
167 | 173 | c = c.substring( 1, c.length ); |
168 | 174 | } |
169 | | - if ( c.indexOf( nameVA ) == 0 ) { |
| 175 | + if ( c.indexOf( nameVA ) === 0 ) { |
170 | 176 | return c.substring( nameVA.length, c.length ); |
171 | 177 | } |
172 | 178 | } |
— | — | @@ -179,8 +185,8 @@ |
180 | 186 | |
181 | 187 | function utilities( el ) { |
182 | 188 | function addClass( name ) { |
183 | | - var className = el.className; |
184 | | - var classNames = className.split( ' ' ); |
| 189 | + var className = el.className, |
| 190 | + classNames = className.split( ' ' ); |
185 | 191 | classNames.push(name); // TODO: only push if unique |
186 | 192 | el.className = classNames.join( ' ' ); |
187 | 193 | } |
— | — | @@ -213,5 +219,4 @@ |
214 | 220 | utils: utilities |
215 | 221 | }; |
216 | 222 | |
217 | | -}(); |
218 | | - |
| 223 | +}()); |
Index: trunk/extensions/MobileFrontend/javascripts/application.js |
— | — | @@ -1,23 +1,28 @@ |
2 | | -MobileFrontend = function() { |
| 2 | +/*global document, window */ |
| 3 | +/*jslint sloppy: true, white:true, maxerr: 50, indent: 4, plusplus: true*/ |
| 4 | +MobileFrontend = (function() { |
3 | 5 | |
4 | 6 | function init() { |
| 7 | + var i, search, clearSearch, results, languageSelection, a, |
| 8 | + sectionHeadings = document.getElementsByClassName( 'section_heading' ), |
| 9 | + dismissNotification, cookieNameZeroVisibility, zeroRatedBanner, zeroRatedBannerVisibility; |
5 | 10 | document.body.className = "jsEnabled"; |
6 | | - var sectionHeadings = document.getElementsByClassName( 'section_heading' ); |
7 | | - for( var i = 0; i < sectionHeadings.length; i++ ) { |
8 | | - sectionHeadings[i].addEventListener( 'click', function() { |
9 | | - var sectionNumber = this.id ? this.id.split( '_' )[1] : -1; |
10 | | - if(sectionNumber > -1) { |
11 | | - wm_toggle_section( sectionNumber ); |
12 | | - } |
13 | | - }, false ); |
| 11 | + function openSectionHandler() { |
| 12 | + var sectionNumber = this.id ? this.id.split( '_' )[1] : -1; |
| 13 | + if( sectionNumber > -1 ) { |
| 14 | + wm_toggle_section( sectionNumber ); |
| 15 | + } |
14 | 16 | } |
15 | | - var search = document.getElementById( 'search' ); |
16 | | - var clearSearch = document.getElementById( 'clearsearch' ); |
17 | | - var results = document.getElementById( 'results' ); |
18 | | - var languageSelection = document.getElementById( 'languageselection' ); |
| 17 | + for( i = 0; i < sectionHeadings.length; i++ ) { |
| 18 | + sectionHeadings[i].addEventListener( 'click', openSectionHandler, false ); |
| 19 | + } |
| 20 | + search = document.getElementById( 'search' ); |
| 21 | + clearSearch = document.getElementById( 'clearsearch' ); |
| 22 | + results = document.getElementById( 'results' ); |
| 23 | + languageSelection = document.getElementById( 'languageselection' ); |
19 | 24 | |
20 | 25 | function initClearSearchLink() { |
21 | | - clearSearch.setAttribute( 'title','Clear' ); |
| 26 | + clearSearch.setAttribute( 'title', 'Clear' ); |
22 | 27 | clearSearch.addEventListener( 'mousedown', clearSearchBox, true ); |
23 | 28 | search.addEventListener( 'keyup', handleClearSearchLink, false ); |
24 | 29 | } |
— | — | @@ -31,7 +36,7 @@ |
32 | 37 | } |
33 | 38 | } |
34 | 39 | } |
35 | | - document.getElementById( 'languageselection' ).addEventListener( 'change', navigateToLanguageSelection ); |
| 40 | + languageSelection.addEventListener( 'change', navigateToLanguageSelection ); |
36 | 41 | |
37 | 42 | function handleClearSearchLink() { |
38 | 43 | if ( clearSearch ) { |
— | — | @@ -58,25 +63,25 @@ |
59 | 64 | } |
60 | 65 | |
61 | 66 | function logoClick() { |
62 | | - var n = document.getElementById( 'nav' ).style; |
63 | | - n.display = n.display == 'block' ? 'none' : 'block'; |
64 | | - if (n.display == 'block') { |
| 67 | + var n = document.getElementById( 'nav' ).style, newWidth; |
| 68 | + n.display = n.display === 'block' ? 'none' : 'block'; |
| 69 | + if (n.display === 'block') { |
65 | 70 | if ( languageSelection ) { |
66 | 71 | if ( languageSelection.offsetWidth > 175 ) { |
67 | | - var newWidth = languageSelection.offsetWidth + 30; |
| 72 | + newWidth = languageSelection.offsetWidth + 30; |
68 | 73 | n.width = newWidth + 'px'; |
69 | 74 | } |
70 | 75 | } |
71 | 76 | } |
72 | | - }; |
| 77 | + } |
73 | 78 | initClearSearchLink(); |
74 | 79 | document.getElementById( 'logo' ).addEventListener( 'click', logoClick ); |
75 | | - var dismissNotification = document.getElementById( 'dismiss-notification' ); |
| 80 | + dismissNotification = document.getElementById( 'dismiss-notification' ); |
76 | 81 | |
77 | 82 | if ( dismissNotification ) { |
78 | | - var cookieNameZeroVisibility = 'zeroRatedBannerVisibility'; |
79 | | - var zeroRatedBanner = document.getElementById( 'zero-rated-banner' ); |
80 | | - var zeroRatedBannerVisibility = readCookie( cookieNameZeroVisibility ); |
| 83 | + cookieNameZeroVisibility = 'zeroRatedBannerVisibility'; |
| 84 | + zeroRatedBanner = document.getElementById( 'zero-rated-banner' ); |
| 85 | + zeroRatedBannerVisibility = readCookie( cookieNameZeroVisibility ); |
81 | 86 | |
82 | 87 | if ( zeroRatedBannerVisibility === 'off' ) { |
83 | 88 | zeroRatedBanner.style.display = 'none'; |
— | — | @@ -89,17 +94,17 @@ |
90 | 95 | } |
91 | 96 | }; |
92 | 97 | } |
93 | | - if ( document.location.hash.indexOf( '#' ) == 0 ) { |
94 | | - wm_reveal_for_hash( document.location.hash ); |
95 | | - } |
96 | 98 | |
97 | | - for ( var a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) { |
98 | | - a[i].addEventListener( 'click', function() { |
99 | | - if ( this.hash.indexOf( '#' ) == 0 ) { |
100 | | - wm_reveal_for_hash( this.hash ); |
101 | | - } |
102 | | - }); |
| 99 | + function checkHash() { |
| 100 | + var hash = this.hash || document.location.hash; |
| 101 | + if ( hash.indexOf( '#' ) === 0 ) { |
| 102 | + wm_reveal_for_hash( hash ); |
| 103 | + } |
103 | 104 | } |
| 105 | + checkHash(); |
| 106 | + for ( a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) { |
| 107 | + a[i].addEventListener( 'click', checkHash ); |
| 108 | + } |
104 | 109 | |
105 | 110 | // Try to scroll and hide URL bar |
106 | 111 | window.scrollTo( 0, 1 ); |
— | — | @@ -107,13 +112,16 @@ |
108 | 113 | init(); |
109 | 114 | |
110 | 115 | function wm_reveal_for_hash( hash ) { |
111 | | - var targetel = document.getElementById( hash.substr(1) ); |
| 116 | + var targetel = document.getElementById( hash.substr(1) ), |
| 117 | + p, section_idx; |
112 | 118 | if ( targetel ) { |
113 | | - for (var p = targetel.parentNode; p && p.className != 'content_block' && p.className != 'section_heading'; ) { |
| 119 | + p = targetel; |
| 120 | + while ( p && p.className !== 'content_block' && |
| 121 | + p.className !== 'section_heading' ) { |
114 | 122 | p = p.parentNode; |
115 | 123 | } |
116 | | - if ( p && p.style.display != 'block' ) { |
117 | | - var section_idx = parseInt( p.id.split( '_' )[1] ); |
| 124 | + if ( p && p.style.display !== 'block' ) { |
| 125 | + section_idx = parseInt( p.id.split( '_' )[1], 10 ); |
118 | 126 | wm_toggle_section( section_idx ); |
119 | 127 | } |
120 | 128 | } |
— | — | @@ -121,40 +129,41 @@ |
122 | 130 | |
123 | 131 | function wm_toggle_section( section_id ) { |
124 | 132 | var b = document.getElementById( 'section_' + section_id ), |
125 | | - bb = b.getElementsByTagName( 'button' ); |
126 | | - for ( var i = 0; i <= 1; i++ ) { |
127 | | - var s = bb[i].style; |
128 | | - s.display = s.display == 'none' || ( i && !s.display ) ? 'inline-block' : 'none'; |
| 133 | + bb = b.getElementsByTagName( 'button' ), i, s, e; |
| 134 | + for ( i = 0; i <= 1; i++ ) { |
| 135 | + s = bb[i].style; |
| 136 | + s.display = s.display === 'none' || ( i && !s.display ) ? 'inline-block' : 'none'; |
129 | 137 | } |
130 | | - for ( var i = 0, d = ['content_','anchor_']; i<=1; i++ ) { |
131 | | - var e = document.getElementById( d[i] + section_id ); |
132 | | - |
| 138 | + for ( i = 0, d = ['content_','anchor_']; i<=1; i++ ) { |
| 139 | + e = document.getElementById( d[i] + section_id ); |
133 | 140 | if ( e ) { |
134 | | - e.style.display = e.style.display == 'block' ? 'none' : 'block'; |
| 141 | + e.style.display = e.style.display === 'block' ? 'none' : 'block'; |
135 | 142 | } |
136 | 143 | } |
137 | 144 | } |
138 | 145 | |
139 | 146 | function writeCookie( name, value, days ) { |
| 147 | + var date, expires; |
140 | 148 | if ( days ) { |
141 | | - var date = new Date(); |
| 149 | + date = new Date(); |
142 | 150 | date.setTime( date.getTime() + ( days * 24 * 60 * 60 *1000 ) ); |
143 | | - var expires = '; expires=' + date.toGMTString(); |
| 151 | + expires = '; expires=' + date.toGMTString(); |
144 | 152 | } else { |
145 | | - var expires = ''; |
| 153 | + expires = ''; |
146 | 154 | } |
147 | 155 | document.cookie = name + '=' + value + expires + '; path=/'; |
148 | 156 | } |
149 | 157 | |
150 | 158 | function readCookie( name ) { |
151 | | - var nameVA = name + '='; |
152 | | - var ca = document.cookie.split( ';' ); |
153 | | - for( var i=0; i < ca.length; i++ ) { |
154 | | - var c = ca[i]; |
| 159 | + var nameVA = name + '=', |
| 160 | + ca = document.cookie.split( ';' ), |
| 161 | + c, i; |
| 162 | + for( i=0; i < ca.length; i++ ) { |
| 163 | + c = ca[i]; |
155 | 164 | while ( c.charAt(0) === ' ' ) { |
156 | 165 | c = c.substring( 1, c.length ); |
157 | 166 | } |
158 | | - if ( c.indexOf( nameVA ) == 0 ) { |
| 167 | + if ( c.indexOf( nameVA ) === 0 ) { |
159 | 168 | return c.substring( nameVA.length, c.length ); |
160 | 169 | } |
161 | 170 | } |
— | — | @@ -168,8 +177,8 @@ |
169 | 178 | |
170 | 179 | function utilities( el ) { |
171 | 180 | function addClass( name ) { |
172 | | - var className = el.className; |
173 | | - var classNames = className.split( ' ' ); |
| 181 | + var className = el.className, |
| 182 | + classNames = className.split( ' ' ); |
174 | 183 | classNames.push(name); // TODO: only push if unique |
175 | 184 | el.className = classNames.join( ' ' ); |
176 | 185 | } |
— | — | @@ -202,5 +211,4 @@ |
203 | 212 | utils: utilities |
204 | 213 | }; |
205 | 214 | |
206 | | -}(); |
207 | | - |
| 215 | +}()); |