DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:toolbox

This is an old revision of the document!


toolbox plugin

Compatible with DokuWiki

2009-12-25+

plugin Adds various tools to the editor toolbar

Last updated on
2010-02-24
Provides
CSS/JS-only
Repository
Source
Conflicts with
codemirror

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Tagged with indent, javascript, list, sort, tables, toolbar, wordcount

Download and Installation

Download and install the plugin using the Plugin Manager using the URL given above. Refer to Plugins on how to install plugins manually.

Changes

Usage

The plugin adds a new picker to the toolbar which provides the following functions.

Sort Ascending

Selected text is sorted line by line in ascending order. Use this to sort tables or lists. No, this does not let you sort a table by the second column or any other sophisticated thing. It just sorts text lines alphabetically.

Sort Descending

Same as above but reversed

Add Indention

Selected lines are indented by two spaces. Nice to quickly change the level of a bunch of list items.

Remove Indention

Same as above but removes two spaces.

Word Count

This basically implements the features of wordcounter into an on-demand counter. It counts characters and words of the total page, the currently edited section (if any) and the selected text (if any).

Might not always be 100% correct, but should be good enough.

More features

Might come some day. Earlier if you send patches. Here are a few ideas:

Added codebutton plugin

I integrated the codebutton plugin into the toolbox plugin, also modified the plugin to show all the buttons in the toolbar

if(window.toolbar!=undefined){
	toolbar[toolbar.length] = {
		"type":  "format",
                "title": LANG.plugins.toolbox.insertcode,
                "icon":  DOKU_BASE+"lib/plugins/toolbox/pix/code.png",
		"open": "<file>\n",
		"close": "\n</file>",
            };
	toolbar[toolbar.length] = {
                "type":  "toolbox_sort",
                "title": LANG.plugins.toolbox.sortasc,
                "icon":  DOKU_BASE+"lib/plugins/toolbox/pix/sort_ascending.png",
                "key":   "",
                "reverse": 0
            };
	toolbar[toolbar.length] ={
                "type":  "toolbox_sort",
                "title": LANG.plugins.toolbox.sortdesc,
                "icon":  DOKU_BASE+"lib/plugins/toolbox/pix/sort_descending.png",
                "key":   "",
                "reverse": 1
            };
	toolbar[toolbar.length] ={
                "type":  "toolbox_indent",
                "title": LANG.plugins.toolbox.outdent,
                "icon":  DOKU_BASE+"lib/plugins/toolbox/pix/text_indent_remove.png",
                "key":   "",
                "reverse": 1
            };
	toolbar[toolbar.length] ={
                "type":  "toolbox_indent",
                "title": LANG.plugins.toolbox.indent,
                "icon":  DOKU_BASE+"lib/plugins/toolbox/pix/text_indent.png",
                "key":   "",
                "reverse": 0
            };
	toolbar[toolbar.length] ={
                "type":  "toolbox_counter",
                "title": LANG.plugins.toolbox.counter,
                "icon":  DOKU_BASE+"lib/plugins/toolbox/pix/application_view_list.png",
                "key":   "",
			};
}

/**
 * Sort the selected text
 */
function tb_toolbox_sort(btn, opts, edid){
    var selection = getSelection($(edid));
    if(!selection.getLength()){
        alert(LANG.plugins.toolbox.notext);
        return;
    }

    var text = selection.getText();
    text = text.split("\n");
    text.sort();
    if(opts['reverse']) text.reverse();
    text = text.join("\n");

    pasteText(selection,text,{});
    pickerClose();
}

/**
 * Indent the selected text
 */
function tb_toolbox_indent(btn, opts, edid){
    var selection = getSelection($(edid));
    if(!selection.getLength()){
        alert(LANG.plugins.toolbox.notext);
        return;
    }

    var text = selection.getText();
    text = text.split("\n");
    for(var i=0; i<text.length; i++){
        if(opts['reverse']){
            text[i] = text[i].replace(/^  ?/,'');
        }else{
            text[i] = '  '+text[i];
        }
    }
    text = text.join("\n");

    pasteText(selection,text,{});
    pickerClose();
}

/**
 * Count words and characters
 *
 * @link http://www.dokuwiki.org/tips:wordcounter
 */
function tb_toolbox_counter(btn, opts, edid){

    function charcounter(text){
        var list = text.split(/[^\w\-_]+/);
        var len  = text.length;
        if(list[len-1] == '') len--;
        if(list[0] == '') len--;
        if(len < 0) len=0;
        return len;
    }

    function wordcounter(text){
        var list = text.split(/[^\w\-_]+/);
        var len  = list.length;
        if(list[len-1] == '') len--;
        if(list[0] == '') len--;
        if(len < 0) len=0;
        return len;
    }


    var obj  = $(edid);
    var call = 0;
    var wall = 0;
    var csec = charcounter(obj.value);
    var wsec = wordcounter(obj.value);

    if(obj.form.elements.prefix && obj.form.elements.prefix.value){
        call += charcounter(obj.form.elements.prefix.value);
        wall += wordcounter(obj.form.elements.prefix.value);
    }
    if(obj.form.elements.suffix && obj.form.elements.suffix.value){
        call += charcounter(obj.form.elements.suffix.value);
        wall += wordcounter(obj.form.elements.suffix.value);
    }

    var out = '';

    if(call){
        out += LANG.plugins.toolbox.total;
        out += "  "+LANG.plugins.toolbox.chars.replace('%d',(call + csec));
        out += "  "+LANG.plugins.toolbox.words.replace('%d',(wall + wsec))+"\n";

        out += LANG.plugins.toolbox.section;
    }else{
        out += LANG.plugins.toolbox.total;
    }
    out += "  "+LANG.plugins.toolbox.chars.replace('%d',csec);
    out += "  "+LANG.plugins.toolbox.words.replace('%d',wsec)+"\n";

    var selection = getSelection($(edid));
    if(selection.getLength()){
        var text = selection.getText();

        out += LANG.plugins.toolbox.selection;
        out += "  "+LANG.plugins.toolbox.chars.replace('%d',charcounter(text));
        out += "  "+LANG.plugins.toolbox.words.replace('%d',wordcounter(text))+"\n";
    }

    pickerClose();
    alert(out);
}

Perhaps someone could use it.

Note: I also added this tot the lang.php:

$lang['js']['insertcode'] = 'Insert Code';

And the image (code.png) of the codebutton plugin to the pix map.

Theo

plugin/toolbox.1270754551.txt.gz · Last modified: 2010-04-08 21:22 by 71.142.80.55