r111740 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111739‎ | r111740 | r111741 >
Date:10:45, 17 February 2012
Author:jdlrobson
Status:ok
Tags:
Comment:
encapsulate application.js in MobileFrontend variable

return functions that we want to be able to test
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,59 +1,5 @@
2 -var search = document.getElementById( 'search' );
3 -var clearSearch = document.getElementById( 'clearsearch' );
4 -var results = document.getElementById( 'results' );
5 -var languageSelection = document.getElementById( 'languageselection' );
 2+MobileFrontend = function() {
63
7 -var zeroRatedBanner = document.getElementById( 'zero-rated-banner' );
8 -
9 -if ( !zeroRatedBanner ) {
10 - var zeroRatedBanner = document.getElementById( 'zero-rated-banner-red' );
11 -}
12 -
13 -function initClearSearchLink() {
14 - clearSearch.setAttribute( 'title','Clear' );
15 - clearSearch.addEventListener( 'mousedown', clearSearchBox, true );
16 - search.addEventListener( 'keyup', handleClearSearchLink, false );
17 - search.addEventListener( 'keydown', handleDefaultText, false );
18 -}
19 -
20 -function handleDefaultText() {
21 - var pE = document.getElementById( 'placeholder' );
22 - if ( pE ) {
23 - pE.style.display = 'none';
24 - }
25 -}
26 -
27 -function handleClearSearchLink() {
28 - if ( clearSearch ) {
29 - if ( search.value.length > 0 ) {
30 - clearSearch.style.display = 'block';
31 - } else {
32 - clearSearch.style.display = 'none';
33 - }
34 - }
35 -}
36 -
37 -function clearSearchBox( event ) {
38 - search.value = '';
39 - clearSearch.style.display = 'none';
40 - if ( event ) {
41 - event.preventDefault();
42 - }
43 -}
44 -
45 -function logoClick() {
46 - var n = document.getElementById( 'nav' ).style;
47 - n.display = n.display == 'block' ? 'none' : 'block';
48 - if (n.display == 'block') {
49 - if ( languageSelection ) {
50 - if ( languageSelection.offsetWidth > 175 ) {
51 - var newWidth = languageSelection.offsetWidth + 30;
52 - n.width = newWidth + 'px';
53 - }
54 - }
55 - }
56 -};
57 -
584 function init() {
595 document.body.className = "jsEnabled";
606 var sectionHeadings = document.getElementsByClassName( 'section_heading' );
@@ -65,7 +11,24 @@
6612 }
6713 }, false );
6814 }
 15+ var search = document.getElementById( 'search' );
 16+ var clearSearch = document.getElementById( 'clearsearch' );
 17+ var results = document.getElementById( 'results' );
 18+ var languageSelection = document.getElementById( 'languageselection' );
6919
 20+ var zeroRatedBanner = document.getElementById( 'zero-rated-banner' );
 21+
 22+ if ( !zeroRatedBanner ) {
 23+ var zeroRatedBanner = document.getElementById( 'zero-rated-banner-red' );
 24+ }
 25+
 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+ }
 32+
7033 function navigateToLanguageSelection() {
7134 var url;
7235 if ( languageSelection ) {
@@ -77,6 +40,43 @@
7841 }
7942 document.getElementById( 'languageselection' ).addEventListener( 'change', navigateToLanguageSelection );
8043
 44+ function handleDefaultText() {
 45+ var pE = document.getElementById( 'placeholder' );
 46+ if ( pE ) {
 47+ pE.style.display = 'none';
 48+ }
 49+ }
 50+
 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+ }
 58+ }
 59+ }
 60+
 61+ function clearSearchBox( event ) {
 62+ search.value = '';
 63+ clearSearch.style.display = 'none';
 64+ if ( event ) {
 65+ event.preventDefault();
 66+ }
 67+ }
 68+
 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+ }
 78+ }
 79+ }
 80+ };
8181 initClearSearchLink();
8282 search.onpaste = function() {
8383 handleDefaultText();
@@ -176,3 +176,15 @@
177177 writeCookie( name, '', -1 );
178178 return null;
179179 }
 180+
 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+
 190+}();
 191+
Index: trunk/extensions/MobileFrontend/javascripts/application.js
@@ -1,51 +1,5 @@
2 -var search = document.getElementById( 'search' );
3 -var clearSearch = document.getElementById( 'clearsearch' );
4 -var results = document.getElementById( 'results' );
5 -var languageSelection = document.getElementById( 'languageselection' );
 2+MobileFrontend = function() {
63
7 -function initClearSearchLink() {
8 - clearSearch.setAttribute( 'title','Clear' );
9 - clearSearch.addEventListener( 'mousedown', clearSearchBox, true );
10 - search.addEventListener( 'keyup', handleClearSearchLink, false );
11 -}
12 -
13 -function handleClearSearchLink() {
14 - if ( clearSearch ) {
15 - if ( search.value.length > 0 ) {
16 - clearSearch.style.display = 'block';
17 - } else {
18 - clearSearch.style.display = 'none';
19 - if ( results ) {
20 - results.style.display = 'none';
21 - }
22 - }
23 - }
24 -}
25 -
26 -function clearSearchBox( event ) {
27 - search.value = '';
28 - clearSearch.style.display = 'none';
29 - if ( results ) {
30 - results.style.display = 'none';
31 - }
32 - if ( event ) {
33 - event.preventDefault();
34 - }
35 -}
36 -
37 -function logoClick() {
38 - var n = document.getElementById( 'nav' ).style;
39 - n.display = n.display == 'block' ? 'none' : 'block';
40 - if (n.display == 'block') {
41 - if ( languageSelection ) {
42 - if ( languageSelection.offsetWidth > 175 ) {
43 - var newWidth = languageSelection.offsetWidth + 30;
44 - n.width = newWidth + 'px';
45 - }
46 - }
47 - }
48 -};
49 -
504 function init() {
515 document.body.className = "jsEnabled";
526 var sectionHeadings = document.getElementsByClassName( 'section_heading' );
@@ -57,7 +11,17 @@
5812 }
5913 }, false );
6014 }
 15+ var search = document.getElementById( 'search' );
 16+ var clearSearch = document.getElementById( 'clearsearch' );
 17+ var results = document.getElementById( 'results' );
 18+ var languageSelection = document.getElementById( 'languageselection' );
6119
 20+ function initClearSearchLink() {
 21+ clearSearch.setAttribute( 'title','Clear' );
 22+ clearSearch.addEventListener( 'mousedown', clearSearchBox, true );
 23+ search.addEventListener( 'keyup', handleClearSearchLink, false );
 24+ }
 25+
6226 function navigateToLanguageSelection() {
6327 var url;
6428 if ( languageSelection ) {
@@ -69,6 +33,42 @@
7034 }
7135 document.getElementById( 'languageselection' ).addEventListener( 'change', navigateToLanguageSelection );
7236
 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+ }
 46+ }
 47+ }
 48+ }
 49+
 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+ }
 59+ }
 60+
 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+ }
 70+ }
 71+ }
 72+ };
7373 initClearSearchLink();
7474 document.getElementById( 'logo' ).addEventListener( 'click', logoClick );
7575 var dismissNotification = document.getElementById( 'dismiss-notification' );
@@ -165,3 +165,15 @@
166166 writeCookie( name, '', -1 );
167167 return null;
168168 }
 169+
 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+
 179+}();
 180+

Status & tagging log