1 ////////////////////////////////////////////////////////////////////////////////
4 // Description: Common Javascript functions
5 // Author: Andrew@DeFaria.com
6 // Created: Thu Oct 6 14:16:05 PDT 2011
7 // Language: javascript
9 ////////////////////////////////////////////////////////////////////////////////
10 function basename (path) {
11 return path.replace (/\\/g, '/').replace (/.*\//, '');
14 function dirname (path) {
15 return path.replace (/\\/g, '/').replace (/\/[^\/]*$/, '');
18 function getText (item) {
19 // There's this annoying thing about getting the text of an HTML object - both
20 // Chrome and IE use innerText but Firefox uses textContent.
21 return item.innerText ? item.innerText : item.textContent;
24 function getVar (variable) {
25 var query = window.location.search.substring (1);
27 var vars = query.split ('&');
29 for (var i=0; i < vars.length; i++) {
30 var pair = vars[i].split ('=');
32 if (pair[0] == variable) {
41 // keys: Emulate Perl's keys function. Note that hashes in Javascript are
42 // implemented as associative arrays, which are really objects. There is no
43 // keys function and as an Objects there are functions in there. So we use the
44 // hasOwnProperty function to insure that this is a pproperty and not a
49 if (obj.hasOwnProperty (key)) keys.push (key);
55 function objLength (object) {
56 // The .length property doesn't exist for JavaScript objects and associative
57 // arrays. You need to count the properties instead.
60 for (property in object) {
61 if (object.hasOwnProperty (property)) {