Skip to content

Commit

Permalink
1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Dec 11, 2012
1 parent ba34bdc commit c72034d
Show file tree
Hide file tree
Showing 8 changed files with 2,289 additions and 1,289 deletions.
66 changes: 17 additions & 49 deletions ImperaviRedactorWidget.php
Expand Up @@ -3,61 +3,29 @@
* ImperaviRedactorWidget class file.
*
* @author Veaceslav Medvedev <slavcopost@gmail.com>
* @link https://github.com/yiiext/imperavi-redactor-widget
* @license http://www.opensource.org/licenses/bsd-license.php
*/
/**
* ImperaviRedactorWidget wrapper around {@link http://redactorjs.com Fantastic WYSIWYG-editor on jQuery}.
*
* Usage:
*
* First, import the class file
* <pre>
* Yii::import('ext.imperavi-redactor-widget.ImperaviRedactorWidget');
* </pre>
* @authro Alexander Makarov <sam@rmcreative.ru>
*
* Next, render the textarea and create it into redactor
* <pre>
* $this->widget('ImperaviRedactorWidget',array(
* // you can either use it for model attribute
* 'model'=>$my_model,
* 'attribute'=>'my_field',
* // or just for input field
* 'name'=>'my_input_name',
* // imperavi redactor {@link http://redactorjs.com/docs/ options}
* 'options'=>array(
* 'lang'=>'en',
* ),
* ));
* </pre>
* Or create redactor from textarea by selector
* <pre>
* $this->widget('ImperaviRedactorWidget',array(
* // the textarea selector
* 'selector'=>'.redactor',
* // imperavi redactor {@link http://redactorjs.com/docs/ options}
* 'options'=>array(),
* ));
* </pre>
* @version 1.0
*
* @author Veaceslav Medvedev <slavcopost@gmail.com>
* @version 0.7
* @package yiiext.imperavi-redactor-widget
* @link http://redactorjs.com
* @link https://github.com/yiiext/imperavi-redactor-widget
* @license https://github.com/yiiext/imperavi-redactor-widget/blob/master/license.md
*/
class ImperaviRedactorWidget extends \CInputWidget
{
/**
* Assets package ID.
*/
const PACKAGE_ID = 'imperavi-redactor';

/**
* @var array {@link http://redactorjs.com/docs redactor options}.
* @var array {@link http://imperavi.com/redactor/docs/ redactor options}.
*/
public $options = array();

/**
* @var string|null The textarea selector. If it null, will be render the textarea.
* Defaults to null.
* @var string|null Selector pointing to textareas to initialize redactor for.
* Defaults to null meaning that textarea doesn't exist yet and will be
* rendered by this widget.
*/
public $selector;

Expand All @@ -73,10 +41,10 @@ public function init()
$this->selector = '#' . $this->id;

if ($this->hasModel()) {
echo \CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
echo CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
} else {
$this->htmlOptions['id'] = $this->id;
echo \CHtml::textArea($this->name, $this->value, $this->htmlOptions);
echo CHtml::textArea($this->name, $this->value, $this->htmlOptions);
}
}

Expand All @@ -88,10 +56,10 @@ public function init()
*/
protected function registerClientScript()
{
/** @var $cs \CClientScript */
/** @var $cs CClientScript */
$cs = Yii::app()->clientScript;
if (!isset($cs->packages[self::PACKAGE_ID])) {
/** @var $am \CAssetManager */
/** @var $am CAssetManager */
$am = Yii::app()->assetManager;
$cs->packages[self::PACKAGE_ID] = array(
'basePath' => dirname(__FILE__) . '/assets',
Expand All @@ -110,9 +78,9 @@ protected function registerClientScript()
$cs->registerPackage(self::PACKAGE_ID);

$cs->registerScript(
__CLASS__ . '#' . $this->id,
'jQuery(' . \CJavaScript::encode($this->selector) . ').redactor(' . \CJavaScript::encode($this->options) . ');',
\CClientScript::POS_READY
get_class($this) . '#' . $this->id,
'jQuery(' . CJavaScript::encode($this->selector) . ').redactor(' . CJavaScript::encode($this->options) . ');',
CClientScript::POS_READY
);
}
}
398 changes: 265 additions & 133 deletions assets/redactor.css

Large diffs are not rendered by default.

0 comments on commit c72034d

Please sign in to comment.