scripts/domutils.js
author Dan
Sun, 23 Mar 2008 15:24:06 -0400
changeset 1 cddc2ba706d6
child 2 860ba7141641
permissions -rw-r--r--
Preliminary groundwork for AJAX interface
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     1
// The "Dynano" Javascript framework. Similar in syntax to JQuery but only has what Enano needs.
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     2
// License = GPLv2
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     3
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     4
var $ = function(id)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     5
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     6
  return new DNobj(id);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     7
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     8
var $dynano = $;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
     9
function DNobj(id)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    10
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    11
  this.object = ( typeof(id) == 'object' ) ? id : document.getElementById(id);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    12
  if ( !this.object )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    13
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    14
    console.warn('Dynano: requested object is bad. id parameter follows.');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    15
    console.debug(id);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    16
    console.debug(tinyMCE.getInstanceById(id));
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    17
    this.object = false;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    18
    return this;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    19
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    20
  this.height = __DNObjGetHeight(this.object);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    21
  this.width = __DNObjGetWidth(this.object);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    22
  
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    23
  if ( this.object.tagName == 'TEXTAREA' && typeof(tinyMCE) == 'object' )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    24
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    25
    this.object.dnIsMCE = 'no';
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    26
    this.switchToMCE = DN_switchToMCE;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    27
    this.destroyMCE = DN_destroyMCE;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    28
    this.getContent = DN_mceFetchContent;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    29
    this.setContent = DN_mceSetContent;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    30
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    31
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    32
function __DNObjGetHeight(o) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    33
  return o.offsetHeight;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    34
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    35
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    36
function __DNObjGetWidth(o) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    37
  return o.offsetWidth;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    38
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    39
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    40
function addClass(obj, clsname)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    41
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    42
  var cnt = obj.className;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    43
  var space = ( (cnt + '').length > 0 ) ? ' ' : '';
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    44
  var cls = cnt + space + clsname;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    45
  obj.className = cls;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    46
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    47
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    48
function rmClass(obj, clsname)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    49
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    50
  var cnt = obj.className;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    51
  if ( cnt == clsname )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    52
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    53
    obj.className = '';
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    54
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    55
  else
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    56
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    57
    cnt = cnt.replace(clsname, '');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    58
    cnt = trim(cnt);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    59
    obj.className = cnt;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    60
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    61
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    62
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    63
function hasClass(obj, clsname)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    64
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    65
  var cnt = obj.className;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    66
  if ( !cnt )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    67
    return false;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    68
  if ( cnt == clsname )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    69
    return true;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    70
  cnt = cnt.split(' ');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    71
  
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    72
  for ( var i in cnt )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    73
    if ( cnt[i] == clsname )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    74
      return true;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    75
    
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    76
  return false;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    77
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    78
function __DNObjGetLeft(obj) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    79
  var left_offset = obj.offsetLeft;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    80
  while ((obj = obj.offsetParent) != null) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    81
    left_offset += obj.offsetLeft;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    82
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    83
  return left_offset;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    84
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    85
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    86
function __DNObjGetTop(obj) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    87
  var left_offset = obj.offsetTop;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    88
  while ((obj = obj.offsetParent) != null) {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    89
    left_offset += obj.offsetTop;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    90
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    91
  return left_offset;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    92
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    93
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    94
function DN_switchToMCE(performWikiTransform)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    95
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    96
  if ( !this.object.id )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    97
    this.object.id = 'textarea_' + Math.floor(Math.random() * 1000000);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    98
  if ( !this.object.name )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
    99
    this.object.name = 'textarea_' + Math.floor(Math.random() * 1000000);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   100
  // Updated for TinyMCE 3.x
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   101
  if ( performWikiTransform )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   102
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   103
    this.object.value = DN_WikitextToXHTML(this.object.value);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   104
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   105
  // If tinyMCE init hasn't been called yet, do it now.
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   106
  if ( !tinymce_initted )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   107
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   108
    enano_tinymce_options.mode = 'exact';
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   109
    enano_tinymce_options.elements = this.object.id;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   110
    initTinyMCE();
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   111
    this.object.dnIsMCE = 'yes';
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   112
    return true;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   113
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   114
  else
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   115
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   116
    tinyMCE.execCommand("mceAddControl", true, this.object.id);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   117
    this.object.dnIsMCE = 'yes';
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   118
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   119
  return this;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   120
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   121
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   122
function DN_destroyMCE(performWikiTransform)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   123
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   124
  //if ( !this.object.dn_is_mce )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   125
  //  return this;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   126
  if ( this.object.id )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   127
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   128
    // TinyMCE 2.x
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   129
    // tinyMCE.removeMCEControl(this.object.name);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   130
    // TinyMCE 3.x
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   131
    var ed = tinyMCE.getInstanceById(this.object.id);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   132
    if ( ed )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   133
    {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   134
      if ( !tinyMCE.execCommand("mceRemoveEditor", false, this.object.id) )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   135
        alert('could not destroy editor');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   136
      if ( performWikiTransform )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   137
      {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   138
        this.object.value = DN_XHTMLToWikitext(this.object.value);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   139
      }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   140
    }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   141
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   142
  this.object.dnIsMCE = 'no';
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   143
  return this;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   144
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   145
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   146
function DN_mceFetchContent()
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   147
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   148
  if ( this.object.name )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   149
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   150
    var text = this.object.value;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   151
    if ( tinyMCE.get(this.object.id) )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   152
    {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   153
      var editor = tinyMCE.get(this.object.id);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   154
      text = editor.getContent();
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   155
    }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   156
    return text;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   157
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   158
  else
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   159
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   160
    return this.object.value;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   161
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   162
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   163
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   164
function DN_mceSetContent(text)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   165
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   166
  if ( this.object.name )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   167
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   168
    this.object.value = text;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   169
    if ( tinyMCE.get(this.object.id) )
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   170
    {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   171
      var editor = tinyMCE.get(this.object.id);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   172
      editor.setContent(text);
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   173
    }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   174
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   175
  else
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   176
  {
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   177
    this.object.value = text;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   178
  }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   179
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   180
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   181
// A basic Wikitext to XHTML converter
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   182
function DN_WikitextToXHTML(text)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   183
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   184
  text = text.replace(/^===[\s]*(.+?)[\s]*===$/g, '<h3>$1</h3>');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   185
  text = text.replace(/'''(.+?)'''/g, '<b>$1</b>');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   186
  text = text.replace(/''(.+?)''/g, '<i>$1</i>');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   187
  text = text.replace(/\[(http|ftp|irc|mailto):([^ \]])+ ([^\]]+?)\]/g, '<a href="$1:$2">$4</a>');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   188
  return text;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   189
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   190
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   191
// Inverse of the previous function
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   192
function DN_XHTMLToWikitext(text)
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   193
{
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   194
  text = text.replace(/<h3>(.+?)<\/h3>/g, '=== $1 ===');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   195
  text = text.replace(/<(b|strong)>(.+?)<\/(b|strong)>/g, "'''$2'''");
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   196
  text = text.replace(/<(i|em)>(.+?)<\/(i|em)>/g, "''$2''");
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   197
  text = text.replace(/<a href="([^" ]+)">(.+?)<\/a>/g, '[$1 $2]');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   198
  text = text.replace(/<\/?p>/g, '');
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   199
  return text;
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   200
}
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   201
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   202
DNobj.prototype.addClass = function(clsname) { addClass(this.object, clsname); return this; };
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   203
DNobj.prototype.rmClass  = function(clsname) { rmClass( this.object, clsname); return this; };
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   204
DNobj.prototype.hasClass = function(clsname) { return hasClass(this.object, clsname); };
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   205
DNobj.prototype.Height   = function()        { return __DNObjGetHeight(this.object); }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   206
DNobj.prototype.Width    = function()        { return __DNObjGetWidth( this.object); }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   207
DNobj.prototype.Left     = function()        { /* return this.object.offsetLeft; */ return __DNObjGetLeft(this.object); }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   208
DNobj.prototype.Top      = function()        { /* return this.object.offsetTop;  */ return __DNObjGetTop( this.object); }
cddc2ba706d6 Preliminary groundwork for AJAX interface
Dan
parents:
diff changeset
   209