Skip to content

Instantly share code, notes, and snippets.

View jonathantneal's full-sized avatar

Jonathan Neal jonathantneal

View GitHub Profile
@jonathantneal
jonathantneal / allDefined.js
Created October 24, 2011 18:21
A really nice allDefined function
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;
@jonathantneal
jonathantneal / nav.vm
Created October 25, 2011 23:27
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 = "")
@jonathantneal
jonathantneal / agnostic-html-shim.htc.html
Created October 26, 2011 18:17
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 November 2, 2011 04:02
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>
@jonathantneal
jonathantneal / cloneNode.js
Created November 8, 2011 04:39
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
@jonathantneal
jonathantneal / cross-browser-text-selection.js
Created November 8, 2011 05:18
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
@jonathantneal
jonathantneal / ie-currentStyle-without-reflow.js
Created November 9, 2011 21:02
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);
@jonathantneal
jonathantneal / processStyle.js
Created November 15, 2011 05:30
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
@jonathantneal
jonathantneal / cssToObject.js
Created November 15, 2011 21:42
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%'
}, {
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