author | Dan |
Sun, 27 Jan 2008 23:17:15 -0500 | |
changeset 380 | 73444271fd1c |
parent 335 | 67bd3121a12e |
child 413 | 6607cd646d6d |
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 |
||
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
|
89 |
function DN_switchToMCE(performWikiTransform) |
1 | 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); |
|
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
|
97 |
// 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
|
98 |
// 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
|
99 |
// 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
|
100 |
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
|
101 |
{ |
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 |
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
|
103 |
} |
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 |
tinyMCE.execCommand("mceAddControl", true, this.object.id); |
1 | 105 |
this.object.dnIsMCE = 'yes'; |
106 |
return this; |
|
107 |
} |
|
108 |
||
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
|
109 |
function DN_destroyMCE(performWikiTransform) |
1 | 110 |
{ |
111 |
//if ( !this.object.dn_is_mce ) |
|
112 |
// 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
|
113 |
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
|
114 |
{ |
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 |
// 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
|
116 |
// 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
|
117 |
// 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
|
118 |
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
|
119 |
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
|
120 |
{ |
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 |
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
|
122 |
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
|
123 |
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
|
124 |
{ |
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 |
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
|
126 |
} |
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 |
} |
1 | 129 |
this.object.dnIsMCE = 'no'; |
130 |
return this; |
|
131 |
} |
|
132 |
||
133 |
function DN_mceFetchContent() |
|
134 |
{ |
|
135 |
if ( this.object.name ) |
|
136 |
{ |
|
137 |
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
|
138 |
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
|
139 |
{ |
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 |
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
|
141 |
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
|
142 |
} |
1 | 143 |
return text; |
144 |
} |
|
145 |
else |
|
146 |
{ |
|
147 |
return this.object.value; |
|
148 |
} |
|
149 |
} |
|
150 |
||
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
|
151 |
// 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
|
152 |
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
|
153 |
{ |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
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
|
158 |
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
|
159 |
} |
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
|
160 |
|
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
|
161 |
// 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
|
162 |
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
|
163 |
{ |
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
} |
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 |
|
1 | 172 |
DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; }; |
173 |
DNobj.prototype.rmClass = function(clsname) { rmClass( this.object, clsname); return this; }; |
|
174 |
DNobj.prototype.hasClass = function(clsname) { return hasClass(this.object, clsname); }; |
|
175 |
DNobj.prototype.Height = function() { return __DNObjGetHeight(this.object); } |
|
176 |
DNobj.prototype.Width = function() { return __DNObjGetWidth( this.object); } |
|
177 |
DNobj.prototype.Left = function() { /* return this.object.offsetLeft; */ return __DNObjGetLeft(this.object); } |
|
178 |
DNobj.prototype.Top = function() { /* return this.object.offsetTop; */ return __DNObjGetTop( this.object); } |
|
179 |