public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $textarea = parent::render($name, $value, $attributes, $errors);
        $js = sprintf(<<<EOF
<script type="text/javascript">
  tinyMCE.init({
    mode:                              "exact",
    elements:                          "%s",
    theme:                             "advanced",
    %s
    %s
    theme_advanced_toolbar_location:   "top",
    theme_advanced_toolbar_align:      "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing:           false,
    theme_advanced_buttons1 : "bold,italic,separator,bullist,numlist,separator,undo,redo,separator,link",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    %s
  });
</script>
EOF
, $this->generateId($name), $this->getOption('width') ? sprintf('width:                             "%spx",', $this->getOption('width')) : '', $this->getOption('height') ? sprintf('height:                            "%spx",', $this->getOption('height')) : '', $this->getOption('config') ? ",\n" . $this->getOption('config') : '');
        return $textarea . $js;
    }
    /**
     * @param  string $name        The element name
     * @param  string $value       The value selected in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @return string An HTML tag string
     *
     * @see sfWidgetForm
     */
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        if (!isset($attributes['class'])) {
            throw new InvalidArgumentException(sprintf('You must pass a "class" attribute for a TinyMCE widget (%s).', $name));
        }
        $textarea = parent::render($name, $value, $attributes, $errors);
        // take the first class
        $classes = explode(' ', $attributes['class']);
        $class = trim($classes[0]);
        $js = sprintf(<<<EOF
<script type="text/javascript">
  tinyMCE.init({
    mode:                              "textareas",
    theme:                             "%s",
    editor_selector:                   "%s",
    %s
    %s
    theme_advanced_toolbar_location:   "top",
    theme_advanced_toolbar_align:      "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing:           true
    %s
  });
</script>
EOF
, $this->getOption('theme'), $class, $this->getOption('width') ? sprintf('width:                             "%spx",', $this->getOption('width')) : '', $this->getOption('height') ? sprintf('height:                            "%spx",', $this->getOption('height')) : '', $this->getOption('config') ? ",\n" . $this->getOption('config') : '');
        return $textarea . $js;
    }
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $textarea = parent::render($name, $value, $attributes, $errors);
        $js = sprintf(<<<EOF
<script type="text/javascript">
  /* <![CDATA[ */
  lyMediaManager.init('%s');
  
  tinyMCE.init({
    convert_urls : false,
    mode: "exact",
    elements: "%s",
    theme: "%s",
    %s
    %s
    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing: true,
    file_browser_callback : "lyMediaManager.fileBrowserCallBack"
    %s
  });
  /* ]]> */
</script>
EOF
, url_for('@ly_media_asset_icons?popup=1', true), $this->generateId($name), $this->getOption('theme'), $this->getOption('width') ? sprintf('width: "%spx",', $this->getOption('width')) : '', $this->getOption('height') ? sprintf('height: "%spx",', $this->getOption('height')) : '', $this->getOption('config') ? ",\n" . $this->getOption('config') : '');
        return $textarea . $js;
    }
    /**
     * @param  string $name        The element name
     * @param  string $value       The value displayed in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @see sfWidget
     **/
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $javascript = 'tiny_mce/tiny_mce' . ($this->getOption('with_gzip') ? '_gzip' : '');
        sfContext::getInstance()->getResponse()->addJavascript($javascript);
        $options = '';
        foreach ($this->getOption('tiny_options') as $key => $option) {
            $options .= ",\n    " . $key . ': ' . (in_array($key, $this->getOption('options_without_quotes')) ? $option : '\'' . $option . '\'');
        }
        $id = $this->generateId($name, $value);
        $script_gzip_content = '';
        $script_content = <<<JS
//<![CDATA[
  var ib = null;
  tinyMCE.init({
    mode: 'exact',
    elements: '{$id}'{$options}
  });
//]]>
JS;
        if ($this->getOption('with_gzip')) {
            $gz_options = '';
            foreach ($this->getOption('tiny_gz_options') as $key => $option) {
                $gz_options .= "\n    " . $key . ': \'' . $option . '\',';
            }
            $script_gzip_content = <<<JS
//<![CDATA[
  tinyMCE_GZ.init({{$gz_options}
    disk_cache: true,
    debug: false
  });
//]]>
JS;
        }
        return parent::render($name, $value, $attributes, $errors) . ($this->getOption('with_gzip') ? $this->renderContentTag('script', $script_gzip_content, array('type' => 'text/javascript')) : '') . $this->renderContentTag('script', $script_content, array('type' => 'text/javascript'));
    }
    /**
     * @param  string $name        The element name
     * @param  string $value       The value displayed in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @see sfWidget
     * */
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $id = $this->generateId($name, $value);
        $format = sfConfig::get('tinymce_' . $this->getOption('format'));
        $i = count($format);
        $options = 'script_url: "/sfTinymcePlugin/js/tinymce/tiny_mce.js",' . "\n";
        foreach ($format as $key => $val) {
            $options .= !is_bool($val) ? $key . ': "' . $val . '"' : $key . ': ' . intval($val);
            $options .= $i-- != 1 ? ',' : '';
            $options .= "\n";
        }
        $javascript = <<<JS
  <script type="text/javascript">
  \$(function() {
    
    \$('#{$id}').tinymce(
      {
        {$options}
      }
    );
  });
  </script>
