Changeset 15 for trunk


Ignore:
Timestamp:
02/19/05 04:45:48 (15 years ago)
Author:
gogo
Message:
  • Rewrote header comment, added developer notes etc.
  • Removed old commented-out code.
  • Added callback ability to loadPlugin
  • Added loadPlugins, makeEditors and startEditors, these are used by the new example, I should have committed this first.
  • Disabled the insert space at strategic locations code. I can't really remember the original problem I was trying to solve, perhaps EnterParagraphs? helps?
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/htmlarea.js

    r13 r15  
    1 // htmlArea v3.0 - Copyright (c) 2003-2004 dynarch.com 
    2 //                               2002-2003 interactivetools.com, inc. 
    3 // This copyright notice MUST stay intact for use (see license.txt). 
    4 // 
    5 // A free WYSIWYG editor replacement for <textarea> fields. 
    6 // For full source code and docs, visit http://www.interactivetools.com/ 
    7 // 
    8 // Version 3.0 developed by Mihai Bazon. 
    9 //   http://dynarch.com/mishoo/ 
    10 // 
    11 // $Id: htmlarea.js,v 1.95 2004/09/17 11:54:24 mishoo Exp $ 
     1 
     2  /*--------------------------------------:noTabs=true:tabSize=2:indentSize=2:-- 
     3    --  Xinha (is not htmlArea) - http://xinha.gogo.co.nz/ 
     4    -- 
     5    --  Use of Xinha is granted by the terms of the htmlArea License (based on 
     6    --  BSD license)  please read license.txt in this package for details. 
     7    -- 
     8    --  Xinha was originally based on work by Mihai Bazon which is: 
     9    --      Copyright (c) 2003-2004 dynarch.com. 
     10    --      Copyright (c) 2002-2003 interactivetools.com, inc. 
     11    --      This copyright notice MUST stay intact for use. 
     12    -- 
     13    --  Developers - Coding Style: 
     14    --   For the sake of not committing needlessly conflicting changes, 
     15    -- 
     16    --   * New code to be indented with 2 spaces ("soft tab"). 
     17    --   * New code preferably uses BSD-Style Bracing 
     18    --      if(foo) 
     19    --      { 
     20    --        bar(); 
     21    --      } 
     22    --   * Don't change brace styles unless you're working on the non BSD-Style 
     23    --     area (so we don't get spurious changes in line numbering). 
     24    --   * Don't change indentation unless you're working on the badly indented 
     25    --     area (so we don't get spurious changes of large blocks of code). 
     26    --   * Jedit is the recommended editor, a comment of this format should be 
     27    --     included in the top 10 lines of the file (see the embedded edit mode) 
     28    -- 
     29    --  $HeadURL$ 
     30    --  $LastChangedDate$ 
     31    --  $LastChangedRevision$ 
     32    --  $LastChangedBy$ 
     33    --------------------------------------------------------------------------*/ 
    1234 
    1335if (typeof _editor_url == "string") { 
     
    258280  } 
    259281 
    260   /* 
    261   this.toolbar = [ 
    262     [ "fontname", "space", 
    263       "fontsize", "space", 
    264       "formatblock", "space", 
    265       "bold", "italic", "underline", "strikethrough", "separator", 
    266       "subscript", "superscript", "separator", 
    267       "copy", "cut", "paste", "space", "undo", "redo", "space", "removeformat", "killword" ], 
    268  
    269     [ "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator", 
    270       "lefttoright", "righttoleft", "separator", 
    271       "orderedlist", "unorderedlist", "outdent", "indent", "separator", 
    272       "forecolor", "hilitecolor", "separator", 
    273       "inserthorizontalrule", "createlink", "insertimage", "inserttable", "toggleborders", "htmlmode", "separator", 
    274       "popupeditor", "separator", "showhelp", "about" ] 
    275   ]; 
    276   */ 
    277  
    278282  this.fontname = { 
    279283    "&mdash; font &mdash;":         '', 
     
    340344  //    - Enabled in text mode: if false the button gets disabled for text-only mode; otherwise enabled all the time. 
    341345  this.btnList = { 
    342     /* 
    343     bold:          [ "Bold", "ed_format_bold.gif", false, function(e) {e.execCommand("bold");} ], 
    344     italic:        [ "Italic", "ed_format_italic.gif", false, function(e) {e.execCommand("italic");} ], 
    345     underline:     [ "Underline", "ed_format_underline.gif", false, function(e) {e.execCommand("underline");} ], 
    346     strikethrough: [ "Strikethrough", "ed_format_strike.gif", false, function(e) {e.execCommand("strikethrough");} ], 
    347     subscript:     [ "Subscript", "ed_format_sub.gif", false, function(e) {e.execCommand("subscript");} ], 
    348     superscript:   [ "Superscript", "ed_format_sup.gif", false, function(e) {e.execCommand("superscript");} ], 
    349     justifyleft: [ "Justify Left", "ed_align_left.gif", false, function(e) {e.execCommand("justifyleft");} ], 
    350     justifycenter: [ "Justify Center", "ed_align_center.gif", false, function(e){e.execCommand("justifycenter");}], 
    351     justifyright: [ "Justify Right", "ed_align_right.gif", false, function(e) {e.execCommand("justifyright");} ], 
    352     justifyfull: [ "Justify Full", "ed_align_justify.gif", false, function(e) {e.execCommand("justifyfull");} ], 
    353  
    354     orderedlist: [ "Ordered List", "ed_list_num.gif", false, function(e) {e.execCommand("insertorderedlist");} ], 
    355     unorderedlist: [ "Bulleted List", "ed_list_bullet.gif", false, function(e) {e.execCommand("insertunorderedlist");} ], 
    356     insertorderedlist: [ "Ordered List", "ed_list_num.gif", false, function(e) {e.execCommand("insertorderedlist");} ], 
    357     insertunorderedlist: [ "Bulleted List", "ed_list_bullet.gif", false, function(e) {e.execCommand("insertunorderedlist");} ], 
    358  
    359     outdent: [ "Decrease Indent", "ed_indent_less.gif", false, function(e) {e.execCommand("outdent");} ], 
    360     indent: [ "Increase Indent", "ed_indent_more.gif", false, function(e) {e.execCommand("indent");} ], 
    361     forecolor: [ "Font Color", "ed_color_fg.gif", false, function(e) {e.execCommand("forecolor");} ], 
    362     hilitecolor: [ "Background Color", "ed_color_bg.gif", false, function(e) {e.execCommand("hilitecolor");} ], 
    363  
    364     undo: [ "Undoes your last action", "ed_undo.gif", false, function(e) {e.execCommand("undo");} ], 
    365     redo: [ "Redoes your last action", "ed_redo.gif", false, function(e) {e.execCommand("redo");} ], 
    366     cut: [ "Cut selection", "ed_cut.gif", false, cut_copy_paste ], 
    367     copy: [ "Copy selection", "ed_copy.gif", false, cut_copy_paste ], 
    368     paste: [ "Paste from clipboard", "ed_paste.gif", false, cut_copy_paste ], 
    369  
    370     */ 
    371346    bold:          [ "Bold",   ["ed_buttons_main.gif",3,2], false, function(e) {e.execCommand("bold");} ], 
    372347    italic:        [ "Italic", ["ed_buttons_main.gif",2,2], false, function(e) {e.execCommand("italic");} ], 
     
    759734      tb_objects[txt] = obj; 
    760735      // handlers to emulate nice flat toolbar buttons 
    761       /* -- This is now handled by a :hover pseudo class in htmlarea.css 
    762       HTMLArea._addEvent(el, "mouseover", function () { 
    763         if (obj.enabled) { 
    764           HTMLArea._addClass(el, "buttonHover"); 
    765         } 
    766       }); 
    767       */ 
    768736      HTMLArea._addEvent(el, "mouseout", function () { 
    769737        if (obj.enabled) with (HTMLArea) { 
     
    838806    } 
    839807    var group = this.config.toolbar[i]; 
    840     for (var j = 0; j < group.length; ++j) { 
     808    for (var j = 0; j < group.length; ++j) 
     809    { 
    841810      var code = group[j]; 
    842       if (/^([IT])\[(.*?)\]/.test(code)) { 
     811      if (/^([IT])\[(.*?)\]/.test(code)) 
     812      { 
    843813        // special case, create text label 
    844814        var l7ed = RegExp.$1 == "I"; // localized? 
     
    851821        tb_cell.className = "label"; 
    852822        tb_cell.innerHTML = label; 
    853       } else { 
     823      } 
     824      else if(typeof code != 'function') 
     825      { 
    854826        createButton(code); 
    855827      } 
     
    16341606}; 
    16351607 
    1636 HTMLArea.loadPlugin = function(pluginName) { 
     1608HTMLArea.loadPlugin = function(pluginName, callback) { 
     1609  // Might already be loaded 
     1610  if(eval('typeof ' + pluginName) != 'undefined') 
     1611  { 
     1612    if(callback) 
     1613    { 
     1614      callback(); 
     1615    } 
     1616    return; 
     1617  } 
     1618 
    16371619  var dir = this.getPluginDir(pluginName); 
    16381620  var plugin = pluginName.replace(/([a-z])([A-Z])([a-z])/g, 
     
    16421624  var plugin_file = dir + "/" + plugin; 
    16431625  var plugin_lang = dir + "/lang/" + _editor_lang + ".js"; 
    1644   document.write("<script type='text/javascript' src='" + plugin_file + "'></script>"); 
    1645   document.write("<script type='text/javascript' src='" + plugin_lang + "'></script>"); 
    1646   //this.loadScript(plugin_file); 
    1647   //this.loadScript(plugin_lang); 
    1648 }; 
     1626 
     1627  if(callback) 
     1628  { 
     1629    HTMLArea._loadback(plugin_file, function() { HTMLArea._loadback(plugin_lang, callback); }); 
     1630  } 
     1631  else 
     1632  { 
     1633    document.write("<script type='text/javascript' src='" + plugin_file + "'></script>"); 
     1634    document.write("<script type='text/javascript' src='" + plugin_lang + "'></script>"); 
     1635  } 
     1636}; 
     1637 
     1638HTMLArea.loadPlugins = function(plugins, callbackIfNotReady) 
     1639{ 
     1640  var nuPlugins = HTMLArea.cloneObject(plugins); 
     1641 
     1642  while(nuPlugins.length) 
     1643  { 
     1644    // Might already be loaded 
     1645    if(eval('typeof ' + nuPlugins[nuPlugins.length-1]) != 'undefined') 
     1646    { 
     1647      nuPlugins.pop(); 
     1648    } 
     1649    else 
     1650    { 
     1651      break; 
     1652    } 
     1653  } 
     1654 
     1655  if(!nuPlugins.length) 
     1656  { 
     1657    return true; 
     1658  } 
     1659 
     1660  HTMLArea.loadPlugin 
     1661  (nuPlugins.pop(), 
     1662      function() 
     1663      { 
     1664        if(HTMLArea.loadPlugins(nuPlugins, callbackIfNotReady)) 
     1665        { 
     1666          if(typeof callbackIfNotReady == 'function') 
     1667          { 
     1668            callbackIfNotReady(); 
     1669          } 
     1670        } 
     1671      } 
     1672  ); 
     1673  return false; 
     1674} 
     1675 
    16491676 
    16501677HTMLArea.loadStyle = function(style, plugin) { 
     
    21502177  // TODO: Make this work for IE? 
    21512178  // TODO: Perhaps should use a plain space character, I'm not sure. 
    2152   if(HTMLArea.is_gecko) 
     2179  //  OK, I've disabled this temporarily, to be honest, I can't rightly remember what the 
     2180  //  original problem was I was trying to solve with it.  I think perhaps that EnterParagraphs 
     2181  //  might solve the problem, whatever the hell it was.  I'm going senile, I'm sure. 
     2182  if(0 && HTMLArea.is_gecko) 
    21532183  { 
    21542184    var s = this._getSelection(); 
    21552185    // If the last character in the last text node of the parent tag 
     2186    // and the parent tag is not a block tag 
    21562187    if(s && s.isCollapsed && s.anchorNode 
    21572188         && s.anchorNode.parentNode.tagName.toLowerCase() != 'body' 
     
    21612192           && s.anchorNode.parentNode.nextSibling.nodeType == 3 
    21622193          ) 
     2194         && !HTMLArea.isBlockElement(s.anchorNode.parentNode) 
    21632195      ) 
    21642196    { 
     
    21692201      { 
    21702202        s.anchorNode.parentNode.parentNode.insertBefore 
    2171           (this._doc.createTextNode('\u200A'), s.anchorNode.parentNode.nextSibling); 
     2203          (this._doc.createTextNode('\t'), s.anchorNode.parentNode.nextSibling); 
    21722204      } 
    21732205      catch(e) 
     
    34743506 
    34753507  var newblock = block.parentNode.insertBefore(df.firstChild, block.nextSibling); 
    3476  
    3477   /* 
    3478   if(block.nextSibling) 
    3479   { 
    3480     block.parentNode.insertBefore(df, block.nextSibling); 
    3481   } 
    3482   else 
    3483   { 
    3484     block.parentNode.appendChild(df); 
    3485   } 
    3486   */ 
    34873508 
    34883509  // Select the range (to set the insertion) 
     
    45374558} 
    45384559 
     4560HTMLArea.makeEditors = function(editor_names, default_config, plugin_names) 
     4561{ 
     4562  if(typeof default_config == 'function') 
     4563  { 
     4564    default_config = default_config(); 
     4565  } 
     4566 
     4567  var editors = { }; 
     4568  for(var x = 0; x < editor_names.length; x++) 
     4569  { 
     4570    editors[editor_names[x]] = new HTMLArea(editor_names[x], HTMLArea.cloneObject(default_config)); 
     4571    if(plugin_names) 
     4572    { 
     4573      for(var i = 0; i < plugin_names.length; i++) 
     4574      { 
     4575        editors[editor_names[x]].registerPlugin(eval(plugin_names[i])); 
     4576      } 
     4577    } 
     4578  } 
     4579  return editors; 
     4580} 
     4581 
     4582HTMLArea.startEditors = function(editors) 
     4583{ 
     4584  for(var i in editors) 
     4585  { 
     4586    if(editors[i].generate) editors[i].generate(); 
     4587  } 
     4588} 
    45394589 
    45404590 
    45414591HTMLArea.init(); 
    4542 // EOF 
    4543 // Local variables: // 
    4544 // c-basic-offset:8 // 
    4545 // indent-tabs-mode:t // 
    4546 // End: // 
Note: See TracChangeset for help on using the changeset viewer.