Clemens, 01.08.2013 15:13:
Hi.

How can I add custom buttons to the wiki toolbar which appears above the
text area when editing tickets and wiki pages?

Per default it offers "bold", "italic", "headline" etc. I would like to
add some own buttons which simply insert some text snippets e.g.
[[PageOutline]] to insert a  "table of contents".


Hello List.

I managed to get my desired custom buttons to the wiki-toolbar. However, due to struggeling with JavaScript I decided to "hack" the TRAC templates. Here is what I have got:

1.
Edited the toolbar background image "trac/htdocs/edit_toolbar.png". Instead modifying the central Trac templates one may put a custom version in "<repo>/htdocs".

2.
Edit CSS for the new toolbar, see [1]. In CSS the ID selects what action to call and what icon to show.

3.
Edited the central Javascript "trac/htdocs/js/wikitoolbar.js", see [2]. It is enough to insert a customized call of the addButton() function. You need the corresponding ID from CSS here.

I know that it is not recommended to edit TRAC central templates, but I did not manage to get it properly working with local templates instead central ones. I have a partly solution, but I could not properly handle that the ticket view has 2 wiki text edit fields. (see my other mail from this discussion...)

Best regards
Clemens



---------------------------------------
[1]  style.css:

.wikitoolbar
{
/* make wider than normal 234px wikitoolbar (each button needs plus 26px): */
 width: 260px;
}
.wikitoolbar :link, .wikitoolbar :visited
{
 /* customized background image which contains the button pictures: */
 background: transparent url(edit_toolbar_extended.png) no-repeat;
}

.wikitoolbar a#pageoutline { background-position: 0 -144px; }


------------------------------------------
[2]  trac/htdocs/js/wikitoolbar.js:

(function($){

  window.addWikiFormattingToolbar = function(textarea) {
    if ((document.selection == undefined)
     && (textarea.setSelectionRange == undefined)) {
      return;
    }

    var toolbar = document.createElement("div");
    toolbar.className = "wikitoolbar";

    function addButton(id, title, fn) {
     SNIP SNIP SNIP

    function encloseSelection(prefix, suffix) {
      SNIP SNIP SNIP

    addButton("strong", _("Bold text: '''Example'''"), function() {
      encloseSelection("'''", "'''");
    });
    addButton("em", _("Italic text: ''Example''"), function() {
      encloseSelection("''", "''");
    });
        SNIP SNIP SNIP
        
    // CUSTOM BUTTONS FOLLOW: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
addButton("pageoutline", _("Table of Contens: [[PageOutline]]"), function() {
      encloseSelection("= Table of Contents =\n[[PageOutline]]\n\n", "");
    });

    $(textarea).before(toolbar);
  }

})(jQuery);

// Add the toolbar to all <textarea> elements on the page with the class
// 'wikitext'.
jQuery(document).ready(function($) {
$("textarea.wikitext").each(function() { addWikiFormattingToolbar(this) });
});

--
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/trac-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to