r111763 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111762‎ | r111763 | r111764 >
Date:16:41, 17 February 2012
Author:jdlrobson
Status:ok
Tags:
Comment:
indent opensearch.js and beta counterpart
Modified paths:
  • /trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/opensearch.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/javascripts/opensearch.js
@@ -1,197 +1,197 @@
22 MobileFrontend.opensearch = function() {
33
4 -var apiUrl = '/api.php';
 4+ var apiUrl = '/api.php';
55
6 -if ( scriptPath ) {
7 - apiUrl = scriptPath + apiUrl;
8 -}
 6+ if ( scriptPath ) {
 7+ apiUrl = scriptPath + apiUrl;
 8+ }
99
10 -var timer = -1;
11 -var typingDelay = 500;
12 -var numResults = 5;
13 -var pixels = 'px';
 10+ var timer = -1;
 11+ var typingDelay = 500;
 12+ var numResults = 5;
 13+ var pixels = 'px';
1414
15 -var results = document.getElementById( 'results' );
16 -var search = document.getElementById( 'search' );
17 -var sq = document.getElementById( 'sq' );
18 -var sb = document.getElementById( 'searchbox' );
19 -
20 -function hideResults() {
2115 var results = document.getElementById( 'results' );
22 - results.style.display = 'none';
23 -}
 16+ var search = document.getElementById( 'search' );
 17+ var sq = document.getElementById( 'sq' );
 18+ var sb = document.getElementById( 'searchbox' );
2419
25 -function whichElement( e ) {
26 - var targ;
27 - if ( !e ) {
28 - var e = window.event;
 20+ function hideResults() {
 21+ var results = document.getElementById( 'results' );
 22+ results.style.display = 'none';
2923 }
30 - if ( e.target ) {
31 - targ = e.target;
32 - } else if ( e.srcElement ) {
33 - targ = e.srcElement;
34 - }
 24+
 25+ function whichElement( e ) {
 26+ var targ;
 27+ if ( !e ) {
 28+ var e = window.event;
 29+ }
 30+ if ( e.target ) {
 31+ targ = e.target;
 32+ } else if ( e.srcElement ) {
 33+ targ = e.srcElement;
 34+ }
3535
36 - if ( targ.nodeType == 3 ) {
37 - targ = targ.parentNode;
38 - }
 36+ if ( targ.nodeType == 3 ) {
 37+ targ = targ.parentNode;
 38+ }
3939
40 - e.cancelBubble = true;
41 - e.stopPropagation();
 40+ e.cancelBubble = true;
 41+ e.stopPropagation();
4242
43 - if ( targ.className == "suggestion-result" ||
44 - targ.className == "search-result-item" ||
45 - targ.className == "suggestions-result" ||
46 - targ.className == "sq-val-update" ) {
47 - } else {
48 - hideResults();
 43+ if ( targ.className == "suggestion-result" ||
 44+ targ.className == "search-result-item" ||
 45+ targ.className == "suggestions-result" ||
 46+ targ.className == "sq-val-update" ) {
 47+ } else {
 48+ hideResults();
 49+ }
4950 }
50 -}
5151
52 -function updateSearchWidth() {
53 - if ( sq && search && sb ) {
54 - var iw = ( document.documentElement.clientWidth ) ? document.documentElement.clientWidth : document.body.clientWidth;
55 - sb.style.width = ( iw - 30 ) + pixels;
56 - sq.style.width = ( iw - 110 ) + pixels;
57 - search.style.width = ( iw - 130 ) + pixels;
58 - if ( results ) {
59 - results.style.width = ( sq.offsetWidth - 2 ) + pixels;
60 - results.style.left = sq.offsetLeft + pixels;
61 - results.style.top = ( sq.offsetTop + sq.offsetHeight ) + pixels;
 52+ function updateSearchWidth() {
 53+ if ( sq && search && sb ) {
 54+ var iw = ( document.documentElement.clientWidth ) ? document.documentElement.clientWidth : document.body.clientWidth;
 55+ sb.style.width = ( iw - 30 ) + pixels;
 56+ sq.style.width = ( iw - 110 ) + pixels;
 57+ search.style.width = ( iw - 130 ) + pixels;
 58+ if ( results ) {
 59+ results.style.width = ( sq.offsetWidth - 2 ) + pixels;
 60+ results.style.left = sq.offsetLeft + pixels;
 61+ results.style.top = ( sq.offsetTop + sq.offsetHeight ) + pixels;
 62+ }
6263 }
6364 }
64 -}
6565
66 -updateSearchWidth();
 66+ updateSearchWidth();
6767
68 -function updateOrientationSearchWidth() {
69 - switch( window.orientation ) {
70 - case 0:
71 - case -90:
72 - case 90:
73 - case 180:
74 - setTimeout( updateSearchWidth, 200 );
75 - break;
76 - }
77 -}
 68+ function updateOrientationSearchWidth() {
 69+ switch( window.orientation ) {
 70+ case 0:
 71+ case -90:
 72+ case 90:
 73+ case 180:
 74+ setTimeout( updateSearchWidth, 200 );
 75+ break;
 76+ }
 77+ }
7878
79 -// Point to the updateOrientation function when iPhone switches between portrait and landscape modes.
80 -window.onorientationchange = updateOrientationSearchWidth;
 79+ // Point to the updateOrientation function when iPhone switches between portrait and landscape modes.
 80+ window.onorientationchange = updateOrientationSearchWidth;
8181
82 -window.onload = function () {
83 - search.addEventListener( 'keyup',
84 - function() {
85 - clearTimeout( timer );
86 - var term = this.value;
87 - if ( term.length < 1 ) {
88 - results.innerHTML = '';
89 - } else {
90 - timer = setTimeout( function () { searchApi( term ); }, typingDelay );
91 - }
92 - }, false );
93 -}
 82+ window.onload = function () {
 83+ search.addEventListener( 'keyup',
 84+ function() {
 85+ clearTimeout( timer );
 86+ var term = this.value;
 87+ if ( term.length < 1 ) {
 88+ results.innerHTML = '';
 89+ } else {
 90+ timer = setTimeout( function () { searchApi( term ); }, typingDelay );
 91+ }
 92+ }, false );
 93+ }
9494
95 -function searchApi( term ) {
96 - var xmlHttp;
97 - if ( window.XMLHttpRequest ) {
98 - xmlHttp = new XMLHttpRequest();
99 - } else {
100 - xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
101 - }
102 - xmlHttp.overrideMimeType( 'text/xml' );
103 - xmlHttp.onreadystatechange = function() {
104 - if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 ) {
105 - var sections = createObjectArray( xmlHttp.responseXML );
106 - writeResults( sections );
 95+ function searchApi( term ) {
 96+ var xmlHttp;
 97+ if ( window.XMLHttpRequest ) {
 98+ xmlHttp = new XMLHttpRequest();
 99+ } else {
 100+ xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
107101 }
 102+ xmlHttp.overrideMimeType( 'text/xml' );
 103+ xmlHttp.onreadystatechange = function() {
 104+ if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 ) {
 105+ var sections = createObjectArray( xmlHttp.responseXML );
 106+ writeResults( sections );
 107+ }
 108+ }
 109+ term = encodeURIComponent( term );
 110+ var url = apiUrl + '?action=opensearch&limit=' + numResults + '&namespace=0&format=xml&search=' + term;
 111+ xmlHttp.open( 'GET', url, true );
 112+ xmlHttp.send();
108113 }
109 - term = encodeURIComponent( term );
110 - var url = apiUrl + '?action=opensearch&limit=' + numResults + '&namespace=0&format=xml&search=' + term;
111 - xmlHttp.open( 'GET', url, true );
112 - xmlHttp.send();
113 -}
114114
115 -function createObjectArray( responseXml ) {
116 - var sections = new Array();
117 - var items = responseXml.getElementsByTagName( 'Item' );
118 - for ( i = 0; i < items.length; i++ ) {
119 - var item = items[i];
120 - var section = {
121 - label: item.getElementsByTagName( 'Text' )[0].textContent,
122 - value: item.getElementsByTagName( 'Url' )[0].textContent,
 115+ function createObjectArray( responseXml ) {
 116+ var sections = new Array();
 117+ var items = responseXml.getElementsByTagName( 'Item' );
 118+ for ( i = 0; i < items.length; i++ ) {
 119+ var item = items[i];
 120+ var section = {
 121+ label: item.getElementsByTagName( 'Text' )[0].textContent,
 122+ value: item.getElementsByTagName( 'Url' )[0].textContent,
 123+ }
 124+ sections.push( section );
123125 }
124 - sections.push( section );
 126+ return sections;
125127 }
126 - return sections;
127 -}
128128
129 -function sqValUpdate( sqValue ) {
130 - var search = document.getElementById( 'search' );
131 - if ( search ) {
132 - search.value = sqValue + ' ';
133 - search.focus();
134 - searchApi( search.value );
 129+ function sqValUpdate( sqValue ) {
 130+ var search = document.getElementById( 'search' );
 131+ if ( search ) {
 132+ search.value = sqValue + ' ';
 133+ search.focus();
 134+ searchApi( search.value );
 135+ }
135136 }
136 -}
137137
138 -function writeResults( sections ) {
139 - var results = document.getElementById( 'results' );
140 - results.style.display = 'block';
141 - if ( !sections || sections.length < 1 ) {
142 - results.innerHTML = "No results";
143 - } else {
144 - if( results.firstChild ) {
145 - results.removeChild( results.firstChild );
146 - }
147 - var suggestions = document.createElement( 'div' );
148 - suggestions.className = 'suggestions-results';
149 - results.appendChild( suggestions );
150 - for ( i = 0; i < sections.length; i++ ) {
151 - var section = sections[i], suggestionsResult = document.createElement( 'div' ),
152 - link = document.createElement( 'a' ), label;
153 - suggestionsResult.setAttribute( 'title', section.label );
154 - suggestionsResult.className = 'suggestions-result';
155 - label = document.createTextNode( '+' );
156 - link.appendChild(label);
157 - link.className = 'sq-val-update';
158 - link.addEventListener( 'click', function() {
159 - var title = this.parentNode.getAttribute( 'title' );
160 - sqValUpdate( title );
161 - });
162 - suggestionsResult.appendChild( link );
 138+ function writeResults( sections ) {
 139+ var results = document.getElementById( 'results' );
 140+ results.style.display = 'block';
 141+ if ( !sections || sections.length < 1 ) {
 142+ results.innerHTML = "No results";
 143+ } else {
 144+ if( results.firstChild ) {
 145+ results.removeChild( results.firstChild );
 146+ }
 147+ var suggestions = document.createElement( 'div' );
 148+ suggestions.className = 'suggestions-results';
 149+ results.appendChild( suggestions );
 150+ for ( i = 0; i < sections.length; i++ ) {
 151+ var section = sections[i], suggestionsResult = document.createElement( 'div' ),
 152+ link = document.createElement( 'a' ), label;
 153+ suggestionsResult.setAttribute( 'title', section.label );
 154+ suggestionsResult.className = 'suggestions-result';
 155+ label = document.createTextNode( '+' );
 156+ link.appendChild(label);
 157+ link.className = 'sq-val-update';
 158+ link.addEventListener( 'click', function() {
 159+ var title = this.parentNode.getAttribute( 'title' );
 160+ sqValUpdate( title );
 161+ });
 162+ suggestionsResult.appendChild( link );
163163
164 - link = document.createElement( 'a' );
165 - link.setAttribute( 'href', section.value );
166 - link.className = 'search-result-item';
167 - label = document.createTextNode( section.label );
168 - link.appendChild( label );
169 - suggestionsResult.appendChild( link );
170 - suggestions.appendChild( suggestionsResult );
 164+ link = document.createElement( 'a' );
 165+ link.setAttribute( 'href', section.value );
 166+ link.className = 'search-result-item';
 167+ label = document.createTextNode( section.label );
 168+ link.appendChild( label );
 169+ suggestionsResult.appendChild( link );
 170+ suggestions.appendChild( suggestionsResult );
 171+ }
171172 }
172173 }
173 -}
174174
175 -function init() {
176 - var results = document.getElementById( 'results' );
177 - results.onmousedown = function( event ) {
178 - whichElement( event );
 175+ function init() {
 176+ var results = document.getElementById( 'results' );
 177+ results.onmousedown = function( event ) {
 178+ whichElement( event );
 179+ };
 180+ document.body.onmousedown = function( event ) {
 181+ whichElement( event );
 182+ };
 183+ document.body.ontouchstart = function( event ) {
 184+ whichElement( event );
 185+ };
 186+ results.ontouchstart = function( event ) {
 187+ whichElement( event );
 188+ };
 189+ }
 190+ init();
 191+
 192+ return {
 193+ init: init,
 194+ writeResults: writeResults,
 195+ createObjectArray: createObjectArray
179196 };
180 - document.body.onmousedown = function( event ) {
181 - whichElement( event );
182 - };
183 - document.body.ontouchstart = function( event ) {
184 - whichElement( event );
185 - };
186 - results.ontouchstart = function( event ) {
187 - whichElement( event );
188 - };
189 -}
190 -init();
191197
192 -return {
193 - init: init,
194 - writeResults: writeResults,
195 - createObjectArray: createObjectArray
196 -};
197 -
198198 }();
Index: trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js
@@ -1,387 +1,387 @@
22 MobileFrontend.opensearch = function() {
33
4 -var apiUrl = '/api.php';
 4+ var apiUrl = '/api.php';
55
6 -if ( scriptPath ) {
7 - apiUrl = scriptPath + apiUrl;
8 -}
 6+ if ( scriptPath ) {
 7+ apiUrl = scriptPath + apiUrl;
 8+ }
99
10 -var timer = -1;
11 -var typingDelay = 500;
12 -var numResults = 15;
13 -var pixels = 'px';
14 -var term;
 10+ var timer = -1;
 11+ var typingDelay = 500;
 12+ var numResults = 15;
 13+ var pixels = 'px';
 14+ var term;
1515
16 -var results = document.getElementById( 'results' );
17 -var search = document.getElementById( 'search' );
18 -var sq = document.getElementById( 'sq' );
19 -var sb = document.getElementById( 'searchbox' );
20 -var logo = document.getElementById( 'logo' );
21 -var goButton = document.getElementById( 'goButton' );
22 -var content = document.getElementById( 'content' );
23 -var footer = document.getElementById( 'footer' );
24 -var zeroRatedBanner = document.getElementById( 'zero-rated-banner' ) ||
25 - document.getElementById( 'zero-rated-banner-red' );
26 -var clearSearch = document.getElementById( 'clearsearch' );
 16+ var results = document.getElementById( 'results' );
 17+ var search = document.getElementById( 'search' );
 18+ var sq = document.getElementById( 'sq' );
 19+ var sb = document.getElementById( 'searchbox' );
 20+ var logo = document.getElementById( 'logo' );
 21+ var goButton = document.getElementById( 'goButton' );
 22+ var content = document.getElementById( 'content' );
 23+ var footer = document.getElementById( 'footer' );
 24+ var zeroRatedBanner = document.getElementById( 'zero-rated-banner' ) ||
 25+ document.getElementById( 'zero-rated-banner-red' );
 26+ var clearSearch = document.getElementById( 'clearsearch' );
2727
28 -function hideResults() {
29 - results.style.display = 'none';
30 -}
31 -function resetViewPort() {
32 - if ( navigator.userAgent.match( /iPhone/i ) || navigator.userAgent.match( /iPad/i ) ) {
33 - var viewportmeta = document.querySelector( 'meta[name="viewport"]' );
34 - if ( viewportmeta ) {
35 - viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
36 - document.body.addEventListener( 'gesturestart', function () {
37 - viewportmeta.content = 'width=device-width, initial-scale=1.0';
38 - }, false );
39 - }
 28+ function hideResults() {
 29+ results.style.display = 'none';
4030 }
41 -}
 31+ function resetViewPort() {
 32+ if ( navigator.userAgent.match( /iPhone/i ) || navigator.userAgent.match( /iPad/i ) ) {
 33+ var viewportmeta = document.querySelector( 'meta[name="viewport"]' );
 34+ if ( viewportmeta ) {
 35+ viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
 36+ document.body.addEventListener( 'gesturestart', function () {
 37+ viewportmeta.content = 'width=device-width, initial-scale=1.0';
 38+ }, false );
 39+ }
 40+ }
 41+ }
4242
43 -resetViewPort();
 43+ resetViewPort();
4444
45 -var focused = false;
46 -var ol = new Object();
47 -search.onfocus = function() {
 45+ var focused = false;
 46+ var ol = new Object();
 47+ search.onfocus = function() {
4848
49 - resetViewPort();
 49+ resetViewPort();
5050
51 - if ( zeroRatedBanner ) {
52 - zeroRatedBanner.style.display = 'none';
53 - }
 51+ if ( zeroRatedBanner ) {
 52+ zeroRatedBanner.style.display = 'none';
 53+ }
5454
55 - if ( !focused ) {
56 - content.style.display = 'none';
57 - footer.style.display = 'none';
58 - ol.sqLeft = sq.offsetLeft;
59 - ol.sqTop = sq.offsetTop;
60 - sq.style.position = 'absolute';
 55+ if ( !focused ) {
 56+ content.style.display = 'none';
 57+ footer.style.display = 'none';
 58+ ol.sqLeft = sq.offsetLeft;
 59+ ol.sqTop = sq.offsetTop;
 60+ sq.style.position = 'absolute';
6161
62 - if ( !ol.properOffsetWidth ) {
63 - ol.properOffsetWidth = search.offsetLeft + 44;
 62+ if ( !ol.properOffsetWidth ) {
 63+ ol.properOffsetWidth = search.offsetLeft + 44;
 64+ }
 65+
 66+ sq.className = '';
 67+ sq.style.left = sb.offsetLeft + pixels;
 68+ sq.style.top = sb.offsetTop + pixels;
 69+ sq.style.height = sb.offsetHeight + pixels;
 70+ sq.style.width = sb.offsetWidth + pixels;
 71+ sq.style.left = 0 + pixels;
 72+ sq.style.top = 0 + pixels;
 73+ sq.style.height = 40 + pixels;
 74+ sq.style.width = document.body.clientWidth + pixels;
 75+ search.style.position = 'absolute';
 76+ search.style.left = ol.properOffsetWidth + pixels;
 77+ search.style.height = 34 + pixels;
 78+ search.style.width = ( document.body.clientWidth - 90 ) + pixels;
 79+ search.style.fontSize = 16 + pixels;
 80+ results.style.left = 0 + pixels;
 81+ results.style.top = ( sq.offsetTop + sq.offsetHeight ) + pixels;
 82+ results.style.width = document.body.clientWidth + pixels;
 83+ results.style.minHeight = '100%';
 84+ results.style.borderTop = 'solid 1px #A6A6A6';
 85+ results.style.backgroundColor = '#E6E6E6';
 86+ results.style.paddingTop = 5 + pixels;
 87+ results.style.display = 'block';
 88+ sb.style.border = 0 + pixels;
 89+ logo.style.visibility = 'hidden';
 90+ goButton.style.visibility = 'hidden';
 91+
 92+ var pE = document.getElementById( 'placeholder' );
 93+ if ( !pE ) {
 94+ pT = document.createElement( 'span' );
 95+ var pTT = document.createTextNode(placeholder);
 96+ pT.setAttribute( 'id', 'placeholder' );
 97+ pT.appendChild(pTT);
 98+ sb.insertBefore( pT, sb.firstChild );
 99+ }
 100+ var pE = document.getElementById( 'placeholder' );
 101+ if ( pE ) {
 102+ pE.style.position = 'absolute';
 103+ pE.style.left = ( search.offsetLeft + 5 ) + pixels;
 104+ pE.style.top = ( sq.offsetTop + 12 ) + pixels;
 105+ pE.style.color = '#666666';
 106+ pE.style.fontSize = 16 + pixels;
 107+ pE.style.display = 'block';
 108+ search.style.backgroundColor = 'transparent';
 109+ }
 110+
 111+ if ( pE && search.value != '' ) {
 112+ pE.style.display = 'none';
 113+ }
 114+
 115+ var removeResultsEl = document.getElementById( 'remove-results' );
 116+ if ( !removeResultsEl ) {
 117+ rrd = document.createElement( 'a' );
 118+ rrd.setAttribute( 'href', '#' );
 119+ rrd.setAttribute( 'id', 'remove-results' );
 120+ rrd.addEventListener( 'click', removeResults );
 121+ rrdD = document.createElement( 'div' );
 122+ rrdD.setAttribute( 'id', 'left-arrow' );
 123+ rrd.appendChild( rrdD );
 124+ sq.insertBefore( rrd, sq.firstChild );
 125+ } else {
 126+ removeResultsEl.style.display = 'block';
 127+ }
 128+ focused = true;
64129 }
 130+ }
65131
66 - sq.className = '';
67 - sq.style.left = sb.offsetLeft + pixels;
68 - sq.style.top = sb.offsetTop + pixels;
69 - sq.style.height = sb.offsetHeight + pixels;
70 - sq.style.width = sb.offsetWidth + pixels;
71 - sq.style.left = 0 + pixels;
72 - sq.style.top = 0 + pixels;
73 - sq.style.height = 40 + pixels;
74 - sq.style.width = document.body.clientWidth + pixels;
75 - search.style.position = 'absolute';
76 - search.style.left = ol.properOffsetWidth + pixels;
77 - search.style.height = 34 + pixels;
78 - search.style.width = ( document.body.clientWidth - 90 ) + pixels;
79 - search.style.fontSize = 16 + pixels;
80 - results.style.left = 0 + pixels;
81 - results.style.top = ( sq.offsetTop + sq.offsetHeight ) + pixels;
82 - results.style.width = document.body.clientWidth + pixels;
83 - results.style.minHeight = '100%';
84 - results.style.borderTop = 'solid 1px #A6A6A6';
85 - results.style.backgroundColor = '#E6E6E6';
86 - results.style.paddingTop = 5 + pixels;
87 - results.style.display = 'block';
88 - sb.style.border = 0 + pixels;
89 - logo.style.visibility = 'hidden';
90 - goButton.style.visibility = 'hidden';
 132+ function removeResults() {
 133+ if ( content ) {
 134+ content.style.display = 'block';
 135+ }
 136+ if ( footer ) {
 137+ footer.style.display = 'block';
 138+ }
91139
92140 var pE = document.getElementById( 'placeholder' );
93 - if ( !pE ) {
94 - pT = document.createElement( 'span' );
95 - var pTT = document.createTextNode(placeholder);
96 - pT.setAttribute( 'id', 'placeholder' );
97 - pT.appendChild(pTT);
98 - sb.insertBefore( pT, sb.firstChild );
99 - }
100 - var pE = document.getElementById( 'placeholder' );
101141 if ( pE ) {
102 - pE.style.position = 'absolute';
103 - pE.style.left = ( search.offsetLeft + 5 ) + pixels;
104 - pE.style.top = ( sq.offsetTop + 12 ) + pixels;
105 - pE.style.color = '#666666';
106 - pE.style.fontSize = 16 + pixels;
107 - pE.style.display = 'block';
108 - search.style.backgroundColor = 'transparent';
109 - }
110 -
111 - if ( pE && search.value != '' ) {
112142 pE.style.display = 'none';
113143 }
 144+
 145+ if ( zeroRatedBanner ) {
 146+ zeroRatedBanner.style.display = 'block';
 147+ }
114148
115 - var removeResultsEl = document.getElementById( 'remove-results' );
116 - if ( !removeResultsEl ) {
117 - rrd = document.createElement( 'a' );
118 - rrd.setAttribute( 'href', '#' );
119 - rrd.setAttribute( 'id', 'remove-results' );
120 - rrd.addEventListener( 'click', removeResults );
121 - rrdD = document.createElement( 'div' );
122 - rrdD.setAttribute( 'id', 'left-arrow' );
123 - rrd.appendChild( rrdD );
124 - sq.insertBefore( rrd, sq.firstChild );
125 - } else {
126 - removeResultsEl.style.display = 'block';
 149+ if ( ol ) {
 150+ if ( sq ) {
 151+ logo.style.visibility = 'visible';
 152+ goButton.style.visibility = 'visible';
 153+ sq.className = 'divclearable';
 154+ sq.style.position = 'static';
 155+ sq.style.left = ol.sqLeft + pixels;
 156+ sq.style.top = ol.sqTop + pixels;
 157+ sq.style.height = 'auto';
 158+ }
 159+ if ( search ) {
 160+ search.style.left = ( search.offsetLeft - 44 ) + pixels;
 161+ search.style.position = 'static';
 162+ search.style.fontSize = 11 + pixels;
 163+ search.style.height = 'auto';
 164+ updateSearchWidth();
 165+ }
 166+ if ( sb ) {
 167+ sb.style.border = 'solid #CCC 1px';
 168+ var removeResults = document.getElementById( 'remove-results' );
 169+ if ( removeResults ) {
 170+ removeResults.style.display = 'none';
 171+ }
 172+ }
 173+ if ( focused ) {
 174+ focused = false;
 175+ }
 176+ if ( clearSearch ) {
 177+ clearSearch.style.display = 'none';
 178+ }
127179 }
128 - focused = true;
129180 }
130 -}
131181
132 -function removeResults() {
133 - if ( content ) {
134 - content.style.display = 'block';
135 - }
136 - if ( footer ) {
137 - footer.style.display = 'block';
138 - }
139 -
140 - var pE = document.getElementById( 'placeholder' );
141 - if ( pE ) {
142 - pE.style.display = 'none';
143 - }
144 -
145 - if ( zeroRatedBanner ) {
146 - zeroRatedBanner.style.display = 'block';
147 - }
148 -
149 - if ( ol ) {
150 - if ( sq ) {
151 - logo.style.visibility = 'visible';
152 - goButton.style.visibility = 'visible';
153 - sq.className = 'divclearable';
154 - sq.style.position = 'static';
155 - sq.style.left = ol.sqLeft + pixels;
156 - sq.style.top = ol.sqTop + pixels;
157 - sq.style.height = 'auto';
 182+ function whichElement( e ) {
 183+ var targ;
 184+ if ( !e ) {
 185+ var e = window.event;
158186 }
159 - if ( search ) {
160 - search.style.left = ( search.offsetLeft - 44 ) + pixels;
161 - search.style.position = 'static';
162 - search.style.fontSize = 11 + pixels;
163 - search.style.height = 'auto';
164 - updateSearchWidth();
 187+ if ( e.target ) {
 188+ targ = e.target;
 189+ } else if ( e.srcElement ) {
 190+ targ = e.srcElement;
165191 }
166 - if ( sb ) {
167 - sb.style.border = 'solid #CCC 1px';
168 - var removeResults = document.getElementById( 'remove-results' );
169 - if ( removeResults ) {
170 - removeResults.style.display = 'none';
171 - }
 192+
 193+ if ( targ.nodeType == 3 ) {
 194+ targ = targ.parentNode;
172195 }
173 - if ( focused ) {
174 - focused = false;
 196+
 197+ e.cancelBubble = true;
 198+ e.stopPropagation();
 199+ if ( targ.className == "suggestion-result" ||
 200+ targ.className == "search-result-item" ||
 201+ targ.className == "suggestions-result" ||
 202+ targ.className == "sq-val-update" ||
 203+ targ.id == 'results' ||
 204+ targ.id == 'search' ||
 205+ targ.id == 'searchbox' ||
 206+ targ.id == 'sq' ||
 207+ targ.id == 'placeholder' ||
 208+ targ.id == 'clearsearch' ||
 209+ targ.tagName == 'BODY' ) {
 210+ if ( targ.id == 'clearsearch' && results ) {
 211+ results.innerHTML = '';
 212+ }
 213+ } else {
 214+ hideResults();
175215 }
176 - if ( clearSearch ) {
177 - clearSearch.style.display = 'none';
178 - }
179216 }
180 -}
181217
182 -function whichElement( e ) {
183 - var targ;
184 - if ( !e ) {
185 - var e = window.event;
 218+ function updateSearchWidth() {
 219+ if ( sq && search && sb ) {
 220+ var iw = ( document.documentElement.clientWidth ) ? document.documentElement.clientWidth : document.body.clientWidth;
 221+ sb.style.width = ( iw - 30 ) + pixels;
 222+ sq.style.width = ( iw - 110 ) + pixels;
 223+ search.style.width = ( iw - 130 ) + pixels;
 224+ if ( results ) {
 225+ results.style.width = ( sq.offsetWidth - 2 ) + pixels;
 226+ results.style.left = sq.offsetLeft + pixels;
 227+ results.style.top = ( sq.offsetTop + sq.offsetHeight ) + pixels;
 228+ if ( results.style.display == 'block' ) {
 229+ focused = false;
 230+ search.blur();
 231+ search.focus();
 232+ }
 233+ }
 234+ }
186235 }
187 - if ( e.target ) {
188 - targ = e.target;
189 - } else if ( e.srcElement ) {
190 - targ = e.srcElement;
191 - }
192236
193 - if ( targ.nodeType == 3 ) {
194 - targ = targ.parentNode;
 237+ updateSearchWidth();
 238+
 239+ function updateOrientationSearchWidth() {
 240+ switch( window.orientation ) {
 241+ case 0:
 242+ case -90:
 243+ case 90:
 244+ case 180:
 245+ setTimeout( "updateSearchWidth()", 300 );
 246+ break;
 247+ }
195248 }
196249
197 - e.cancelBubble = true;
198 - e.stopPropagation();
199 - if ( targ.className == "suggestion-result" ||
200 - targ.className == "search-result-item" ||
201 - targ.className == "suggestions-result" ||
202 - targ.className == "sq-val-update" ||
203 - targ.id == 'results' ||
204 - targ.id == 'search' ||
205 - targ.id == 'searchbox' ||
206 - targ.id == 'sq' ||
207 - targ.id == 'placeholder' ||
208 - targ.id == 'clearsearch' ||
209 - targ.tagName == 'BODY' ) {
210 - if ( targ.id == 'clearsearch' && results ) {
211 - results.innerHTML = '';
212 - }
213 - } else {
214 - hideResults();
 250+ // Point to the updateOrientation function when iPhone switches between portrait and landscape modes.
 251+ window.onorientationchange = updateOrientationSearchWidth;
 252+
 253+ window.onload = function () {
 254+ search.addEventListener( 'keyup',
 255+ function() {
 256+ clearTimeout( timer );
 257+ term = this.value;
 258+ if ( term.length < 1 ) {
 259+ results.innerHTML = '';
 260+ } else {
 261+ term = encodeURIComponent( term );
 262+ timer = setTimeout( function () { searchApi( term ); }, typingDelay );
 263+ }
 264+ }, false );
215265 }
216 -}
217266
218 -function updateSearchWidth() {
219 - if ( sq && search && sb ) {
220 - var iw = ( document.documentElement.clientWidth ) ? document.documentElement.clientWidth : document.body.clientWidth;
221 - sb.style.width = ( iw - 30 ) + pixels;
222 - sq.style.width = ( iw - 110 ) + pixels;
223 - search.style.width = ( iw - 130 ) + pixels;
224 - if ( results ) {
225 - results.style.width = ( sq.offsetWidth - 2 ) + pixels;
226 - results.style.left = sq.offsetLeft + pixels;
227 - results.style.top = ( sq.offsetTop + sq.offsetHeight ) + pixels;
228 - if ( results.style.display == 'block' ) {
229 - focused = false;
230 - search.blur();
231 - search.focus();
 267+ function searchApi( term ) {
 268+ var xmlHttp;
 269+ if ( window.XMLHttpRequest ) {
 270+ xmlHttp = new XMLHttpRequest();
 271+ } else {
 272+ xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
 273+ }
 274+ xmlHttp.overrideMimeType( 'text/xml' );
 275+ xmlHttp.onreadystatechange = function() {
 276+ if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 ) {
 277+ var sections = createObjectArray( xmlHttp.responseXML );
 278+ writeResults( sections );
232279 }
233280 }
 281+ var url = apiUrl + '?action=opensearch&limit=' + numResults + '&namespace=0&format=xml&search=' + term;
 282+ xmlHttp.open( 'GET', url, true );
 283+ xmlHttp.send();
234284 }
235 -}
236285
237 -updateSearchWidth();
238 -
239 -function updateOrientationSearchWidth() {
240 - switch( window.orientation ) {
241 - case 0:
242 - case -90:
243 - case 90:
244 - case 180:
245 - setTimeout( "updateSearchWidth()", 300 );
246 - break;
247 - }
248 -}
249 -
250 -// Point to the updateOrientation function when iPhone switches between portrait and landscape modes.
251 -window.onorientationchange = updateOrientationSearchWidth;
252 -
253 -window.onload = function () {
254 - search.addEventListener( 'keyup',
255 - function() {
256 - clearTimeout( timer );
257 - term = this.value;
258 - if ( term.length < 1 ) {
259 - results.innerHTML = '';
260 - } else {
261 - term = encodeURIComponent( term );
262 - timer = setTimeout( function () { searchApi( term ); }, typingDelay );
 286+ function createObjectArray( responseXml ) {
 287+ var sections = new Array();
 288+ var items = responseXml.getElementsByTagName( 'Item' );
 289+ for ( i = 0; i < items.length; i++ ) {
 290+ var item = items[i];
 291+ var section = {
 292+ label: item.getElementsByTagName( 'Text' )[0].textContent,
 293+ value: item.getElementsByTagName( 'Url' )[0].textContent,
263294 }
264 - }, false );
265 -}
266 -
267 -function searchApi( term ) {
268 - var xmlHttp;
269 - if ( window.XMLHttpRequest ) {
270 - xmlHttp = new XMLHttpRequest();
271 - } else {
272 - xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
273 - }
274 - xmlHttp.overrideMimeType( 'text/xml' );
275 - xmlHttp.onreadystatechange = function() {
276 - if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 ) {
277 - var sections = createObjectArray( xmlHttp.responseXML );
278 - writeResults( sections );
 295+ sections.push( section );
279296 }
 297+ return sections;
280298 }
281 - var url = apiUrl + '?action=opensearch&limit=' + numResults + '&namespace=0&format=xml&search=' + term;
282 - xmlHttp.open( 'GET', url, true );
283 - xmlHttp.send();
284 -}
285299
286 -function createObjectArray( responseXml ) {
287 - var sections = new Array();
288 - var items = responseXml.getElementsByTagName( 'Item' );
289 - for ( i = 0; i < items.length; i++ ) {
290 - var item = items[i];
291 - var section = {
292 - label: item.getElementsByTagName( 'Text' )[0].textContent,
293 - value: item.getElementsByTagName( 'Url' )[0].textContent,
 300+ function sqValUpdate( sqValue ) {
 301+ var search = document.getElementById( 'search' );
 302+ if ( search ) {
 303+ search.value = sqValue + ' ';
 304+ search.focus();
 305+ searchApi( search.value );
294306 }
295 - sections.push( section );
296307 }
297 - return sections;
298 -}
299308
300 -function sqValUpdate( sqValue ) {
301 - var search = document.getElementById( 'search' );
302 - if ( search ) {
303 - search.value = sqValue + ' ';
304 - search.focus();
305 - searchApi( search.value );
 309+ function htmlEntities( str ) {
 310+ return String( str ).replace( /&/g, '&amp;' ).replace( /</g, '&lt;' ).replace( />/g, '&gt;' ).replace( /"/g, '&quot;' ).replace( /'/g, '&#39;' );
306311 }
307 -}
308312
309 -function htmlEntities( str ) {
310 - return String( str ).replace( /&/g, '&amp;' ).replace( /</g, '&lt;' ).replace( />/g, '&gt;' ).replace( /"/g, '&quot;' ).replace( /'/g, '&#39;' );
311 -}
 313+ function escapeJsString( str ) {
 314+ return String( str ).replace( /\\/g, '\\\\' ).replace( /'/g, "\\'" ).replace( /\n/g, '\\n' );
 315+ }
312316
313 -function escapeJsString( str ) {
314 - return String( str ).replace( /\\/g, '\\\\' ).replace( /'/g, "\\'" ).replace( /\n/g, '\\n' );
315 -}
316 -
317 -function writeResults( sections ) {
318 - var results = document.getElementById( 'results' );
319 - var term = htmlEntities( document.getElementById( 'search' ).value );
320 - results.style.display = 'block';
321 - if ( search ) {
322 - search.focus();
323 - }
324 - if ( !sections || sections.length < 1 ) {
325 - results.innerHTML = "<div class=\"suggestions-results\" title=\"No Results\">No Results</div>";
326 - } else {
327 - if( results.firstChild ) {
328 - results.removeChild( results.firstChild );
 317+ function writeResults( sections ) {
 318+ var results = document.getElementById( 'results' );
 319+ var term = htmlEntities( document.getElementById( 'search' ).value );
 320+ results.style.display = 'block';
 321+ if ( search ) {
 322+ search.focus();
329323 }
330 - var suggestions = document.createElement( 'div' );
331 - suggestions.className = 'suggestions-results';
332 - results.appendChild( suggestions );
333 - for ( i = 0; i < sections.length; i++ ) {
334 - var section = sections[i], suggestionsResult = document.createElement( 'div' ),
335 - link = document.createElement( 'a' ), label;
336 - suggestionsResult.setAttribute( 'title', section.label );
337 - suggestionsResult.className = 'suggestions-result';
338 - label = document.createTextNode( '+' );
339 - link.appendChild(label);
340 - link.className = 'sq-val-update';
341 - link.addEventListener( 'click', function() {
342 - var title = this.parentNode.getAttribute( 'title' );
343 - sqValUpdate( title );
344 - });
345 - suggestionsResult.appendChild( link );
 324+ if ( !sections || sections.length < 1 ) {
 325+ results.innerHTML = "<div class=\"suggestions-results\" title=\"No Results\">No Results</div>";
 326+ } else {
 327+ if( results.firstChild ) {
 328+ results.removeChild( results.firstChild );
 329+ }
 330+ var suggestions = document.createElement( 'div' );
 331+ suggestions.className = 'suggestions-results';
 332+ results.appendChild( suggestions );
 333+ for ( i = 0; i < sections.length; i++ ) {
 334+ var section = sections[i], suggestionsResult = document.createElement( 'div' ),
 335+ link = document.createElement( 'a' ), label;
 336+ suggestionsResult.setAttribute( 'title', section.label );
 337+ suggestionsResult.className = 'suggestions-result';
 338+ label = document.createTextNode( '+' );
 339+ link.appendChild(label);
 340+ link.className = 'sq-val-update';
 341+ link.addEventListener( 'click', function() {
 342+ var title = this.parentNode.getAttribute( 'title' );
 343+ sqValUpdate( title );
 344+ });
 345+ suggestionsResult.appendChild( link );
346346
347 - link = document.createElement( 'a' );
348 - link.setAttribute( 'href', section.value );
349 - link.className = 'search-result-item';
350 - label = document.createTextNode( section.label );
351 - link.appendChild( label );
 347+ link = document.createElement( 'a' );
 348+ link.setAttribute( 'href', section.value );
 349+ link.className = 'search-result-item';
 350+ label = document.createTextNode( section.label );
 351+ link.appendChild( label );
352352
353 - suggestionsResult.appendChild( link );
354 - suggestions.appendChild( suggestionsResult );
355 - // TODO: simplify the highlighting code to not use htmlEntities
356 - // highlight matched term
357 - var escapedTerm = escapeJsString( term );
358 - link.innerHTML = link.innerHTML.replace( new RegExp( '(' + escapedTerm + ')' , 'ig'),
359 - '<strong>$1</strong>' );
 353+ suggestionsResult.appendChild( link );
 354+ suggestions.appendChild( suggestionsResult );
 355+ // TODO: simplify the highlighting code to not use htmlEntities
 356+ // highlight matched term
 357+ var escapedTerm = escapeJsString( term );
 358+ link.innerHTML = link.innerHTML.replace( new RegExp( '(' + escapedTerm + ')' , 'ig'),
 359+ '<strong>$1</strong>' );
 360+ }
360361 }
361362 }
362 -}
363363
364 -function init() {
365 - var results = document.getElementById( 'results' );
366 - results.onmousedown = function( event ) {
367 - whichElement( event );
 364+ function init() {
 365+ var results = document.getElementById( 'results' );
 366+ results.onmousedown = function( event ) {
 367+ whichElement( event );
 368+ };
 369+ document.body.onmousedown = function( event ) {
 370+ whichElement( event );
 371+ };
 372+ document.body.ontouchstart = function( event ) {
 373+ whichElement( event );
 374+ };
 375+ results.ontouchstart = function( event ) {
 376+ whichElement( event );
 377+ };
 378+ }
 379+ init();
 380+
 381+ return {
 382+ init: init,
 383+ writeResults: writeResults,
 384+ createObjectArray: createObjectArray,
 385+ removeResults: removeResults
368386 };
369 - document.body.onmousedown = function( event ) {
370 - whichElement( event );
371 - };
372 - document.body.ontouchstart = function( event ) {
373 - whichElement( event );
374 - };
375 - results.ontouchstart = function( event ) {
376 - whichElement( event );
377 - };
378 -}
379 -init();
380387
381 -return {
382 - init: init,
383 - writeResults: writeResults,
384 - createObjectArray: createObjectArray,
385 - removeResults: removeResults
386 -};
387 -
388388 }();

Status & tagging log