Modify

Opened 13 years ago

Closed 11 years ago

#9596 closed defect (fixed)

dynamically adding textareas causes multiple toolbars for existing textareas

Reported by: wasserman Owned by: Jun Omae
Priority: normal Component: TracWysiwygPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description

I have a use case where new textarea form fields can be added dynamically via JavaScript. The current logic adds new TracWysiwyg instances with corresponding toolbars to all textareas via TracWysiwyg.initialize. When a new textarea is created this causes each existing textarea to get an additional toolbar. This can be avoided by creating a property in each textarea and associating it to its TracWysiwyg instance after it is created. Here is suggested patch:

  • tracwysiwyg/htdocs/wysiwyg.js

     Index: tracwysiwyg/htdocs/wysiwyg.js
     
    40054005    var textareas = document.getElementsByTagName("textarea");
    40064006    for (var i = 0; i < textareas.length; i++) {
    40074007        var textarea = textareas[i];
    4008         if (/\bwikitext\b/.test(textarea.className || "")) {
    4009             TracWysiwyg.newInstance(textarea, options);
     4008        if (/\bwikitext\b/.test(textarea.className || "")
     4009            && !textarea.wysiwyg) {
     4010            textarea.wysiwyg = TracWysiwyg.newInstance(textarea, options);
    40104011        }
    40114012    }
    40124013};

Attachments (0)

Change History (2)

comment:1 Changed 13 years ago by wasserman

Summary: dynamically adding textareas causes multiple toolbars to existing textareasdynamically adding textareas causes multiple toolbars for existing textareas

comment:2 Changed 11 years ago by Jun Omae

Resolution: fixed
Status: newclosed

In 13453:

TracWysiwygPlugin: marks initialized on data-tracwysiwyg-initialized attribute of textarea to prevent double-initializing (fixed #9596)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.