HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

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(){}

}

Comments

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    You can also add Cleditor to the Contact plugin message form and I would assume any other message form in other plugins;

    I added the plugin controller to the cleditor

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

    and added #Form_Message to the jquery

    **jQuery("#Form_Body.TextBox,#Form_Comment.TextBox,#Form_Message").livequery(function() {**

Sign In or Register to comment.