source: main/kwarapoly.theme/trunk/kwarapoly/theme/kwarapoly_theme/js/css3-mediaqueries.js @ 11423

Last change on this file since 11423 was 10866, checked in by Henrik Bettermann, 11 years ago

Fill trunk

File size: 15.6 KB
Line 
1if(typeof Object.create!=="function"){
2Object.create=function(o){
3function F(){
4};
5F.prototype=o;
6return new F();
7};
8}
9var ua={toString:function(){
10return navigator.userAgent;
11},test:function(s){
12return this.toString().toLowerCase().indexOf(s.toLowerCase())>-1;
13}};
14ua.version=(ua.toString().toLowerCase().match(/[\s\S]+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1];
15ua.webkit=ua.test("webkit");
16ua.gecko=ua.test("gecko")&&!ua.webkit;
17ua.opera=ua.test("opera");
18ua.ie=ua.test("msie")&&!ua.opera;
19ua.ie6=ua.ie&&document.compatMode&&typeof document.documentElement.style.maxHeight==="undefined";
20ua.ie7=ua.ie&&document.documentElement&&typeof document.documentElement.style.maxHeight!=="undefined"&&typeof XDomainRequest==="undefined";
21ua.ie8=ua.ie&&typeof XDomainRequest!=="undefined";
22var domReady=function(){
23var _1=[];
24var _2=function(){
25if(!arguments.callee.done){
26arguments.callee.done=true;
27for(var i=0;i<_1.length;i++){
28_1[i]();
29}
30}
31};
32if(document.addEventListener){
33document.addEventListener("DOMContentLoaded",_2,false);
34}
35if(ua.ie){
36(function(){
37try{
38document.documentElement.doScroll("left");
39}
40catch(e){
41setTimeout(arguments.callee,50);
42return;
43}
44_2();
45})();
46document.onreadystatechange=function(){
47if(document.readyState==="complete"){
48document.onreadystatechange=null;
49_2();
50}
51};
52}
53if(ua.webkit&&document.readyState){
54(function(){
55if(document.readyState!=="loading"){
56_2();
57}else{
58setTimeout(arguments.callee,10);
59}
60})();
61}
62window.onload=_2;
63return function(fn){
64if(typeof fn==="function"){
65_1[_1.length]=fn;
66}
67return fn;
68};
69}();
70var cssHelper=function(){
71var _3={BLOCKS:/[^\s{][^{]*\{(?:[^{}]*\{[^{}]*\}[^{}]*|[^{}]*)*\}/g,BLOCKS_INSIDE:/[^\s{][^{]*\{[^{}]*\}/g,DECLARATIONS:/[a-zA-Z\-]+[^;]*:[^;]+;/g,RELATIVE_URLS:/url\(['"]?([^\/\)'"][^:\)'"]+)['"]?\)/g,REDUNDANT_COMPONENTS:/(?:\/\*([^*\\\\]|\*(?!\/))+\*\/|@import[^;]+;)/g,REDUNDANT_WHITESPACE:/\s*(,|:|;|\{|\})\s*/g,MORE_WHITESPACE:/\s{2,}/g,FINAL_SEMICOLONS:/;\}/g,NOT_WHITESPACE:/\S+/g};
72var _4,_5=false;
73var _6=[];
74var _7=function(fn){
75if(typeof fn==="function"){
76_6[_6.length]=fn;
77}
78};
79var _8=function(){
80for(var i=0;i<_6.length;i++){
81_6[i](_4);
82}
83};
84var _9={};
85var _a=function(n,v){
86if(_9[n]){
87var _b=_9[n].listeners;
88if(_b){
89for(var i=0;i<_b.length;i++){
90_b[i](v);
91}
92}
93}
94};
95var _c=function(_d,_e,_f){
96if(ua.ie&&!window.XMLHttpRequest){
97window.XMLHttpRequest=function(){
98return new ActiveXObject("Microsoft.XMLHTTP");
99};
100}
101if(!XMLHttpRequest){
102return "";
103}
104var r=new XMLHttpRequest();
105try{
106r.open("get",_d,true);
107r.setRequestHeader("X_REQUESTED_WITH","XMLHttpRequest");
108}
109catch(e){
110_f();
111return;
112}
113var _10=false;
114setTimeout(function(){
115_10=true;
116},5000);
117document.documentElement.style.cursor="progress";
118r.onreadystatechange=function(){
119if(r.readyState===4&&!_10){
120if(!r.status&&location.protocol==="file:"||(r.status>=200&&r.status<300)||r.status===304||navigator.userAgent.indexOf("Safari")>-1&&typeof r.status==="undefined"){
121_e(r.responseText);
122}else{
123_f();
124}
125document.documentElement.style.cursor="";
126r=null;
127}
128};
129r.send("");
130};
131var _11=function(_12){
132_12=_12.replace(_3.REDUNDANT_COMPONENTS,"");
133_12=_12.replace(_3.REDUNDANT_WHITESPACE,"$1");
134_12=_12.replace(_3.MORE_WHITESPACE," ");
135_12=_12.replace(_3.FINAL_SEMICOLONS,"}");
136return _12;
137};
138var _13={mediaQueryList:function(s){
139var o={};
140var idx=s.indexOf("{");
141var lt=s.substring(0,idx);
142s=s.substring(idx+1,s.length-1);
143var mqs=[],rs=[];
144var qts=lt.toLowerCase().substring(7).split(",");
145for(var i=0;i<qts.length;i++){
146mqs[mqs.length]=_13.mediaQuery(qts[i],o);
147}
148var rts=s.match(_3.BLOCKS_INSIDE);
149if(rts!==null){
150for(i=0;i<rts.length;i++){
151rs[rs.length]=_13.rule(rts[i],o);
152}
153}
154o.getMediaQueries=function(){
155return mqs;
156};
157o.getRules=function(){
158return rs;
159};
160o.getListText=function(){
161return lt;
162};
163o.getCssText=function(){
164return s;
165};
166return o;
167},mediaQuery:function(s,mql){
168s=s||"";
169var not=false,_14;
170var exp=[];
171var _15=true;
172var _16=s.match(_3.NOT_WHITESPACE);
173for(var i=0;i<_16.length;i++){
174var _17=_16[i];
175if(!_14&&(_17==="not"||_17==="only")){
176if(_17==="not"){
177not=true;
178}
179}else{
180if(!_14){
181_14=_17;
182}else{
183if(_17.charAt(0)==="("){
184var _18=_17.substring(1,_17.length-1).split(":");
185exp[exp.length]={mediaFeature:_18[0],value:_18[1]||null};
186}
187}
188}
189}
190return {getList:function(){
191return mql||null;
192},getValid:function(){
193return _15;
194},getNot:function(){
195return not;
196},getMediaType:function(){
197return _14;
198},getExpressions:function(){
199return exp;
200}};
201},rule:function(s,mql){
202var o={};
203var idx=s.indexOf("{");
204var st=s.substring(0,idx);
205var ss=st.split(",");
206var ds=[];
207var dts=s.substring(idx+1,s.length-1).split(";");
208for(var i=0;i<dts.length;i++){
209ds[ds.length]=_13.declaration(dts[i],o);
210}
211o.getMediaQueryList=function(){
212return mql||null;
213};
214o.getSelectors=function(){
215return ss;
216};
217o.getSelectorText=function(){
218return st;
219};
220o.getDeclarations=function(){
221return ds;
222};
223o.getPropertyValue=function(n){
224for(var i=0;i<ds.length;i++){
225if(ds[i].getProperty()===n){
226return ds[i].getValue();
227}
228}
229return null;
230};
231return o;
232},declaration:function(s,r){
233var idx=s.indexOf(":");
234var p=s.substring(0,idx);
235var v=s.substring(idx+1);
236return {getRule:function(){
237return r||null;
238},getProperty:function(){
239return p;
240},getValue:function(){
241return v;
242}};
243}};
244var _19=function(el){
245if(typeof el.cssHelperText!=="string"){
246return;
247}
248var o={mediaQueryLists:[],rules:[],selectors:{},declarations:[],properties:{}};
249var _1a=o.mediaQueryLists;
250var ors=o.rules;
251var _1b=el.cssHelperText.match(_3.BLOCKS);
252if(_1b!==null){
253for(var i=0;i<_1b.length;i++){
254if(_1b[i].substring(0,7)==="@media "){
255_1a[_1a.length]=_13.mediaQueryList(_1b[i]);
256ors=o.rules=ors.concat(_1a[_1a.length-1].getRules());
257}else{
258ors[ors.length]=_13.rule(_1b[i]);
259}
260}
261}
262var oss=o.selectors;
263var _1c=function(r){
264var ss=r.getSelectors();
265for(var i=0;i<ss.length;i++){
266var n=ss[i];
267if(!oss[n]){
268oss[n]=[];
269}
270oss[n][oss[n].length]=r;
271}
272};
273for(i=0;i<ors.length;i++){
274_1c(ors[i]);
275}
276var ods=o.declarations;
277for(i=0;i<ors.length;i++){
278ods=o.declarations=ods.concat(ors[i].getDeclarations());
279}
280var ops=o.properties;
281for(i=0;i<ods.length;i++){
282var n=ods[i].getProperty();
283if(!ops[n]){
284ops[n]=[];
285}
286ops[n][ops[n].length]=ods[i];
287}
288el.cssHelperParsed=o;
289_4[_4.length]=el;
290return o;
291};
292var _1d=function(el,s){
293el.cssHelperText=_11(s||el.innerHTML);
294return _19(el);
295};
296var _1e=function(){
297_5=true;
298_4=[];
299var _1f=[];
300var _20=function(){
301for(var i=0;i<_1f.length;i++){
302_19(_1f[i]);
303}
304var _21=document.getElementsByTagName("style");
305for(i=0;i<_21.length;i++){
306_1d(_21[i]);
307}
308_5=false;
309_8();
310};
311var _22=document.getElementsByTagName("link");
312for(var i=0;i<_22.length;i++){
313var _23=_22[i];
314if(_23.getAttribute("rel").indexOf("style")>-1&&_23.href&&_23.href.length!==0&&!_23.disabled){
315_1f[_1f.length]=_23;
316}
317}
318if(_1f.length>0){
319var c=0;
320var _24=function(){
321c++;
322if(c===_1f.length){
323_20();
324}
325};
326var _25=function(_26){
327var _27=_26.href;
328_c(_27,function(_28){
329_28=_11(_28).replace(_3.RELATIVE_URLS,"url("+_27.substring(0,_27.lastIndexOf("/"))+"/$1)");
330_26.cssHelperText=_28;
331_24();
332},_24);
333};
334for(i=0;i<_1f.length;i++){
335_25(_1f[i]);
336}
337}else{
338_20();
339}
340};
341var _29={mediaQueryLists:"array",rules:"array",selectors:"object",declarations:"array",properties:"object"};
342var _2a={mediaQueryLists:null,rules:null,selectors:null,declarations:null,properties:null};
343var _2b=function(_2c,v){
344if(_2a[_2c]!==null){
345if(_29[_2c]==="array"){
346return (_2a[_2c]=_2a[_2c].concat(v));
347}else{
348var c=_2a[_2c];
349for(var n in v){
350if(v.hasOwnProperty(n)){
351if(!c[n]){
352c[n]=v[n];
353}else{
354c[n]=c[n].concat(v[n]);
355}
356}
357}
358return c;
359}
360}
361};
362var _2d=function(_2e){
363_2a[_2e]=(_29[_2e]==="array")?[]:{};
364for(var i=0;i<_4.length;i++){
365_2b(_2e,_4[i].cssHelperParsed[_2e]);
366}
367return _2a[_2e];
368};
369domReady(function(){
370var els=document.body.getElementsByTagName("*");
371for(var i=0;i<els.length;i++){
372els[i].checkedByCssHelper=true;
373}
374if(document.implementation.hasFeature("MutationEvents","2.0")||window.MutationEvent){
375document.body.addEventListener("DOMNodeInserted",function(e){
376var el=e.target;
377if(el.nodeType===1){
378_a("DOMElementInserted",el);
379el.checkedByCssHelper=true;
380}
381},false);
382}else{
383setInterval(function(){
384var els=document.body.getElementsByTagName("*");
385for(var i=0;i<els.length;i++){
386if(!els[i].checkedByCssHelper){
387_a("DOMElementInserted",els[i]);
388els[i].checkedByCssHelper=true;
389}
390}
391},1000);
392}
393});
394var _2f=function(d){
395if(typeof window.innerWidth!="undefined"){
396return window["inner"+d];
397}else{
398if(typeof document.documentElement!="undefined"&&typeof document.documentElement.clientWidth!="undefined"&&document.documentElement.clientWidth!=0){
399return document.documentElement["client"+d];
400}
401}
402};
403return {addStyle:function(s,_30){
404var el=document.createElement("style");
405el.setAttribute("type","text/css");
406document.getElementsByTagName("head")[0].appendChild(el);
407if(el.styleSheet){
408el.styleSheet.cssText=s;
409}else{
410el.appendChild(document.createTextNode(s));
411}
412el.addedWithCssHelper=true;
413if(typeof _30==="undefined"||_30===true){
414cssHelper.parsed(function(_31){
415var o=_1d(el,s);
416for(var n in o){
417if(o.hasOwnProperty(n)){
418_2b(n,o[n]);
419}
420}
421_a("newStyleParsed",el);
422});
423}else{
424el.parsingDisallowed=true;
425}
426return el;
427},removeStyle:function(el){
428return el.parentNode.removeChild(el);
429},parsed:function(fn){
430if(_5){
431_7(fn);
432}else{
433if(typeof _4!=="undefined"){
434if(typeof fn==="function"){
435fn(_4);
436}
437}else{
438_7(fn);
439_1e();
440}
441}
442},mediaQueryLists:function(fn){
443cssHelper.parsed(function(_32){
444fn(_2a.mediaQueryLists||_2d("mediaQueryLists"));
445});
446},rules:function(fn){
447cssHelper.parsed(function(_33){
448fn(_2a.rules||_2d("rules"));
449});
450},selectors:function(fn){
451cssHelper.parsed(function(_34){
452fn(_2a.selectors||_2d("selectors"));
453});
454},declarations:function(fn){
455cssHelper.parsed(function(_35){
456fn(_2a.declarations||_2d("declarations"));
457});
458},properties:function(fn){
459cssHelper.parsed(function(_36){
460fn(_2a.properties||_2d("properties"));
461});
462},broadcast:_a,addListener:function(n,fn){
463if(typeof fn==="function"){
464if(!_9[n]){
465_9[n]={listeners:[]};
466}
467_9[n].listeners[_9[n].listeners.length]=fn;
468}
469},removeListener:function(n,fn){
470if(typeof fn==="function"&&_9[n]){
471var ls=_9[n].listeners;
472for(var i=0;i<ls.length;i++){
473if(ls[i]===fn){
474ls.splice(i,1);
475i-=1;
476}
477}
478}
479},getViewportWidth:function(){
480return _2f("Width");
481},getViewportHeight:function(){
482return _2f("Height");
483}};
484}();
485domReady(function enableCssMediaQueries(){
486var _37;
487var _38={LENGTH_UNIT:/[0-9]+(em|ex|px|in|cm|mm|pt|pc)$/,RESOLUTION_UNIT:/[0-9]+(dpi|dpcm)$/,ASPECT_RATIO:/^[0-9]+\/[0-9]+$/,ABSOLUTE_VALUE:/^[0-9]*(\.[0-9]+)*$/};
488var _39=[];
489var _3a=function(){
490var id="css3-mediaqueries-test";
491var el=document.createElement("div");
492el.id=id;
493var _3b=cssHelper.addStyle("@media all and (width) { #"+id+" { width: 1px !important; } }",false);
494document.body.appendChild(el);
495var ret=el.offsetWidth===1;
496_3b.parentNode.removeChild(_3b);
497el.parentNode.removeChild(el);
498_3a=function(){
499return ret;
500};
501return ret;
502};
503var _3c=function(){
504_37=document.createElement("div");
505_37.style.cssText="position:absolute;top:-9999em;left:-9999em;"+"margin:0;border:none;padding:0;width:1em;font-size:1em;";
506document.body.appendChild(_37);
507if(_37.offsetWidth!==16){
508_37.style.fontSize=16/_37.offsetWidth+"em";
509}
510_37.style.width="";
511};
512var _3d=function(_3e){
513_37.style.width=_3e;
514var _3f=_37.offsetWidth;
515_37.style.width="";
516return _3f;
517};
518var _40=function(_41,_42){
519var l=_41.length;
520var min=(_41.substring(0,4)==="min-");
521var max=(!min&&_41.substring(0,4)==="max-");
522if(_42!==null){
523var _43;
524var _44;
525if(_38.LENGTH_UNIT.exec(_42)){
526_43="length";
527_44=_3d(_42);
528}else{
529if(_38.RESOLUTION_UNIT.exec(_42)){
530_43="resolution";
531_44=parseInt(_42,10);
532var _45=_42.substring((_44+"").length);
533}else{
534if(_38.ASPECT_RATIO.exec(_42)){
535_43="aspect-ratio";
536_44=_42.split("/");
537}else{
538if(_38.ABSOLUTE_VALUE){
539_43="absolute";
540_44=_42;
541}else{
542_43="unknown";
543}
544}
545}
546}
547}
548var _46,_47;
549if("device-width"===_41.substring(l-12,l)){
550_46=screen.width;
551if(_42!==null){
552if(_43==="length"){
553return ((min&&_46>=_44)||(max&&_46<_44)||(!min&&!max&&_46===_44));
554}else{
555return false;
556}
557}else{
558return _46>0;
559}
560}else{
561if("device-height"===_41.substring(l-13,l)){
562_47=screen.height;
563if(_42!==null){
564if(_43==="length"){
565return ((min&&_47>=_44)||(max&&_47<_44)||(!min&&!max&&_47===_44));
566}else{
567return false;
568}
569}else{
570return _47>0;
571}
572}else{
573if("width"===_41.substring(l-5,l)){
574_46=document.documentElement.clientWidth||document.body.clientWidth;
575if(_42!==null){
576if(_43==="length"){
577return ((min&&_46>=_44)||(max&&_46<_44)||(!min&&!max&&_46===_44));
578}else{
579return false;
580}
581}else{
582return _46>0;
583}
584}else{
585if("height"===_41.substring(l-6,l)){
586_47=document.documentElement.clientHeight||document.body.clientHeight;
587if(_42!==null){
588if(_43==="length"){
589return ((min&&_47>=_44)||(max&&_47<_44)||(!min&&!max&&_47===_44));
590}else{
591return false;
592}
593}else{
594return _47>0;
595}
596}else{
597if("device-aspect-ratio"===_41.substring(l-19,l)){
598return _43==="aspect-ratio"&&screen.width*_44[1]===screen.height*_44[0];
599}else{
600if("color-index"===_41.substring(l-11,l)){
601var _48=Math.pow(2,screen.colorDepth);
602if(_42!==null){
603if(_43==="absolute"){
604return ((min&&_48>=_44)||(max&&_48<_44)||(!min&&!max&&_48===_44));
605}else{
606return false;
607}
608}else{
609return _48>0;
610}
611}else{
612if("color"===_41.substring(l-5,l)){
613var _49=screen.colorDepth;
614if(_42!==null){
615if(_43==="absolute"){
616return ((min&&_49>=_44)||(max&&_49<_44)||(!min&&!max&&_49===_44));
617}else{
618return false;
619}
620}else{
621return _49>0;
622}
623}else{
624if("resolution"===_41.substring(l-10,l)){
625var res;
626if(_45==="dpcm"){
627res=_3d("1cm");
628}else{
629res=_3d("1in");
630}
631if(_42!==null){
632if(_43==="resolution"){
633return ((min&&res>=_44)||(max&&res<_44)||(!min&&!max&&res===_44));
634}else{
635return false;
636}
637}else{
638return res>0;
639}
640}else{
641return false;
642}
643}
644}
645}
646}
647}
648}
649}
650};
651var _4a=function(mq){
652var _4b=mq.getValid();
653var _4c=mq.getExpressions();
654var l=_4c.length;
655if(l>0){
656for(var i=0;i<l&&_4b;i++){
657_4b=_40(_4c[i].mediaFeature,_4c[i].value);
658}
659var not=mq.getNot();
660return (_4b&&!not||not&&!_4b);
661}
662};
663var _4d=function(mql){
664var mqs=mql.getMediaQueries();
665var t={};
666for(var i=0;i<mqs.length;i++){
667if(_4a(mqs[i])){
668t[mqs[i].getMediaType()]=true;
669}
670}
671var s=[],c=0;
672for(var n in t){
673if(t.hasOwnProperty(n)){
674if(c>0){
675s[c++]=",";
676}
677s[c++]=n;
678}
679}
680if(s.length>0){
681_39[_39.length]=cssHelper.addStyle("@media "+s.join("")+"{"+mql.getCssText()+"}",false);
682}
683};
684var _4e=function(_4f){
685for(var i=0;i<_4f.length;i++){
686_4d(_4f[i]);
687}
688if(ua.ie){
689document.documentElement.style.display="block";
690setTimeout(function(){
691document.documentElement.style.display="";
692},0);
693setTimeout(function(){
694cssHelper.broadcast("cssMediaQueriesTested");
695},100);
696}else{
697cssHelper.broadcast("cssMediaQueriesTested");
698}
699};
700var _50=function(){
701for(var i=0;i<_39.length;i++){
702cssHelper.removeStyle(_39[i]);
703}
704_39=[];
705cssHelper.mediaQueryLists(_4e);
706};
707var _51=0;
708var _52=function(){
709var _53=cssHelper.getViewportWidth();
710var _54=cssHelper.getViewportHeight();
711if(ua.ie){
712var el=document.createElement("div");
713el.style.position="absolute";
714el.style.top="-9999em";
715el.style.overflow="scroll";
716document.body.appendChild(el);
717_51=el.offsetWidth-el.clientWidth;
718document.body.removeChild(el);
719}
720var _55;
721var _56=function(){
722var vpw=cssHelper.getViewportWidth();
723var vph=cssHelper.getViewportHeight();
724if(Math.abs(vpw-_53)>_51||Math.abs(vph-_54)>_51){
725_53=vpw;
726_54=vph;
727clearTimeout(_55);
728_55=setTimeout(function(){
729if(!_3a()){
730_50();
731}else{
732cssHelper.broadcast("cssMediaQueriesTested");
733}
734},500);
735}
736};
737window.onresize=function(){
738var x=window.onresize||function(){
739};
740return function(){
741x();
742_56();
743};
744}();
745};
746var _57=document.documentElement;
747_57.style.marginLeft="-32767px";
748setTimeout(function(){
749_57.style.marginTop="";
750},20000);
751return function(){
752if(!_3a()){
753cssHelper.addListener("newStyleParsed",function(el){
754_4e(el.cssHelperParsed.mediaQueryLists);
755});
756cssHelper.addListener("cssMediaQueriesTested",function(){
757if(ua.ie){
758_57.style.width="1px";
759}
760setTimeout(function(){
761_57.style.width="";
762_57.style.marginLeft="";
763},0);
764cssHelper.removeListener("cssMediaQueriesTested",arguments.callee);
765});
766_3c();
767_50();
768}else{
769_57.style.marginLeft="";
770}
771_52();
772};
773}());
774try{
775document.execCommand("BackgroundImageCache",false,true);
776}
777catch(e){
778}
779
Note: See TracBrowser for help on using the repository browser.