Completed
Push — master ( 7146f9...4447ca )
by Julito
09:33
created

TinyMce::setJavascriptToInclude()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Component\Editor\TinyMce;
5
6
use Chamilo\CoreBundle\Component\Editor\Editor;
7
8
/**
9
 * Class TinyMce.
10
 *
11
 * @package Chamilo\CoreBundle\Component\Editor\TinyMce
12
 */
13
class TinyMce extends Editor
14
{
15
    /**
16
     * Return the HTML code required to run editor.
17
     *
18
     * @return string
19
     */
20
    public function createHtml()
21
    {
22
        $html = '<textarea id="'.$this->name.'" name="'.$this->name.'" class="ckeditor" >'.$this->value.'</textarea>';
23
        $html .= $this->editorReplace();
24
25
        return $html;
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    public function editorReplace()
32
    {
33
        $toolbar = new Toolbar\Basic($this->urlGenerator, $this->toolbarSet, $this->config, 'TinyMce');
34
        $toolbar->setLanguage($this->getLocale());
35
        $config = $toolbar->getConfig();
36
        $config['selector'] = "#".$this->name;
37
        $javascript = $this->toJavascript($config);
38
        $javascript = str_replace('"elFinderBrowser"', "elFinderBrowser", $javascript);
39
40
        $html = "<script>
41
            function elFinderBrowser (field_name, url, type, win) {
42
                tinymce.activeEditor.windowManager.open({
43
                    file: '".$this->urlGenerator->generate('filemanager')."',
44
                    title: 'elFinder 2.0',
45
                    width: 900,
46
                    height: 450,
47
                    resizable: 'yes'
48
                    }, {
49
                    setUrl: function (url) {
50
                        win.document.getElementById(field_name).value = url;
51
                    }
52
                });
53
                return false;
54
            }
55
56
            $(document).ready(function() {
57
                tinymce.init(
58
                    $javascript
59
                 );
60
             });
61
        </script>";
62
63
        return $html;
64
    }
65
}
66