author | Dan |
Sun, 23 Mar 2008 22:44:52 -0400 | |
changeset 5 | 9b96265b5918 |
parent 2 | 860ba7141641 |
child 11 | 0faea3a6c881 |
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 |