| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Editor

Page history last edited by webberoo 15 years, 8 months ago

I've updated the Editor Plugin to be compatible with CodeEx RC14.  Not sure if I did it right, better check.  Here's the code:

 

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Editor extends codexForms

{

    function Editor($name,$params) {

        codexForms::initiate($name,$params);

    }

    function prepForDb($value){

        return $value;

    }

    function getHTML()

    {

        $CI = &get_instance();  

        $CI->codextemplates->js('js-tinymce','/tiny_mce/tiny_mce.js');

 

        $html = "";

        $theme = !isset($this->params['theme'])? "simple" : $this->params['theme'];

        $html .='

                <script language="javascript" type="text/javascript">

                tinyMCE.init({

                    mode : "exact",

                    elements : "'.$this->name.'",

                    theme : "'.$theme.'"

                });

                </script>

        ';

        $html .= $this->prefix;

        $html .= $this->getMessage($this->name);

        $html .= '

            <label for="'.$this->name.'">

                '.$this->label.'

            </label>

            <textarea id="'.$this->name.'" name="'.$this->name.'" '.$this->getAttributes($this->attributes).'>'.$this->value.'</textarea>

        ';

        $html .= $this->suffix;

 

        return $html;

    }

}

?>

 

Here is my revised editor plugin.

 

+adds a link to tinyMCE within the assets folder

+adds tinyMCE config options in between the html tags

+allows for custom tinyMCE options to be set using yaml files

 

Insert the following into a file called editor.php and save to plugin directory.

 

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/*

 * =======================================================

 *

 *                 

 *              Editor Plugin for CodeExtinguisher

 *                    Revised by webberoo

 *                  -------------------------

 *

 *                  YAML Configuration Options:

 *

 *      +=============+================+================+

 *      |  Required?  |      Name      |     Value      |

 *      +=============+================+================+

 *      |     Yes     |      class     |    Editor      |

 *      |     No      |    Attributes  |  Rows, Cols    |

 *      |     No      |      Label     |     Label      |

 *      |     No      |      Params    | theme, options |

 *      +-------------+----------------+----------------+

 *

 *                           Example:

 *

 *      field_name:

 *          class: Editor

 *          attributes:

 *              rows: 10 <-sample row length

 *              cols: 50 <-sample col length

 *          label: This is a sample Label

 *          params:

 *              theme: advanced

 *              options:

 *                  tinyMCE_configuration_option: sample value

 *

 * =======================================================

 */

class Editor extends codexForms

{

    function Editor($name,$params) {

        codexForms::initiate($name,$params);

    }

    function prepForDb($value){

        return $value;

    }

   

    function getHTML()

    {

        $CI = &get_instance(); 

       

        $CI->codextemplates->jsFromAssets('js-tinymce','tiny_mce/tiny_mce.js');

       

        $tinyMce = $this->getTinyMCEOptions();

       

        $CI->codextemplates->inlineJS('js-editor',$tinyMce);

       

         $html = "";

        $html .= $this->prefix;

        $html .= $this->getMessage($this->name);

        $html .= '

            <label for="'.$this->name.'">

                '.$this->label.'

            </label>

            <textarea id="'.$this->name.'" name="'.$this->name.'" '.$this->getAttributes($this->attributes).'>'.$this->value.'</textarea>

        ';

        $html .= $this->suffix;

        return $html;

    }

   

    function getTinyMCEOptions()

    {

        $theme = '';

        $theme .= !isset($this->params['theme'])? "simple" : $this->params['theme'];

   

        $html = '';

        $html .= 'tinyMCE.init({';

        $html .= '    mode:"exact",';

        $html .= '    elements:"'.$this->name.'",';

        $html .= '    theme:"'.$theme.'",';

        foreach($this->params['options'] as $k => $v)

        {

            $html .= '    '.$k.':"'.$v.'",';   

        }

        $html .= '    });';

       

        return $html;

       

    }   

}

?>

 

 

Comments (0)

You don't have permission to comment on this page.