diff --git a/editors/epiceditor.inc b/editors/epiceditor.inc new file mode 100755 index 0000000..3c62f48 --- /dev/null +++ b/editors/epiceditor.inc @@ -0,0 +1,161 @@ + 'EpicEditor', + 'vendor url' => 'http://oscargodson.github.com/EpicEditor', + 'download url' => 'http://oscargodson.github.com/EpicEditor/docs/downloads/EpicEditor-v0.1.1.zip', + 'library path' => wysiwyg_get_path('epiceditor') . '', + 'libraries' => array( + '' => array( + 'title' => 'Minified', + 'files' => array('js/epiceditor.min.js'), + ), + 'src' => array( + 'title' => 'Default', + 'files' => array('js/epiceditor.js'), + ), + ), + 'version callback' => 'wysiwyg_epiceditor_version', + 'themes callback' => 'wysiwyg_epiceditor_themes', + 'settings callback' => 'wysiwyg_epiceditor_settings', + 'plugin callback' => 'wysiwyg_epiceditor_plugins', + 'plugin settings callback' => 'wysiwyg_epiceditor_plugin_settings', + 'proxy plugin' => array( + 'drupal' => array( + 'load' => TRUE, + 'proxy' => TRUE, + ), + ), + 'proxy plugin settings callback' => 'wysiwyg_epiceditor_proxy_plugin_settings', + 'versions' => array( + '0.1.1' => array( + 'js files' => array('epiceditor-0.0.1.js'), + 'download url' => 'http://oscargodson.github.com/EpicEditor/docs/downloads/EpicEditor-v0.1.1.zip', + ), + ), + ); + return $editor; +} + +/** + * Detect editor version. + * + * @param $editor + * An array containing editor properties as returned from hook_editor(). + * + * @return + * The installed editor version. + */ +function wysiwyg_epiceditor_version($editor) { + $library = $editor['library path'] . '/js/epiceditor.js'; + if (!file_exists($library)) { + return; + } + $library = file_get_contents($library, 'r'); + $version = preg_match('%EpicEditor\.version = \'(.*)\'\;%', $library, $matches); + if(!isset($matches[1])) { + return; + } + return $matches[1]; +} + +/** + * Determine available editor themes or check/reset a given one. + * + * @param $editor + * A processed hook_editor() array of editor properties. + * @param $profile + * A wysiwyg editor profile. + * + * @return + * An array of theme names. The first returned name should be the default + * theme name. + */ +function wysiwyg_epiceditor_themes($editor, $profile) { + // there are themes both for the preview mode and the editor mode. I + // decidet to put the editor themes here. + + // @TODO: add some code to determine the avalible themes + return array('epic-dark', 'epic-light'); +} + +/** + * Determine available editor preview themes or check/reset a given one. + * + * @param $editor + * A processed hook_editor() array of editor properties. + * @param $profile + * A wysiwyg editor profile. + * + * @return + * An array of theme names. The first returned name should be the default + * theme name. + */ +function wysiwyg_epiceditor_preview_themes($editor, $profile) { + // @TODO: add some code to determine the avalible preview themes + return array('preview-dark', 'github'); +} + +/** + * Return runtime editor settings for a given wysiwyg profile. + * + * @param $editor + * A processed hook_editor() array of editor properties. + * @param $config + * An array containing wysiwyg editor profile settings. + * @param $theme + * The name of a theme/GUI/skin to use. + * + * @return + * A settings array to be populated in + * Drupal.settings.wysiwyg.configs.{editor} + */ +function wysiwyg_epiceditor_settings($editor, $config, $theme) { + $settings = array( + 'baseHref' => $GLOBALS['base_root'], + 'client_side_storage' => FALSE, + 'mode' => 'none', + 'theme' => $theme, + 'preview_theme' => wysiwyg_epiceditor_preview_themes($editor, $config), + 'shortcuts' => array( + 'modifier' => 18, // alt key + 'fullscreen' => 70, // f key + 'preview' => 80, // p key + 'edit' => 79, // o key + ), + ); + + return $settings; +} + +/** + * Build a JS settings array of native external plugins that need to be loaded separately. + */ +function wysiwyg_epiceditor_plugin_settings($editor, $profile, $plugins) { + // I don't really know what to put here. There are no plugins yet. +} + +/** + * Build a JS settings array for Drupal plugins loaded via the proxy plugin. + */ +function wysiwyg_epiceditor_proxy_plugin_settings($editor, $profile, $plugins) { + // See wysiwyg_epiceditor_plugin_settings(); +} + +/** + * Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin(). + */ +function wysiwyg_epiceditor_plugins($editor) { + return array(); +} + diff --git a/editors/js/epiceditor-0.0.1.js b/editors/js/epiceditor-0.0.1.js new file mode 100755 index 0000000..0412329 --- /dev/null +++ b/editors/js/epiceditor-0.0.1.js @@ -0,0 +1,52 @@ +(function($) { + + Drupal.wysiwyg.editor.init.epiceditor = function(settings) { + Drupal.wysiwyg.editor.instance.epiceditor = []; + }; + + Drupal.wysiwyg.editor.attach.epiceditor = function (context, params, settings) { + var config = Drupal.settings.wysiwyg.configs.epiceditor; + var fieldId = params.field; + var containerId = fieldId + '-epiceditor'; + var editorBaseDir = config.formatepiceditor.baseHref + config.global.editorBasePath; + var theme = config.formatepiceditor.theme; + + var target = $('#' + fieldId); + var defaultContent = target.val(); + + target.hide().after('
'); + + var opts = { + container: containerId, + basePath: editorBaseDir, + clientSideStorage: false, + localStorageName: 'epiceditor', + parser: marked, + file: { + name: 'epiceditor', + defaultContent: defaultContent, + autoSave: 100 + }, + theme: { + base: '/themes/base/epiceditor.css', + preview: '/themes/preview/preview-dark.css', + editor: '/themes/editor/' + theme + '.css' + }, + } + + Drupal.wysiwyg.editor.instance.epiceditor[fieldId] = new EpicEditor(opts); + Drupal.wysiwyg.editor.instance.epiceditor[fieldId].load(); + }; + + Drupal.wysiwyg.editor.detach.epiceditor = function (context, params, trigger) { + var fieldId = params.field; + var target = $('#' + fieldId); + var containerId = fieldId + '-epiceditor'; + var content = Drupal.wysiwyg.editor.instance.epiceditor[fieldId].exportFile('epiceditor'); + Drupal.wysiwyg.editor.instance.epiceditor[fieldId].unload(function() { + target.show().val(content); + }); + + }; + +})(jQuery);