Changeset 160


Ignore:
Timestamp:
05/12/05 11:47:25 (15 years ago)
Author:
gogo
Message:

Fixes to problem shown in ticket:237 that was introduced in changeset:69

This change puts it back so that only one editor is active at any given
time, and that editors must initially be activated by a mouse-down on
the area by the user (in both gecko and IE now).

This may fix some other tickets with similar types of problem
(insertHTML placing text outside of the editor). The problem mostly
came down to focusEditor() not doing work when it should have because of
a misplaced bang, but some other issues needed cleaning up too.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/htmlarea.js

    r149 r160  
    15031503  } 
    15041504 
     1505  /* 
     1506   * EDITOR ACTIVATION NOTES: 
     1507   *  when a page has multiple Xinha editors, ONLY ONE should be activated at any time (this is mostly to 
     1508   *  work around a bug in Mozilla, but also makes some sense).  No editor should be activated or focused 
     1509   *  automatically until at least one editor has been activated through user action (by mouse-clicking in 
     1510   *  the editor). 
     1511   */ 
     1512 
    15051513  HTMLArea.prototype.editorIsActivated = function() { 
    15061514    try { 
     
    15131521  } 
    15141522 
     1523  HTMLArea._someEditorHasBeenActivated = false; 
     1524  HTMLArea._currentlyActiveEditor      = false; 
    15151525  HTMLArea.prototype.activateEditor = function() 
    15161526  { 
    1517     if (HTMLArea.is_gecko && this._doc.designMode != 'on') { 
    1518       try { 
    1519  
     1527    // We only want ONE editor at a time to be active 
     1528    if(HTMLArea._currentlyActiveEditor) 
     1529    { 
     1530      if(HTMLArea._currentlyActiveEditor == this) return true; 
     1531      HTMLArea._currentlyActiveEditor.deactivateEditor(); 
     1532    } 
     1533 
     1534    if (HTMLArea.is_gecko && this._doc.designMode != 'on') 
     1535    { 
     1536      try 
     1537      { 
    15201538        // cannot set design mode if no display 
    15211539        if (this._iframe.style.display == 'none') 
     
    15351553      this._doc.body.contentEditable = true; 
    15361554    } 
     1555 
     1556    // We need to know that at least one editor on the page has been activated 
     1557    // this is because we will not focus any editor until an editor has been activated 
     1558    HTMLArea._someEditorHasBeenActivated = true; 
     1559    HTMLArea._currentlyActiveEditor      = this; 
     1560 
     1561    var editor = this; 
     1562    this._timerToolbar = setTimeout(function() { 
     1563      editor.updateToolbar(); 
     1564      editor._timerToolbar = null; 
     1565    }, 250); 
    15371566  } 
    15381567 
     
    15471576      this._doc.body.contentEditable = false; 
    15481577    } 
     1578 
     1579    if(HTMLArea._currentlyActiveEditor != this) 
     1580    { 
     1581      // We just deactivated an editor that wasn't marked as the currentlyActiveEditor 
     1582 
     1583      return; // I think this should really be an error, there shouldn't be a situation where 
     1584              // an editor is deactivated without first being activated.  but it probably won't 
     1585              // hurt anything. 
     1586    } 
     1587    HTMLArea._currentlyActiveEditor = false; 
    15491588  } 
    15501589 
     
    15721611        } 
    15731612      } 
    1574       editor.activateEditor(); 
    15751613    } 
    15761614    catch(e) 
     
    16211659 
    16221660    // if we have multiple editors some bug in Mozilla makes some lose editing ability 
    1623     // so activation is done only when mouse down 
    1624     if(HTMLArea.is_gecko) 
    1625     { 
    1626       HTMLArea._addEvents( 
    1627         editor._iframe.contentWindow, 
    1628         ["mousedown"], 
    1629         function() { editor.activateEditor();  } 
    1630       ); 
    1631     } 
    1632     else 
    1633     { 
    1634         // redo it for some obscure reason that IE need it.. 
    1635         editor.activateEditor(); 
    1636     } 
    1637  
    1638     // seems that focusEditor is redondant with the mouse down event handler 
    1639     // and should be better used 
    1640     // editor.focusEditor(); 
     1661    HTMLArea._addEvents 
     1662    ( 
     1663      doc, 
     1664      ["mousedown"], 
     1665      function() { editor.activateEditor(); return true; } 
     1666    ); 
     1667 
     1668 
    16411669    // intercept some events; for updating the toolbar & keyboard handlers 
    16421670    HTMLArea._addEvents 
     
    16561684      editor._onGenerate(); 
    16571685    } 
    1658  
    1659     // update toolbar (hope this will arrive enough late...) 
    1660     editor._timerToolbar = setTimeout(function() { 
    1661       editor.updateToolbar(); 
    1662       editor._timerToolbar = null; 
    1663     }, 250); 
    16641686  } 
    16651687 
     
    17221744  } 
    17231745  this._editMode = mode; 
    1724   // this.focusEditor(); 
    17251746 
    17261747  for (var i in this.plugins) { 
     
    17501771    this._doc.close(); 
    17511772    this.activateEditor(); 
    1752     // this._doc.body.contentEditable = true; 
    17531773    return true; 
    17541774  } 
     
    20682088      { 
    20692089        // We don't want to focus the field unless at least one field has been activated. 
    2070         if(!this.editorIsActivated()) 
     2090        if(HTMLArea._someEditorHasBeenActivated) 
    20712091        { 
    2072           this.activateEditor(); 
    2073           this._iframe.contentWindow.focus(); 
    2074         } 
    2075  
     2092          this.activateEditor(); // Ensure *this* editor is activated 
     2093          this._iframe.contentWindow.focus(); // and focus it 
     2094        } 
    20762095      } catch (e) {} break; 
    20772096      case "textmode": try { this._textArea.focus() } catch (e) {} break; 
Note: See TracChangeset for help on using the changeset viewer.