first commit

This commit is contained in:
alazhar
2020-01-02 22:20:31 +07:00
commit 10eb3340ad
5753 changed files with 631345 additions and 0 deletions

View File

@ -0,0 +1,402 @@
// Angie Radtke 2009 - 2012 thanks to daniel //
/*global window, localStorage, Cookie, altopen, altclose, big, small, rightopen, rightclose, bildauf, bildzu */
Object.append(Browser.Features, {
localstorage: (function() {
return ('localStorage' in window) && window.localStorage !== null;
})()
});
function saveIt(name) {
var x = document.id(name).style.display;
if (!x) {
alert('No cookie available');
} else {
if (Browser.Features.localstorage) {
localStorage[name] = x;
} else {
Cookie.write(name, x, {duration: 7});
}
}
}
function readIt(name) {
if (Browser.Features.localstorage) {
return localStorage[name];
} else {
return Cookie.read(name);
}
}
function wrapperwidth(width) {
document.id('wrapper').setStyle('width', width);
}
// add Wai-Aria landmark-roles
window.addEvent('domready', function () {
if (document.id('nav')) {
document.id('nav').setProperties( {
role : 'navigation'
});
}
if (document.id('mod-search-searchword')) {
document.id(document.id('mod-search-searchword').form).set( {
role : 'search'
});
}
if (document.id('main')) {
document.id('main').setProperties( {
role : 'main'
});
}
if (document.id('right')) {
document.id('right').setProperties( {
role : 'contentinfo'
});
}
});
window.addEvent('domready', function() {
// get ankers
var myankers = document.id(document.body).getElements('a.opencloselink');
myankers.each(function(element) {
element.setProperty('role', 'tab');
var myid = element.getProperty('id');
myid = myid.split('_');
myid = 'module_' + myid[1];
document.id(element).setProperty('aria-controls', myid);
});
var list = document.id(document.body).getElements('div.moduletable_js');
list.each(function(element) {
if (element.getElement('div.module_content')) {
var el = element.getElement('div.module_content');
el.setProperty('role', 'tabpanel');
var myid = el.getProperty('id');
myid = myid.split('_');
myid = 'link_' + myid[1];
el.setProperty('aria-labelledby', myid);
var myclass = el.get('class');
var one = myclass.split(' ');
// search for active menu-item
var listelement = el.getElement('a.active');
var unique = el.id;
var nocookieset = readIt(unique);
if ((listelement) ||
((one[1] == 'open') && (nocookieset == null))) {
el.setStyle('display', 'block');
var eltern = el.getParent();
var elternh = eltern.getElement('h3');
var elternbild = eltern.getElement('img');
elternbild.setProperties( {
alt : altopen,
src : bildzu
});
elternbild.focus();
} else {
el.setStyle('display', 'none');
el.setProperty('aria-expanded', 'false');
}
unique = el.id;
var cookieset = readIt(unique);
if (cookieset == 'block') {
el.setStyle('display', 'block');
el.setProperty('aria-expanded', 'true');
}
}
});
});
window.addEvent('domready', function() {
var what = document.id('right');
// if rightcolumn
if (what != null) {
var whatid = what.id;
var rightcookie = readIt(whatid);
if (rightcookie == 'none') {
what.setStyle('display', 'none');
document.id('nav').addClass('leftbigger');
wrapperwidth(big);
var grafik = document.id('bild');
grafik.innerHTML = rightopen;
grafik.focus();
}
}
});
function auf(key) {
var el = document.id(key);
if (el.style.display == 'none') {
el.setStyle('display', 'block');
el.setProperty('aria-expanded', 'true');
if (key != 'right') {
el.slide('hide').slide('in');
el.getParent().setProperty('class', 'slide');
eltern = el.getParent().getParent();
elternh = eltern.getElement('h3');
elternh.addClass('high');
elternbild = eltern.getElement('img');
// elternbild.focus();
el.focus();
elternbild.setProperties( {
alt : altopen,
src : bildzu
});
}
if (key == 'right') {
document.id('right').setStyle('display', 'block');
wrapperwidth(small);
document.id('nav').removeClass('leftbigger');
grafik = document.id('bild');
document.id('bild').innerHTML = rightclose;
grafik.focus();
}
} else {
el.setStyle('display', 'none');
el.setProperty('aria-expanded', 'false');
el.removeClass('open');
if (key != 'right') {
eltern = el.getParent().getParent();
elternh = eltern.getElement('h3');
elternh.removeClass('high');
elternbild = eltern.getElement('img');
// alert(bildauf);
elternbild.setProperties( {
alt : altclose,
src : bildauf
});
elternbild.focus();
}
if (key == 'right') {
document.id('right').setStyle('display', 'none');
wrapperwidth(big);
document.id('nav').addClass('leftbigger');
grafik = document.id('bild');
grafik.innerHTML = rightopen;
grafik.focus();
}
}
// write cookie
saveIt(key);
}
// ########### Tabfunctions ####################
window.addEvent('domready', function() {
var alldivs = document.id(document.body).getElements('div.tabcontent');
var outerdivs = document.id(document.body).getElements('div.tabouter');
outerdivs = outerdivs.getProperty('id');
for (var i = 0; i < outerdivs.length; i++) {
alldivs = document.id(outerdivs[i]).getElements('div.tabcontent');
count = 0;
alldivs.each(function(element) {
count++;
var el = document.id(element);
el.setProperty('role', 'tabpanel');
el.setProperty('aria-hidden', 'false');
el.setProperty('aria-expanded', 'true');
elid = el.getProperty('id');
elid = elid.split('_');
elid = 'link_' + elid[1];
el.setProperty('aria-labelledby', elid);
if (count != 1) {
el.addClass('tabclosed').removeClass('tabopen');
el.setProperty('aria-hidden', 'true');
el.setProperty('aria-expanded', 'false');
}
});
countankers = 0;
allankers = document.id(outerdivs[i]).getElement('ul.tabs').getElements('a');
allankers.each(function(element) {
countankers++;
var el = document.id(element);
el.setProperty('aria-selected', 'true');
el.setProperty('role', 'tab');
linkid = el.getProperty('id');
moduleid = linkid.split('_');
moduleid = 'module_' + moduleid[1];
el.setProperty('aria-controls', moduleid);
if (countankers != 1) {
el.addClass('linkclosed').removeClass('linkopen');
el.setProperty('aria-selected', 'false');
}
});
}
});
function tabshow(elid) {
var el = document.id(elid);
var outerdiv = el.getParent();
outerdiv = outerdiv.getProperty('id');
var alldivs = document.id(outerdiv).getElements('div.tabcontent');
var liste = document.id(outerdiv).getElement('ul.tabs');
liste.getElements('a').setProperty('aria-selected', 'false');
alldivs.each(function(element) {
element.addClass('tabclosed').removeClass('tabopen');
element.setProperty('aria-hidden', 'true');
element.setProperty('aria-expanded', 'false');
});
el.addClass('tabopen').removeClass('tabclosed');
el.setProperty('aria-hidden', 'false');
el.setProperty('aria-expanded', 'true');
el.focus();
var getid = elid.split('_');
var activelink = 'link_' + getid[1];
document.id(activelink).setProperty('aria-selected', 'true');
liste.getElements('a').addClass('linkclosed').removeClass('linkopen');
document.id(activelink).addClass('linkopen').removeClass('linkclosed');
}
function nexttab(el) {
var outerdiv = document.id(el).getParent();
var liste = outerdiv.getElement('ul.tabs');
var getid = el.split('_');
var activelink = 'link_' + getid[1];
var aktiverlink = document.id(activelink).getProperty('aria-selected');
var tablinks = liste.getElements('a').getProperty('id');
for ( var i = 0; i < tablinks.length; i++) {
if (tablinks[i] == activelink) {
if (document.id(tablinks[i + 1]) != null) {
document.id(tablinks[i + 1]).onclick();
break;
}
}
}
}
// mobilemenuheader
var mobileMenu = new Class({
displayed:false,
initialize:function () {
var self = this;
// create the elements once
self.createElements();
// show the elements if the browser size is smaller
if (self.getX() <= 461 && !self.displayed) {
self.display();
}
// react on resize events
window.addEvent('resize', function () {
if (self.getX() >= 461) {
if (self.displayed) {
self.mobile.setStyle('display', 'none');
document.id('menuwrapper').setStyle('display', 'block');
self.displayed = false;
}
}
if (self.getX() < 461) {
if(!self.displayed) {
self.display();
}
}
});
},
getX: function() {
return document.body.getSize().x;
},
createElements:function () {
var self = this;
var Openmenu=Joomla.JText._('TPL_BEEZ3_OPENMENU');
var Closemenu=Joomla.JText._('TPL_BEEZ3_CLOSEMENU');
this.menu = document.id("header").getElement('ul.menu');
this.menuWrapper = new Element('div#menuwrapper', {
'role':'menubar'
});
// create the menu opener and assign events
this.mobile = new Element('div', {
'id':'mobile_select',
html:'<h2><a href=#" id="menuopener" onclick="return false;"><span>Openmenu</span></a></h2>',
styles:{
display:'block'
},
events:{
click:function () {
var state = self.menuWrapper.getStyle('display');
self.wrapper.toggle();
if (state == 'none') {
document.id('menuopener').set('html', Closemenu);
document.id('menuwrapper').setProperties({
'aria-expanded':'true',
'aria-hidden':'false'
});
} else {
document.id('menuopener').set('html', Openmenu);
document.id('menuwrapper').setProperties({
'aria-expanded':'false',
'aria-hidden':'true'
});
}
}
}
});
// add the menu to the dom
this.menuWrapper.wraps(this.menu);
// create the effect
this.wrapper = new Fx.Reveal(document.id('menuwrapper'), {
duration:'long',
transition:'bounce:out',
link:'chain'
});
// add the menuopener to the dom and hide it
this.mobile.setStyle('display', 'none')
.inject(document.id("header").getElement('#menuwrapper'), 'before');
},
display:function () {
this.menuWrapper.setStyle('display', 'none');
this.mobile.setStyle('display', 'block');
this.displayed = true;
}
});
window.addEvent('domready', function () {
new mobileMenu();
});
//For discussion and comments, see: http://remysharp.com/2009/01/07/html5-enabling-script/
(function(){if(!/*@cc_on!@*/0)return;var e = "abbr,article,aside,audio,canvas,datalist,details,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(','),i=e.length;while(i--){document.createElement(e[i])}})()

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,82 @@
/*global window, localStorage, fontSizeTitle, bigger, reset, smaller, biggerTitle, resetTitle, smallerTitle, Cookie */
var prefsLoaded = false;
var defaultFontSize = 100;
var currentFontSize = defaultFontSize;
Object.append(Browser.Features, {
localstorage: (function() {
return ('localStorage' in window) && window.localStorage !== null;
})()
});
function setFontSize(fontSize) {
document.body.style.fontSize = fontSize + '%';
}
function changeFontSize(sizeDifference) {
currentFontSize = parseInt(currentFontSize, 10) + parseInt(sizeDifference * 5, 10);
if (currentFontSize > 180) {
currentFontSize = 180;
} else if (currentFontSize < 60) {
currentFontSize = 60;
}
setFontSize(currentFontSize);
}
function revertStyles() {
currentFontSize = defaultFontSize;
changeFontSize(0);
}
function writeFontSize(value) {
if (Browser.Features.localstorage) {
localStorage.fontSize = value;
} else {
Cookie.write("fontSize", value, {duration: 180});
}
}
function readFontSize() {
if (Browser.Features.localstorage) {
return localStorage.fontSize;
} else {
return Cookie.read("fontSize");
}
}
function setUserOptions() {
if (!prefsLoaded) {
var size = readFontSize();
currentFontSize = size ? size : defaultFontSize;
setFontSize(currentFontSize);
prefsLoaded = true;
}
}
function addControls() {
var container = document.id('fontsize');
var content = '<h3>'+ fontSizeTitle +'</h3><p><a title="'+ biggerTitle +'" href="#" onclick="changeFontSize(2); return false">'+ bigger +'</a><span class="unseen">.</span><a href="#" title="'+resetTitle+'" onclick="revertStyles(); return false">'+ reset +'</a><span class="unseen">.</span><a href="#" title="'+ smallerTitle +'" onclick="changeFontSize(-2); return false">'+ smaller +'</a></p>';
container.set('html', content);
}
function saveSettings() {
writeFontSize(currentFontSize);
}
window.addEvent('domready', function () {
smaller = Joomla.JText._('TPL_BEEZ3_SMALLER');
fontSizeTitle = Joomla.JText._('TPL_BEEZ3_FONTSIZE');
bigger = Joomla.JText._('TPL_BEEZ3_BIGGER');
reset = Joomla.JText._('TPL_BEEZ3_RESET');
biggerTitle = Joomla.JText._('TPL_BEEZ3_INCREASE_SIZE');
smallerTitle = Joomla.JText._('TPL_BEEZ3_DECREASE_SIZE');
resetTitle = Joomla.JText._('TPL_BEEZ3_REVERT_STYLES_TO_DEFAULT');
});
window.addEvent('domready', setUserOptions);
window.addEvent('domready', addControls);
window.addEvent('unload', saveSettings);

View File

@ -0,0 +1,326 @@
/*! 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(doc, undefined){
var bool,
docElem = doc.documentElement,
refNode = docElem.firstElementChild || docElem.firstChild,
// fakeBody required for <FF4 when executed in <head>
fakeBody = doc.createElement('body'),
div = doc.createElement('div');
div.id = 'mq-test-1';
div.style.cssText = "position:absolute;top:-100em";
fakeBody.style.background = "none";
fakeBody.appendChild(div);
return function(q){
div.innerHTML = '&shy;<style media="'+q+'"> #mq-test-1 { width: 42px; }</style>';
docElem.insertBefore(fakeBody, refNode);
bool = div.offsetWidth == 42;
docElem.removeChild(fakeBody);
return { matches: bool, media: q };
};
})(document);
/*! Respond.js v1.1.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
(function( win ){
//exposed namespace
win.respond = {};
//define update even in native-mq-supporting browsers, to avoid errors
respond.update = function(){};
//expose media query support flag for external use
respond.mediaQueriesSupported = win.matchMedia && win.matchMedia( "only all" ).matches;
//if media queries are supported, exit here
if ( respond.mediaQueriesSupported ){ return; }
//define vars
var doc = win.document,
docElem = doc.documentElement,
mediastyles = [],
rules = [],
appendedEls = [],
parsedSheets = {},
resizeThrottle = 30,
head = doc.getElementsByTagName( "head" )[0] || docElem,
base = doc.getElementsByTagName( "base" )[0],
links = head.getElementsByTagName( "link" ),
requestQueue = [],
//loop stylesheets, send text content to translate
ripCSS = function(){
var sheets = links,
sl = sheets.length,
i = 0,
//vars for loop:
sheet, href, media, isCSS;
for( ; i < sl; i++ ){
sheet = sheets[ i ],
href = sheet.href,
media = sheet.media,
isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet";
//only links plz and prevent re-parsing
if ( !!href && isCSS && !parsedSheets[ href ] ){
// selectivizr exposes css through the rawCssText expando
if (sheet.styleSheet && sheet.styleSheet.rawCssText) {
translate( sheet.styleSheet.rawCssText, href, media );
parsedSheets[ href ] = true;
} else {
if ( (!/^([a-zA-Z:]*\/\/)/.test( href ) && !base)
|| href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ){
requestQueue.push( {
href: href,
media: media
} );
}
}
}
}
makeRequests();
},
//recurse through request queue, get css text
makeRequests = function(){
if ( requestQueue.length ){
var thisRequest = requestQueue.shift();
ajax( thisRequest.href, function( styles ){
translate( styles, thisRequest.href, thisRequest.media );
parsedSheets[ thisRequest.href ] = true;
makeRequests();
} );
}
},
//find media blocks in css text, convert to style blocks
translate = function( styles, href, media ){
var qs = styles.match( /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi ),
ql = qs && qs.length || 0,
//try to get CSS path
href = href.substring( 0, href.lastIndexOf( "/" )),
repUrls = function( css ){
return css.replace( /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, "$1" + href + "$2$3" );
},
useMedia = !ql && media,
//vars used in loop
i = 0,
j, fullq, thisq, eachq, eql;
//if path exists, tack on trailing slash
if ( href.length ){ href += "/"; }
//if no internal queries exist, but media attr does, use that
//note: this currently lacks support for situations where a media attr is specified on a link AND
//its associated stylesheet has internal CSS media queries.
//In those cases, the media attribute will currently be ignored.
if ( useMedia ){
ql = 1;
}
for( ; i < ql; i++ ){
j = 0;
//media attr
if ( useMedia ){
fullq = media;
rules.push( repUrls( styles ) );
}
//parse for styles
else{
fullq = qs[ i ].match( /@media *([^\{]+)\{([\S\s]+?)$/ ) && RegExp.$1;
rules.push( RegExp.$2 && repUrls( RegExp.$2 ) );
}
eachq = fullq.split( "," );
eql = eachq.length;
for( ; j < eql; j++ ){
thisq = eachq[ j ];
mediastyles.push( {
media : thisq.split( "(" )[ 0 ].match( /(only\s+)?([a-zA-Z]+)\s?/ ) && RegExp.$2 || "all",
rules : rules.length - 1,
hasquery: thisq.indexOf("(") > -1,
minw : thisq.match( /\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ),
maxw : thisq.match( /\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" )
} );
}
}
applyMedia();
},
lastCall,
resizeDefer,
// returns the value of 1em in pixels
getEmValue = function() {
var ret,
div = doc.createElement('div'),
body = doc.body,
fakeUsed = false;
div.style.cssText = "position:absolute;font-size:1em;width:1em";
if ( !body ){
body = fakeUsed = doc.createElement( "body" );
body.style.background = "none";
}
body.appendChild( div );
docElem.insertBefore( body, docElem.firstChild );
ret = div.offsetWidth;
if ( fakeUsed ){
docElem.removeChild( body );
}
else {
body.removeChild( div );
}
//also update eminpx before returning
ret = eminpx = parseFloat(ret);
return ret;
},
//cached container for 1em value, populated the first time it's needed
eminpx,
//enable/disable styles
applyMedia = function( fromResize ){
var name = "clientWidth",
docElemProp = docElem[ name ],
currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[ name ] || docElemProp,
styleBlocks = {},
lastLink = links[ links.length-1 ],
now = (new Date()).getTime();
//throttle resize calls
if ( fromResize && lastCall && now - lastCall < resizeThrottle ){
clearTimeout( resizeDefer );
resizeDefer = setTimeout( applyMedia, resizeThrottle );
return;
}
else {
lastCall = now;
}
for( var i in mediastyles ){
var thisstyle = mediastyles[ i ],
min = thisstyle.minw,
max = thisstyle.maxw,
minnull = min === null,
maxnull = max === null,
em = "em";
if ( !!min ){
min = parseFloat( min ) * ( min.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
}
if ( !!max ){
max = parseFloat( max ) * ( max.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
}
// if there's no media query at all (the () part), or min or max is not null, and if either is present, they're true
if ( !thisstyle.hasquery || ( !minnull || !maxnull ) && ( minnull || currWidth >= min ) && ( maxnull || currWidth <= max ) ){
if ( !styleBlocks[ thisstyle.media ] ){
styleBlocks[ thisstyle.media ] = [];
}
styleBlocks[ thisstyle.media ].push( rules[ thisstyle.rules ] );
}
}
//remove any existing respond style element(s)
for( var i in appendedEls ){
if ( appendedEls[ i ] && appendedEls[ i ].parentNode === head ){
head.removeChild( appendedEls[ i ] );
}
}
//inject active styles, grouped by media type
for( var i in styleBlocks ){
var ss = doc.createElement( "style" ),
css = styleBlocks[ i ].join( "\n" );
ss.type = "text/css";
ss.media = i;
//originally, ss was appended to a documentFragment and sheets were appended in bulk.
//this caused crashes in IE in a number of circumstances, such as when the HTML element had a bg image set, so appending beforehand seems best. Thanks to @dvelyk for the initial research on this one!
head.insertBefore( ss, lastLink.nextSibling );
if ( ss.styleSheet ){
ss.styleSheet.cssText = css;
}
else {
ss.appendChild( doc.createTextNode( css ) );
}
//push to appendedEls to track for later removal
appendedEls.push( ss );
}
},
//tweaked Ajax functions from Quirksmode
ajax = function( url, callback ) {
var req = xmlHttp();
if (!req){
return;
}
req.open( "GET", url, true );
req.onreadystatechange = function () {
if ( req.readyState != 4 || req.status != 200 && req.status != 304 ){
return;
}
callback( req.responseText );
}
if ( req.readyState == 4 ){
return;
}
req.send( null );
},
//define ajax obj
xmlHttp = (function() {
var xmlhttpmethod = false;
try {
xmlhttpmethod = new XMLHttpRequest();
}
catch( e ){
xmlhttpmethod = new ActiveXObject( "Microsoft.XMLHTTP" );
}
return function(){
return xmlhttpmethod;
};
})();
//translate CSS
ripCSS();
//expose update for re-running respond later on
respond.update = ripCSS;
//adjust on resize
function callMedia(){
applyMedia( true );
}
if ( win.addEventListener ){
win.addEventListener( "resize", callMedia, false );
}
else if( win.attachEvent ){
win.attachEvent( "onresize", callMedia );
}
})(this);

View File

@ -0,0 +1,331 @@
/*! 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(doc, undefined){
var bool,
docElem = doc.documentElement,
refNode = docElem.firstElementChild || docElem.firstChild,
// fakeBody required for <FF4 when executed in <head>
fakeBody = doc.createElement('body'),
div = doc.createElement('div');
div.id = 'mq-test-1';
div.style.cssText = "position:absolute;top:-100em";
fakeBody.style.background = "none";
fakeBody.appendChild(div);
return function(q){
div.innerHTML = '&shy;<style media="'+q+'"> #mq-test-1 { width: 42px; }</style>';
docElem.insertBefore(fakeBody, refNode);
bool = div.offsetWidth == 42;
docElem.removeChild(fakeBody);
return { matches: bool, media: q };
};
})(document);
/*! Respond.js v1.1.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
(function( win ){
//exposed namespace
win.respond = {};
//define update even in native-mq-supporting browsers, to avoid errors
respond.update = function(){};
//expose media query support flag for external use
respond.mediaQueriesSupported = win.matchMedia && win.matchMedia( "only all" ).matches;
//if media queries are supported, exit here
if ( respond.mediaQueriesSupported ){ return; }
//define vars
var doc = win.document,
docElem = doc.documentElement,
mediastyles = [],
rules = [],
appendedEls = [],
parsedSheets = {},
resizeThrottle = 30,
head = doc.getElementsByTagName( "head" )[0] || docElem,
base = doc.getElementsByTagName( "base" )[0],
links = head.getElementsByTagName( "link" ),
requestQueue = [],
//loop stylesheets, send text content to translate
ripCSS = function(){
var sheets = links,
sl = sheets.length,
i = 0,
//vars for loop:
sheet, href, media, isCSS;
for( ; i < sl; i++ ){
sheet = sheets[ i ],
href = sheet.href,
media = sheet.media,
isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet";
//only links plz and prevent re-parsing
if ( !!href && isCSS && !parsedSheets[ href ] ){
// selectivizr exposes css through the rawCssText expando
if (sheet.styleSheet && sheet.styleSheet.rawCssText) {
translate( sheet.styleSheet.rawCssText, href, media );
parsedSheets[ href ] = true;
} else {
if ( (!/^([a-zA-Z:]*\/\/)/.test( href ) && !base)
|| href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ){
requestQueue.push( {
href: href,
media: media
} );
}
}
}
}
makeRequests();
},
//recurse through request queue, get css text
makeRequests = function(){
if ( requestQueue.length ){
var thisRequest = requestQueue.shift();
ajax( thisRequest.href, function( styles ){
translate( styles, thisRequest.href, thisRequest.media );
parsedSheets[ thisRequest.href ] = true;
makeRequests();
} );
}
},
//find media blocks in css text, convert to style blocks
translate = function( styles, href, media ){
var qs = styles.match( /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi ),
ql = qs && qs.length || 0,
//try to get CSS path
href = href.substring( 0, href.lastIndexOf( "/" )),
repUrls = function( css ){
return css.replace( /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, "$1" + href + "$2$3" );
},
useMedia = !ql && media,
//vars used in loop
i = 0,
j, fullq, thisq, eachq, eql;
//if path exists, tack on trailing slash
if ( href.length ){ href += "/"; }
//if no internal queries exist, but media attr does, use that
//note: this currently lacks support for situations where a media attr is specified on a link AND
//its associated stylesheet has internal CSS media queries.
//In those cases, the media attribute will currently be ignored.
if ( useMedia ){
ql = 1;
}
for( ; i < ql; i++ ){
j = 0;
//media attr
if ( useMedia ){
fullq = media;
rules.push( repUrls( styles ) );
}
//parse for styles
else{
fullq = qs[ i ].match( /@media *([^\{]+)\{([\S\s]+?)$/ ) && RegExp.$1;
rules.push( RegExp.$2 && repUrls( RegExp.$2 ) );
}
eachq = fullq.split( "," );
eql = eachq.length;
for( ; j < eql; j++ ){
thisq = eachq[ j ];
mediastyles.push( {
media : thisq.split( "(" )[ 0 ].match( /(only\s+)?([a-zA-Z]+)\s?/ ) && RegExp.$2 || "all",
rules : rules.length - 1,
hasquery: thisq.indexOf("(") > -1,
minw : thisq.match( /\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ),
maxw : thisq.match( /\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" )
} );
}
}
applyMedia();
},
lastCall,
resizeDefer,
// returns the value of 1em in pixels
getEmValue = function() {
var ret,
div = doc.createElement('div'),
body = doc.body,
fakeUsed = false;
div.style.cssText = "position:absolute;font-size:1em;width:1em";
if ( !body ){
body = fakeUsed = doc.createElement( "body" );
body.style.background = "none";
}
body.appendChild( div );
docElem.insertBefore( body, docElem.firstChild );
ret = div.offsetWidth;
if ( fakeUsed ){
docElem.removeChild( body );
}
else {
body.removeChild( div );
}
//also update eminpx before returning
ret = eminpx = parseFloat(ret);
return ret;
},
//cached container for 1em value, populated the first time it's needed
eminpx,
//enable/disable styles
applyMedia = function( fromResize ){
var name = "clientWidth",
docElemProp = docElem[ name ],
currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[ name ] || docElemProp,
styleBlocks = {},
lastLink = links[ links.length-1 ],
now = (new Date()).getTime();
//throttle resize calls
if ( fromResize && lastCall && now - lastCall < resizeThrottle ){
clearTimeout( resizeDefer );
resizeDefer = setTimeout( applyMedia, resizeThrottle );
return;
}
else {
lastCall = now;
}
for( var i in mediastyles ){
var thisstyle = mediastyles[ i ],
min = thisstyle.minw,
max = thisstyle.maxw,
minnull = min === null,
maxnull = max === null,
em = "em";
if ( !!min ){
min = parseFloat( min ) * ( min.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
}
if ( !!max ){
max = parseFloat( max ) * ( max.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
}
// if there's no media query at all (the () part), or min or max is not null, and if either is present, they're true
if ( !thisstyle.hasquery || ( !minnull || !maxnull ) && ( minnull || currWidth >= min ) && ( maxnull || currWidth <= max ) ){
if ( !styleBlocks[ thisstyle.media ] ){
styleBlocks[ thisstyle.media ] = [];
}
styleBlocks[ thisstyle.media ].push( rules[ thisstyle.rules ] );
}
}
//remove any existing respond style element(s)
for( var i in appendedEls ){
if ( appendedEls[ i ] && appendedEls[ i ].parentNode === head ){
head.removeChild( appendedEls[ i ] );
}
}
//inject active styles, grouped by media type
for( var i in styleBlocks ){
var ss = doc.createElement( "style" ),
css = styleBlocks[ i ].join( "\n" );
ss.type = "text/css";
ss.media = i;
//originally, ss was appended to a documentFragment and sheets were appended in bulk.
//this caused crashes in IE in a number of circumstances, such as when the HTML element had a bg image set, so appending beforehand seems best. Thanks to @dvelyk for the initial research on this one!
head.insertBefore( ss, lastLink.nextSibling );
if ( ss.styleSheet ){
ss.styleSheet.cssText = css;
}
else {
ss.appendChild( doc.createTextNode( css ) );
}
//push to appendedEls to track for later removal
appendedEls.push( ss );
}
},
//tweaked Ajax functions from Quirksmode
ajax = function( url, callback ) {
var req = xmlHttp();
if (!req){
return;
}
req.open( "GET", url, true );
req.onreadystatechange = function () {
if ( req.readyState != 4 || req.status != 200 && req.status != 304 ){
return;
}
callback( req.responseText );
}
if ( req.readyState == 4 ){
return;
}
req.send( null );
},
//define ajax obj
xmlHttp = (function() {
var xmlhttpmethod = false;
try {
xmlhttpmethod = new XMLHttpRequest();
}
catch( e ){
xmlhttpmethod = new ActiveXObject( "Microsoft.XMLHTTP" );
}
return function(){
return xmlhttpmethod;
};
})();
//translate CSS
ripCSS();
//expose update for re-running respond later on
respond.update = ripCSS;
//adjust on resize
function callMedia(){
applyMedia( true );
}
if ( win.addEventListener ){
win.addEventListener( "resize", callMedia, false );
}
else if( win.attachEvent ){
win.attachEvent( "onresize", callMedia );
}
})(this);