Skip to content

Instantly share code, notes, and snippets.

@xyqfer
xyqfer / delegating.js
Created October 6, 2013 07:42
特殊事件委托
/* http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html */
<ol id="dropdown">
<li><a href="#">List item 1</a>
<ol>
<li><a href="#">List item 1.1</a></li>
<li><a href="#">List item 1.2</a></li>
<li><a href="#">List item 1.3</a></li>
</ol>
tests['localstorage'] = function() {
try {
localStorage.setItem(mod, mod);
localStorage.removeItem(mod);
return true;
} catch(e) {
return false;
}
};
@xyqfer
xyqfer / test.video.audio.js
Created October 2, 2013 08:03
检测多媒体
tests['video'] = function() {
var elem = document.createElement('video'),
bool = false;
// IE9 Running on Windows Server SKU can cause an exception to be thrown, bug #224
try {
if ( bool = !!elem.canPlayType ) {
bool = new Boolean(bool);
bool.ogg = elem.canPlayType('video/ogg; codecs="theora"') .replace(/^no$/,'');
@xyqfer
xyqfer / test.textshadow.js
Created October 2, 2013 08:00
检测 textshadow
tests['textshadow'] = function() {
return document.createElement('div').style.textShadow === '';
};
@xyqfer
xyqfer / test.multiplebgs.js
Created October 2, 2013 07:59
检测 多背景
tests['multiplebgs'] = function() {
setCss('background:url(https://),url(https://),red url(https://)');
return (/(url\s*\(.*?){3}/).test(mStyle.background);
};
@xyqfer
xyqfer / test.rgba.js
Created October 2, 2013 01:46
检测 rgba
function testRGBA() {
var elem = document.createElement("div");
elem.style.cssText = "background-color:rgba(150, 78, 9, .5);";
return !(elem.style.backgroundColor.indexOf("rgba") === -1);
}
@xyqfer
xyqfer / test.websocket.js
Created October 2, 2013 01:41
检测 websocket
tests['websockets'] = function() {
return 'WebSocket' in window || 'MozWebSocket' in window;
};
@xyqfer
xyqfer / test.drag.drop.js
Created October 2, 2013 01:40
检测 drag and drop
tests['draganddrop'] = function() {
var div = document.createElement('div');
return ('draggable' in div) || ('ondragstart' in div && 'ondrop' in div);
};
@xyqfer
xyqfer / test.history.js
Created October 2, 2013 01:39
检测 history
tests['history'] = function() {
return !!(window.history && history.pushState);
};
@xyqfer
xyqfer / test.post.message.js
Created October 2, 2013 01:37
检测 postMessage
tests['postmessage'] = function() {
return !!window.postMessage;
};