author | Dan |
Fri, 15 Aug 2008 23:31:37 -0400 | |
changeset 33 | 3b4aef1efff6 |
parent 11 | 0faea3a6c881 |
child 58 | 05a69bab5f10 |
permissions | -rw-r--r-- |
1 | 1 |
// The "Dynano" Javascript framework. Similar in syntax to JQuery but only has what Enano needs. |
2 |
// License = GPLv2 |
|
3 |
||
4 |
var $ = function(id) |
|
5 |
{ |
|
6 |
return new DNobj(id); |
|
7 |
} |
|
8 |
var $dynano = $; |
|
9 |
function DNobj(id) |
|
10 |
{ |
|
11 |
this.object = ( typeof(id) == 'object' ) ? id : document.getElementById(id); |
|
12 |
if ( !this.object ) |
|
13 |
{ |
|
14 |
this.object = false; |
|
15 |
return this; |
|
16 |
} |
|
17 |
this.height = __DNObjGetHeight(this.object); |
|
18 |
this.width = __DNObjGetWidth(this.object); |
|
19 |
} |
|
20 |
function __DNObjGetHeight(o) { |
|
21 |
return o.offsetHeight; |
|
22 |
} |
|
23 |
||
24 |
function __DNObjGetWidth(o) { |
|
25 |
return o.offsetWidth; |
|
26 |
} |
|
27 |
||
28 |
function addClass(obj, clsname) |
|
29 |
{ |
|
30 |
var cnt = obj.className; |
|
31 |
var space = ( (cnt + '').length > 0 ) ? ' ' : ''; |
|
32 |
var cls = cnt + space + clsname; |
|
33 |
obj.className = cls; |
|
34 |
} |
|
35 |
||
36 |
function rmClass(obj, clsname) |
|
37 |
{ |
|
38 |
var cnt = obj.className; |
|
39 |
if ( cnt == clsname ) |
|
40 |
{ |
|
41 |
obj.className = ''; |
|
42 |
} |
|
43 |
else |
|
44 |
{ |
|
45 |
cnt = cnt.replace(clsname, ''); |
|
46 |
cnt = trim(cnt); |
|
47 |
obj.className = cnt; |
|
48 |
} |
|
49 |
} |
|
50 |
||
51 |
function hasClass(obj, clsname) |
|
52 |
{ |
|
53 |
var cnt = obj.className; |
|
54 |
if ( !cnt ) |
|
55 |
return false; |
|
56 |
if ( cnt == clsname ) |
|
57 |
return true; |
|
58 |
cnt = cnt.split(' '); |
|
59 |
||
60 |
for ( var i in cnt ) |
|
61 |
if ( cnt[i] == clsname ) |
|
62 |
return true; |
|
63 |
||
64 |
return false; |
|
65 |
} |
|
66 |
function __DNObjGetLeft(obj) { |
|
67 |
var left_offset = obj.offsetLeft; |
|
68 |
while ((obj = obj.offsetParent) != null) { |
|
69 |
left_offset += obj.offsetLeft; |
|
70 |
} |
|
71 |
return left_offset; |
|
72 |
} |
|
73 |
||
74 |
function __DNObjGetTop(obj) { |
|
75 |
var left_offset = obj.offsetTop; |
|
76 |
while ((obj = obj.offsetParent) != null) { |
|
77 |
left_offset += obj.offsetTop; |
|
78 |
} |
|
79 |
return left_offset; |
|
80 |
} |
|
81 |
||
82 |
DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; }; |
|
83 |
DNobj.prototype.rmClass = function(clsname) { rmClass( this.object, clsname); return this; }; |
|
84 |
DNobj.prototype.hasClass = function(clsname) { return hasClass(this.object, clsname); }; |
|
85 |
DNobj.prototype.Height = function() { return __DNObjGetHeight(this.object); } |
|
86 |
DNobj.prototype.Width = function() { return __DNObjGetWidth( this.object); } |
|
87 |
DNobj.prototype.Left = function() { /* return this.object.offsetLeft; */ return __DNObjGetLeft(this.object); } |
|
88 |
DNobj.prototype.Top = function() { /* return this.object.offsetTop; */ return __DNObjGetTop( this.object); } |
|
89 |
||
2
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
90 |
// Equivalent to PHP trim() function |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
91 |
function trim(text) |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
92 |
{ |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
93 |
text = text.replace(/^([\s]+)/, ''); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
94 |
text = text.replace(/([\s]+)$/, ''); |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
95 |
return text; |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
96 |
} |
860ba7141641
Should be nearly finished now - includes volume control, length measurement, and seems pretty stable
Dan
parents:
1
diff
changeset
|
97 |
|
11
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
98 |
// Tell which elements have the specified CSS class |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
99 |
// Parameters: |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
100 |
// * object - HTMLElement |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
101 |
// * string - class name |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
102 |
// * string - tag name, if omitted will test all elements (slow) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
103 |
function getElementsByClassName(oRoot, className, tagName) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
104 |
{ |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
105 |
tagName = ( tagName ) ? tagName : '*'; |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
106 |
var arrEls = document.getElementsByTagName(tagName); |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
107 |
var arrResult = []; |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
108 |
for ( var i = 0; i < arrEls.length; i++ ) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
109 |
{ |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
110 |
if ( $(arrEls[i]).hasClass(className) ) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
111 |
{ |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
112 |
arrResult.push(arrEls[i]); |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
113 |
} |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
114 |
} |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
115 |
return arrResult; |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
116 |
} |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
117 |
|
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
118 |
// shortcut :) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
119 |
document.getElementsByClassName = function(a, b) |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
120 |
{ |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
121 |
return getElementsByClassName(document, a, b); |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
122 |
} |
0faea3a6c881
Fixed some position slider issues; added a pulsing effect to the current track (fun!)
Dan
parents:
2
diff
changeset
|
123 |