Alanaktion / lwrte

Automatically exported from code.google.com/p/lwrte
0 stars 0 forks source link

Ability to switch off design/html toggle functionality #65

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The editor always comes with the ability to switch between html and design mode 
and there is no ability to switch this button off.  My solution is to update 
the toolbar and add this to the beginning

var rte_toolbar = {
    disable         : {ignore: true},
        .....

Then update the create_toolbar function in the code to check if ignore is set 
thus not physically adding the button to the toolbar can be used on any button 
to disable.  also since the second item on the tool bar might be a separator 
add a counter that will only show a separator if an icon has been shown before 
it so this will remove multiple separators in a row.

lwRTE.prototype.create_toolbar = function(controls) {
        var iCounter =0;
        var self = this;
        var tb = $("<div></div>").addClass('rte-toolbar').width('100%').append($("<ul></ul>")).append($("<div></div>").addClass('clear'));
        var obj, li;

        for (var key in controls){
                if(controls[key].ignore) {
                    li = "";
                } else if(controls[key].separator) {
                    if(iCounter>0){
                        li = $("<li></li>").addClass('separator');
                        iCounter=0;
                    }
                } else {
                        if(controls[key].init) {
                                try {
                                        controls[key].init.apply(controls[key], [this]);
                                } catch(e) {
                                }
                        }

                        if(controls[key].select) {
                                obj = $(controls[key].select)
                                        .change( function(e) {
                                                self.event = e;
                                                self.toolbar_click(this, controls[this.className]); 
                                                return false;
                                        });
                        } else {
                                obj = $("<a href='#'></a>")
                                        .attr('title', (controls[key].hint) ? controls[key].hint : key)
                                        .attr('rel', key)
                                        .click( function(e) {
                                                self.event = e;
                                                self.toolbar_click(this, controls[this.rel]); 
                                                return false;
                                        })
                        }

                        li = $("<li></li>").append(obj.addClass(key));
                        iCounter++;
                }

                $("ul",tb).append(li);
        }

        $('.enable', tb).click(function() {
                self.enable_design_mode();
                return false; 
        });

        $('.disable', tb).click(function() {
                self.disable_design_mode();
                return false; 
        });

        return tb.get(0);
}

Original issue reported on code.google.com by spambot....@googlemail.com on 11 Oct 2010 at 11:04