⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Add a custom wysiwyg editor.



mrtakdnz

mrtakdnz
  • profile picture
  • Member

Posted 06 April 2013 - 15:30 PM

Hi, i want to add a custom text editor (which is very useful for me, actually my clients!) easy and built in uploader (or something like that) (which name is Redactor)

How can i add this html editor to my GC. Or is it possible to add new version of GC?

 

I try to find an easy way to add this but probably updating the GC will broke up all the things.

 

http://imperavi.com/redactor/

 

Thanks in advance.


davidoster

davidoster
  • profile picture
  • Member

Posted 06 April 2013 - 18:28 PM

Well there isn't a straight forward answer to this because in order to use another editor than the default ones (ckeditor, markitup, tinymce) you need to hack the GC library itself!

Specifically, under class grocery_CRUD_Layout there is a protected function that is called 

protected function get_text_input($field_info,$value)

 

If you feel confident enough you might have a go and include your favourite text editor same as the other ones that are defined there.

Just follow the paradigm of the others, copy the appropriate files under assets/grocery_crud/texteditor and good luck!


Zalo

Zalo
  • profile picture
  • Member

Posted 06 April 2013 - 19:09 PM

I've got another idea...

It's FAR from optimal, but it's a more or less easy way to solve the issue. (Ok, let's be clear, this solution is worthy of a Lord of the Rings Orc, but it should work non the less)

You MAY be able to use the default included editors to your advantage with a few steps:

 

1) You load custom js.

2) You let ckeeditor load.

3) On your custom js you unset each ckeditor (cke class) and get the textarea on that same field-box.

4) On your custom js you set your own editor for each of the textareas you got in the previous step.

 

Again, it's far from an optimal solution (loads lots of unused things...), but it lets you implement your editor relatively easy. Also, depending on the server and clients speed, you may want to hide the ckeditors and the textareas until your editor is loaded. 

 

The RIGHT way of doing it would be what david said and it's what I would recommend if you use that editor all the time, but if it is for just one site you may want to skip the trouble of editing the library and making any update more complicated. 

 

Hope it helped!


nullart

nullart
  • profile picture
  • Member

Posted 24 June 2013 - 10:05 AM

This method only adds the editor to grocerycrud, no minified or full version. Only one function in the library is modified. Why? It's easier to track. 

 

So far theres no easier way but to modify the library/Grocery_CRUD.php. Hope someone could provide a better way.

 

 

1. Copy redactor files (css, js) to /assets/grocery_crud/texteditor. create a "redactor" folder.

 

2. In library/Grocery_CRUD.php look the function below (maybe line 2146)

protected function get_text_input($field_info,$value)

3. Add this code before each "break" statement. This is to ensure the other wysiwig doesnt break if you want to use them again.

$input = "<textarea id='field-{$field_info->name}' name='{$field_info->name}' class='$class_name' >$value</textarea>";

4. comment the same above code found after the "switch" statement. 

 

5. Add these lines in the "switch" statement.

case 'redactor':
$this->set_css($this->default_texteditor_path.'/redactor/redactor.css');
$this->set_js($this->default_texteditor_path.'/redactor/redactor.js');

$input = "<textarea id='field-{$field_info->name}' class='redactor' name='{$field_info->name}' >$value</textarea>";
break;

6. Change the text editor in grocery crud's config file to "redactor".

 

 

Cheers!