r113283 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113282‎ | r113283 | r113284 >
Date:19:59, 7 March 2012
Author:jdlrobson
Status:ok
Tags:
Comment:
provide minified javascript

running make minified now generates minified versions of
all javascript code
these can be toggled between using the $minifyJS flag in
MobileFrontend.body.php

TODO: move to resource loader for JS - I understand there
are issues with using it at the current time

filesavings:
(beta_)application.js 5.1K ->2.6K
opensearch.js 5.3K -> 2.9K
beta_opensearch.js 8.5K->4.9K
banner.js 1.6K -> 831B

non-beta: 12K -> 6.331K
beta: 15.2K -> 8.33K

also change to version=1331146675 to bust varnish cache
Modified paths:
  • /trunk/extensions/MobileFrontend/Makefile (added) (history)
  • /trunk/extensions/MobileFrontend/MobileFrontend.body.php (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/application.min.js (added) (history)
  • /trunk/extensions/MobileFrontend/javascripts/banner.min.js (added) (history)
  • /trunk/extensions/MobileFrontend/javascripts/beta_application.min.js (added) (history)
  • /trunk/extensions/MobileFrontend/javascripts/beta_opensearch.min.js (added) (history)
  • /trunk/extensions/MobileFrontend/javascripts/opensearch.min.js (added) (history)
  • /trunk/extensions/MobileFrontend/templates/ApplicationTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php
@@ -34,6 +34,7 @@
3535 public static $leaveFeedbackURL;
3636 public static $mobileRedirectFormAction;
3737 public static $isBetaGroupMember = false;
 38+ public static $minifyJS = true;
3839 public static $hideSearchBox = false;
3940 public static $hideLogo = false;
4041 public static $hideFooter = false;
@@ -1209,6 +1210,7 @@
12101211 'dismissNotification' => self::$messages['mobile-frontend-dismiss-notification'],
12111212 'wgAppleTouchIcon' => $wgAppleTouchIcon,
12121213 'isBetaGroupMember' => self::$isBetaGroupMember,
 1214+ 'minifyJS' => self::$minifyJS,
12131215 'device' => self::$device,
12141216 'wgExtensionAssetsPath' => $wgExtensionAssetsPath,
12151217 'wgScriptPath' => $wgScriptPath,
Index: trunk/extensions/MobileFrontend/javascripts/beta_opensearch.min.js
@@ -0,0 +1 @@
 2+MobileFrontend.opensearch=(function(){var c="/api.php",p=-1,f=500,E=15,v,w=document.getElementById("results"),o=document.getElementById("search"),z=document.getElementById("sq"),a=document.getElementById("searchbox"),e=document.getElementById("logo"),g=document.getElementById("goButton"),y=document.getElementById("content"),s=document.getElementById("footer"),F=document.getElementById("zero-rated-banner")||document.getElementById("zero-rated-banner-red"),C=document.getElementById("clearsearch"),n=false,q={},r=MobileFrontend.utils;if(scriptPath){c=scriptPath+c}function x(){w.style.display="none"}function k(){if(navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)){var u=r('meta[name="viewport"]');if(u){u=u[0];u.content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0";r(document.body).bind("gesturestart",function(){u.content="width=device-width, initial-scale=1.0"})}}}k();o.onfocus=function(){var u,J,K,G,H,I;a=document.getElementById("searchbox");z=document.getElementById("sq");y=document.getElementById("content");s=document.getElementById("footer");k();if(!n){MobileFrontend.utils(document.body).addClass("full-screen-search");u=document.getElementById("placeholder");if(!u){J=document.createElement("span");K=document.createTextNode(placeholder);J.setAttribute("id","placeholder");J.appendChild(K);a.insertBefore(J,a.firstChild)}u=document.getElementById("placeholder");if(u){u.style.display="block"}if(u&&o.value!==""){u.style.display="none"}I=document.getElementById("remove-results");if(!I){G=document.createElement("a");G.setAttribute("href","#");G.setAttribute("id","remove-results");r(G).bind("click",D);H=document.createElement("div");H.setAttribute("id","left-arrow");G.appendChild(H);z.insertBefore(G,z.firstChild)}n=true}};function D(){MobileFrontend.utils(document.body).removeClass("full-screen-search");var G,u=document.getElementById("placeholder");if(u){u.style.display="none"}if(n){n=false}if(C){C.style.display="none"}}function b(G){var u;if(!G){G=window.event}if(G.target){u=G.target}else{if(G.srcElement){u=G.srcElement}}if(u.nodeType===3){u=u.parentNode}G.cancelBubble=true;G.stopPropagation();if(u.className==="suggestion-result"||u.className==="search-result-item"||u.className==="suggestions-result"||u.className==="sq-val-update"||u.id==="results"||u.id==="search"||u.id==="searchbox"||u.id==="sq"||u.id==="placeholder"||u.id==="clearsearch"||u.tagName==="BODY"){if(u.id==="clearsearch"&&w){w.innerHTML=""}}else{x()}}window.onload=function(){r(o).bind("keyup",function(){clearTimeout(p);v=this.value;if(v.length<1){w.innerHTML=""}else{v=encodeURIComponent(v);p=setTimeout(function(){m(v)},f)}})};function m(u){url=c+"?action=opensearch&limit="+E+"&namespace=0&format=xml&search="+u;r.ajax({url:url,success:function(G){t(j(G))}})}function j(J){var K=[],G,H,I,u=J.getElementsByTagName("Item");for(G=0;G<u.length;G++){H=u[G];I={label:H.getElementsByTagName("Text")[0].textContent,value:H.getElementsByTagName("Url")[0].textContent};K.push(I)}return K}function l(G){var u=document.getElementById("search");if(u){u.value=G+" ";u.focus();m(u.value)}}function h(H){var G=document.createTextNode(H);var u=document.createElement("div");u.appendChild(G);return u.innerHTML}function B(u){return u.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}function t(P){var J=document.getElementById("results"),L,K,I=h(document.getElementById("search").value),H,O,G,u,M,N;J.style.display="block";if(o){o.focus()}if(!P||P.length<1){J.innerHTML='<div class="suggestions-results" title="No Results">No Results</div>'}else{if(J.firstChild){J.removeChild(J.firstChild)}L=document.createElement("div");L.className="suggestions-results";J.appendChild(L);H=function(){var Q=this.parentNode.getAttribute("title");l(Q)};for(K=0;K<P.length;K++){O=P[K];u=document.createElement("div");M=document.createElement("a");u.setAttribute("title",O.label);u.className="suggestions-result";N=document.createTextNode("+");M.appendChild(N);M.className="sq-val-update";r(M).bind("click",H);u.appendChild(M);M=document.createElement("a");M.setAttribute("href",O.value);M.className="search-result-item";N=document.createTextNode(O.label);M.appendChild(N);u.appendChild(M);L.appendChild(u);G=B(I);M.innerHTML=M.innerHTML.replace(new RegExp("("+G+")","ig"),"<strong>$1</strong>")}}}function d(){var u=document.getElementById("placeholder");if(u){u.style.display="none"}}function i(){var K=document.getElementById("clearsearch"),G=document.getElementById("search"),u=document.getElementById("results");function I(){if(K){if(G.value.length>0){K.style.display="block"}else{K.style.display="none"}}}function H(L){G.value="";K.style.display="none";if(L){L.preventDefault()}}function J(){G.select()}r(K).bind("mousedown",H);r(G).bind("keyup",I);r(G).bind("keydown",d);r(G).bind("click",J)}function A(){var u=document.getElementById("results");u.onmousedown=b;document.body.onmousedown=b;document.body.ontouchstart=b;u.ontouchstart=b;o.onpaste=d}A();i();return{init:A,initClearSearch:i,writeResults:t,createObjectArray:j,removeResults:D}}());
\ No newline at end of file
Index: trunk/extensions/MobileFrontend/javascripts/application.min.js
@@ -0,0 +1 @@
 2+MobileFrontend=(function(){var a;function c(){var j,k,f,o,r,h,n=a(".section_heading");a(document.body).addClass("jsEnabled");window.wm_toggle_section=b;var h=a(".section_heading button");for(j=0;j<h.length;j++){a(h[j]).remove()}function m(){var i=this.id?this.id.split("_")[1]:-1;if(i>-1){b(i)}}function p(t){var s,i;s=document.createElement("button");i=document.createTextNode(t?"Show":"Hide");s.className=t?"show":"hide";s.appendChild(i);s.style.display=t?"inline-block":"none";return s}if(!n){n=[]}else{a(document.body).addClass("togglingEnabled")}for(j=0;j<n.length;j++){r=n[j];r.removeAttribute("onclick");r.insertBefore(p(true),r.firstChild);r.insertBefore(p(false),r.firstChild);a(r).bind("click",m)}k=document.getElementById("results");f=document.getElementById("languageselection");function g(){var i;if(f){i=f.options[f.selectedIndex].value;if(i){location.href=i}}}a(f).bind("change",g);function l(){var i=document.getElementById("nav").style;i.display=i.display==="block"?"none":"block"}a(document.getElementById("logo")).bind("click",l);function q(){var i=this.hash||document.location.hash;if(i.indexOf("#")===0){e(i)}}q();for(o=document.getElementsByTagName("a"),j=0;j<o.length;j++){a(o[j]).bind("click",q)}window.scrollTo(0,1)}function e(i){var g=document.getElementById(i.substr(1)),h,f;if(g){h=g;while(h&&h.className!=="content_block"&&h.className!=="section_heading"){h=h.parentNode}if(h&&h.style.display!=="block"){f=parseInt(h.id.split("_")[1],10);b(f)}}}function b(g){var f=document.getElementById("section_"+g),l=f.getElementsByTagName("button"),h,j,k;for(h=0;h<=1;h++){j=l[h].style;j.display=j.display==="none"||(h&&!j.display)?"inline-block":"none"}for(h=0,d=["content_","anchor_"];h<=1;h++){k=document.getElementById(d[h]+g);if(k){k.style.display=k.style.display==="block"?"none":"block"}}}a=typeof jQuery!=="undefined"?jQuery:function(g){if(typeof(g)==="string"){if(document.querySelectorAll){return[].slice.call(document.querySelectorAll(g))}}function h(k){var l=g.className,m=l.split(" ");m.push(k);g.className=m.join(" ")}function i(k){var m=g.className,n=m.split(" "),o=[],l;for(l=0;l<n.length;l++){if(n[l]!==k){o.push(n[l])}}g.className=o.join(" ")}function j(l,k){g.addEventListener(l,k,false)}function f(){g.parentNode.removeChild(g)}return{addClass:h,bind:j,remove:f,removeClass:i}};a.ajax=a.ajax||function(h){var f,g;if(window.XMLHttpRequest){f=new XMLHttpRequest()}else{f=new ActiveXObject("Microsoft.XMLHTTP")}if(f.overrideMimeType){f.overrideMimeType("text/xml")}f.onreadystatechange=function(){if(f.readyState===4&&f.status===200){h.success(f.responseXML)}};f.open("GET",h.url,true);f.send()};c();return{wm_reveal_for_hash:e,wm_toggle_section:b,init:c,utils:a}}());
\ No newline at end of file
Index: trunk/extensions/MobileFrontend/javascripts/banner.min.js
@@ -0,0 +1 @@
 2+MobileFrontend.banner=(function(){function d(){var f,h,e,g;f=document.getElementById("dismiss-notification");if(f){h="zeroRatedBannerVisibility";e=document.getElementById("zero-rated-banner")||document.getElementById("zero-rated-banner-red");g=c(h);if(g==="off"){e.style.display="none"}f.onclick=function(){if(e){e.style.display="none";a(h,"off",1)}}}}function a(g,h,i){var f,e;if(i){f=new Date();f.setTime(f.getTime()+(i*24*60*60*1000));e="; expires="+f.toGMTString()}else{e=""}document.cookie=g+"="+h+e+"; path=/"}function c(g){var f=g+"=",e=document.cookie.split(";"),j,h;for(h=0;h<e.length;h++){j=e[h];while(j.charAt(0)===" "){j=j.substring(1,j.length)}if(j.indexOf(f)===0){return j.substring(f.length,j.length)}}return null}function b(e){a(e,"",-1);return null}d();return{init:d,readCookie:c,writeCookie:a,removeCookie:b}})();
\ No newline at end of file
Index: trunk/extensions/MobileFrontend/javascripts/opensearch.min.js
@@ -0,0 +1 @@
 2+MobileFrontend.opensearch=(function(){var l="/api.php",c=-1,f=500,g=5,h=document.getElementById("results"),p=document.getElementById("search"),k=document.getElementById("searchbox"),m=MobileFrontend.utils;if(scriptPath){l=scriptPath+l}function b(){var q=document.getElementById("results");q.style.display="none"}function e(r){var q;if(!r){r=window.event}if(r.target){q=r.target}else{if(r.srcElement){q=r.srcElement}}if(q.nodeType===3){q=q.parentNode}r.cancelBubble=true;r.stopPropagation();if(!(q.className==="suggestion-result"||q.className==="search-result-item"||q.className==="suggestions-result"||q.className==="sq-val-update")){b()}}window.onload=function(){m(p).bind("keyup",function(){clearTimeout(c);var q=this.value;if(q.length<1){h.innerHTML=""}else{c=setTimeout(function(){o(q)},f)}})};function o(q){q=encodeURIComponent(q);url=l+"?action=opensearch&limit="+g+"&namespace=0&format=xml&search="+q;m.ajax({url:url,success:function(r){j(i(r))}})}function i(u){var v=[],r,s,t,q=u.getElementsByTagName("Item");for(r=0;r<q.length;r++){s=q[r];t={label:s.getElementsByTagName("Text")[0].textContent,value:s.getElementsByTagName("Url")[0].textContent};v.push(t)}return v}function d(r){var q=document.getElementById("search");if(q){q.value=r+" ";q.focus();o(q.value)}}function j(B){var t=document.getElementById("results"),w,u,s,A,q,y,z,r=document.getElementById("sq"),v=document.getElementById("header");t.style.display="block";var x=r.offsetParent.offsetTop+r.offsetHeight+r.offsetTop-1+v.offsetTop;t.style.top=x+"px";if(!B||B.length<1){t.innerHTML='<div class="suggestions-results"><div class="suggestions-result">No results</div></div>'}else{if(t.firstChild){t.removeChild(t.firstChild)}w=document.createElement("div");w.className="suggestions-results";t.appendChild(w);s=function(){var C=this.parentNode.getAttribute("title");d(C)};for(u=0;u<B.length;u++){A=B[u];q=document.createElement("div");y=document.createElement("a");q.setAttribute("title",A.label);q.className="suggestions-result";z=document.createTextNode("+");y.appendChild(z);y.className="sq-val-update";m(y).bind("click",s);q.appendChild(y);y=document.createElement("a");y.setAttribute("href",A.value);y.className="search-result-item";z=document.createTextNode(A.label);y.appendChild(z);q.appendChild(y);w.appendChild(q)}}}function a(){var v=document.getElementById("clearsearch"),r=document.getElementById("search"),q=document.getElementById("results");function t(){if(v){if(r.value.length>0){v.style.display="block"}else{v.style.display="none";if(q){q.style.display="none"}}}}function s(w){r.value="";v.style.display="none";if(q){q.style.display="none"}if(w){w.preventDefault()}}function u(){r.select()}m(v).bind("mousedown",s);m(r).bind("keyup",t);m(r).bind("click",u)}function n(){var q=document.getElementById("results");q.onmousedown=e;document.body.onmousedown=e;document.body.ontouchstart=e;q.ontouchstart=e}n();a();return{init:n,initClearSearch:a,writeResults:j,createObjectArray:i}}());
\ No newline at end of file
Index: trunk/extensions/MobileFrontend/javascripts/beta_application.min.js
@@ -0,0 +1 @@
 2+MobileFrontend=(function(){var a;function c(){var j,t,q,k,f,o,s,h,n=a(".section_heading");a(document.body).addClass("jsEnabled");window.wm_toggle_section=b;var h=a(".section_heading button");for(j=0;j<h.length;j++){a(h[j]).remove()}function m(){var i=this.id?this.id.split("_")[1]:-1;if(i>-1){b(i)}}function p(v){var u,i;u=document.createElement("button");i=document.createTextNode(v?"Show":"Hide");u.className=v?"show":"hide";u.appendChild(i);u.style.display=v?"inline-block":"none";return u}if(!n){n=[]}else{a(document.body).addClass("togglingEnabled")}for(j=0;j<n.length;j++){s=n[j];s.removeAttribute("onclick");s.insertBefore(p(true),s.firstChild);s.insertBefore(p(false),s.firstChild);a(s).bind("click",m)}k=document.getElementById("results");f=document.getElementById("languageselection");function g(){var i;if(f){i=f.options[f.selectedIndex].value;if(i){location.href=i}}}a(f).bind("change",g);function l(){var i=document.getElementById("nav").style;i.display=i.display==="block"?"none":"block"}a(document.getElementById("logo")).bind("click",l);function r(){var i=this.hash||document.location.hash;if(i.indexOf("#")===0){e(i)}}r();for(o=document.getElementsByTagName("a"),j=0;j<o.length;j++){a(o[j]).bind("click",r)}window.scrollTo(0,1)}function e(i){var g=document.getElementById(i.substr(1)),h,f;if(g){h=g;while(h&&h.className!=="content_block"&&h.className!=="section_heading"){h=h.parentNode}if(h&&h.style.display!=="block"){f=parseInt(h.id.split("_")[1],10);b(f)}}}function b(g){var f=document.getElementById("section_"+g),l=f.getElementsByTagName("button"),h,j,k;for(h=0;h<=1;h++){j=l[h].style;j.display=j.display==="none"||(h&&!j.display)?"inline-block":"none"}for(h=0,d=["content_","anchor_"];h<=1;h++){k=document.getElementById(d[h]+g);if(k){k.style.display=k.style.display==="block"?"none":"block"}}}a=typeof jQuery!=="undefined"?jQuery:function(g){if(typeof(g)==="string"){if(document.querySelectorAll){return[].slice.call(document.querySelectorAll(g))}}function h(k){var l=g.className,m=l.split(" ");m.push(k);g.className=m.join(" ")}function i(k){var m=g.className,n=m.split(" "),o=[],l;for(l=0;l<n.length;l++){if(n[l]!==k){o.push(n[l])}}g.className=o.join(" ")}function j(l,k){g.addEventListener(l,k,false)}function f(){g.parentNode.removeChild(g)}return{addClass:h,bind:j,remove:f,removeClass:i}};a.ajax=a.ajax||function(h){var f,g;if(window.XMLHttpRequest){f=new XMLHttpRequest()}else{f=new ActiveXObject("Microsoft.XMLHTTP")}if(f.overrideMimeType){f.overrideMimeType("text/xml")}f.onreadystatechange=function(){if(f.readyState===4&&f.status===200){h.success(f.responseXML)}};f.open("GET",h.url,true);f.send()};c();return{wm_reveal_for_hash:e,wm_toggle_section:b,init:c,utils:a}}());
\ No newline at end of file
Index: trunk/extensions/MobileFrontend/Makefile
@@ -0,0 +1,6 @@
 2+minified:
 3+ java -jar yuicompressor-2.4.6.jar javascripts/application.js -o javascripts/application.min.js
 4+ java -jar yuicompressor-2.4.6.jar javascripts/banner.js -o javascripts/banner.min.js
 5+ java -jar yuicompressor-2.4.6.jar javascripts/opensearch.js -o javascripts/opensearch.min.js
 6+ java -jar yuicompressor-2.4.6.jar javascripts/beta_application.js -o javascripts/beta_application.min.js
 7+ java -jar yuicompressor-2.4.6.jar javascripts/beta_opensearch.js -o javascripts/beta_opensearch.min.js
Index: trunk/extensions/MobileFrontend/templates/ApplicationTemplate.php
@@ -23,6 +23,7 @@
2424 }
2525 }
2626
 27+ $resourceSuffix = ( $this->data['minifyJS'] ) ? 'min.' : '';
2728 $betaPrefix = ( $this->data['isBetaGroupMember'] ) ? 'beta_' : '';
2829
2930 $noticeHtml = ( isset( $this->data['noticeHtml'] ) ) ? $this->data['noticeHtml'] : '';
@@ -33,7 +34,6 @@
3435 $endScriptTag = '"></script>';
3536 $javaScriptPath = $this->data['wgExtensionAssetsPath'] . '/MobileFrontend/javascripts/';
3637
37 - $openSearchScript = $startScriptTag . $javaScriptPath . $betaPrefix . 'opensearch.js?version=12142011129437' . $endScriptTag;
3838 $jQueryScript = ( $this->data['device']['supports_jquery'] ) ? $startScriptTag . $javaScriptPath . 'jquery-1.7.1.min.js' . $endScriptTag : '';
3939 $filePageScript = ( $this->data['isFilePage'] ) ? $startScriptTag . $javaScriptPath . 'filepage.js?version=122920111241' . $endScriptTag : '';
4040
@@ -48,7 +48,7 @@
4949 <head>
5050 <title>{$this->data['htmlTitle']}</title>
5151 <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
52 - <link href='{$this->data['wgExtensionAssetsPath']}/MobileFrontend/stylesheets/{$betaPrefix}common.css?version=01182012210728' media='all' rel='Stylesheet' type='text/css' />
 52+ <link href='{$this->data['wgExtensionAssetsPath']}/MobileFrontend/stylesheets/{$betaPrefix}common.css?version=1331146675' media='all' rel='Stylesheet' type='text/css' />
5353 <link href='{$this->data['wgExtensionAssetsPath']}/MobileFrontend/stylesheets/{$cssFileName}.css?version=01182012210728' media='all' rel='Stylesheet' type='text/css' />
5454 {$filePageStyle}
5555 <meta name="ROBOTS" content="NOINDEX, NOFOLLOW" />
@@ -72,9 +72,9 @@
7373 </div>
7474 {$this->data['footerHtml']}
7575 <!--[if gt IE 9]><!-->
76 - {$startScriptTag}{$javaScriptPath}{$betaPrefix}application.js?version=01132011120915{$endScriptTag}
77 - {$startScriptTag}{$javaScriptPath}banner.js{$endScriptTag}
78 - {$openSearchScript}
 76+ {$startScriptTag}{$javaScriptPath}{$betaPrefix}application.{$resourceSuffix}js?version=1331146675{$endScriptTag}
 77+ {$startScriptTag}{$javaScriptPath}banner.{$resourceSuffix}js?version=1331146675{$endScriptTag}
 78+ {$startScriptTag}{$javaScriptPath}{$betaPrefix}opensearch.{$resourceSuffix}js?version=1331146675{$endScriptTag}
7979 {$filePageScript}
8080 <!--[endif]-->
8181 </body>

Status & tagging log