JS;
        return $javascript . "\n" . parent::render($name, $value, $attributes, $errors);
    }
 /**
  * Render field
  * @param   string  $name       Element name
  * @param   string  $value      Field value [optional]
  * @param   array   $attributes HTML attributes [optional]
  * @param   array   $errors     Field errors [optional]
  * @return  string  XHTML compliant tag
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $textarea = parent::render($name, $value, $attributes, $errors);
     $genId = $this->generateId($name);
     $init[] = "tinyMCE.init({mode:'none',elements:'" . $genId . "',";
     $init[] = "theme:'" . $this->getOption('theme') . "',";
     $init[] = $this->getOption('width') ? "width:'" . $this->getOption('width') . "px'," : '';
     $init[] = $this->getOption('height') ? "height:'" . $this->getOption('height') . "px'," : '';
     $init[] = "theme_advanced_toolbar_location:'top',theme_advanced_toolbar_align:'left',";
     $init[] = "theme_advanced_statusbar_location:'bottom',theme_advanced_resizing:true";
     $init[] = $this->getOption('config') ? "," . $this->getOption('config') : '';
     $init[] = "});";
     $fix[] = "if(tinyMCE.get('" . $genId . "'))tinyMCE.remove(tinyMCE.get('" . $genId . "'));";
     $fix[] = "setTimeout('tinyMCE.execCommand(\\'mceAddControl\\',false,\\'" . $genId . "\\');', 100);";
     // remove this shit
     if (!$this->getOption('activate')) {
         $ext[] = '<a id="tmcAct' . $genId . '" class="tinymce_activation" ';
         $ext[] = 'href="javascript:void(0)" onclick="tmcActivation' . $genId . '()" title="';
         $ext[] = I18n::__('admin.labels.tmcActivation') . '"></a>';
     }
     $ext[] = '<script type="text/javascript">';
     if (!$this->getOption('activate')) {
         $ext[] = 'if(typeof jQuery!=\'undefined\'){';
         $ext[] = '$(\'#tmcAct' . $genId . "').button({icons:{primary:'ui-icon-contact'},text:false});";
         $ext[] = "function tmcActivation" . $genId . '(){$(\'#tmcAct' . $genId . "').hide();";
         $ext[] = implode($init) . implode($fix) . '}}';
     } else {
         $ext[] = implode($init) . implode($fix);
     }
     $ext[] = "</script>";
     return $textarea . implode($ext);
 }
    /**
     * @param  string $name        The element name
     * @param  string $value       The value selected in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @return string An HTML tag string
     *
     * @see sfWidgetForm
     */
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $name = isset($attributes['name']) ? $attributes['name'] : $name;
        $textarea = parent::render($name, $value, $attributes, $errors);
        $id = $this->generateId($name, null);
        $config = json_encode(array_merge(array('toolbar' => 'ShortToolbar'), $this->getOption('config')));
        $js = <<<HTML
<script type="text/javascript">
  \$(function(){
    var editor_{$id} = CKEDITOR.replace( '{$name}',
      {$config}
    );
    var saveChanges = function () {
      var textarea = \$('#{$id}');
      if (textarea.val() !=  editor_{$id}.getData()) {
        \$('#{$id}').val(editor_{$id}.getData()).trigger('change');
      }
    };
    editor_{$id}.on('destroy', function () {
      editor_{$id}.removeListener('blur', saveChanges);
    });
    editor_{$id}.on('blur', saveChanges);
HTML;
        if ($this->getOption('with_ckfinder')) {
            $js .= "CKFinder.setupCKEditor( editor_{$id}, '/laWidgetCKEditorPlugin/ckfinder/' );";
        }
        $js .= <<<HTML
  });
