Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

In this Discussion

Vanilla 2.6 is here! It includes security fixes and requires PHP 7.0. We have therefore ALSO released Vanilla 2.5.2 with security patches if you are still on PHP 5.6 to give you additional time to upgrade.

Add Cleditor to other forms in 2.0

vrijvlindervrijvlinder Papillon-Sauvage MVP
edited January 2014 in Tutorials

I managed to add Cleditor editor to all my forms in my forum. That is Activity, Conversations,Messages also.

This is what I did

class cleditorPlugin extends Gdn_Plugin {

    public function PostController_Render_Before($Sender) {
        $this->_AddCLEditor($Sender);
    }

    public function DiscussionController_Render_Before($Sender) {
        $this->_AddCLEditor($Sender);
    }
//adds Cleditor to Activity Form    
         public function ActivityController_Render_Before($Sender) {
                 $this->_AddCLEditor($Sender);
    }
//adds Cleditor to Profile Activity Form
 public function ProfileController_Render_Before($Sender) {
                 $this->_AddCLEditor($Sender);
    }
//adds Cleditor to the Conversations Form
 public function ConversationsController_Render_Before($Sender) {
                 $this->_AddCLEditor($Sender);
    }
//adds Cleditor to the Messages Form
 public function MessagesController_Render_Before($Sender) {
                 $this->_AddCLEditor($Sender);
    }
    private function _AddCLEditor($Sender) {
        // Turn off safestyles so the inline styles get applied to comments
        $Config = Gdn::Factory(Gdn::AliasConfig);
        $Config->Set('Garden.Html.SafeStyles', FALSE);

        // Add the CLEditor to the form
        $Options = array('ie' => 'gt IE 6', 'notie' => TRUE); // Exclude IE6
        $Sender->RemoveJsFile('jquery.autogrow.js');
        $Sender->AddJsFile('jquery.cleditor'.(Debug() ? '' : '.min').'.js', 'plugins/cleditor', $Options);
        $Sender->AddCssFile('jquery.cleditor.css', 'plugins/cleditor', $Options);
        $Sender->Head->AddString('
<style type="text/css">
a.PreviewButton {
    display: none !important;
}
</style>
<script type="text/javascript">
    jQuery(document).ready(function($) {
        // Make sure the removal of autogrow does not break anything
        jQuery.fn.autogrow = function(o) { return; }
        // Attach the editor to comment boxes
        jQuery("#Form_Body.TextBox,#Form_Comment.TextBox").livequery(function() {
            var frm = $(this).parents("div.CommentForm");
            ed = jQuery(this).cleditor({width:"100%", height:"100%"})[0];
            this.editor = ed;
 // Support other plugins!
            jQuery(frm).bind("clearCommentForm", {editor:ed}, function(e) {
                frm.find("textarea").hide();
                e.data.editor.clear();
            });
        });
    });
</script>');
   }

    public function Setup(){}

}
peregrinehgtonight

Comments

Sign In or Register to comment.