1 // Inside closure to prevent any collisions or leaks 2 (function( Simples, DOC ){ 3 4 var root = DOC.documentElement, div = DOC.createElement("div"), script = DOC.createElement(SCRIPT), id = SCRIPT + new Date().getTime(); 5 6 div.style.display = "none"; 7 div.innerHTML = " <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>"; 8 9 var all = div.getElementsByTagName("*"), a = div.getElementsByTagName("a")[0]; 10 11 // Can't get basic test support 12 if ( !all || !all.length || !a ) { 13 return; 14 } 15 var fragment = DOC.createDocumentFragment(), testDiv = DOC.createElement("div"); 16 testDiv.innerHTML = "<input type='radio' name='radiotest' checked='checked'/>"; 17 fragment.appendChild( testDiv.firstChild ); 18 19 // Technique from Juriy Zaytsev 20 // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/ 21 var eventSupported = function( eventName ) { 22 var el = DOC.createElement("div"); 23 eventName = "on" + eventName; 24 25 var isSupported = (eventName in el); 26 if ( !isSupported ) { 27 el.setAttribute(eventName, "return;"); 28 isSupported = typeof el[eventName] === "function"; 29 } 30 el = null; 31 32 return isSupported; 33 }; 34 35 Simples.merge( /** @lends Simples */ { 36 support : { 37 // to determine whether querySelector is avaliable 38 useQuerySelector : typeof DOC.querySelectorAll === "function", 39 // Make sure that element opacity exists 40 // (IE uses filter instead) 41 // Use a regex to work around a WebKit issue. See jQuery #5145 42 opacity : /^0.55$/.test( a.style.opacity ), 43 // Verify style float existence 44 // (IE uses styleFloat instead of cssFloat) 45 cssFloat: !!a.style.cssFloat, 46 // IE strips leading whitespace when .innerHTML is used 47 leadingWhitespace: div.firstChild.nodeType === 3, 48 // Make sure that if no value is specified for a checkbox 49 // that it defaults to "on". 50 // (WebKit defaults to "" instead) 51 checkOn: div.getElementsByTagName("input")[0].value === "on", 52 // WebKit doesn't clone checked state correctly in fragments 53 checkClone : fragment.cloneNode(true).cloneNode(true).lastChild.checked, 54 // Event support 55 submitBubbles : eventSupported("submit"), 56 changeBubbles : eventSupported("change"), 57 // standard setup 58 scriptEval: false, 59 // standard setup 60 noCloneEvent: true, 61 // Box model support 62 isBoxModel: null 63 }, 64 // Use of Simples.browser is frowned upon. 65 // More details: http://docs.jquery.com/Utilities/jQuery.browser 66 /** 67 * @description takes a navigator.userAgent and returns a usable rendition of it 68 * @params {String} navigator.userAgent 69 * @returns {Object} i.e. { browser: msie|opera|webkit|mozilla, version: 1 } 70 */ 71 uaMatch: function( ua ) { 72 ua = ua.toLowerCase(); 73 74 var match = /(webkit)[ \/]([\w.]+)/.exec( ua ) || 75 /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) || 76 /(msie) ([\w.]+)/.exec( ua ) || 77 !/compatible/.test( ua ) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) || 78 []; 79 80 return { browser: match[1] || "", version: match[2] || "0" }; 81 }, 82 browser : {} 83 }); 84 85 script.type = "text/javascript"; 86 try { 87 script.appendChild( document.createTextNode( "window." + id + "=1;" ) ); 88 } catch(e) {} 89 90 root.insertBefore( script, root.firstChild ); 91 92 // Make sure that the execution of code works by injecting a script 93 // tag with appendChild/createTextNode 94 // (IE doesn't support this, fails, and uses .text instead) 95 if ( WIN[ id ] ) { 96 Simples.support.scriptEval = true; 97 delete WIN[ id ]; 98 } 99 100 root.removeChild( script ); 101 102 if ( div.attachEvent && div.fireEvent ) { 103 div.attachEvent("onclick", function click() { 104 // Cloning a node shouldn't copy over any 105 // bound event handlers (IE does this) 106 Simples.support.noCloneEvent = false; 107 div.detachEvent("onclick", click); 108 }); 109 div.cloneNode(true).fireEvent("onclick"); 110 } 111 112 var browserMatch = Simples.uaMatch( navigator.userAgent ); 113 if ( browserMatch.browser ) { 114 Simples.browser[ browserMatch.browser ] = true; 115 Simples.browser.version = browserMatch.version; 116 } 117 118 Simples.ready(function(){ 119 var div = DOC.createElement("div"); 120 div.style.width = div.style.paddingLeft = "1px"; 121 122 DOC.body.appendChild( div ); 123 Simples.support.isBoxModel = div.offsetWidth === 2; 124 DOC.body.removeChild( div ).style.display = 'none'; 125 div = null; 126 }); 127 // nulling out support varaibles as finished 128 root = div = script = id = testDiv = null; 129 130 })( Simples, document ); 131