author | Dan |
Sat, 01 Mar 2008 18:55:30 -0500 | |
changeset 465 | fe8b8c9b54e8 |
parent 413 | 6607cd646d6d |
child 474 | 3d751a6f2b05 |
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; |
|
413
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
25 |
this.setContent = DN_mceSetContent; |
1 | 26 |
} |
27 |
} |
|
28 |
function __DNObjGetHeight(o) { |
|
29 |
return o.offsetHeight; |
|
30 |
} |
|
31 |
||
32 |
function __DNObjGetWidth(o) { |
|
33 |
return o.offsetWidth; |
|
34 |
} |
|
35 |
||
36 |
function addClass(obj, clsname) |
|
37 |
{ |
|
38 |
var cnt = obj.className; |
|
39 |
var space = ( (cnt + '').length > 0 ) ? ' ' : ''; |
|
40 |
var cls = cnt + space + clsname; |
|
41 |
obj.className = cls; |
|
42 |
} |
|
43 |
||
44 |
function rmClass(obj, clsname) |
|
45 |
{ |
|
46 |
var cnt = obj.className; |
|
47 |
if ( cnt == clsname ) |
|
48 |
{ |
|
49 |
obj.className = ''; |
|
50 |
} |
|
51 |
else |
|
52 |
{ |
|
53 |
cnt = cnt.replace(clsname, ''); |
|
54 |
cnt = trim(cnt); |
|
55 |
obj.className = cnt; |
|
56 |
} |
|
57 |
} |
|
58 |
||
59 |
function hasClass(obj, clsname) |
|
60 |
{ |
|
61 |
var cnt = obj.className; |
|
62 |
if ( !cnt ) |
|
63 |
return false; |
|
64 |
if ( cnt == clsname ) |
|
65 |
return true; |
|
66 |
cnt = cnt.split(' '); |
|
67 |
||
68 |
for ( var i in cnt ) |
|
69 |
if ( cnt[i] == clsname ) |
|
70 |
return true; |
|
71 |
||
72 |
return false; |
|
73 |
} |
|
74 |
function __DNObjGetLeft(obj) { |
|
75 |
var left_offset = obj.offsetLeft; |
|
76 |
while ((obj = obj.offsetParent) != null) { |
|
77 |
left_offset += obj.offsetLeft; |
|
78 |
} |
|
79 |
return left_offset; |
|
80 |
} |
|
81 |
||
82 |
function __DNObjGetTop(obj) { |
|
83 |
var left_offset = obj.offsetTop; |
|
84 |
while ((obj = obj.offsetParent) != null) { |
|
85 |
left_offset += obj.offsetTop; |
|
86 |
} |
|
87 |
return left_offset; |
|
88 |
} |
|
89 |
||
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
90 |
function DN_switchToMCE(performWikiTransform) |
1 | 91 |
{ |
92 |
//if ( this.object.dn_is_mce ) |
|
93 |
// return this; |
|
94 |
if ( !this.object.id ) |
|
95 |
this.object.id = 'textarea_' + Math.floor(Math.random() * 1000000); |
|
96 |
if ( !this.object.name ) |
|
97 |
this.object.name = 'textarea_' + Math.floor(Math.random() * 1000000); |
|
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
98 |
// TinyMCE 2.x |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
99 |
// tinyMCE.addMCEControl(this.object, this.object.name, document); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
100 |
// TinyMCE 3.x |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
101 |
if ( performWikiTransform ) |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
102 |
{ |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
103 |
this.object.value = DN_WikitextToXHTML(this.object.value); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
104 |
} |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
105 |
tinyMCE.execCommand("mceAddControl", true, this.object.id); |
1 | 106 |
this.object.dnIsMCE = 'yes'; |
107 |
return this; |
|
108 |
} |
|
109 |
||
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
110 |
function DN_destroyMCE(performWikiTransform) |
1 | 111 |
{ |
112 |
//if ( !this.object.dn_is_mce ) |
|
113 |
// return this; |
|
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
114 |
if ( this.object.id ) |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
115 |
{ |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
116 |
// TinyMCE 2.x |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
117 |
// tinyMCE.removeMCEControl(this.object.name); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
118 |
// TinyMCE 3.x |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
119 |
var ed = tinyMCE.getInstanceById(this.object.id); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
120 |
if ( ed ) |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
121 |
{ |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
122 |
if ( !tinyMCE.execCommand("mceRemoveEditor", false, this.object.id) ) |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
123 |
alert('could not destroy editor'); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
124 |
if ( performWikiTransform ) |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
125 |
{ |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
126 |
this.object.value = DN_XHTMLToWikitext(this.object.value); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
127 |
} |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
128 |
} |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
129 |
} |
1 | 130 |
this.object.dnIsMCE = 'no'; |
131 |
return this; |
|
132 |
} |
|
133 |
||
134 |
function DN_mceFetchContent() |
|
135 |
{ |
|
136 |
if ( this.object.name ) |
|
137 |
{ |
|
138 |
var text = this.object.value; |
|
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
139 |
if ( tinyMCE.get(this.object.id) ) |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
140 |
{ |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
141 |
var editor = tinyMCE.get(this.object.id); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
142 |
text = editor.getContent(); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
143 |
} |
1 | 144 |
return text; |
145 |
} |
|
146 |
else |
|
147 |
{ |
|
148 |
return this.object.value; |
|
149 |
} |
|
150 |
} |
|
151 |
||
413
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
152 |
function DN_mceSetContent(text) |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
153 |
{ |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
154 |
if ( this.object.name ) |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
155 |
{ |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
156 |
this.object.value = text; |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
157 |
if ( tinyMCE.get(this.object.id) ) |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
158 |
{ |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
159 |
var editor = tinyMCE.get(this.object.id); |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
160 |
editor.setContent(text); |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
161 |
} |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
162 |
} |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
163 |
else |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
164 |
{ |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
165 |
this.object.value = text; |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
166 |
} |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
167 |
} |
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
parents:
335
diff
changeset
|
168 |
|
335
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
169 |
// A basic Wikitext to XHTML converter |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
170 |
function DN_WikitextToXHTML(text) |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
171 |
{ |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
172 |
text = text.replace(/^===[\s]*(.+?)[\s]*===$/g, '<h3>$1</h3>'); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
173 |
text = text.replace(/'''(.+?)'''/g, '<b>$1</b>'); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
174 |
text = text.replace(/''(.+?)''/g, '<i>$1</i>'); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
175 |
text = text.replace(/\[(http|ftp|irc|mailto):([^ \]])+ ([^\]]+?)\]/g, '<a href="$1:$2">$4</a>'); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
176 |
return text; |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
177 |
} |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
178 |
|
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
179 |
// Inverse of the previous function |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
180 |
function DN_XHTMLToWikitext(text) |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
181 |
{ |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
182 |
text = text.replace(/<h3>(.+?)<\/h3>/g, '=== $1 ==='); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
183 |
text = text.replace(/<(b|strong)>(.+?)<\/(b|strong)>/g, "'''$2'''"); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
184 |
text = text.replace(/<(i|em)>(.+?)<\/(i|em)>/g, "''$2''"); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
185 |
text = text.replace(/<a href="([^" ]+)">(.+?)<\/a>/g, '[$1 $2]'); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
186 |
text = text.replace(/<\/?p>/g, ''); |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
187 |
return text; |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
188 |
} |
67bd3121a12e
Replaced TinyMCE 2.x with 3.0 beta 3. Supports everything but IE. Also rewrote the editor interface completely from the ground up.
Dan
parents:
29
diff
changeset
|
189 |
|
1 | 190 |
DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; }; |
191 |
DNobj.prototype.rmClass = function(clsname) { rmClass( this.object, clsname); return this; }; |
|
192 |
DNobj.prototype.hasClass = function(clsname) { return hasClass(this.object, clsname); }; |
|
193 |
DNobj.prototype.Height = function() { return __DNObjGetHeight(this.object); } |
|
194 |
DNobj.prototype.Width = function() { return __DNObjGetWidth( this.object); } |
|
195 |
DNobj.prototype.Left = function() { /* return this.object.offsetLeft; */ return __DNObjGetLeft(this.object); } |
|
196 |
DNobj.prototype.Top = function() { /* return this.object.offsetTop; */ return __DNObjGetTop( this.object); } |
|
197 |