Skip to content

Commit

Permalink
update to iepp v2.1pre - mostly for an Access Denied bugfix.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Aug 29, 2011
1 parent 664064c commit 3b721d0
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions modernizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,44 +921,56 @@ window.Modernizr = (function( window, document, undefined ) {
elem.innerHTML = '<elem></elem>';
return elem.childNodes.length !== 1; })() ) {

// iepp v2 by @jon_neal & afarkas : github.com/aFarkas/iepp/
// iepp v2.1pre by @jon_neal & afarkas : github.com/aFarkas/iepp/
(function(win, doc) {
win.iepp = win.iepp || {};
var iepp = win.iepp,
elems = iepp.html5elements || 'abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video',
elems = iepp.html5elements || 'abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|subline|summary|time|video',
elemsArr = elems.split('|'),
elemsArrLen = elemsArr.length,
elemRegExp = new RegExp('(^|\\s)('+elems+')', 'gi'),
elemRegExp = new RegExp('(^|\\s)('+elems+')', 'gi'),
tagRegExp = new RegExp('<(\/*)('+elems+')', 'gi'),
filterReg = /^\s*[\{\}]\s*$/,
ruleRegExp = new RegExp('(^|[^\\n]*?\\s)('+elems+')([^\\n]*)({[\\n\\w\\W]*?})', 'gi'),
docFrag = doc.createDocumentFragment(),
html = doc.documentElement,
head = html.firstChild,
head = doc.getElementsByTagName('script')[0].parentNode,
bodyElem = doc.createElement('body'),
styleElem = doc.createElement('style'),
printMedias = /print|all/,
body;

function shim(doc) {
var a = -1;
while (++a < elemsArrLen)
while (++a < elemsArrLen) {
// Use createElement so IE allows HTML5-named elements in a document
doc.createElement(elemsArr[a]);
}
}

iepp.getCSS = function(styleSheetList, mediaType) {
if(styleSheetList+'' === undefined){return '';}
try {
if(styleSheetList+'' === undefined){
return '';
}
} catch(er){
return '';
}
var a = -1,
len = styleSheetList.length,
styleSheet,
cssTextArr = [];
while (++a < len) {
styleSheet = styleSheetList[a];
//currently no test for disabled/alternate stylesheets
if(styleSheet.disabled){continue;}
if(styleSheet.disabled){
continue;
}
mediaType = styleSheet.media || mediaType;
// Get css from all non-screen stylesheets and their imports
if (printMedias.test(mediaType)) cssTextArr.push(iepp.getCSS(styleSheet.imports, mediaType), styleSheet.cssText);
if (printMedias.test(mediaType)){
cssTextArr.push(iepp.getCSS(styleSheet.imports, mediaType), styleSheet.cssText);
}
//reset mediaType to all with every new *not imported* stylesheet
mediaType = 'all';
}
Expand All @@ -970,7 +982,7 @@ window.Modernizr = (function( window, document, undefined ) {
rule;
while ((rule = ruleRegExp.exec(cssText)) != null){
// Replace all html5 element references with iepp substitute classnames
cssTextArr.push(( (filterReg.exec(rule[1]) ? '\n' : rule[1]) +rule[2]+rule[3]).replace(elemRegExp, '$1.iepp_$2')+rule[4]);
cssTextArr.push(( (filterReg.exec(rule[1]) ? '\n' : rule[1]) + rule[2] + rule[3]).replace(elemRegExp, '$1.iepp-$2') + rule[4]);
}
return cssTextArr.join('\n');
};
Expand All @@ -982,10 +994,13 @@ window.Modernizr = (function( window, document, undefined ) {
var nodeList = doc.getElementsByTagName(elemsArr[a]),
nodeListLen = nodeList.length,
b = -1;
while (++b < nodeListLen)
if (nodeList[b].className.indexOf('iepp_') < 0)
while (++b < nodeListLen){
if (nodeList[b].className.indexOf('iepp-') < 0){
// Append iepp substitute classnames to all html5 elements
nodeList[b].className += ' iepp_'+elemsArr[a];
nodeList[b].className += ' iepp-'+elemsArr[a];
}
}

}
docFrag.appendChild(body);
html.appendChild(bodyElem);
Expand All @@ -996,34 +1011,33 @@ window.Modernizr = (function( window, document, undefined ) {
bodyElem.innerHTML = body.innerHTML.replace(tagRegExp, '<$1font');
};


iepp._beforePrint = function() {
if(iepp.disablePP){return;}
// Write iepp custom print CSS
styleElem.styleSheet.cssText = iepp.parseCSS(iepp.getCSS(doc.styleSheets, 'all'));
iepp.writeHTML();
};

iepp.restoreHTML = function(){
iepp.restoreHTML = function() {
if(iepp.disablePP){return;}
// Undo everything done in onbeforeprint
bodyElem.innerHTML = '';
html.removeChild(bodyElem);
html.appendChild(body);
bodyElem.swapNode(body);
};

iepp._afterPrint = function(){
iepp._afterPrint = function() {
// Undo everything done in onbeforeprint
iepp.restoreHTML();
styleElem.styleSheet.cssText = '';
};



// Shim the document and iepp fragment
shim(doc);
shim(docFrag);

//
if(iepp.disablePP){return;}
if(iepp.disablePP){
return;
}

// Add iepp custom print style element
head.insertBefore(styleElem, head.firstChild);
Expand Down

0 comments on commit 3b721d0

Please sign in to comment.