</script>
HTML;
        return $js . $textarea;
    }
    /**
     * @param  string $name        The element name
     * @param  string $value       The value selected in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @return string An HTML tag string
     *
     * @see sfWidgetForm
     */
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $textarea = parent::render($name, $value, $attributes, $errors);
        $js = sprintf(<<<EOF
<script type="text/javascript">
  tinyMCE.init({
    mode:                              "exact",
    elements:                          "%s",
    plugins:                           "media,table,paste,fullscreen",        
    extended_valid_elements : "input[name|size|type|value|onclick],iframe[height|width|src]",
    theme:                             "%s",
    language:                          "ca",
    %s
    %s
    paste_auto_cleanup_on_paste:       true,
    paste_strip_class_attributes:      "all",
    theme_advanced_toolbar_location:   "top",
    theme_advanced_toolbar_align:      "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing:           true,
\ttheme_advanced_blockformats :      "p,div,h1,h2,h3,h4,h5,h6,blockquote,dt,dd,code,samp",
\ttheme_advanced_buttons1 :          "fullscreen,bold,italic,underline,separator,justifycenter,justifyfull,bullist,indent,separator,table,separator,undo,redo,separator,link,unlink,image,media,separator,formatselect,separator,code",
\ttheme_advanced_buttons2 :          "",
\ttheme_advanced_buttons3 :          "",
\tfile_browser_callback:             'ajaxfilemanager',
\trelative_urls:  \t\t\t\t   false,\t    
    %s
  })
  function ajaxfilemanager(field_name, url, type, win) {
      var ajaxfilemanagerurl = "../../../../js/tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php";
      switch (type) {
        case "image":
          break;
        case "media":
          break;
        case "flash": 
          break;
        case "file":
          break;
        default:
          return false;
      }
            tinyMCE.activeEditor.windowManager.open({
                url: "../../../../js/tiny_mce/plugins/ajaxfilemanager/ajaxfilemanager.php",
                width: 782,
                height: 440,
                inline : "yes",
                close_previous : "no"
            },{
                window : win,
                input : field_name
            });
    }
  ;
</script>
EOF
, $this->generateId($name), $this->getOption('theme'), $this->getOption('width') ? sprintf('width:                             "%spx",', $this->getOption('width')) : '', $this->getOption('height') ? sprintf('height:                            "%spx",', $this->getOption('height')) : '', $this->getOption('config') ? ",\n" . $this->getOption('config') : '');
        return $textarea . $js;
    }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $response = sfContext::getInstance()->getResponse();
     $response->addJavascript('/sfExtraWidgetsPlugin/js/tinymce/plugins/tinybrowser/tb_tinymce.js.php');
     $response->addJavascript('/sfExtraWidgetsPlugin/js/tinymce/tiny_mce.js');
     $js = "\n            tinyMCE.init({\n                // General options\n                mode : 'exact',\n                elements: '" . $this->generateId($name) . "',\n                skin : '" . sfConfig::get('app_tinymce_skin', 'o2k7') . "',\n                language: '" . substr(sfContext::getInstance()->getUser()->getCulture(), 0, 2) . "',\n                theme : 'advanced',\n                height: " . $this->getOption('height') . ",\n                width: " . $this->getOption('width') . ",\n                dialog_type: '" . sfConfig::get('app_tinymce_dialog_type', 'window') . "',\n                editor_selector : 'mceEditor',\n                editor_deselector : 'mceNoEditor',\n                relative_urls : " . sfConfig::get('app_tinymce_relative_urls', 'false') . ",\n                gecko_spellcheck: " . sfConfig::get('app_tinymce_gecko_spellcheck', 'true') . ",\n                entity_encoding : '" . sfConfig::get('app_tinymce_entity_encoding', 'raw') . "',\n                plugins : '" . sfConfig::get('app_tinymce_plugins') . "',\n\n                // Theme options\n                theme_advanced_buttons1 : '" . sfConfig::get('app_tinymce_theme_advanced_buttons1') . "',\n                theme_advanced_buttons2 : '" . sfConfig::get('app_tinymce_theme_advanced_buttons2') . "',\n                theme_advanced_buttons3 : '" . sfConfig::get('app_tinymce_theme_advanced_buttons3') . "',\n                theme_advanced_toolbar_location : '" . sfConfig::get('app_tinymce_theme_advanced_toolbar_location') . "',\n                theme_advanced_toolbar_align : '" . sfConfig::get('app_tinymce_theme_advanced_toolbar_align') . "',\n                theme_advanced_statusbar_location : '" . sfConfig::get('app_tinymce_theme_advanced_statusbar_location') . "',\n                theme_advanced_resizing : " . sfConfig::get('app_tinymce_theme_advanced_resizing') . ",\n                \n                file_browser_callback : '" . sfConfig::get('app_tinymce_file_browser_callback') . "'\n            });\n        ";
     return javascript_tag($js) . parent::render($name, $value, $attributes, $errors);
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $jsoptions = $this->getOption('jsoptions');
     if ($jsoptions) {
         $this->setJSOptions($name, $value, $attributes, $errors);
     }
     return parent::render($name, $value, $attributes, $errors) . $this->_editor->replace($name);
 }
 /**
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetForm
  */
 protected function configure($options = array(), $attributes = array())
 {
     $this->addOption('editor', 'fck');
     $this->addOption('css', false);
     $this->addOption('tool', 'Default');
     $this->addOption('height', '225');
     $this->addOption('width', '100%');
     parent::configure($options, $attributes);
 }
 /**
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (isset($attributes['class'])) {
         $attributes['class'] .= ' w-richtext';
     } else {
         $attributes['class'] = 'w-richtext';
     }
     return parent::render($name, $value, $attributes, $errors);
 }
 /**
  * 
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  * @see sfWidgetForm
  */
 protected function configure($options = array(), $attributes = array())
 {
     $this->addOption('editor', sfConfig::get('app_a_editor', 'fck'));
     // For bc. Does nothing
     $this->addOption('css', false);
     $this->addOption('tool', 'Default');
     $this->addOption('height', '225');
     $this->addOption('width', '100%');
     parent::configure($options, $attributes);
 }
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        if (sfConfig::get('sf_app') == 'mobile_frontend') {
            return parent::render($name, $value, $attributes, $errors);
        }
        $toggle = '';
        $js = '';
        $id = $this->getId($name, $attributes);
        $changerName = $id . '_changer';
        $offId = $id . '_changer_1';
        $onId = $id . '_changer_2';
        if (self::$isFirstRender) {
            sfContext::getInstance()->getResponse()->addJavascript('/sfProtoculousPlugin/js/prototype');
            sfContext::getInstance()->getResponse()->addJavascript('tiny_mce/tiny_mce');
            $js .= <<<EOF
  function op_toggle_mce_editor(id)
  {
    var textmode_checked    = \$(id + "_changer_1").checked;
    var previewmode_checked = \$(id + "_changer_2").checked;
    var relational_objects  = \$\$("." + id);
    var editor = tinyMCE.get(id);
    if (!editor) {
      if (previewmode_checked) {
        tinyMCE.execCommand('mceAddControl', false, id);
        relational_objects.each(function(object){ object.style.display = "none"; });
      }
      return true;
    }
    if (editor.isHidden() && previewmode_checked) {
      editor.show();
      relational_objects.each(function(object){ object.style.display = "none"; });
    } else if (!editor.isHidden() && textmode_checked) {
      editor.hide();
      relational_objects.each(function(object){ object.style.display = "block"; });
    }
  }

EOF;
            $js .= sprintf("  tinyMCE.init(%s);\n", json_encode($this->tinyMCEConfigs));
            self::$isFirstRender = false;
        }
        $js .= sprintf("  op_toggle_mce_editor('%s');\n", $id);
        if ($js) {
            sfProjectConfiguration::getActive()->loadHelpers('Javascript');
            $js = javascript_tag($js);
        }
        if ($this->getOption('is_toggle')) {
            $toggle = sprintf(<<<EOF
<input id="%s" type="radio" name="%s" onclick="%s"%s /><label for="%s">%s</label>
<input id="%s" type="radio" name="%s" onclick="%s"%s /><label for="%s">%s</label><br />
EOF
, $offId, $changerName, sprintf("op_toggle_mce_editor('%s')", $id), $this->getOption('is_textmode') ? ' checked="checked"' : '', $offId, sfContext::getInstance()->getI18N()->__('Text Mode'), $onId, $changerName, sprintf("op_toggle_mce_editor('%s')", $id), $this->getOption('is_textmode') ? '' : ' checked="checked"', $onId, sfContext::getInstance()->getI18N()->__('Preview Mode'));
        }
        return $toggle . sprintf($this->getOption('textarea_template'), $this->renderTextarea($name, $value, $attributes, $errors)) . $js;
    }
 /**
  * @param  string $name         The element name
  * @param  string $value        The value selected in this widget
  * @param  array $attributes    An array of HTML attributes to be merged with the default HTML attributes
  * @param  array $errors        An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $data = $this->parseConfiguration();
     if (isset($attributes['class'])) {
         $attributes['class'] = $attributes['class'] . json_encode(array('tiny_mce_config' => $data));
     } else {
         $attributes['class'] = json_encode(array('tiny_mce_config' => $data));
     }
     $attributes['data-dme-richeditor'] = 'tiny_mce';
     return parent::render($name, $value, $attributes, $errors);
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $response = sfContext::getInstance()->getResponse();
     $response->addJavascript('/sfExtraWidgetsPlugin/js/livepipe.js');
     $response->addStylesheet('/sfExtraWidgetsPlugin/css/markdown.css');
     $this->setAttribute('style', 'width: ' . ($this->getOption('width') - $this->getOption('padding')) . 'px; height: ' . $this->getOption('height') . 'px;');
     if (array_key_exists('class', $attributes)) {
         $attributes['class'] .= ' ' . 'markdown_field';
     } else {
         $attributes['class'] = 'markdown_field';
     }
     return content_tag('div', parent::render($name, $value, $attributes, $errors) . $this->addScript($name), array('style' => 'width:' . $this->getOption('width') . 'px'));
 }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (!isset($this->attributes['config'])) {
         $this->attributes['config'] = 'default';
     }
     $config = $this->attributes['config'];
     $route = sfContext::getInstance()->getRouting();
     $url = $route->generate('ckeditor_config', array('name_config' => $config, 'sf_format' => 'js'));
     $urlBrowse = $route->generate('browse_media', array('test' => array('naam' => 'joris')));
     $response = sfContext::getInstance()->getResponse();
     $response->addJavascript('/sfWidgetCKEditorPlugin/js/ckeditor/ckeditor.js');
     return parent::render($name, $value, $attributes, $errors) . "\n            <script>\n                document.addEventListener(\"DOMContentLoaded\", function(event) {\n                    CKEDITOR.replace( '" . $name . "', {\n                        customConfig: '" . $url . "',\n                    });\n\n                    CKEDITOR.config.filebrowserBrowseUrl = '" . $urlBrowse . "';\n                    CKEDITOR.config.filebrowserUploadUrl = '/upload.php';\n                });\n            </script>\n        ";
 }
   /**
    * @param  string $name        The element name
    * @param  string $value       The value selected in this widget
    * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
    * @param  array  $errors      An array of errors for the field
    *
    * @return string An HTML tag string
    *
    * @see sfWidgetForm
    */
   public function render($name, $value = null, $attributes = array(), $errors = array())
   {
       $textarea = parent::render($name, $value, $attributes, $errors);
       $js = '
  <script type="text/javascript">
     CKEDITOR.replace(\'' . $this->generateId($name) . '\', { 
     		language: \'ca\',
     		width: \'100%\'
 		});
     CKEDITOR.add            
  </script>';
       return $textarea . $js;
   }
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $id = $this->generateId($name, $value);
        $previewUrl = $this->getPreviewUrl();
        $javascript = <<<JS
