author | Dan |
Thu, 27 Dec 2007 11:35:00 -0500 | |
changeset 266 | 5d62ef764b0d |
parent 29 | e5484a9e0818 |
permissions | -rw-r--r-- |
1 | 1 |
// The "Dynano" Javascript framework. Similar in syntax to JQuery but only has what Enano needs. |
2 |
||
3 |
var $ = function(id) |
|
4 |
{ |
|
5 |
return new DNobj(id); |
|
6 |
} |
|
7 |
var $dynano = $; |
|
8 |
function DNobj(id) |
|
9 |
{ |
|
10 |
this.object = ( typeof(id) == 'object' ) ? id : document.getElementById(id); |
|
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
1
diff
changeset
|
11 |
if ( !this.object ) |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
1
diff
changeset
|
12 |
{ |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
1
diff
changeset
|
13 |
this.object = false; |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
1
diff
changeset
|
14 |
return this; |
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
parents:
1
diff
changeset
|
15 |
} |
1 | 16 |
this.height = __DNObjGetHeight(this.object); |
17 |
this.width = __DNObjGetWidth(this.object); |
|
18 |
||
19 |
if ( this.object.tagName == 'TEXTAREA' && typeof(tinyMCE) == 'object' ) |
|
20 |
{ |
|
21 |
this.object.dnIsMCE = 'no'; |
|
22 |
this.switchToMCE = DN_switchToMCE; |
|
23 |
this.destroyMCE = DN_destroyMCE; |
|
24 |
this.getContent = DN_mceFetchContent; |
|
25 |
} |
|
26 |
} |
|
27 |
function __DNObjGetHeight(o) { |
|
28 |
return o.offsetHeight; |
|
29 |
} |
|
30 |
||
31 |
function __DNObjGetWidth(o) { |
|
32 |
return o.offsetWidth; |
|
33 |
} |
|
34 |
||
35 |
function addClass(obj, clsname) |
|
36 |
{ |
|
37 |
var cnt = obj.className; |
|
38 |
var space = ( (cnt + '').length > 0 ) ? ' ' : ''; |
|
39 |
var cls = cnt + space + clsname; |
|
40 |
obj.className = cls; |
|
41 |
} |
|
42 |
||
43 |
function rmClass(obj, clsname) |
|
44 |
{ |
|
45 |
var cnt = obj.className; |
|
46 |
if ( cnt == clsname ) |
|
47 |
{ |
|
48 |
obj.className = ''; |
|
49 |
} |
|
50 |
else |
|
51 |
{ |
|
52 |
cnt = cnt.replace(clsname, ''); |
|
53 |
cnt = trim(cnt); |
|
54 |
obj.className = cnt; |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
function hasClass(obj, clsname) |
|
59 |
{ |
|
60 |
var cnt = obj.className; |
|
61 |
if ( !cnt ) |
|
62 |
return false; |
|
63 |
if ( cnt == clsname ) |
|
64 |
return true; |
|
65 |
cnt = cnt.split(' '); |
|
66 |
||
67 |
for ( var i in cnt ) |
|
68 |
if ( cnt[i] == clsname ) |
|
69 |
return true; |
|
70 |
||
71 |
return false; |
|
72 |
} |
|
73 |
function __DNObjGetLeft(obj) { |
|
74 |
var left_offset = obj.offsetLeft; |
|
75 |
while ((obj = obj.offsetParent) != null) { |
|
76 |
left_offset += obj.offsetLeft; |
|
77 |
} |
|
78 |
return left_offset; |
|
79 |
} |
|
80 |
||
81 |
function __DNObjGetTop(obj) { |
|
82 |
var left_offset = obj.offsetTop; |
|
83 |
while ((obj = obj.offsetParent) != null) { |
|
84 |
left_offset += obj.offsetTop; |
|
85 |
} |
|
86 |
return left_offset; |
|
87 |
} |
|
88 |
||
89 |
function DN_switchToMCE() |
|
90 |
{ |
|
91 |
//if ( this.object.dn_is_mce ) |
|
92 |
// return this; |
|
93 |
if ( !this.object.id ) |
|
94 |
this.object.id = 'textarea_' + Math.floor(Math.random() * 1000000); |
|
95 |
if ( !this.object.name ) |
|
96 |
this.object.name = 'textarea_' + Math.floor(Math.random() * 1000000); |
|
97 |
tinyMCE.addMCEControl(this.object, this.object.name, document); |
|
98 |
this.object.dnIsMCE = 'yes'; |
|
99 |
return this; |
|
100 |
} |
|
101 |
||
102 |
function DN_destroyMCE() |
|
103 |
{ |
|
104 |
//if ( !this.object.dn_is_mce ) |
|
105 |
// return this; |
|
106 |
if ( this.object.name ) |
|
107 |
tinyMCE.removeMCEControl(this.object.name); |
|
108 |
this.object.dnIsMCE = 'no'; |
|
109 |
return this; |
|
110 |
} |
|
111 |
||
112 |
function DN_mceFetchContent() |
|
113 |
{ |
|
114 |
if ( this.object.name ) |
|
115 |
{ |
|
116 |
var text = this.object.value; |
|
117 |
if ( tinyMCE.getInstanceById(this.object.name) ) |
|
118 |
text = tinyMCE.getContent(this.object.name); |
|
119 |
return text; |
|
120 |
} |
|
121 |
else |
|
122 |
{ |
|
123 |
return this.object.value; |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; }; |
|
128 |
DNobj.prototype.rmClass = function(clsname) { rmClass( this.object, clsname); return this; }; |
|
129 |
DNobj.prototype.hasClass = function(clsname) { return hasClass(this.object, clsname); }; |
|
130 |
DNobj.prototype.Height = function() { return __DNObjGetHeight(this.object); } |
|
131 |
DNobj.prototype.Width = function() { return __DNObjGetWidth( this.object); } |
|
132 |
DNobj.prototype.Left = function() { /* return this.object.offsetLeft; */ return __DNObjGetLeft(this.object); } |
|
133 |
DNobj.prototype.Top = function() { /* return this.object.offsetTop; */ return __DNObjGetTop( this.object); } |
|
134 |