Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (87 sloc) 4.09 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>jQuery Grab Bag - DOM Builder Plugin</title>
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://onehackoranother.com/feed/" />
<link rel="alternate" type="text/xml" title="RSS .92" href="http://onehackoranother.com/feed/rss/" />
<link rel="alternate" type="application/atom+xml" title="Atom 1.0" href="http://onehackoranother.com/feed/atom/" />
<script type='text/javascript' src='javascripts/jquery-1.2.6.min.js'></script>
<script type='text/javascript' src='javascripts/jquery.dom-builder.js'></script>
<link rel="stylesheet" href="stylesheets/main.css" type="text/css" />
<style type='text/css'>
#foo { background-color: #cdcdcd; }
td, th { padding: 0.2em; }
th { font-weight: bold; }
.col-1 { color: red; }
.col-2 { color: green; }
.col-3 { color: blue; }
</style>
<script type='text/javascript'>
$(function() {
$$('table#foo',
$$('tr', $$('th.col-1', 'ID'), $$('th.col-2', 'Username'), $$('th.col-3', 'Email')),
$$('tr', $$('td', 1), $$('td', 'jaz303'), $$('td', 'jason@magiclamp.co.uk')),
{ style: "margin:20px auto",
hover: [
function() { $(this).css('backgroundColor', '#efefef'); },
function() { $(this).css('backgroundColor', '#cdcdcd'); }
]
}
).appendTo('#test-container');
});
</script>
</head>
<body>
<div id='container'>
<h1>
grab bag <span class='subtitle'>- assorted jQuery plugins</span>
</h1>
<div id='sidebar'>
<ul id='project-nav'>
<li><a href='index.html'>Plugin List</a></li>
</ul>
<ul id='ohoa-nav'>
<li><a href='http://onehackoranother.com/feed/' id='subscribe'>Subscribe for updates &raquo;</a></li>
<li><a href='http://onehackoranother.com/projects/'>Back to projects &raquo;</a></li>
<li><a href='http://onehackoranother.com/'>Back to onehackoranother.com &raquo;</a></li>
</ul>
</div>
<div id='main'>
<h2>DOM Builder</h2>
<p>
This plugin defines the double-dollar function which can be used to create
DOM node hierarchies, set attributes, hook up event handlers and return the
resulting structure as a jQuery object. Probably best illustrated with some
code:
</p>
<div class='caption'>Example:</div>
<pre>$$('table#foo',
$$('tr', $$('th.col-1', 'ID'), $$('th.col-2', 'Username'), $$('th.col-3', 'Email')),
$$('tr', $$('td', 1), $$('td', 'jaz303'), $$('td', 'jason@magiclamp.co.uk')),
{ style: "margin:20px auto",
hover: [
function() { $(this).css('backgroundColor', '#efefef'); },
function() { $(this).css('backgroundColor', '#cdcdcd'); }
]
}
).appendTo('#test-container');</pre>
<p>And here's the resulting table (it's auto-generated, trust me):</p>
<div id='test-container'></div>
<p>The general form of each call to <code>$$()</code> is:</p>
<pre>$$(nodeName, content1, content2 ... contentN, options);</pre>
<p>
This will create a node with the given <code>nodeName</code>, apply to it
the given options (if any) and then append the content, each of which may
be a string, jQuery object or DOM element. Options are objects of key-value
pairs; function values will be bound to the event denoted by the key, otherwise
the corresponding attribute will be set. The <code>hover</code> option is
special; when set to an array, it is assumed to contain two functions to handle
hover in/out events on the element.
</p>
<h3>Direct Link</h3>
<p><a href='http://github.com/jaz303/jquery-grab-bag/tree/master/javascripts/jquery.dom-builder.js'>jquery.dom-builder.js</a></p>
</div>
</div>
</body>
</html>