//<![CDATA[
\$(document).ready(function() {
  mySettings.previewParserPath = "{$previewUrl}";
  \$("#{$id}").markItUp(mySettings);
});
//]]>
JS;
        return parent::render($name, $value, $attributes, $errors) . $this->renderContentTag('script', $javascript, array('type' => 'text/javascript'));
    }
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $textarea = parent::render($name, $value, $attributes, $errors);
        $chars_left = $this->getOption('limit') - strlen($value);
        $text_field_id = $this->generateId($name);
        $char_left_tag_id = $text_field_id . '_left';
        $limit_text = '<span id="' . $char_left_tag_id . '">' . $chars_left . '</span>' . $this->getOption('text');
        $text = $this->renderContentTag($this->getOption('text_tag'), $limit_text, $this->getOption('text_tag_options'));
        $js = '<script type="text/javascript">
                var char_limit = ' . $this->getOption('limit') . ';
    ';
        $limit_field_id = $this->getOption('limit_field_id');
        $js .= '
        $(function () {';
        if (!is_null($limit_field_id)) {
            $js .= '$(\'#' . $limit_field_id . '\').keyup(function () {
                    $(\'#' . $text_field_id . '\').keyup();
                });
                ';
        }
        $js .= '$(\'#' . $text_field_id . '\').keyup(function () {
                var $this = $(this);
                var limit_id = $this.attr(\'id\') + \'_left\';
                ';
        if (!is_null($limit_field_id)) {
            $js .= 'var limit = $(\'#' . $limit_field_id . '\').val()';
        } else {
            $js .= 'var limit = ' . $this->getOption('limit') . ';';
        }
        $js .= '
		newlength = limit - $this.val().length;
		
		if (newlength < 0) {
		    $this.val($this.val().substr(0,limit));
		    $(\'#\'+ limit_id ).addClass(\'error\');
		    newlength = 0;
		} else {
		    $this.val($this.val().substr(0,limit));
		    $(\'#\'+ limit_id ).removeClass(\'error\');
		}
		$(\'#\'+ limit_id ).html(newlength);
                
            });
        });
        

    ';
        $js .= '</script>';
        return $textarea . $text . $js;
    }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $id = $this->generateId($name);
     $options = array();
     foreach ((array) $this->getOption('editarea_options') as $key => $val) {
         if (is_bool($val)) {
             $options[] = "{$key}: " . ($val ? 'true' : 'false');
         } else {
             $options[] = "{$key}: '{$val}'";
         }
     }
     $options = '{' . implode(', ', $options) . '}';
     $contentTag = parent::render($name, $value, $attributes, $errors);
     $contentTag .= javascript_tag("\n      if(\$.fn.editArea)\n        \$('#{$id}').editArea({$options});\n      else\n        throw 'EditArea JS not included!';\n    ");
     return $contentTag;
 }
    /**
     * @param  string $name        The element name
     * @param  string $value       The value selected in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @return string An HTML tag string
     *
     * @see sfWidgetForm
     */
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $textarea = parent::render($name, $value, $attributes, $errors);
        $js = sprintf(<<<EOF
<script type="text/javascript">
  tinyMCE.init({
    plugins: [
            "advlist autolink autosave link image lists charmap print preview hr anchor pagebreak spellchecker",
            "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
            "table contextmenu directionality emoticons template textcolor paste textcolor"],

    toolbar1: "newdocument | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | styleselect formatselect fontselect fontsizeselect",
    toolbar2: "cut copy paste | searchreplace | bullist numlist | outdent indent blockquote | undo redo | link unlink anchor image media code | inserttime preview | forecolor backcolor",
    toolbar3: "table | hr removeformat | subscript superscript | charmap emoticons | print fullscreen | ltr rtl | spellchecker | visualchars visualblocks nonbreaking template pagebreak restoredraft",
    
    style_formats: [
            {title: 'Bold text', inline: 'b'},
            {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
            {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
            {title: 'Example 1', inline: 'span', classes: 'example1'},
            {title: 'Example 2', inline: 'span', classes: 'example2'},
            {title: 'Table styles'},
            {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ],

    templates: [
            {title: 'Test template 1', content: 'Test 1'},
            {title: 'Test template 2', content: 'Test 2'}
    ],

    mode:                              "exact",
    elements:                          "%s",
    theme:                             "%s",
    %s
    %s
    theme_advanced_toolbar_location:   "top",
    theme_advanced_toolbar_align:      "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing:           true
    %s
  });
</script>
EOF
, $this->generateId($name), $this->getOption('theme'), $this->getOption('width') ? sprintf('width:                             "%spx",', $this->getOption('width')) : '', $this->getOption('height') ? sprintf('height:                            "%spx",', $this->getOption('height')) : '', $this->getOption('config') ? ",\n" . $this->getOption('config') : '');
        return $textarea . $js;
    }
  /**
   * @param  string $name        The element name
   * @param  string $value       The value selected in this widget
   * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
   * @param  array  $errors      An array of errors for the field
   *
   * @return string An HTML tag string
   *
   * @see sfWidgetForm
   */
  public function render($name, $value = null, $attributes = array(), $errors = array())
  {
    $textarea = parent::render($name, $value, $attributes, $errors);

		$generatedId = $this->generateId($name);
		$this->configurePlugins( $this->getOption('plugins') );

    $js = sprintf(<<< EOF

<script type="text/javascript">


function xinha_init_%s()
{
	var xinha_plugins = [ "%s" ];
	var xinha_editors = [ "%s" ];
  _editor_skin = "xp-blue";
  

  if(!Xinha.loadPlugins(xinha_plugins, xinha_init_%s)) return;

  var xinha_config = new Xinha.Config();
  %s
  %s
	xinha_config.formatblock={"- format -":"","Title":"h1","Subtitle":"h2","Chapter":"h3","Section":"h4","Heading 5":"h5","Heading 6":"h6",Normal:"p",Address:"address",Formatted:"pre",Code:"blockquote"};
  xinha_editors = Xinha.makeEditors(xinha_editors, xinha_config, xinha_plugins);
  Xinha.startEditors(xinha_editors);
}
Xinha.addOnloadHandler(xinha_init_%s);

</script>

EOF
    ,
      $generatedId,
      implode('", "', $this->getOption('plugins')),
      $generatedId,
      $generatedId,
      $this->_additionalConfig,
      $this->getOption('config'),
      $generatedId
    );

    return $textarea.$js;
  }
    /**
     * @param  string $name        The element name
     * @param  string $value       The value displayed in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @see sfWidget
     **/
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $id = $this->generateId($name, $value);
        $script_content = <<<JS
    //<![CDATA[
    \$(document).ready(function()\t{
      \$('#{$id}').markItUp(mySettings,
                    { \troot:'markupsets/markdown/',
                      previewTemplatePath:'/downloads/preview.php',
                      previewAutoRefresh:false
                    }
                  );

      });
    //]]>
JS;
        return parent::render($name, $value, $attributes, $errors) . $this->renderContentTag('script', $script_content, array('type' => 'text/javascript'));
    }
    /**
     *
     *
     * if we need to modify the editor someday..
     *
     * http://stackoverflow.com/questions/432036/help-with-tinymce-configuration-to-allow-font-tags
     *
     * @param  string $name        The element name
     * @param  string $value       The value selected in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @return string An HTML tag string
     *
     * @see sfWidgetForm
     */
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $textarea = parent::render($name, $value, $attributes, $errors);
        $js = sprintf(<<<EOF
<script type="text/javascript">
  tinyMCE.init({
    mode:                              "exact",
    elements:                          "%s",
    theme:                             "%s",
force_p_newlines : true,
    %s
    %s
    theme_advanced_toolbar_location:   "top",
    theme_advanced_toolbar_align:      "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing:           true
    %s
  });
</script>
EOF
, $this->generateId($name), $this->getOption('theme'), $this->getOption('width') ? sprintf('width:                             "%spx",', $this->getOption('width')) : '', $this->getOption('height') ? sprintf('height:                            "%spx",', $this->getOption('height')) : '', $this->getOption('config') ? ",\n" . $this->getOption('config') : '');
        return $textarea . $js;
    }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $response = sfContext::getInstance()->getResponse();
     $response->addJavascript('/sfExtraWidgetsPlugin/codepress/codepress.js');
     $this->addClass('codepress');
     $this->addClass($this->getOption('language'));
     if ($this->getOption('autocomplete')) {
         $this->addClass('autocomplete-on');
     } else {
         $this->addClass('autocomplete-off');
     }
     if ($this->getOption('readonly')) {
         $this->addClass('readonly-on');
     } else {
         $this->addClass('readonly-off');
     }
     if ($this->getOption('linenumbers')) {
         $this->addClass('linenumbers-on');
     } else {
         $this->addClass('linenumbers-off');
     }
     return parent::render($name, $value, $this->getAttributes(), $errors);
 }
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        //$textarea = parent::render($name, $value, $attributes, $errors);
        //La ligne ci-dessous est utilisée contrairement à celle au dessus pour
        //permettre l'utilisation du code tel que saisit par l'utilisateur ( htmlentities($value) )
        $textarea = parent::renderContentTag('textarea', htmlentities($value), array_merge(array('name' => $name), $attributes));
        $js = sprintf(<<<EOF
    <script type="text/javascript">
    \$(document).ready(function() {
        tinymce.init({
                selector: "textarea.tinyMceContent , textarea.tinyMceNoticeExpect ,textarea.tinyMceNoticeResult", 
                paste_data_images: true , 
                plugins: [
                    " example advlist autolink lists link image charmap print preview anchor",
                    "searchreplace visualblocks code fullscreen",
                    "insertdatetime media table  paste "
                ],   
                menu : { 
                    //edit: { title: 'Edit', items: 'undo redo  | cut copy paste selectall | searchreplace' },
                    insert: { title: 'Insert', items: 'link charmap' },
                    format: { title: 'Format', items: 'bold italic underline strikethrough superscript subscript | removeformat' },
                    table: { title: 'Table', items: 'inserttable tableprops deletetable | cell row column' }
                  },
                //menubar: "file edit format table view insert tools parameters",
                entity_encoding: "raw",
                toolbar: " undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent "
                
            });
    });
       

    </script>
EOF
, $this->generateId($name), $this->getOption('width') ? sprintf('width:                             "%spx",', $this->getOption('width')) : '', $this->getOption('height') ? sprintf('height:                            "%spx",', $this->getOption('height')) : '', $this->getOption('config') ? ",\n" . $this->getOption('config') : '');
        return $textarea . $js;
    }
    /**
     * @param  string $name        The element name
     * @param  string $value       The value selected in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @return string An HTML tag string
     *
     * @see sfWidgetForm
     */
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $textarea = parent::render($name, $value, $attributes, $errors);
        if (!isset($attributes['id'])) {
            $attributes['id'] = $this->generateId($name, isset($attributes['value']) ? $attributes['value'] : null);
        }
        $rand = rand();
        $id = $attributes['id'];
        $uri = sfContext::getInstance()->getController()->genUrl('@rt_search_ajax?sf_format=json');
        $uri_snippet = sfContext::getInstance()->getController()->genUrl('@rt_search_ajax?models=rtSnippet&sf_format=json');
        $textarea_id = $attributes['id'];
        $js = <<<EOF
