Hello guys, I tried to create an extension, a widget to replace the textarea with the jquery plugin Markitup.
<?php
class YiiMarkitup extends CInputWidget {
public function init()
{
parent::init();
$assetsFolder=Yii::app()->assetManager->publish(
Yii::getPathOfAlias('application.extensions.yiimarkitup.assets')
);
Yii::app()->clientScript->registerCssFile($assetsFolder.'/skins/markitup/style.css');
Yii::app()->clientScript->registerCssFile($assetsFolder.'/sets/bbcode/style.css');
Yii::app()->clientScript->registerScriptFile($assetsFolder.'/jquery.markitup.js');
Yii::app()->clientScript->registerScriptFile($assetsFolder.'/sets/bbcode/set.js');
Yii::app()->clientScript->registerCoreScript('jquery');
if (isset($this->htmlOptions['id']))
$id = $this->htmlOptions['id'];
else
$id = CHtml::activeId($this->model, $this->attribute);
Yii::app()->clientScript->registerScript("{$id}",
'$(document).ready(function() {
$("textarea").markItUp(mySettings);
});'
);
}
public function run()
{
echo CHtml::activeTextArea($this->model, $this->attribute, $this->htmlOptions);
}
}
Usage:
<?php $this->widget('YiiMarkitup', array('model'=>$model, 'attribute'=>'contents')); ?>
But I have some problem:
- The plugin has several folders that contain different sets of configurations (bbcode, html, wiki …), I thought that to use the one chosen by the user (and here’s another question: how does the user to choose the sets they prefer?) would be enough to do it this way:
Yii::app()->clientScript->registerCssFile($assetsFolder.'/sets/'.$type.'/style.css');
Yii::app()->clientScript->registerScriptFile($assetsFolder.'/sets/'.$type.'/set.js');
Where type can be "bbcode", "wiki", "html"…
Any suggestion? Any best way?
- The config script is in format json, called set.js. How can I do a merge this with some of user-defined options when calling the widget, and where the user can write them?
Thanks