123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*!
  2. Support JS for legacy browsers.
  3. Includes:
  4. HTML5 Shiv
  5. @afarkas @jdalton @jon_neal @rem
  6. MIT/GPL2 Licensed
  7. https://github.com/aFarkas/html5shiv
  8. matchMedia() polyfill
  9. (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license
  10. Respond.js
  11. min/max-width media query polyfill
  12. (c) Scott Jehl. MIT/GPLv2 Lic.
  13. http://j.mp/respondjs
  14. */
  15. /*
  16. HTML5 Shiv v3.6.2 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
  17. */
  18. (function(l,f){function m(){var a=e.elements;return"string"==typeof a?a.split(" "):a}function i(a){var b=n[a[o]];b||(b={},h++,a[o]=h,n[h]=b);return b}function p(a,b,c){b||(b=f);if(g)return b.createElement(a);c||(c=i(b));b=c.cache[a]?c.cache[a].cloneNode():r.test(a)?(c.cache[a]=c.createElem(a)).cloneNode():c.createElem(a);return b.canHaveChildren&&!s.test(a)?c.frag.appendChild(b):b}function t(a,b){if(!b.cache)b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag();
  19. a.createElement=function(c){return!e.shivMethods?b.createElem(c):p(c,a,b)};a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+m().join().replace(/\w+/g,function(a){b.createElem(a);b.frag.createElement(a);return'c("'+a+'")'})+");return n}")(e,b.frag)}function q(a){a||(a=f);var b=i(a);if(e.shivCSS&&!j&&!b.hasCSS){var c,d=a;c=d.createElement("p");d=d.getElementsByTagName("head")[0]||d.documentElement;c.innerHTML="x<style>article,aside,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}</style>";
  20. c=d.insertBefore(c.lastChild,d.firstChild);b.hasCSS=!!c}g||t(a,b);return a}var k=l.html5||{},s=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,r=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,j,o="_html5shiv",h=0,n={},g;(function(){try{var a=f.createElement("a");a.innerHTML="<xyz></xyz>";j="hidden"in a;var b;if(!(b=1==a.childNodes.length)){f.createElement("a");var c=f.createDocumentFragment();b="undefined"==typeof c.cloneNode||
  21. "undefined"==typeof c.createDocumentFragment||"undefined"==typeof c.createElement}g=b}catch(d){g=j=!0}})();var e={elements:k.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup main mark meter nav output progress section summary time video",version:"3.6.2",shivCSS:!1!==k.shivCSS,supportsUnknownElements:g,shivMethods:!1!==k.shivMethods,type:"default",shivDocument:q,createElement:p,createDocumentFragment:function(a,b){a||(a=f);if(g)return a.createDocumentFragment();
  22. for(var b=b||i(a),c=b.frag.cloneNode(),d=0,e=m(),h=e.length;d<h;d++)c.createElement(e[d]);return c}};l.html5=e;q(f)})(this,document);
  23. /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
  24. /*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */
  25. window.matchMedia = window.matchMedia || (function( doc, undefined ) {
  26. "use strict";
  27. var bool,
  28. docElem = doc.documentElement,
  29. refNode = docElem.firstElementChild || docElem.firstChild,
  30. // fakeBody required for <FF4 when executed in <head>
  31. fakeBody = doc.createElement( "body" ),
  32. div = doc.createElement( "div" );
  33. div.id = "mq-test-1";
  34. div.style.cssText = "position:absolute;top:-100em";
  35. fakeBody.style.background = "none";
  36. fakeBody.appendChild(div);
  37. return function(q){
  38. div.innerHTML = "&shy;<style media=\"" + q + "\"> #mq-test-1 { width: 42px; }</style>";
  39. docElem.insertBefore( fakeBody, refNode );
  40. bool = div.offsetWidth === 42;
  41. docElem.removeChild( fakeBody );
  42. return {
  43. matches: bool,
  44. media: q
  45. };
  46. };
  47. }( document ));
  48. /*! Respond.js v1.1.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
  49. (function( win ){
  50. "use strict";
  51. //exposed namespace
  52. var respond = {};
  53. win.respond = respond;
  54. //define update even in native-mq-supporting browsers, to avoid errors
  55. respond.update = function(){};
  56. //expose media query support flag for external use
  57. respond.mediaQueriesSupported = win.matchMedia && win.matchMedia( "only all" ).matches;
  58. //if media queries are supported, exit here
  59. if( respond.mediaQueriesSupported ){
  60. return;
  61. }
  62. //define vars
  63. var doc = win.document,
  64. docElem = doc.documentElement,
  65. mediastyles = [],
  66. rules = [],
  67. appendedEls = [],
  68. parsedSheets = {},
  69. resizeThrottle = 30,
  70. head = doc.getElementsByTagName( "head" )[0] || docElem,
  71. base = doc.getElementsByTagName( "base" )[0],
  72. links = head.getElementsByTagName( "link" ),
  73. requestQueue = [],
  74. //loop stylesheets, send text content to translate
  75. ripCSS = function(){
  76. for( var i = 0; i < links.length; i++ ){
  77. var sheet = links[ i ],
  78. href = sheet.href,
  79. media = sheet.media,
  80. isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet";
  81. //only links plz and prevent re-parsing
  82. if( !!href && isCSS && !parsedSheets[ href ] ){
  83. // selectivizr exposes css through the rawCssText expando
  84. if (sheet.styleSheet && sheet.styleSheet.rawCssText) {
  85. translate( sheet.styleSheet.rawCssText, href, media );
  86. parsedSheets[ href ] = true;
  87. } else {
  88. if( (!/^([a-zA-Z:]*\/\/)/.test( href ) && !base) ||
  89. href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ){
  90. requestQueue.push( {
  91. href: href,
  92. media: media
  93. } );
  94. }
  95. }
  96. }
  97. }
  98. makeRequests();
  99. },
  100. //recurse through request queue, get css text
  101. makeRequests = function(){
  102. if( requestQueue.length ){
  103. var thisRequest = requestQueue.shift();
  104. ajax( thisRequest.href, function( styles ){
  105. translate( styles, thisRequest.href, thisRequest.media );
  106. parsedSheets[ thisRequest.href ] = true;
  107. // by wrapping recursive function call in setTimeout
  108. // we prevent "Stack overflow" error in IE7
  109. win.setTimeout(function(){ makeRequests(); },0);
  110. } );
  111. }
  112. },
  113. //find media blocks in css text, convert to style blocks
  114. translate = function( styles, href, media ){
  115. var qs = styles.match( /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi ),
  116. ql = qs && qs.length || 0;
  117. //try to get CSS path
  118. href = href.substring( 0, href.lastIndexOf( "/" ) );
  119. var repUrls = function( css ){
  120. return css.replace( /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, "$1" + href + "$2$3" );
  121. },
  122. useMedia = !ql && media;
  123. //if path exists, tack on trailing slash
  124. if( href.length ){ href += "/"; }
  125. //if no internal queries exist, but media attr does, use that
  126. //note: this currently lacks support for situations where a media attr is specified on a link AND
  127. //its associated stylesheet has internal CSS media queries.
  128. //In those cases, the media attribute will currently be ignored.
  129. if( useMedia ){
  130. ql = 1;
  131. }
  132. for( var i = 0; i < ql; i++ ){
  133. var fullq, thisq, eachq, eql;
  134. //media attr
  135. if( useMedia ){
  136. fullq = media;
  137. rules.push( repUrls( styles ) );
  138. }
  139. //parse for styles
  140. else{
  141. fullq = qs[ i ].match( /@media *([^\{]+)\{([\S\s]+?)$/ ) && RegExp.$1;
  142. rules.push( RegExp.$2 && repUrls( RegExp.$2 ) );
  143. }
  144. eachq = fullq.split( "," );
  145. eql = eachq.length;
  146. for( var j = 0; j < eql; j++ ){
  147. thisq = eachq[ j ];
  148. mediastyles.push( {
  149. media : thisq.split( "(" )[ 0 ].match( /(only\s+)?([a-zA-Z]+)\s?/ ) && RegExp.$2 || "all",
  150. rules : rules.length - 1,
  151. hasquery : thisq.indexOf("(") > -1,
  152. minw : thisq.match( /\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ),
  153. maxw : thisq.match( /\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" )
  154. } );
  155. }
  156. }
  157. applyMedia();
  158. },
  159. lastCall,
  160. resizeDefer,
  161. // returns the value of 1em in pixels
  162. getEmValue = function() {
  163. var ret,
  164. div = doc.createElement('div'),
  165. body = doc.body,
  166. fakeUsed = false;
  167. div.style.cssText = "position:absolute;font-size:1em;width:1em";
  168. if( !body ){
  169. body = fakeUsed = doc.createElement( "body" );
  170. body.style.background = "none";
  171. }
  172. body.appendChild( div );
  173. docElem.insertBefore( body, docElem.firstChild );
  174. ret = div.offsetWidth;
  175. if( fakeUsed ){
  176. docElem.removeChild( body );
  177. }
  178. else {
  179. body.removeChild( div );
  180. }
  181. //also update eminpx before returning
  182. ret = eminpx = parseFloat(ret);
  183. return ret;
  184. },
  185. //cached container for 1em value, populated the first time it's needed
  186. eminpx,
  187. //enable/disable styles
  188. applyMedia = function( fromResize ){
  189. var name = "clientWidth",
  190. docElemProp = docElem[ name ],
  191. currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[ name ] || docElemProp,
  192. styleBlocks = {},
  193. lastLink = links[ links.length-1 ],
  194. now = (new Date()).getTime();
  195. //throttle resize calls
  196. if( fromResize && lastCall && now - lastCall < resizeThrottle ){
  197. win.clearTimeout( resizeDefer );
  198. resizeDefer = win.setTimeout( applyMedia, resizeThrottle );
  199. return;
  200. }
  201. else {
  202. lastCall = now;
  203. }
  204. for( var i in mediastyles ){
  205. if( mediastyles.hasOwnProperty( i ) ){
  206. var thisstyle = mediastyles[ i ],
  207. min = thisstyle.minw,
  208. max = thisstyle.maxw,
  209. minnull = min === null,
  210. maxnull = max === null,
  211. em = "em";
  212. if( !!min ){
  213. min = parseFloat( min ) * ( min.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
  214. }
  215. if( !!max ){
  216. max = parseFloat( max ) * ( max.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
  217. }
  218. // 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
  219. if( !thisstyle.hasquery || ( !minnull || !maxnull ) && ( minnull || currWidth >= min ) && ( maxnull || currWidth <= max ) ){
  220. if( !styleBlocks[ thisstyle.media ] ){
  221. styleBlocks[ thisstyle.media ] = [];
  222. }
  223. styleBlocks[ thisstyle.media ].push( rules[ thisstyle.rules ] );
  224. }
  225. }
  226. }
  227. //remove any existing respond style element(s)
  228. for( var j in appendedEls ){
  229. if( appendedEls.hasOwnProperty( j ) ){
  230. if( appendedEls[ j ] && appendedEls[ j ].parentNode === head ){
  231. head.removeChild( appendedEls[ j ] );
  232. }
  233. }
  234. }
  235. //inject active styles, grouped by media type
  236. for( var k in styleBlocks ){
  237. if( styleBlocks.hasOwnProperty( k ) ){
  238. var ss = doc.createElement( "style" ),
  239. css = styleBlocks[ k ].join( "\n" );
  240. ss.type = "text/css";
  241. ss.media = k;
  242. //originally, ss was appended to a documentFragment and sheets were appended in bulk.
  243. //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!
  244. head.insertBefore( ss, lastLink.nextSibling );
  245. if ( ss.styleSheet ){
  246. ss.styleSheet.cssText = css;
  247. }
  248. else {
  249. ss.appendChild( doc.createTextNode( css ) );
  250. }
  251. //push to appendedEls to track for later removal
  252. appendedEls.push( ss );
  253. }
  254. }
  255. },
  256. //tweaked Ajax functions from Quirksmode
  257. ajax = function( url, callback ) {
  258. var req = xmlHttp();
  259. if (!req){
  260. return;
  261. }
  262. req.open( "GET", url, true );
  263. req.onreadystatechange = function () {
  264. if ( req.readyState !== 4 || req.status !== 200 && req.status !== 304 ){
  265. return;
  266. }
  267. callback( req.responseText );
  268. };
  269. if ( req.readyState === 4 ){
  270. return;
  271. }
  272. req.send( null );
  273. },
  274. //define ajax obj
  275. xmlHttp = (function() {
  276. var xmlhttpmethod = false;
  277. try {
  278. xmlhttpmethod = new win.XMLHttpRequest();
  279. }
  280. catch( e ){
  281. xmlhttpmethod = new win.ActiveXObject( "Microsoft.XMLHTTP" );
  282. }
  283. return function(){
  284. return xmlhttpmethod;
  285. };
  286. })();
  287. //translate CSS
  288. ripCSS();
  289. //expose update for re-running respond later on
  290. respond.update = ripCSS;
  291. //adjust on resize
  292. function callMedia(){
  293. applyMedia( true );
  294. }
  295. if( win.addEventListener ){
  296. win.addEventListener( "resize", callMedia, false );
  297. }
  298. else if( win.attachEvent ){
  299. win.attachEvent( "onresize", callMedia );
  300. }
  301. })(this);