<div id="rtLinkPanel{$rand}" class="rt-modal-panel {$id}-link rtLinkPanel"  title="Create a new link">

  <fieldset><legend>Build your own link to any URL</legend>
  <p class="inline-text-form-row inline-text-form-row-simple">
    [ <input type="text" name="linkText" id="linkText{$rand}" value="Your links text" /> ]
    ( <input type="text" name="linkUrl" id="linkUrl{$rand}" value="http://example.com/" /> )
    <button class="rtLinkPanelInsertButton">Insert Link</button>
  </p>
  </fieldset>
  <fieldset style="margin-bottom:none;"><legend>Or, find an existing page to link to</legend>
  <p class="inline-text-form-row"><strong>Enter search Terms:</strong>
      <input type="text" name="q" id="rtLinkPanelQuery{$rand}" value="" />
      <button type="submit" class="rtPanelSearchButton" id="rtLinkPanelId{$rand}">Search</button>
  </p>
  <ul id="rtLinkPanelResults{$rand}" class="inner-panel results-panel">&nbsp;</ul>
  </fieldset>
</div>

<div id="rtSnippetPanel{$rand}" class="rt-modal-panel {$id}-snippet rtSnippetPanel"  title="Create a snippet include">
  <fieldset style="margin-bottom:none;"><legend>Find a snippet to include in your content</legend>
  <p class="inline-text-form-row"><strong>Enter search Terms:</strong>
      <input type="text" name="q" id="rtSnippetPanelQuery{$rand}" value="" />
      <button type="submit" class="rtPanelSearchButton" id="rtSnippetPanelId{$rand}">Search</button>
  </p>
  <ul id="rtSnippetPanelResults{$rand}" class="inner-panel results-panel">&nbsp;</ul>
  </fieldset>
