diff --git a/editors/css/wymeditor.css b/editors/css/wymeditor.css new file mode 100644 index 0000000..ea86604 --- /dev/null +++ b/editors/css/wymeditor.css @@ -0,0 +1,6 @@ +.wym_skin_compact .wym_dropdown ul { + margin-top: 0; +} +.wym_skin_compact .wym_iframe iframe { + height: 400px !important; +} diff --git a/editors/js/wymeditor-1.js b/editors/js/wymeditor-1.js new file mode 100644 index 0000000..369e415 --- /dev/null +++ b/editors/js/wymeditor-1.js @@ -0,0 +1,63 @@ +(function($) { + +/** + * Attach this editor to a target element. + */ +Drupal.wysiwyg.editor.attach.wymeditor = function (context, params, settings) { + // Prepend basePath to wymPath. + settings.wymPath = settings.basePath + settings.wymPath; + settings.postInit = function (instance) { + var $doc = $(instance._doc); + // Inject stylesheet for backwards compatibility. + if (settings.stylesheet) { + $doc.find('head').append(''); + } + // Update activeId on focus. + $doc.find('body').focus(function () { + Drupal.wysiwyg.activeId = params.field; + }); + }; + // Attach editor. + $('#' + params.field).wymeditor(settings); +}; + +/** + * Detach a single editor instance. + */ +Drupal.wysiwyg.editor.detach.wymeditor = function (context, params, trigger) { + var $field = $('#' + params.field, context); + var index = $field.data(WYMeditor.WYM_INDEX); + if (typeof index == 'undefined' || !WYMeditor.INSTANCES[index]) { + return; + } + var instance = WYMeditor.INSTANCES[index]; + instance.update(); + if (trigger != 'serialize') { + instance.vanish(); + } +}; + +Drupal.wysiwyg.editor.instance.wymeditor = { + insert: function (content) { + this.getInstance().insert(content); + }, + + setContent: function (content) { + this.getInstance().html(content); + }, + + getContent: function () { + return this.getInstance().html(); + }, + + getInstance: function () { + var $field = $('#' + this.field); + var index = $field.data(WYMeditor.WYM_INDEX); + if (typeof index != 'undefined') { + return WYMeditor.INSTANCES[index]; + } + return null; + } +}; + +})(jQuery); diff --git a/editors/js/wymeditor.js b/editors/js/wymeditor.js index db4f570..6c195dd 100644 --- a/editors/js/wymeditor.js +++ b/editors/js/wymeditor.js @@ -8,7 +8,7 @@ Drupal.wysiwyg.editor.attach.wymeditor = function (context, params, settings) { settings.wymPath = settings.basePath + settings.wymPath; // Update activeId on focus. settings.postInit = function (instance) { - $(instance._doc).focus(function () { + $(instance._doc).find('body').focus(function () { Drupal.wysiwyg.activeId = params.field; }); }; @@ -26,11 +26,17 @@ Drupal.wysiwyg.editor.detach.wymeditor = function (context, params, trigger) { return; } var instance = WYMeditor.INSTANCES[index]; + var i; instance.update(); if (trigger != 'serialize') { $(instance._box).remove(); $(instance._element).show(); - delete WYMeditor.INSTANCES[index]; + $field.removeData(WYMeditor.WYM_INDEX); + WYMeditor.INSTANCES.splice(index, 1); + // Reindex the editors to maintain internal state.. + for (i = 0; i < WYMeditor.INSTANCES.length; i++) { + WYMeditor.INSTANCES[i]._index = i; + } $field.show(); } }; diff --git a/editors/wymeditor.inc b/editors/wymeditor.inc index af1917f..0e180cb 100644 --- a/editors/wymeditor.inc +++ b/editors/wymeditor.inc @@ -11,24 +11,20 @@ function wysiwyg_wymeditor_editor() { $editor['wymeditor'] = array( 'title' => 'WYMeditor', - 'vendor url' => 'http://www.wymeditor.org/', - 'download url' => 'http://www.wymeditor.org/download/', - 'library path' => wysiwyg_get_path('wymeditor') . '/wymeditor', + 'vendor url' => 'http://wymeditor.github.io/wymeditor/', + 'download url' => 'https://github.com/wymeditor/wymeditor/releases', + 'library path' => wysiwyg_get_path('wymeditor'), 'libraries' => array( 'min' => array( 'title' => 'Minified', 'files' => array('jquery.wymeditor.min.js'), ), - 'pack' => array( - 'title' => 'Packed', - 'files' => array('jquery.wymeditor.pack.js'), - ), 'src' => array( 'title' => 'Source', 'files' => array('jquery.wymeditor.js'), ), ), - 'verified version range' => array('0.5', '1.0.0b5'), + 'verified version range' => array('0.5', '1.1.1'), 'version callback' => 'wysiwyg_wymeditor_version', 'themes callback' => 'wysiwyg_wymeditor_themes', 'settings form callback' => 'wysiwyg_wymeditor_settings_form', @@ -36,8 +32,18 @@ function wysiwyg_wymeditor_editor() { 'plugin callback' => '_wysiwyg_wymeditor_plugins', 'versions' => array( '0.5-rc1' => array( + 'library path' => wysiwyg_get_path('wymeditor') . '/wymeditor', 'js files' => array('wymeditor.js'), ), + '1.0.0a1' => array( + 'library path' => wysiwyg_get_path('wymeditor') . '/wymeditor', + 'js files' => array('wymeditor-1.js'), + 'css files' => array('wymeditor.css'), + ), + '1.0.0b5' => array( + 'js files' => array('wymeditor-1.js'), + 'css files' => array('wymeditor.css'), + ), ), ); return $editor; @@ -53,16 +59,23 @@ function wysiwyg_wymeditor_editor() { * The installed editor version. */ function wysiwyg_wymeditor_version($editor) { - $script = $editor['library path'] . '/jquery.wymeditor.js'; + $script = $editor['library path'] . '/wymeditor/jquery.wymeditor.js'; + if (!file_exists($script)) { + $script = $editor['library path'] . '/jquery.wymeditor.js'; + if (!file_exists($script)) { + return; + } + } if (!file_exists($script)) { return; } $script = fopen($script, 'r'); - fgets($script); - $line = fgets($script); - if (preg_match('@version\s+([0-9a-z\.-]+)@', $line, $version)) { - fclose($script); - return $version[1]; + for ($i = 0; $i < 189; $i++) { + $line = fgets($script); + if (preg_match('@version\s+([0-9\.]+(?:-?[a-z0-9\.]+)?[^\.])@', $line, $version)) { + fclose($script); + return $version[1]; + } } fclose($script); } @@ -127,8 +140,6 @@ function wysiwyg_wymeditor_settings($editor, $config, $theme) { $settings = array( 'basePath' => base_path() . $editor['library path'] . '/', 'wymPath' => $editor['libraries'][$library]['files'][0], - // @todo Does not work in Drupal; jQuery can live anywhere. - 'jQueryPath' => base_path() . 'misc/jquery.js', // WYMeditor's update event handler will revert the field contents if // changes were made after it was detached. Wysiwyg takes care of submit // events anyway so make sure WYMeditor does not bind it anywhere. @@ -136,6 +147,13 @@ function wysiwyg_wymeditor_settings($editor, $config, $theme) { 'updateEvent' => 'wysiwyg-no-event', 'skin' => $theme, ); + if (version_compare($editor['installed version'], '1.0.0-b5', '>=')) { + drupal_add_css(wysiwyg_get_path('wymeditor') . '/skins/' . $settings['skin'] . '/skin.css'); + } + else { + // @todo Does not work in Drupal; jQuery can live anywhere. + $settings['jQueryPath'] = base_path() . 'misc/jquery.js'; + } if (isset($config['language'])) { $settings['lang'] = $config['language']; @@ -144,7 +162,7 @@ function wysiwyg_wymeditor_settings($editor, $config, $theme) { // Add configured buttons. $settings['toolsItems'] = array(); if (!empty($config['buttons'])) { - $buttoninfo = _wysiwyg_wymeditor_button_info(); + $buttoninfo = _wysiwyg_wymeditor_button_info($editor['installed version']); $plugins = wysiwyg_get_plugins($editor['name']); foreach ($config['buttons'] as $plugin => $buttons) { foreach ($buttons as $button => $enabled) { @@ -246,8 +264,8 @@ function _wysiwyg_wymeditor_plugins($editor) { /** * Helper function to provide additional meta-data for internal default buttons. */ -function _wysiwyg_wymeditor_button_info() { - return array( +function _wysiwyg_wymeditor_button_info($version) { + $info = array( 'Bold' => array('title' => 'Strong', 'css' => 'wym_tools_strong'), 'Italic' => array('title' => 'Emphasis', 'css' => 'wym_tools_emphasis'), 'Superscript' => array('title' => 'Superscript', 'css' => 'wym_tools_superscript'), @@ -266,4 +284,10 @@ function _wysiwyg_wymeditor_button_info() { 'ToggleHtml' => array('title' => 'HTML', 'css' => 'wym_tools_html'), 'Preview' => array('title' => 'Preview', 'css' => 'wym_tools_preview'), ); + if (version_compare($version, '1.0.0-rc2', '>=')) { + foreach (array('CreateLink', 'InsertImage', 'InsertTable', 'Paste', 'Preview') as $button) { + $info[$button]['css'] .= ' wym_opens_dialog'; + } + } + return $info; }