23.04.2013 Views

javascript

javascript

javascript

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

function traverseTree (node, func) {<br />

func(node);<br />

node = node.firstChild;<br />

while (node !== null) {<br />

traverseTree(node, func);<br />

node = node.nextSibling;<br />

}<br />

} ;<br />

var findClass = document.getElementsByClassName ?<br />

function (name, root) {<br />

root = root || document.documentElement;<br />

return root.getElementsByClassName(name);<br />

} :<br />

document.querySelectorAll ?<br />

function (name, root) {<br />

root = root || document.documentElement;<br />

return root.querySelectorAll("." + name);<br />

} :<br />

function (name, root) {<br />

var found = [];<br />

root = root || document.documentElement;<br />

traverseTree(root, function (node) {<br />

if (!! node.className) {<br />

for (var names = node.className.split(/\s+/), i = names.length; i --; ) {<br />

if (names[i] === name) {<br />

found.push(node);<br />

}<br />

}<br />

}<br />

});<br />

return found;<br />

} ;<br />

var queryCascade = window.getComputedStyle ?<br />

function (element, property) {<br />

return getComputedStyle(element, null)[property];<br />

} :<br />

function (element, property) {<br />

return element.currentStyle[property];<br />

} ;<br />

var doZ = function () {<br />

var z = 400;<br />

return function () {<br />

return z ++;<br />

};<br />

}();<br />

var getCookie = function (name) {<br />

var batch = document.cookie, i, firstCut, secondCut;<br />

i = batch.indexOf(name + "=");<br />

if (i !== -1) {<br />

firstCut = i + name.length + 1;<br />

CHAPTER 10 ■ SCRIPTING BOM<br />

453

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!