From 9c9087b99cacd4c9621d5cb876e00900f4af5f28 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 2 Apr 2013 17:44:08 +1100 Subject: [PATCH] less bloated browser update no need for respond.js (ie8 compat stuff) preload store should not be naming stuff get, its reserved bad js generates for preload store use browse happy, cause its better --- .../javascripts/external/browser-update.js | 200 ++++-------------- .../javascripts/external/respond.min.js | 6 - app/assets/javascripts/preload_store.js | 2 +- app/views/layouts/application.html.erb | 4 +- config/locales/client.en.yml | 2 +- 5 files changed, 52 insertions(+), 162 deletions(-) delete mode 100644 app/assets/javascripts/external/respond.min.js diff --git a/app/assets/javascripts/external/browser-update.js b/app/assets/javascripts/external/browser-update.js index dce394ff66e..23eb4023d65 100644 --- a/app/assets/javascripts/external/browser-update.js +++ b/app/assets/javascripts/external/browser-update.js @@ -3,172 +3,66 @@ (function() { -var $buo = function(op,test) { -var jsv=5; -var n = window.navigator,b; -this.op=op||{}; -//options -this.op.l = op.l||n["language"]||n["userLanguage"]||document.documentElement.getAttribute("lang")||"en"; -this.op.vsakt = {i:9,f:13,o:12,s:5.1,n:20}; -this.op.vsdefault = {i:7,f:3.6,o:10.6,s:4,n:10}; -this.op.vs =op.vs||this.op.vsdefault; -for (b in this.op.vsakt) - if (this.op.vs[b]>=this.op.vsakt[b]) - this.op.vs[b]=this.op.vsakt[b]-0.05; +var $buo = function() { -if (!op.reminder || op.reminder<0.1 ) - this.op.reminder=0; -else - this.op.reminder=op.reminder||24; + this.op = {}; -this.op.onshow = op.onshow||function(o){}; -this.op.url= op.url||"http://browser-update.org/update.html"; -this.op.pageurl = op.pageurl || window.location.hostname || "unknown"; -this.op.newwindow=op.newwindow||false; + // sam: my main concern here is mobile, but its an outlier, for now we support ie9, set conditionally and stuff with pushState + if (window.ie === "new" || (window.history && window.history.pushState)) { + return; + } -this.op.test=test||op.test||false; -if (window.location.hash=="#test-bu") - this.op.test=true; + var t = I18n.t('js.browser_update'); -/* -if (op.new7 || (this.op.l=="de" && !this.op.test && Math.round(Math.random()*3)==1)) { //test new script - var e = document.createElement("script"); - e.setAttribute("type", "text/javascript"); - e.setAttribute("src", "http://browser-update.org/update7.js"); - document.body.appendChild(e); - return; -} -*/ + var div = document.createElement("div"); + this.op.div = div; + div.id="buorg"; + div.className="buorg"; + div.innerHTML= '
' + t + '
×
'; -function getBrowser() { - var n,v,t,ua = navigator.userAgent; - var names={i:'Internet Explorer',f:'Firefox',o:'Opera',s:'Apple Safari',n:'Netscape Navigator', c:"Chrome", x:"Other"}; - if (/like firefox|chromeframe|seamonkey|opera mini|meego|netfront|moblin|maemo|arora|camino|flot|k-meleon|fennec|kazehakase|galeon|android|mobile|iphone|ipod|ipad|epiphany|rekonq|symbian|webos/i.test(ua)) n="x"; - else if (/trident.(\d+\.\d+);/.test(ua)) n="io"; - else if (/MSIE (\d+\.\d+);/.test(ua)) n="i"; - else if (/Chrome.(\d+\.\d+)/i.test(ua)) n="c"; - else if (/Firefox.(\d+\.\d+)/i.test(ua)) n="f"; - else if (/Version.(\d+.\d+).{0,10}Safari/i.test(ua)) n="s"; - else if (/Safari.(\d+)/i.test(ua)) n="so"; - else if (/Opera.*Version.(\d+\.?\d+)/i.test(ua)) n="o"; - else if (/Opera.(\d+\.?\d+)/i.test(ua)) n="o"; - else if (/Netscape.(\d+)/i.test(ua)) n="n"; - else return {n:"x",v:0,t:names[n]}; - if (n=="x") return {n:"x",v:0,t:names[n]}; - v=new Number(RegExp.$1); - if (n=="so") { - v=((v<100) && 1.0) || ((v<130) && 1.2) || ((v<320) && 1.3) || ((v<520) && 2.0) || ((v<524) && 3.0) || ((v<526) && 3.2) ||4.0; - n="s"; - } - if (n=="i" && v==7 && window.XDomainRequest) { - v=8; - } -if (n=="io") { -n="i"; -if (v>4) v=9; -else if (v>3.1) v=8; -else if (v>3) v=7; -} -return {n:n,v:v,t:names[n]+" "+v} -} + var sheet = document.createElement("style"); -this.op.browser=getBrowser(); -if (!this.op.test && (!this.op.browser || !this.op.browser.n || this.op.browser.n=="x" || this.op.browser.n=="c" || document.cookie.indexOf("browserupdateorg=pause")>-1 || this.op.browser.v>this.op.vs[this.op.browser.n])) - return; + var style = ".buorg {position:absolute; z-index:111111;" + + "width:100%; top:0px; left:0px" + + "border-bottom:1px solid #A29330; " + + "background:#FDF2AB;" + + "text-align:left; " + + "font-family: sans-serif; color:#000; font-size: 14px;}" + + ".buorg div { padding: 8px; } " + + ".buorg a, .buorg a:visited {color:#E25600; text-decoration: underline;}" + + "#buorgclose { position: absolute; right: .5em; top:.2em; font-weight: bold; font-size:28px; padding:0; color: #A29330; }"; -if (!this.op.test) { - var i = new Image(); - //DISABLED TEMPORARYLY - //i.src="http://browser-update.org/viewcount.php?n="+this.op.browser.n+"&v="+this.op.browser.v + "&p="+ escape(this.op.pageurl) + "&jsv="+jsv; -} -if (this.op.reminder>0) { - var d = new Date(new Date().getTime() +1000*3600*this.op.reminder); - document.cookie = 'browserupdateorg=pause; expires='+d.toGMTString()+'; path=/'; -} -var ll=this.op.l.substr(0,2); -var languages = "de,en"; -if (languages.indexOf(ll)!==false) - this.op.url="http://browser-update.org/"+ll+"/update.html#"+jsv; -var tar=""; -if (this.op.newwindow) - tar=' target="_blank"'; - -function busprintf() { - var args=arguments; - var data = args[ 0 ]; - for( var k=1; kX'; - -var sheet = document.createElement("style"); -//sheet.setAttribute("type", "text/css"); -var style = ".buorg {position:absolute;z-index:111111;\ -width:100%; top:0px; left:0px; \ -border-bottom:1px solid #A29330; \ -background:#FDF2AB no-repeat 10px center url(http://browser-update.org/img/dialog-warning.gif);\ -text-align:left; cursor:pointer; \ -font-family: Arial,Helvetica,sans-serif; color:#000; font-size: 12px;}\ -.buorg div { padding:5px 36px 5px 40px; } \ -.buorg a,.buorg a:visited {color:#E25600; text-decoration: underline;}\ -#buorgclose { position: absolute; right: .5em; top:.2em; height: 20px; width: 12px; font-weight: bold;font-size:14px; padding:0; }"; -document.body.insertBefore(div,document.body.firstChild); -document.getElementsByTagName("head")[0].appendChild(sheet); -try { + document.body.insertBefore(div,document.body.firstChild); + document.getElementsByTagName("head")[0].appendChild(sheet); + try { sheet.innerText=style; sheet.innerHTML=style; -} -catch(e) { + } + catch(e) { try { - sheet.styleSheet.cssText=style; + sheet.styleSheet.cssText = style; } - catch(e) { - return; + catch(ex) { + return; } -} -var me=this; -div.onclick=function(){ - if (me.op.newwindow) - window.open(me.op.url,"_blank"); - else - window.location.href=me.op.url; - return false; + } + var me=this; + + + this.op.bodymt = document.body.style.marginTop; + document.body.style.marginTop = (div.clientHeight)+"px"; + + document.getElementById("buorgclose").onclick = function(e) { + var evt = e || window.event; + if (evt.stopPropagation) evt.stopPropagation(); + else evt.cancelBubble = true; + me.op.div.style.display="none"; + document.body.style.marginTop = me.op.bodymt; + return true; + }; + }; -div.getElementsByTagName("a")[0].onclick = function(e) { - var e = e || window.event; - if (e.stopPropagation) e.stopPropagation(); - else e.cancelBubble = true; - return true; -} -this.op.bodymt = document.body.style.marginTop; -document.body.style.marginTop = (div.clientHeight)+"px"; -document.getElementById("buorgclose").onclick = function(e) { - var e = e || window.event; - if (e.stopPropagation) e.stopPropagation(); - else e.cancelBubble = true; - me.op.div.style.display="none"; - document.body.style.marginTop = me.op.bodymt; - return true; -} -op.onshow(this.op); - -} -// var $buoop = $buoop||{}; -var $buoop = {vs:{i:8,f:13,o:10.6,s:4,n:9}, l:I18n.locale}; -$bu=$buo($buoop); +$bu=$buo(); })(this); diff --git a/app/assets/javascripts/external/respond.min.js b/app/assets/javascripts/external/respond.min.js deleted file mode 100644 index 21437ba0b0b..00000000000 --- a/app/assets/javascripts/external/respond.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */ -/*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */ -window.matchMedia=window.matchMedia||(function(e,f){var c,a=e.documentElement,b=a.firstElementChild||a.firstChild,d=e.createElement("body"),g=e.createElement("div");g.id="mq-test-1";g.style.cssText="position:absolute;top:-100em";d.style.background="none";d.appendChild(g);return function(h){g.innerHTML='­';a.insertBefore(d,b);c=g.offsetWidth==42;a.removeChild(d);return{matches:c,media:h}}})(document); - -/*! Respond.js v1.1.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */ -(function(e){e.respond={};respond.update=function(){};respond.mediaQueriesSupported=e.matchMedia&&e.matchMedia("only all").matches;if(respond.mediaQueriesSupported){return}var w=e.document,s=w.documentElement,i=[],k=[],q=[],o={},h=30,f=w.getElementsByTagName("head")[0]||s,g=w.getElementsByTagName("base")[0],b=f.getElementsByTagName("link"),d=[],a=function(){var D=b,y=D.length,B=0,A,z,C,x;for(;B-1,minw:F.match(/\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:F.match(/\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}}j()},l,r,v=function(){var z,A=w.createElement("div"),x=w.body,y=false;A.style.cssText="position:absolute;font-size:1em;width:1em";if(!x){x=y=w.createElement("body");x.style.background="none"}x.appendChild(A);s.insertBefore(x,s.firstChild);z=A.offsetWidth;if(y){s.removeChild(x)}else{x.removeChild(A)}z=p=parseFloat(z);return z},p,j=function(I){var x="clientWidth",B=s[x],H=w.compatMode==="CSS1Compat"&&B||w.body[x]||B,D={},G=b[b.length-1],z=(new Date()).getTime();if(I&&l&&z-l-1?(p||v()):1)}if(!!J){J=parseFloat(J)*(J.indexOf(y)>-1?(p||v()):1)}if(!K.hasquery||(!A||!L)&&(A||H>=C)&&(L||H<=J)){if(!D[K.media]){D[K.media]=[]}D[K.media].push(k[K.rules])}}for(var E in q){if(q[E]&&q[E].parentNode===f){f.removeChild(q[E])}}for(var E in D){var M=w.createElement("style"),F=D[E].join("\n");M.type="text/css";M.media=E;f.insertBefore(M,G.nextSibling);if(M.styleSheet){M.styleSheet.cssText=F}else{M.appendChild(w.createTextNode(F))}q.push(M)}},n=function(x,z){var y=c();if(!y){return}y.open("GET",x,true);y.onreadystatechange=function(){if(y.readyState!=4||y.status!=200&&y.status!=304){return}z(y.responseText)};if(y.readyState==4){return}y.send(null)},c=(function(){var x=false;try{x=new XMLHttpRequest()}catch(y){x=new ActiveXObject("Microsoft.XMLHTTP")}return function(){return x}})();a();respond.update=a;function t(){j(true)}if(e.addEventListener){e.addEventListener("resize",t,false)}else{if(e.attachEvent){e.attachEvent("onresize",t)}}})(this); \ No newline at end of file diff --git a/app/assets/javascripts/preload_store.js b/app/assets/javascripts/preload_store.js index 29b2cb6d819..60e89ce1e2f 100644 --- a/app/assets/javascripts/preload_store.js +++ b/app/assets/javascripts/preload_store.js @@ -66,7 +66,7 @@ PreloadStore = { @param {String} key the key to look up the object with @returns {Object} the object from the store **/ - get: function(key) { + "get": function(key) { return this.data[key]; }, diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d498957a1f2..4a2f36b923c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -21,6 +21,8 @@ + + <% unless current_user %>