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