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
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
diff
changeset
|
12 |
{
|
493
|
13 |
console.warn('Dynano: requested object is bad. id parameter follows.');
|
|
14 |
console.debug(id);
|
|
15 |
console.debug(tinyMCE.getInstanceById(id));
|
29
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
|
16 |
this.object = false;
|
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
|
17 |
return this;
|
e5484a9e0818
Rewrote change theme dialog; a few minor stability fixes here and there; fixed IE + St Patty background image
Dan
diff
changeset
|
18 |
}
|
1
|
19 |
this.height = __DNObjGetHeight(this.object);
|
|
20 |
this.width = __DNObjGetWidth(this.object);
|
|
21 |
|
|
22 |
if ( this.object.tagName == 'TEXTAREA' && typeof(tinyMCE) == 'object' )
|
|
23 |
{
|
|
24 |
this.object.dnIsMCE = 'no';
|
|
25 |
this.switchToMCE = DN_switchToMCE;
|
|
26 |
this.destroyMCE = DN_destroyMCE;
|
|
27 |
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
diff
changeset
|
28 |
this.setContent = DN_mceSetContent;
|
1
|
29 |
}
|
|
30 |
}
|
|
31 |
function __DNObjGetHeight(o) {
|
|
32 |
return o.offsetHeight;
|
|
33 |
}
|
|
34 |
|
|
35 |
function __DNObjGetWidth(o) {
|
|
36 |
return o.offsetWidth;
|
|
37 |
}
|
|
38 |
|
|
39 |
function addClass(obj, clsname)
|
|
40 |
{
|
|
41 |
var cnt = obj.className;
|
|
42 |
var space = ( (cnt + '').length > 0 ) ? ' ' : '';
|
|
43 |
var cls = cnt + space + clsname;
|
|
44 |
obj.className = cls;
|
|
45 |
}
|
|
46 |
|
|
47 |
function rmClass(obj, clsname)
|
|
48 |
{
|
|
49 |
var cnt = obj.className;
|
|
50 |
if ( cnt == clsname )
|
|
51 |
{
|
|
52 |
obj.className = '';
|
|
53 |
}
|
|
54 |
else
|
|
55 |
{
|
|
56 |
cnt = cnt.replace(clsname, '');
|
|
57 |
cnt = trim(cnt);
|
|
58 |
obj.className = cnt;
|
|
59 |
}
|
|
60 |
}
|
|
61 |
|
|
62 |
function hasClass(obj, clsname)
|
|
63 |
{
|
|
64 |
var cnt = obj.className;
|
|
65 |
if ( !cnt )
|
|
66 |
return false;
|
|
67 |
if ( cnt == clsname )
|
|
68 |
return true;
|
|
69 |
cnt = cnt.split(' ');
|
|
70 |
|
|
71 |
for ( var i in cnt )
|
|
72 |
if ( cnt[i] == clsname )
|
|
73 |
return true;
|
|
74 |
|
|
75 |
return false;
|
|
76 |
}
|
|
77 |
function __DNObjGetLeft(obj) {
|
|
78 |
var left_offset = obj.offsetLeft;
|
|
79 |
while ((obj = obj.offsetParent) != null) {
|
|
80 |
left_offset += obj.offsetLeft;
|
|
81 |
}
|
|
82 |
return left_offset;
|
|
83 |
}
|
|
84 |
|
|
85 |
function __DNObjGetTop(obj) {
|
|
86 |
var left_offset = obj.offsetTop;
|
|
87 |
while ((obj = obj.offsetParent) != null) {
|
|
88 |
left_offset += obj.offsetTop;
|
|
89 |
}
|
|
90 |
return left_offset;
|
|
91 |
}
|
|
92 |
|
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
diff
changeset
|
93 |
function DN_switchToMCE(performWikiTransform)
|
1
|
94 |
{
|
|
95 |
if ( !this.object.id )
|
|
96 |
this.object.id = 'textarea_' + Math.floor(Math.random() * 1000000);
|
|
97 |
if ( !this.object.name )
|
|
98 |
this.object.name = 'textarea_' + Math.floor(Math.random() * 1000000);
|
474
|
99 |
// Updated for TinyMCE 3.x
|
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
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
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
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
diff
changeset
|
103 |
}
|
474
|
104 |
// If tinyMCE init hasn't been called yet, do it now.
|
|
105 |
if ( !tinymce_initted )
|
|
106 |
{
|
|
107 |
enano_tinymce_options.mode = 'exact';
|
493
|
108 |
enano_tinymce_options.elements = this.object.id;
|
474
|
109 |
initTinyMCE();
|
|
110 |
this.object.dnIsMCE = 'yes';
|
|
111 |
return true;
|
|
112 |
}
|
|
113 |
else
|
|
114 |
{
|
|
115 |
tinyMCE.execCommand("mceAddControl", true, this.object.id);
|
|
116 |
this.object.dnIsMCE = 'yes';
|
|
117 |
}
|
1
|
118 |
return this;
|
|
119 |
}
|
|
120 |
|
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
diff
changeset
|
121 |
function DN_destroyMCE(performWikiTransform)
|
1
|
122 |
{
|
|
123 |
//if ( !this.object.dn_is_mce )
|
|
124 |
// 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
diff
changeset
|
125 |
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
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
diff
changeset
|
127 |
// 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
diff
changeset
|
128 |
// 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
diff
changeset
|
129 |
// 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
diff
changeset
|
130 |
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
diff
changeset
|
131 |
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
diff
changeset
|
132 |
{
|
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
diff
changeset
|
133 |
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
diff
changeset
|
134 |
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
diff
changeset
|
135 |
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
diff
changeset
|
136 |
{
|
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
diff
changeset
|
137 |
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
diff
changeset
|
138 |
}
|
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
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
diff
changeset
|
140 |
}
|
1
|
141 |
this.object.dnIsMCE = 'no';
|
|
142 |
return this;
|
|
143 |
}
|
|
144 |
|
|
145 |
function DN_mceFetchContent()
|
|
146 |
{
|
|
147 |
if ( this.object.name )
|
|
148 |
{
|
|
149 |
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
diff
changeset
|
150 |
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
diff
changeset
|
151 |
{
|
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
diff
changeset
|
152 |
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
diff
changeset
|
153 |
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
diff
changeset
|
154 |
}
|
1
|
155 |
return text;
|
|
156 |
}
|
|
157 |
else
|
|
158 |
{
|
|
159 |
return this.object.value;
|
|
160 |
}
|
|
161 |
}
|
|
162 |
|
413
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
diff
changeset
|
163 |
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
diff
changeset
|
164 |
{
|
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
diff
changeset
|
165 |
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
diff
changeset
|
166 |
{
|
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
diff
changeset
|
167 |
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
diff
changeset
|
168 |
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
diff
changeset
|
169 |
{
|
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
diff
changeset
|
170 |
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
diff
changeset
|
171 |
editor.setContent(text);
|
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
diff
changeset
|
172 |
}
|
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
diff
changeset
|
173 |
}
|
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
diff
changeset
|
174 |
else
|
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
diff
changeset
|
175 |
{
|
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
diff
changeset
|
176 |
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
diff
changeset
|
177 |
}
|
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
diff
changeset
|
178 |
}
|
6607cd646d6d
Added autosave functionality and resurrected the old toolbar code that was added about a year ago but never uesd.
Dan
diff
changeset
|
179 |
|
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
diff
changeset
|
180 |
// 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
diff
changeset
|
181 |
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
diff
changeset
|
182 |
{
|
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
diff
changeset
|
183 |
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
diff
changeset
|
184 |
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
diff
changeset
|
185 |
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
diff
changeset
|
186 |
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
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
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
diff
changeset
|
189 |
|
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
diff
changeset
|
190 |
// 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
diff
changeset
|
191 |
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
diff
changeset
|
192 |
{
|
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
diff
changeset
|
193 |
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
diff
changeset
|
194 |
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
diff
changeset
|
195 |
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
diff
changeset
|
196 |
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
diff
changeset
|
197 |
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
diff
changeset
|
198 |
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
diff
changeset
|
199 |
}
|
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
diff
changeset
|
200 |
|
1
|
201 |
DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; };
|
|
202 |
DNobj.prototype.rmClass = function(clsname) { rmClass( this.object, clsname); return this; };
|
|
203 |
DNobj.prototype.hasClass = function(clsname) { return hasClass(this.object, clsname); };
|
|
204 |
DNobj.prototype.Height = function() { return __DNObjGetHeight(this.object); }
|
|
205 |
DNobj.prototype.Width = function() { return __DNObjGetWidth( this.object); }
|
|
206 |
DNobj.prototype.Left = function() { /* return this.object.offsetLeft; */ return __DNObjGetLeft(this.object); }
|
|
207 |
DNobj.prototype.Top = function() { /* return this.object.offsetTop; */ return __DNObjGetTop( this.object); }
|
|
208 |
|