r111747 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111746‎ | r111747 | r111748 >
Date:12:41, 17 February 2012
Author:jdlrobson
Status:ok
Tags:
Comment:
indent encapsulated code
Modified paths:
  • /trunk/extensions/MobileFrontend/javascripts/application.js (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/beta_application.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js
@@ -1,190 +1,190 @@
22 MobileFrontend = function() {
33
4 -function init() {
5 - 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 );
14 - }
15 - var search = document.getElementById( 'search' );
16 - var clearSearch = document.getElementById( 'clearsearch' );
17 - var results = document.getElementById( 'results' );
18 - var languageSelection = document.getElementById( 'languageselection' );
 4+ function init() {
 5+ 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 );
 14+ }
 15+ var search = document.getElementById( 'search' );
 16+ var clearSearch = document.getElementById( 'clearsearch' );
 17+ var results = document.getElementById( 'results' );
 18+ var languageSelection = document.getElementById( 'languageselection' );
1919
20 - var zeroRatedBanner = document.getElementById( 'zero-rated-banner' );
 20+ var zeroRatedBanner = document.getElementById( 'zero-rated-banner' );
2121
22 - if ( !zeroRatedBanner ) {
23 - var zeroRatedBanner = document.getElementById( 'zero-rated-banner-red' );
24 - }
 22+ if ( !zeroRatedBanner ) {
 23+ var zeroRatedBanner = document.getElementById( 'zero-rated-banner-red' );
 24+ }
2525
26 - function initClearSearchLink() {
27 - clearSearch.setAttribute( 'title','Clear' );
28 - clearSearch.addEventListener( 'mousedown', clearSearchBox, true );
29 - search.addEventListener( 'keyup', handleClearSearchLink, false );
30 - search.addEventListener( 'keydown', handleDefaultText, false );
31 - }
 26+ function initClearSearchLink() {
 27+ clearSearch.setAttribute( 'title','Clear' );
 28+ clearSearch.addEventListener( 'mousedown', clearSearchBox, true );
 29+ search.addEventListener( 'keyup', handleClearSearchLink, false );
 30+ search.addEventListener( 'keydown', handleDefaultText, false );
 31+ }
