Welcome Guest, Not a member yet? Register   Sign In
NicEdit Helper
#1

[eluser]m4ikel[/eluser]
For anyone looking for a good NicEdit CodeIgniter integration below you will find the codebase of my own little creation.

More information on NicEdit: http://nicedit.com

Good luck!

[b]Notice: Be aware of the <$cript> else this forum board stripped it.

Code:
&lt;?php
if(!defined('BASEPATH')) exit('No direct script access allowed');

/*
* NicEdit helper for CodeIgniter
* @author: Maikel Doeze
* @website: www.websitepro.nl
* @version: 1.0.0
* @update: 19-06-2011
*/

/* USAGE ********************************************************
CONTROLLER:

$this->load->helper('nicedit');
$data['nicedit'] = array
(
    'path'    =>    '/global/_js',
    'id' => 'test',
    
    'config' => array
    (
        'iconsPath'    => "'".base_url()."/global/_images/nicEditorIcons.gif'",
        'fullPanel' => true
    )
);

VIEW:

{form_textarea('name','value','id="test"')}
{display_nic($nicedit)}
*****************************************************************/

/*
* Method returns the instance of nicEdit to be returned inside a view
* @param array
* @return string
*/
function nic_display($data = array())
{
    // Initialization
    return nic_initialize($data);
}

/*
* Method will set javascript call and import configs
* @param array
* @return string
*/
function nic_initialize($data = array())
{
    $str = '';
    
    if(!defined('NIC_EDIT_HELPER_LOADED'))
    {
        $str .= '<$cript type="text/javascript" src="'.base_url().$data['path'].'/nicEdit.js"></$cript>';
        define('NIC_EDIT_HELPER_LOADED',true);
    }
    
    $str .= nic_config($data);
    
    return $str;
}

/*
* Method parses config vars set from controller
* @param array
* @return string
*/
function nic_config($data = array())
{
    $str = "<$cript type=\"text/javascript\">\n";
    $str .= "bkLib.onDomLoaded(function(){\n";
    
    if(isset($data['id']))
    {
        $str .= "new nicEditor(";
    }
    else
    {
        $str .= "nicEditors.allTextAreas(";
    }
    
    if(isset($data['config']))
    {
        $str .= "{\n";
        
        foreach($data['config'] as $key => $value)
        {
            $str .= $key." : ".$value.",\n";
        }
        
        $str .= "}";
    }
    
    $str .= ")";
    
    if(isset($data['id']))
    {
        $str .= ".panelInstance(\"".$data['id']."\")";
    }
    
    $str .= ";\n});\n";
    $str .= "</$cript>\n";
    
    return $str;
}




Theme © iAndrew 2016 - Forum software by © MyBB