</div>

<script type="text/javascript">
  \$(document).ready(function() {

    \$('.rtLinkPanelInsertButton').button({
      icons: {
        primary: 'ui-icon-link'
      }
    });

    \$('.rtLinkPanelInsertButton').click(function(){
      \$.markItUp({openWith: '[',closeWith:']('+ \$("#linkUrl{$rand}").val() +')',placeHolder:''+ \$("#linkText{$rand}").attr('value') +'' });
      \$('.rt-modal-panel').dialog('close');
      return false;
    });

    \$('.rtPanelSearchButton').button({
      icons: {
        primary: 'ui-icon-search'
      }
    });

    enableLinkPanel(
      '#rtLinkPanelQuery{$rand}',
      '#rtLinkPanelId{$rand}',
      '#rtLinkPanelResults{$rand}',
      '{$uri}',
      '#{$id}'
    );

    enableLinkPanel(
      '#rtSnippetPanelQuery{$rand}',
      '#rtSnippetPanelId{$rand}',
      '#rtSnippetPanelResults{$rand}',
      '{$uri_snippet}',
      '#{$id}'
    );


\tvar config = {
\t    extraPlugins : 'placeholder',
\t\ttoolbar:
\t\t[
\t\t\t['Source','Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink'],
\t\t\t['Bold', 'CreatePlaceholder']
\t\t]
\t};

\tvar editor{$rand} = \$('#{$textarea_id}').ckeditor(config);

  CKEDITOR.instances['{$textarea_id}'].on('focus', function(e) {
    CKEDITOR.currentActive = '{$textarea_id}';
    //alert(currentActive);
  });

  \$('#testIt').click(function(){

    \$('#'+CKEDITOR.currentActive).ckeditorGet().openDialog('link', function(){

    alert('blah');

    \$(this).getContentElement('info', 'url').setValue('yourValue');

    });

    var dialog = CKEDITOR.dialog.getCurrent();

    CKEDITOR.dialog.getCurrent().getContentElement('info', 'url').setValue('yourValue');

    return false;
  });



  });
</script>

<span class="button" id="testIt">Bam</span>
EOF;
        return $js . $textarea;
    }
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $value = sfYaml::dump($value, 5);
     return parent::render($name, $value, $attributes, $errors);
 }
 /**
  * Constructor.
  *
  * @see sfWidgetFormTextarea
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
 }