3232
33 - function navigateToLanguageSelection() {
34 - var url;
35 - if ( languageSelection ) {
36 - url = languageSelection.options[languageSelection.selectedIndex].value;
37 - if ( url ) {
38 - location.href = url;
 33+ function navigateToLanguageSelection() {
 34+ var url;
 35+ if ( languageSelection ) {
 36+ url = languageSelection.options[languageSelection.selectedIndex].value;
 37+ if ( url ) {
 38+ location.href = url;
 39+ }
3940 }
4041 }
41 - }
42 - document.getElementById( 'languageselection' ).addEventListener( 'change', navigateToLanguageSelection );
 42+ document.getElementById( 'languageselection' ).addEventListener( 'change', navigateToLanguageSelection );
4343
44 - function handleDefaultText() {
45 - var pE = document.getElementById( 'placeholder' );
46 - if ( pE ) {
47 - pE.style.display = 'none';
 44+ function handleDefaultText() {
 45+ var pE = document.getElementById( 'placeholder' );
 46+ if ( pE ) {
 47+ pE.style.display = 'none';
 48+ }
4849 }
49 - }
5050
51 - function handleClearSearchLink() {
52 - if ( clearSearch ) {
53 - if ( search.value.length > 0 ) {
54 - clearSearch.style.display = 'block';
55 - } else {
56 - clearSearch.style.display = 'none';
 51+ function handleClearSearchLink() {
 52+ if ( clearSearch ) {
 53+ if ( search.value.length > 0 ) {
 54+ clearSearch.style.display = 'block';
 55+ } else {
 56+ clearSearch.style.display = 'none';
 57+ }
5758 }
5859 }
59 - }
6060
61 - function clearSearchBox( event ) {
62 - search.value = '';
63 - clearSearch.style.display = 'none';
64 - if ( event ) {
65 - event.preventDefault();
 61+ function clearSearchBox( event ) {
 62+ search.value = '';
 63+ clearSearch.style.display = 'none';
 64+ if ( event ) {
 65+ event.preventDefault();
 66+ }
6667 }
67 - }
6868
69 - function logoClick() {
70 - var n = document.getElementById( 'nav' ).style;
71 - n.display = n.display == 'block' ? 'none' : 'block';
72 - if (n.display == 'block') {
73 - if ( languageSelection ) {
74 - if ( languageSelection.offsetWidth > 175 ) {
75 - var newWidth = languageSelection.offsetWidth + 30;
76 - n.width = newWidth + 'px';
 69+ function logoClick() {
 70+ var n = document.getElementById( 'nav' ).style;
 71+ n.display = n.display == 'block' ? 'none' : 'block';
 72+ if (n.display == 'block') {
 73+ if ( languageSelection ) {
 74+ if ( languageSelection.offsetWidth > 175 ) {
 75+ var newWidth = languageSelection.offsetWidth + 30;
 76+ n.width = newWidth + 'px';
 77+ }
7778 }
7879 }
79 - }
80 - };
81 - initClearSearchLink();
82 - search.onpaste = function() {
83 - handleDefaultText();
84 - };
85 - document.getElementById( 'logo' ).addEventListener( 'click', logoClick );
86 - var dismissNotification = document.getElementById( 'dismiss-notification' );
 80+ };
 81+ initClearSearchLink();
 82+ search.onpaste = function() {
 83+ handleDefaultText();
 84+ };
 85+ document.getElementById( 'logo' ).addEventListener( 'click', logoClick );
 86+ var dismissNotification = document.getElementById( 'dismiss-notification' );
8787
88 - if ( dismissNotification ) {
89 - var cookieNameZeroVisibility = 'zeroRatedBannerVisibility';
90 - var zeroRatedBanner = document.getElementById( 'zero-rated-banner' );
91 - var zeroRatedBannerVisibility = readCookie( cookieNameZeroVisibility );
 88+ if ( dismissNotification ) {
 89+ var cookieNameZeroVisibility = 'zeroRatedBannerVisibility';
 90+ var zeroRatedBanner = document.getElementById( 'zero-rated-banner' );
 91+ var zeroRatedBannerVisibility = readCookie( cookieNameZeroVisibility );
9292
93 - if ( zeroRatedBannerVisibility === 'off' ) {
94 - zeroRatedBanner.style.display = 'none';
 93+ if ( zeroRatedBannerVisibility === 'off' ) {
 94+ zeroRatedBanner.style.display = 'none';
 95+ }
 96+
 97+ dismissNotification.onclick = function() {
 98+ if ( zeroRatedBanner ) {
 99+ zeroRatedBanner.style.display = 'none';
 100+ writeCookie( cookieNameZeroVisibility, 'off', 1 );
 101+ }
 102+ };
95103 }
 104+ if ( document.location.hash.indexOf( '#' ) == 0 ) {
 105+ wm_reveal_for_hash( document.location.hash );
 106+ }
96107
97 - dismissNotification.onclick = function() {
98 - if ( zeroRatedBanner ) {
99 - zeroRatedBanner.style.display = 'none';
100 - writeCookie( cookieNameZeroVisibility, 'off', 1 );
 108+ for ( var a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) {
 109+ a[i].onclick = function() {
 110+ if ( this.hash.indexOf( '#' ) == 0 ) {
 111+ wm_reveal_for_hash( this.hash );
 112+ }
101113 }
102 - };
 114+ }
 115+
 116+ // Try to scroll and hide URL bar
 117+ window.scrollTo( 0, 1 );
103118 }
104 - if ( document.location.hash.indexOf( '#' ) == 0 ) {
105 - wm_reveal_for_hash( document.location.hash );
106 - }
 119+ init();
107120
108 - for ( var a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) {
109 - a[i].onclick = function() {
110 - if ( this.hash.indexOf( '#' ) == 0 ) {
111 - wm_reveal_for_hash( this.hash );
 121+ function wm_reveal_for_hash( hash ) {
 122+ var targetel = document.getElementById( hash.substr(1) );
 123+ if ( targetel ) {
 124+ for (var p = targetel.parentNode; p && p.className != 'content_block' && p.className != 'section_heading'; ) {
 125+ p = p.parentNode;
112126 }
 127+ if ( p && p.style.display != 'block' ) {
 128+ var section_idx = parseInt( p.id.split( '_' )[1] );
 129+ wm_toggle_section( section_idx );
 130+ }
113131 }
114132 }
115133
116 - // Try to scroll and hide URL bar
117 - window.scrollTo( 0, 1 );
118 -}
119 -init();
120 -
121 -function wm_reveal_for_hash( hash ) {
122 - var targetel = document.getElementById( hash.substr(1) );
123 - if ( targetel ) {
124 - for (var p = targetel.parentNode; p && p.className != 'content_block' && p.className != 'section_heading'; ) {
125 - p = p.parentNode;
 134+ function wm_toggle_section( section_id ) {
 135+ 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';
126140 }
127 - if ( p && p.style.display != 'block' ) {
128 - var section_idx = parseInt( p.id.split( '_' )[1] );
129 - wm_toggle_section( section_idx );
 141+ for ( var i = 0, d = ['content_','anchor_']; i<=1; i++ ) {
 142+ var e = document.getElementById( d[i] + section_id );
 143+
 144+ if ( e ) {
 145+ e.style.display = e.style.display == 'block' ? 'none' : 'block';
 146+ }
130147 }
131148 }
132 -}
133149
134 -function wm_toggle_section( section_id ) {
135 - 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';
140 - }
141 - for ( var i = 0, d = ['content_','anchor_']; i<=1; i++ ) {
142 - var e = document.getElementById( d[i] + section_id );
143 -
144 - if ( e ) {
145 - e.style.display = e.style.display == 'block' ? 'none' : 'block';
 150+ function writeCookie( name, value, days ) {
 151+ if ( days ) {
 152+ var date = new Date();
 153+ date.setTime( date.getTime() + ( days * 24 * 60 * 60 *1000 ) );
 154+ var expires = '; expires=' + date.toGMTString();
 155+ } else {
 156+ var expires = '';
146157 }
 158+ document.cookie = name + '=' + value + expires + '; path=/';
147159 }
148 -}
149160
150 -function writeCookie( name, value, days ) {
151 - if ( days ) {
152 - var date = new Date();
153 - date.setTime( date.getTime() + ( days * 24 * 60 * 60 *1000 ) );
154 - var expires = '; expires=' + date.toGMTString();
155 - } else {
156 - var expires = '';
 161+ 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];
 166+ while ( c.charAt(0) === ' ' ) {
 167+ c = c.substring( 1, c.length );
 168+ }
 169+ if ( c.indexOf( nameVA ) == 0 ) {
 170+ return c.substring( nameVA.length, c.length );
 171+ }
 172+ }
 173+ return null;
157174 }
158 - document.cookie = name + '=' + value + expires + '; path=/';
159 -}
160175
161 -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];
166 - while ( c.charAt(0) === ' ' ) {
167 - c = c.substring( 1, c.length );
168 - }
169 - if ( c.indexOf( nameVA ) == 0 ) {
170 - return c.substring( nameVA.length, c.length );
171 - }
 176+ function removeCookie( name ) {
 177+ writeCookie( name, '', -1 );
 178+ return null;
172179 }
173 - return null;
174 -}
175180
176 -function removeCookie( name ) {
177 - writeCookie( name, '', -1 );
178 - return null;
179 -}
 181+ return {
 182+ readCookie: readCookie,
 183+ writeCookie: writeCookie,
 184+ removeCookie: removeCookie,
 185+ wm_reveal_for_hash: wm_reveal_for_hash,
 186+ wm_toggle_section: wm_toggle_section,
 187+ init: init
 188+ };
180189
181 -return {
182 - readCookie: readCookie,
183 - writeCookie: writeCookie,
184 - removeCookie: removeCookie,
185 - wm_reveal_for_hash: wm_reveal_for_hash,
186 - wm_toggle_section: wm_toggle_section,
187 - init: init
188 -};
189 -
190190 }();
191191
Index: trunk/extensions/MobileFrontend/javascripts/application.js
@@ -1,179 +1,179 @@
22 MobileFrontend = function() {
33
4 -function init() {
5 - 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 );
14 - }
15 - var search = document.getElementById( 'search' );
16 - var clearSearch = document.getElementById( 'clearsearch' );
17 - var results = document.getElementById( 'results' );
18 - var languageSelection = document.getElementById( 'languageselection' );
 4+ function init() {
 5+ 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 );
 14+ }
 15+ var search = document.getElementById( 'search' );
 16+ var clearSearch = document.getElementById( 'clearsearch' );
 17+ var results = document.getElementById( 'results' );
 18+ var languageSelection = document.getElementById( 'languageselection' );
1919
20 - function initClearSearchLink() {
21 - clearSearch.setAttribute( 'title','Clear' );
22 - clearSearch.addEventListener( 'mousedown', clearSearchBox, true );
23 - search.addEventListener( 'keyup', handleClearSearchLink, false );
24 - }
 20+ function initClearSearchLink() {
 21+ clearSearch.setAttribute( 'title','Clear' );
 22+ clearSearch.addEventListener( 'mousedown', clearSearchBox, true );
 23+ search.addEventListener( 'keyup', handleClearSearchLink, false );
 24+ }
2525
26 - function navigateToLanguageSelection() {
27 - var url;
28 - if ( languageSelection ) {
29 - url = languageSelection.options[languageSelection.selectedIndex].value;
30 - if ( url ) {
31 - location.href = url;
 26+ function navigateToLanguageSelection() {
 27+ var url;
 28+ if ( languageSelection ) {
 29+ url = languageSelection.options[languageSelection.selectedIndex].value;
 30+ if ( url ) {
 31+ location.href = url;
 32+ }
3233 }
3334 }
34 - }
35 - document.getElementById( 'languageselection' ).addEventListener( 'change', navigateToLanguageSelection );
 35+ document.getElementById( 'languageselection' ).addEventListener( 'change', navigateToLanguageSelection );
3636
37 - function handleClearSearchLink() {
38 - if ( clearSearch ) {
39 - if ( search.value.length > 0 ) {
40 - clearSearch.style.display = 'block';
41 - } else {
42 - clearSearch.style.display = 'none';
43 - if ( results ) {
44 - results.style.display = 'none';
 37+ function handleClearSearchLink() {
 38+ if ( clearSearch ) {
 39+ if ( search.value.length > 0 ) {
 40+ clearSearch.style.display = 'block';
 41+ } else {
 42+ clearSearch.style.display = 'none';
 43+ if ( results ) {
 44+ results.style.display = 'none';
 45+ }
4546 }
4647 }
4748 }
48 - }
4949
50 - function clearSearchBox( event ) {
51 - search.value = '';
52 - clearSearch.style.display = 'none';
53 - if ( results ) {
54 - results.style.display = 'none';
 50+ function clearSearchBox( event ) {
 51+ search.value = '';
 52+ clearSearch.style.display = 'none';
 53+ if ( results ) {
 54+ results.style.display = 'none';
 55+ }
 56+ if ( event ) {
 57+ event.preventDefault();
 58+ }
5559 }
56 - if ( event ) {
57 - event.preventDefault();
58 - }
59 - }
6060
61 - function logoClick() {
62 - var n = document.getElementById( 'nav' ).style;
63 - n.display = n.display == 'block' ? 'none' : 'block';
64 - if (n.display == 'block') {
65 - if ( languageSelection ) {
66 - if ( languageSelection.offsetWidth > 175 ) {
67 - var newWidth = languageSelection.offsetWidth + 30;
68 - n.width = newWidth + 'px';
 61+ function logoClick() {
 62+ var n = document.getElementById( 'nav' ).style;
 63+ n.display = n.display == 'block' ? 'none' : 'block';
 64+ if (n.display == 'block') {
 65+ if ( languageSelection ) {
 66+ if ( languageSelection.offsetWidth > 175 ) {
 67+ var newWidth = languageSelection.offsetWidth + 30;
 68+ n.width = newWidth + 'px';
 69+ }
6970 }
7071 }
71 - }
72 - };
73 - initClearSearchLink();
74 - document.getElementById( 'logo' ).addEventListener( 'click', logoClick );
75 - var dismissNotification = document.getElementById( 'dismiss-notification' );
 72+ };
 73+ initClearSearchLink();
 74+ document.getElementById( 'logo' ).addEventListener( 'click', logoClick );
 75+ var dismissNotification = document.getElementById( 'dismiss-notification' );
7676
77 - if ( dismissNotification ) {
78 - var cookieNameZeroVisibility = 'zeroRatedBannerVisibility';
79 - var zeroRatedBanner = document.getElementById( 'zero-rated-banner' );
80 - var zeroRatedBannerVisibility = readCookie( cookieNameZeroVisibility );
 77+ if ( dismissNotification ) {
 78+ var cookieNameZeroVisibility = 'zeroRatedBannerVisibility';
 79+ var zeroRatedBanner = document.getElementById( 'zero-rated-banner' );
 80+ var zeroRatedBannerVisibility = readCookie( cookieNameZeroVisibility );
8181
82 - if ( zeroRatedBannerVisibility === 'off' ) {
83 - zeroRatedBanner.style.display = 'none';
 82+ if ( zeroRatedBannerVisibility === 'off' ) {
 83+ zeroRatedBanner.style.display = 'none';
 84+ }
 85+
 86+ dismissNotification.onclick = function() {
 87+ if ( zeroRatedBanner ) {
 88+ zeroRatedBanner.style.display = 'none';
 89+ writeCookie( cookieNameZeroVisibility, 'off', 1 );
 90+ }
 91+ };
8492 }
 93+ if ( document.location.hash.indexOf( '#' ) == 0 ) {
 94+ wm_reveal_for_hash( document.location.hash );
 95+ }
8596
86 - dismissNotification.onclick = function() {
87 - if ( zeroRatedBanner ) {
88 - zeroRatedBanner.style.display = 'none';
89 - writeCookie( cookieNameZeroVisibility, 'off', 1 );
 97+ for ( var a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) {
 98+ a[i].onclick = function() {
 99+ if ( this.hash.indexOf( '#' ) == 0 ) {
 100+ wm_reveal_for_hash( this.hash );
 101+ }
90102 }
91 - };
 103+ }
 104+
 105+ // Try to scroll and hide URL bar
 106+ window.scrollTo( 0, 1 );
92107 }
93 - if ( document.location.hash.indexOf( '#' ) == 0 ) {
94 - wm_reveal_for_hash( document.location.hash );
95 - }
 108+ init();
96109
97 - for ( var a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ ) {
98 - a[i].onclick = function() {
99 - if ( this.hash.indexOf( '#' ) == 0 ) {
100 - wm_reveal_for_hash( this.hash );
 110+ function wm_reveal_for_hash( hash ) {
 111+ var targetel = document.getElementById( hash.substr(1) );
 112+ if ( targetel ) {
 113+ for (var p = targetel.parentNode; p && p.className != 'content_block' && p.className != 'section_heading'; ) {
 114+ p = p.parentNode;
101115 }
 116+ if ( p && p.style.display != 'block' ) {
 117+ var section_idx = parseInt( p.id.split( '_' )[1] );
 118+ wm_toggle_section( section_idx );
 119+ }
102120 }
103121 }
104122
105 - // Try to scroll and hide URL bar
106 - window.scrollTo( 0, 1 );
107 -}
108 -init();
109 -
110 -function wm_reveal_for_hash( hash ) {
111 - var targetel = document.getElementById( hash.substr(1) );
112 - if ( targetel ) {
113 - for (var p = targetel.parentNode; p && p.className != 'content_block' && p.className != 'section_heading'; ) {
114 - p = p.parentNode;
 123+ function wm_toggle_section( section_id ) {
 124+ 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';
115129 }
116 - if ( p && p.style.display != 'block' ) {
117 - var section_idx = parseInt( p.id.split( '_' )[1] );
118 - wm_toggle_section( section_idx );
 130+ for ( var i = 0, d = ['content_','anchor_']; i<=1; i++ ) {
 131+ var e = document.getElementById( d[i] + section_id );
 132+
 133+ if ( e ) {
 134+ e.style.display = e.style.display == 'block' ? 'none' : 'block';
 135+ }
119136 }
120137 }
121 -}
122138
123 -function wm_toggle_section( section_id ) {
124 - 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';
129 - }
130 - for ( var i = 0, d = ['content_','anchor_']; i<=1; i++ ) {
131 - var e = document.getElementById( d[i] + section_id );
132 -
133 - if ( e ) {
134 - e.style.display = e.style.display == 'block' ? 'none' : 'block';
 139+ function writeCookie( name, value, days ) {
 140+ if ( days ) {
 141+ var date = new Date();
 142+ date.setTime( date.getTime() + ( days * 24 * 60 * 60 *1000 ) );
 143+ var expires = '; expires=' + date.toGMTString();
 144+ } else {
 145+ var expires = '';
135146 }
 147+ document.cookie = name + '=' + value + expires + '; path=/';
136148 }
137 -}
138149
139 -function writeCookie( name, value, days ) {
140 - if ( days ) {
141 - var date = new Date();
142 - date.setTime( date.getTime() + ( days * 24 * 60 * 60 *1000 ) );
143 - var expires = '; expires=' + date.toGMTString();
144 - } else {
145 - var expires = '';
 150+ 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];
 155+ while ( c.charAt(0) === ' ' ) {
 156+ c = c.substring( 1, c.length );
 157+ }
 158+ if ( c.indexOf( nameVA ) == 0 ) {
 159+ return c.substring( nameVA.length, c.length );
 160+ }
 161+ }
 162+ return null;
146163 }
147 - document.cookie = name + '=' + value + expires + '; path=/';
148 -}
149164
150 -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];
155 - while ( c.charAt(0) === ' ' ) {
156 - c = c.substring( 1, c.length );
157 - }
158 - if ( c.indexOf( nameVA ) == 0 ) {
159 - return c.substring( nameVA.length, c.length );
160 - }
 165+ function removeCookie( name ) {
 166+ writeCookie( name, '', -1 );
 167+ return null;
161168 }
162 - return null;
163 -}
164169
165 -function removeCookie( name ) {
166 - writeCookie( name, '', -1 );
167 - return null;
168 -}
 170+ return {
 171+ readCookie: readCookie,
 172+ writeCookie: writeCookie,
 173+ removeCookie: removeCookie,
 174+ wm_reveal_for_hash: wm_reveal_for_hash,
 175+ wm_toggle_section: wm_toggle_section,
 176+ init: init
 177+ };
169178
170 -return {
171 - readCookie: readCookie,
172 - writeCookie: writeCookie,
173 - removeCookie: removeCookie,
174 - wm_reveal_for_hash: wm_reveal_for_hash,
175 - wm_toggle_section: wm_toggle_section,
176 - init: init
177 -};
178 -
179179 }();
180180

Sign-offs

UserFlagDate
Nikerabbitinspected20:52, 17 February 2012

Status & tagging log