@@ -23,7 +23,9 @@ class TinyMCEHelper extends AppHelper {
23
23
*
24
24
* @var array
25
25
*/
26
- public $ helpers = array ('Html ' );
26
+ public $ helpers = array (
27
+ 'Html '
28
+ );
27
29
28
30
/**
29
31
* Configuration
@@ -37,7 +39,10 @@ class TinyMCEHelper extends AppHelper {
37
39
*
38
40
* @var array
39
41
*/
40
- protected $ _defaults = array ();
42
+ protected $ _defaults = array (
43
+ 'script ' => '/TinyMCE/js/tiny_mce/tiny_mce.js ' ,
44
+ 'loadScript ' => true ,
45
+ );
41
46
42
47
/**
43
48
* Constructor
@@ -51,12 +56,14 @@ public function __construct(View $View, $settings = array()) {
51
56
if (!empty ($ configs ) && is_array ($ configs )) {
52
57
$ this ->configs = $ configs ;
53
58
}
59
+ $ this ->settings = array_merge ($ this ->_defaults , $ settings );
54
60
}
55
61
56
62
/**
57
63
* Adds a new editor to the script block in the head
58
64
*
59
65
* @see http://www.tinymce.com/wiki.php/Configuration for a list of keys
66
+ * @throws RuntimeException
60
67
* @param mixed If array camel cased TinyMCE Init config keys, if string it checks if a config with that name exists
61
68
* @return void
62
69
*/
@@ -65,7 +72,7 @@ public function editor($options = array()) {
65
72
if (isset ($ this ->configs [$ options ])) {
66
73
$ options = $ this ->configs [$ options ];
67
74
} else {
68
- throw new OutOfBoundsException (sprintf (__ ('Invalid TinyMCE configuration preset %s ' ), $ options ));
75
+ throw new RuntimeException (sprintf (__ ('Invalid TinyMCE configuration preset %s ' ), $ options ));
69
76
}
70
77
}
71
78
$ options = array_merge ($ this ->_defaults , $ options );
@@ -74,6 +81,7 @@ public function editor($options = array()) {
74
81
foreach ($ options as $ option => $ value ) {
75
82
$ lines .= Inflector::underscore ($ option ) . ' : " ' . $ value . '", ' . "\n" ;
76
83
}
84
+
77
85
// remove last comma from lines to avoid the editor breaking in Internet Explorer
78
86
$ lines = rtrim ($ lines );
79
87
$ lines = rtrim ($ lines , ', ' );
@@ -92,7 +100,9 @@ public function beforeRender($viewFile) {
92
100
if ($ appOptions !== false && is_array ($ appOptions )) {
93
101
$ this ->_defaults = $ appOptions ;
94
102
}
95
- $ this ->Html ->script ('/TinyMCE/js/tiny_mce/tiny_mce.js ' , array ('inline ' => false ));
103
+ if ($ this ->settings ['loadScript ' ] === true ) {
104
+ $ this ->Html ->script ($ this ->settings ['script ' ], array ('inline ' => false ));
105
+ }
96
106
}
97
107
98
108
}
0 commit comments