return false;
});
});
+
+ // html
+ function ipf_filebrowser(filebrowser_url, field_name, url, type, win) {
+ tinyMCE.activeEditor.windowManager.open({
+ file: filebrowser_url,
+ title: "IPF File Browser",
+ width: 800,
+ height: 600,
+ resizable: "yes",
+ inline: "yes",
+ close_previous: "no"
+ }, {
+ onSelect: function(value) {
+ var input = win.document.getElementById(field_name);
+
+ input.value = value;
+ if ("createEvent" in document) {
+ var evt = document.createEvent("HTMLEvents");
+ evt.initEvent("change", false, true);
+ input.dispatchEvent(evt);
+ } else {
+ input.fireEvent("onchange");
+ }
+ }
+ });
+ return false;
+ }
+
+ var tinyMCEDefaults = {
+ plugins: "anchor, charmap, code, colorpicker, contextmenu, fullscreen, hr, image, insertdatetime, link, lists, media, nonbreaking, paste, preview, print, searchreplace, tabfocus, table, textcolor, visualchars, wordcount",
+ toolbar: [
+ "undo redo | styleselect | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | forecolor backcolor sub sup | preview fullscreen",
+ "code link unlink image charmap | table | pastetext removeformat | formatselect fontselect fontsizeselect"
+ ],
+ extended_valid_elements: "span[class|style],code[class],iframe[src|width|height|name|align|frameborder|scrolling]",
+ fix_list_elements: true,
+ browser_spellcheck: true,
+ width: "80%",
+ height: "300",
+ document_base_url: "/",
+
+ convert_urls: false,
+ relative_urls: false,
+ remove_script_host: true
+ };
+
+ $('.htmlEditor').each(function(){
+ var filebrowser_url = $(this).data('filebrowser');
+ tinyMCE.init($.extend({}, tinyMCEDefaults, $(this).data('config'), {
+ target: this,
+ file_browser_callback: ipf_filebrowser.bind(null, filebrowser_url)
+ }));
+ });
});
public $tinymce_url;
public $force_absolute_urls;
public $editor_config;
+ public $filebrowser_url;
public function __construct($attrs=array())
{
$this->force_absolute_urls = \PFF\Arr::pop($attrs, 'force_absolute_urls', false);
$this->editor_config = \PFF\Arr::pop($attrs, 'editor_config', array());
+ $this->filebrowser_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_FileBrowser', array('/')).'/';
+
parent::__construct($attrs);
}
{
if ($value === null) $value = '';
- $extra_config = '';
- foreach ($this->editor_config as $key => $val) {
- $extra_config .= ",\n{$key} : ";
- if (is_bool($val)) {
- $extra_config .= $val ? 'true' : 'false';
- } else {
- $extra_config .= '"'.$val.'"';
- }
+ $config = $this->editor_config;
+ if ($this->force_absolute_urls) {
+ $config['convert_urls'] = true;
+ $config['relative_urls'] = false;
+ $config['remove_script_host'] = false;
}
return Tag::textarea()
->attrs($this->attrs)
->attrs($extra_attrs)
->attr('name', $name)
- ->addClass($this->force_absolute_urls ? 'htmlEditorAbs' : 'htmlEditor')
+ ->attr('data-config', json_encode($config))
+ ->attr('data-filebrowser', $this->filebrowser_url)
+ ->addClass('htmlEditor')
->append($value)
->html();
}
-
- public function extra_js()
- {
- $filebrowser_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_FileBrowser', array('/'));
- return array(
- '<script type="text/javascript" src="'.$this->tinymce_url.'tinymce.min.js"></script>',
- '<script type="text/javascript">(function(){
-function ipf_filebrowser(field_name, url, type, win) {
- tinyMCE.activeEditor.windowManager.open({
- file: "'.$filebrowser_url.'/",
- title: "IPF File Browser",
- width: 800,
- height: 600,
- resizable: "yes",
- inline: "yes",
- close_previous: "no"
- }, {
- onSelect: function(value) {
- var input = win.document.getElementById(field_name);
-
- input.value = value;
- if ("createEvent" in document) {
- var evt = document.createEvent("HTMLEvents");
- evt.initEvent("change", false, true);
- input.dispatchEvent(evt);
- } else {
- input.fireEvent("onchange");
- }
- }
- });
- return false;
-}
-
-var defaults = {
- plugins: "anchor, charmap, code, colorpicker, contextmenu, fullscreen, hr, image, insertdatetime, link, lists, media, nonbreaking, paste, preview, print, searchreplace, tabfocus, table, textcolor, visualchars, wordcount",
- toolbar: [
- "undo redo | styleselect | bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | forecolor backcolor sub sup | preview fullscreen",
- "code link unlink image charmap | table | pastetext removeformat | formatselect fontselect fontsizeselect"
- ],
- extended_valid_elements: "span[class|style],code[class],iframe[src|width|height|name|align|frameborder|scrolling]",
- fix_list_elements: true,
- browser_spellcheck: true,
- width: "80%",
- height: "300",
- document_base_url: "/",
- file_browser_callback: ipf_filebrowser
-};
-
-tinyMCE.init($.extend({}, defaults, {
- selector: ".htmlEditor",
- convert_urls: false,
- relative_urls: false,
- remove_script_host: true
-}));
-
-tinyMCE.init($.extend({}, defaults, {
- selector: ".htmlEditorAbs",
- convert_urls: true,
- relative_urls: false,
- remove_script_host: false
-}));
-
-})();</script>',
- );
- }
}