Created
May 9, 2012 10:47
-
-
Save phpnode/2643666 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Provides a wrapper for the CKEditor wysiwyg html editor | |
* @author Charles Pick | |
* @package packages.ckeditor | |
*/ | |
class ACKEditorWidget extends CInputWidget { | |
/** | |
* The options for the editor | |
* @var array | |
*/ | |
public $options = array(); | |
/** | |
* The htmlOptions for the container | |
* @var array | |
*/ | |
public $htmlOptions = array(); | |
/** | |
* Runs the widget and shows the CKeditor | |
*/ | |
public function run() | |
{ | |
$clientScript = Yii::app()->clientScript; /* @var CClientScript $clientScript */ | |
list($name, $id) = $this->resolveNameID(); | |
$htmlOptions = $this->htmlOptions; | |
$htmlOptions['id'] = $id; | |
if ($this->hasModel()) { | |
echo CHtml::activeTextArea($this->model,$this->attribute,$htmlOptions); | |
} | |
else { | |
echo CHtml::textArea($this->name,$this->value,$htmlOptions); | |
} | |
$baseUrl = self::registerAssets(); | |
$options = $this->options; | |
if (!isset($options['skin'])) { | |
$options['skin'] = "foundation"; | |
} | |
$options = CJavaScript::encode($options); | |
$clientScript->registerScript(__CLASS__."#".$id,'$("#'.$id.'").ckeditor('.$options.');',CClientScript::POS_END); | |
} | |
/** | |
* Registers the assets used by ckeditor | |
*/ | |
public static function registerAssets() | |
{ | |
$clientScript = Yii::app()->clientScript; /* @var CClientScript $clientScript */ | |
$baseUrl = Yii::app()->assetManager->publish(dirname(__FILE__).DIRECTORY_SEPARATOR."assets"); | |
$clientScript->registerScriptFile($baseUrl."/ckeditor.js",CClientScript::POS_END); | |
$clientScript->registerScriptFile($baseUrl."/adapters/jquery.ckeditor.js",CClientScript::POS_END); | |
return $baseUrl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment