http://www.mediawiki.org/wiki/Special:Code/MediaWiki/97557
Revision: 97557
Author: preilly
Date: 2011-09-19 21:00:35 +0000 (Mon, 19 Sep 2011)
Log Message:
-----------
mft r97556
Modified Paths:
--------------
branches/wmf/1.17wmf1/extensions/MobileFrontend/javascripts/application.js
branches/wmf/1.17wmf1/extensions/MobileFrontend/views/layout/application.html.php
Modified:
branches/wmf/1.17wmf1/extensions/MobileFrontend/javascripts/application.js
===================================================================
--- branches/wmf/1.17wmf1/extensions/MobileFrontend/javascripts/application.js
2011-09-19 20:58:29 UTC (rev 97556)
+++ branches/wmf/1.17wmf1/extensions/MobileFrontend/javascripts/application.js
2011-09-19 21:00:35 UTC (rev 97557)
@@ -1,49 +1,74 @@
-// Ideally, this would be loaded in the head and activated by a script at the
bottom,
-// I think, rather than attached to an onload...
-window.onload = function() {
- // I don't think this makes sense. Loading this here means that this
button
- // won't function until the page is loaded. It would probably be an
- // improvement to just attach an onclick straight into the html.
- document.getElementById( 'logo' ).onclick = function() {
- var n = document.getElementById( 'nav' ).style;
- n.display = n.display == 'block' ? 'none' : 'block';
- };
+var search = document.getElementById( 'search' );
+var clearSearch = document.getElementById( 'clearsearch' );
- // Also problematic, not working until the page loads...
- for( var h = document.getElementsByTagName( 'h2' ), i = 0; i <
h.length; i++ ) {
- if ( h[i].className == 'section_heading' ) {
- h[i].onclick = function() {
- var section_idx = parseInt( this.id.replace(
/section_(\d+)/, '$1' ) );
- wm_toggle_section( section_idx );
- }
- }
- };
+initClearSearchLink();
- // And this...
- for ( var a = document.getElementsByTagName( 'a' ), i = 0; i <
a.length; i++ ) {
- a[i].onclick = function() {
- if ( this.hash.indexOf( '#' ) == 0 ) {
- wm_reveal_for_hash( this.hash );
- }
- }
- };
+function initClearSearchLink() {
+ clearSearch.setAttribute( 'title','Clear' );
+ clearSearch.addEventListener( 'mousedown', clearSearchBox, true );
+ search.addEventListener( 'keyup', _handleClearSearchLink, false );
+}
- if ( document.location.hash.indexOf( '#' ) == 0 ) {
- wm_reveal_for_hash( document.location.hash );
+function _handleClearSearchLink() {
+ if ( clearSearch ) {
+ if ( search.value.length > 0 ) {
+ clearSearch.style.display = 'block';
+ } else {
+ clearSearch.style.display = 'none';
+ }
}
+}
- updateOrientation();
+function clearSearchBox( event ) {
+ search.value = '';
+ clearSearch.style.display = 'none';
+ if ( event ) {
+ event.preventDefault();
+ }
+}
- // Try to scroll and hide URL bar
- window.scrollTo( 0, 1 );
+// I don't think this makes sense. Loading this here means that this button
+// won't function until the page is loaded. It would probably be an
+// improvement to just attach an onclick straight into the html.
+document.getElementById( 'logo' ).onclick = function() {
+ var n = document.getElementById( 'nav' ).style;
+ n.display = n.display == 'block' ? 'none' : 'block';
+};
- // This is a global. I don't know why.
- decode = document.getElementById( 'searchField' );
- decode.value = unescape( decode.value );
- decode = document.getElementsByTagName( 'title' )[0];
- decode.innerHTML = unescape( decode.innerHTML );
+// Also problematic, not working until the page loads...
+for( var h = document.getElementsByTagName( 'h2' ), i = 0; i < h.length; i++ )
{
+ if ( h[i].className == 'section_heading' ) {
+ h[i].onclick = function() {
+ var section_idx = parseInt( this.id.replace(
/section_(\d+)/, '$1' ) );
+ wm_toggle_section( section_idx );
+ }
+ }
};
+// And this...
+for ( var a = document.getElementsByTagName( 'a' ), i = 0; i < a.length; i++ )
{
+ a[i].onclick = function() {
+ if ( this.hash.indexOf( '#' ) == 0 ) {
+ wm_reveal_for_hash( this.hash );
+ }
+ }
+};
+
+if ( document.location.hash.indexOf( '#' ) == 0 ) {
+ wm_reveal_for_hash( document.location.hash );
+}
+
+updateOrientation();
+
+// Try to scroll and hide URL bar
+window.scrollTo( 0, 1 );
+
+// This is a global. I don't know why.
+decode = document.getElementById( 'search' );
+decode.value = unescape( decode.value );
+decode = document.getElementsByTagName( 'title' )[0];
+decode.innerHTML = unescape( decode.innerHTML );
+
/**
* updateOrientation checks the current orientation, sets the body's class
* attribute to portrait, landscapeLeft, or landscapeRight,
Modified:
branches/wmf/1.17wmf1/extensions/MobileFrontend/views/layout/application.html.php
===================================================================
---
branches/wmf/1.17wmf1/extensions/MobileFrontend/views/layout/application.html.php
2011-09-19 20:58:29 UTC (rev 97556)
+++
branches/wmf/1.17wmf1/extensions/MobileFrontend/views/layout/application.html.php
2011-09-19 21:00:35 UTC (rev 97557)
@@ -34,7 +34,6 @@
}
//]]>
</script>
- <script type="text/javascript" language="javascript"
src="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/application.js?version=20110912T172820Z"></script>
</head>
<body>
{$searchWebkitHtml}
@@ -43,6 +42,7 @@
{$contentHtml}
</div>
{$footerHtml}
+ <script type="text/javascript" language="javascript"
src="{$wgExtensionAssetsPath}/MobileFrontend/javascripts/application.js?version=20110919T172820Z"></script>
</body>
</html>
EOT;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs