[dokuwiki] Re: How to add a drop-down list to the edit toolbar?

On Sat, 22 Sep 2007 14:41:34 +0200, "Gunther Pilz"
<dokuwiki@xxxxxxxxxxxxxx> said:
> I want to add a drop-down list to my edit toolbar.
> 

I did this with my 'Format+' plugin. In the plugin's style.js I have an
initialization function that looks like this (simplified for clarity):

    function initFormatPlusToolbar(){
      var editObj = $('wiki__text');
      if (editObj && !editObj.readOnly){
        var toolbarObj = $('tool__bar');
        var menuObj = document.createElement('select');
        menuObj.className = 'toolbutton';
        var opt = document.createElement('option');
        opt.innerHTML = '+Format+';
        menuObj.appendChild(opt);
        for (var i=0; i<FormatPlusOptions.length; i++){
          opt = document.createElement('option');
          opt.innerHTML = FormatPlusOptions[i].label;
          menuObj.appendChild(opt);
        }
        menuObj.onchange =
        function(){selectFormatPlusOption(menuObj);return false;};
        toolbarObj.appendChild(menuObj);
      }
    }

The FormatPlusOptions global is an array of the items that can be
selected. The selectFormatPlusOption function gets the information from
this array to insert text.

    function selectFormatPlusOption(menuObj){
      if (menuObj.selectedIndex > 0){
        var opt = FormatPlusOptions[menuObj.selectedIndex-1];
        insertTags('wiki__text', opt.opentag, opt.closetag, opt.title);
        menuObj.selectedIndex = 0;
      }
    }

-- tom
telliamed@xxxxxxxxxxx

-- 
http://www.fastmail.fm - Access your email from home and the web

-- 
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: