Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Neal jonathantneal

View GitHub Profile
@jonathantneal
jonathantneal / allDefined.js
Created Oct 24, 2011
A really nice allDefined function
View allDefined.js
function isDefined(val) {
return val != null;
}
function allDefined() {
var
i = -1,
a = arguments,
l = as.length;
while (++i < l) if (a[i] == null) return false;
View nav.vm
<nav class="$nav_css_class" id="navigation">
<h1>
<span>#language("navigation")</span>
</h1>
<ul>
#foreach ($nav_item in $nav_items)
<li>
#set($nav_item_class = "")
View agnostic-html-shim.htc.html
<PUBLIC:COMPONENT lightWeight="true">
<PUBLIC:ATTACH EVENT="onreadystatechange" FOR="document" ONEVENT="shim()">
<SCRIPT>
// an agnostic html shim
// it doesn't believe in any particular element... yet!
// usage: <style> body { *behavior: url(iepp.htc); } </style> or anything like that
//
function shim() {
// stop if we already believe
var doc = element.document;//, elem = doc.createElement('i'); elem.innerHTML = "<iii>"; if (elem.childNodes.length) return;
@jonathantneal
jonathantneal / get-that-blasted-button-type-in-ie8.html
Created Nov 2, 2011
get-that-blasted-button-type-in-ie8.html
View get-that-blasted-button-type-in-ie8.html
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<meta charset="utf-8">
<title>GET THAT BLASTED BUTTON TYPE</title>
</head>
<body>
<button id="foo" class="a b c d=e"></button>
<button id="bar" type="submit"></button>
View cloneNode.js
(function (win, doc) {
// clone element with outerHTML
function cloneNodeWithHTML(node) {
var xEl = doc.createElement('x-element');
xEl.innerHTML = node.outerHTML || node.nodeValue;
return xEl.firstChild;
}
// match textnodes
function matchInnerNodes (nodeA, nodeB) {
// get childNodes Length
View cross-browser-text-selection.js
(function (win, doc) {
function getRangeAtCollapse(range, collapsed) {
// get range as item
if (range.item) {
var rangeItem = range.item(0);
// return the data
return { node: rangeItem };
}
// get range as text
var
View ie-currentStyle-without-reflow.js
(function (doc) {
var docEl = document.documentElement;
// get current style
window.getCurrentStyle = function (node) {
if (!node || !node.nodeName) return;
var docElClone = docEl.cloneNode(true), a, l, i;
for (a = docEl.getElementsByTagName(node.nodeName), l = a.length, i = 0; a[i] !== node; ++i);
return docElClone.getElementsByTagName(node.nodeName)[i].currentStyle;
};
})(document);
View processStyle.js
(function (win, doc) {
var frag = doc.createDocumentFragment();
// expand css
function expandCSS(responseText, dirname) {
return responseText
// correct urls
.replace(/url\(['"]?(.+?)['"]?\)/g, 'url(' + dirname + '$1)')
// uncorrect behavior urls
.replace(/behavior:\s*url\((.*?)\)/g, function (url) { return url.replace(dirname, ''); })
// import imports
View cssToObject.js
cssString = '#navbar, #sidebar { width: 80%; height: 23px; ul, ol { list-style-type: none; } li { float: left; a { font-weight: bold; } } } #main { background: #000; }';
cssObject = [{
type: 'rule',
selectors: [ '#navbar', '#sidebar' ],
declarations: [{
type: 'declaration',
property: 'width',
value: '80%'
}, {
View orientation-tests.txt
innerWidth / innerHeight tests @ http://sandbox.thewikies.com/orientation/
--------------------------------------------------------------------------------
Tested (14 devices, 28 browsers):
Droid 2 Global Android 2.2
iPhone 4 iOS5 (Safari, Opera Mini)
Motorola Atrix Android 2.3.4 (Stock browser, Dolphin, Skyfire, Opera Mini, Firefox)
Samsung Galaxy S9000 Android 2.3 (Webkit, Opera Mobile)
Samsung Galaxy Y Android 2.3.5