public function control_panel__add_to_foot() { if (URL::getCurrent(false) == '/publish') { $html = $this->js->link(array('fullscreen.js', 'redactor.min.js')); $options = $this->getConfig(); # Load image browser folder if (class_exists('Fieldtype_redactor') && method_exists('Fieldtype_redactor', 'get_field_settings')) { $field_settings = Fieldtype_redactor::get_field_settings(); if (isset($field_settings['image_dir'])) { $image_path = Path::tidy($field_settings['image_dir'] . '/'); $options['imageGetJson'] = Config::getSiteRoot() . "TRIGGER/redactor/fetch_images?path={$image_path}"; $options['imageUpload'] = Config::getSiteRoot() . "TRIGGER/redactor/upload?path={$image_path}"; } if (isset($field_settings['file_dir'])) { $file_path = Path::tidy($field_settings['file_dir'] . '/'); $options['fileUpload'] = Config::getSiteRoot() . "TRIGGER/redactor/upload?path={$file_path}"; } if (isset($field_settings['image_dir_append_slug'])) { $options['uploadFields'] = array('subfolder' => '#publish-slug'); } } $redactor_options = json_encode($options, JSON_FORCE_OBJECT); $html .= "<script>\n\n var redactor_options = {$redactor_options};\n\n \$(document).ready(\n function() {\n \$.extend(redactor_options, {'imageUploadErrorCallback': callback});\n \$('.redactor-container textarea').redactor(redactor_options);\n }\n\n );\n\n\n \$('body').on('addRow', '.grid', function() {\n \$.extend(redactor_options, {'imageUploadErrorCallback': callback});\n \$('.redactor-container textarea').redactor(redactor_options);\n });\n\n function callback(obj, json) {\n alert(json.error);\n }\n </script>"; return $html; } }
public function control_panel__add_to_foot() { if (URL::getCurrent(false) == '/publish') { $options = $this->getConfig(); // Load Redactor plugins and scripts $plugins = array_get($options, 'plugins', array()); $scripts = array(); foreach ($plugins as $key => $plugin) { $scripts[] = $plugin . '.js'; } $scripts[] = 'redactor.min.js'; $html = $this->js->link($scripts); // Load image browser folder if (class_exists('Fieldtype_redactor') && method_exists('Fieldtype_redactor', 'get_field_settings')) { $field_settings = Fieldtype_redactor::get_field_settings(); $field_config = array_get($field_settings, 'field_config', $field_settings); // Image uploads if (array_get($field_config, 'image_dir', false)) { $image_path = Path::tidy($field_config['image_dir'] . '/'); $resize_options = array_get($field_config, 'resize', array()); if (count($resize_options)) { $resize_options['resize'] = true; } $resize_options_string = http_build_query($resize_options); $options['imageGetJson'] = Config::getSiteRoot() . "TRIGGER/redactor/fetch_images?path={$image_path}"; $options['imageUpload'] = Config::getSiteRoot() . "TRIGGER/redactor/upload?path={$image_path}&{$resize_options_string}&is_image=true"; } // File uploads if (array_get($field_config, 'file_dir', false)) { $file_path = Path::tidy($field_config['file_dir'] . '/'); $options['fileUpload'] = Config::getSiteRoot() . "TRIGGER/redactor/upload?path={$file_path}"; } if (isset($field_config['image_dir_append_slug'])) { $options['uploadFields'] = array('subfolder' => '#publish-slug'); } } $redactor_options = json_encode($options, true); // Initialization $html .= "<script>\n\n var redactor_options = {$redactor_options};\n\n \$(document).ready(function() {\n \n \$.extend(redactor_options, {'imageUploadErrorCallback': function(json) {\n alert(json.error);\n }});\n\n\n \$('.redactor-container textarea').redactor(redactor_options);\n });\n\n\n \$('body').on('addRow', '.grid', function() {\n \$.extend(redactor_options, {'imageUploadErrorCallback': callback});\n \$('.redactor-container textarea').redactor(redactor_options);\n });\n\n function callback(obj, json) {\n alert(json.error);\n }\n </script>"; return $html; } }
function render() { self::$field_settings = $this->field_config; $html = "<div class='redactor-container'><textarea name='{$this->fieldname}' tabindex='{$this->tabindex}'>{$this->field_data}</textarea></div>"; return $html; }