mirror of
https://github.com/discourse/discourse.git
synced 2025-01-22 11:40:06 +08:00
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
This commit is contained in:
parent
ae82b5d0ea
commit
9c9087b99c
200
app/assets/javascripts/external/browser-update.js
vendored
200
app/assets/javascripts/external/browser-update.js
vendored
|
@ -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= '<div>' + t + '<div id="buorgclose">×</div></div>';
|
||||
|
||||
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; k<args.length; ++k ) {
|
||||
data = data.replace( /%s/, args[ k ] );
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
var t = I18n.t('js.browser_update', {url: this.op.url});
|
||||
if (op.text)
|
||||
t = op.text;
|
||||
|
||||
this.op.text=busprintf(t,this.op.browser.t,' href="'+this.op.url+'"'+tar);
|
||||
|
||||
var div = document.createElement("div");
|
||||
this.op.div = div;
|
||||
div.id="buorg";
|
||||
div.className="buorg";
|
||||
div.innerHTML= '<div>' + this.op.text + '<div id="buorgclose">X</div></div>';
|
||||
|
||||
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);
|
||||
|
|
|
@ -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='­<style media="'+h+'"> #mq-test-1 { width: 42px; }</style>';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<y;B++){A=D[B],z=A.href,C=A.media,x=A.rel&&A.rel.toLowerCase()==="stylesheet";if(!!z&&x&&!o[z]){if(A.styleSheet&&A.styleSheet.rawCssText){m(A.styleSheet.rawCssText,z,C);o[z]=true}else{if((!/^([a-zA-Z:]*\/\/)/.test(z)&&!g)||z.replace(RegExp.$1,"").split("/")[0]===e.location.host){d.push({href:z,media:C})}}}}u()},u=function(){if(d.length){var x=d.shift();n(x.href,function(y){m(y,x.href,x.media);o[x.href]=true;u()})}},m=function(I,x,z){var G=I.match(/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi),J=G&&G.length||0,x=x.substring(0,x.lastIndexOf("/")),y=function(K){return K.replace(/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,"$1"+x+"$2$3")},A=!J&&z,D=0,C,E,F,B,H;if(x.length){x+="/"}if(A){J=1}for(;D<J;D++){C=0;if(A){E=z;k.push(y(I))}else{E=G[D].match(/@media *([^\{]+)\{([\S\s]+?)$/)&&RegExp.$1;k.push(RegExp.$2&&y(RegExp.$2))}B=E.split(",");H=B.length;for(;C<H;C++){F=B[C];i.push({media:F.split("(")[0].match(/(only\s+)?([a-zA-Z]+)\s?/)&&RegExp.$2||"all",rules:k.length-1,hasquery:F.indexOf("(")>-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<h){clearTimeout(r);r=setTimeout(j,h);return}else{l=z}for(var E in i){var K=i[E],C=K.minw,J=K.maxw,A=C===null,L=J===null,y="em";if(!!C){C=parseFloat(C)*(C.indexOf(y)>-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);
|
|
@ -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];
|
||||
},
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<!--[if IE 9]><script type="text/javascript">ie = "new";</script><![endif]-->
|
||||
|
||||
<% unless current_user %>
|
||||
<form id='hidden-login-form' method="post" action="<%=login_path%>" style="display: none;">
|
||||
<input name="username" type="text" id="signin_username">
|
||||
|
@ -56,7 +58,7 @@
|
|||
<%- if @preloaded.present? %>
|
||||
<script>
|
||||
<%- @preloaded.each do |key, json| %>
|
||||
PreloadStore.store("<%= key %>", <%= raw json %>)
|
||||
PreloadStore.store("<%= key %>",<%= raw json %>);
|
||||
<% end %>
|
||||
</script>
|
||||
<%- end %>
|
||||
|
|
|
@ -705,7 +705,7 @@ en:
|
|||
other: "{{categoryName}} ({{count}})"
|
||||
help: "latest topics in the {{categoryName}} category"
|
||||
|
||||
browser_update: 'Unfortunately, <a href="http://www.discourse.org/faq/#browser">your browser is too old to work on this Discourse forum</a>. Please <a href="%{url}">upgrade your browser</a>.'
|
||||
browser_update: 'Unfortunately, <a href="http://www.discourse.org/faq/#browser">your browser is too old to work on this Discourse forum</a>. Please <a href="http://browsehappy.com">upgrade your browser</a>.'
|
||||
|
||||
# This section is exported to the javascript for i18n in the admin section
|
||||
admin_js:
|
||||
|
|
Loading…
Reference in New Issue
Block a user