diff --git a/ckeditor.api.php b/ckeditor.api.php index 806ae93..8425749 100644 --- a/ckeditor.api.php +++ b/ckeditor.api.php @@ -45,10 +45,10 @@ function hook_ckeditor_plugin() { // Description of the plugin - it would be displayed in the plugins management section of profile settings. 'desc' => t('Plugin description'), // The full path to the CKEditor plugins directory, with the trailing slash. - 'path' => drupal_get_path('module', 'my_module') . '/plugin_dir/', + 'path' => '/' . drupal_get_path('module', 'my_module') . '/plugin_dir/', 'buttons' => array( 'button_name' => array( - 'icon' => 'path to button icon', + 'icon' => 'icon/plugin_name.png', 'label' => 'Button Label', ) ) @@ -57,6 +57,17 @@ function hook_ckeditor_plugin() { } /** + * Hook to extend/change CKEditor plugins. + * + * @param $plugins + * An associative array of plugins. + */ +function hook_ckeditor_plugin_alter(&$plugins) { + // Remove a plugin button. + unset($plugins['plugin_name']['buttons']['button']); +} + +/** * Hook to register the CKEditor security filter - it would appear in the security filters list on the profile setting page. */ function hook_ckeditor_security_filter() { diff --git a/ckeditor.ckeditor.inc b/ckeditor.ckeditor.inc new file mode 100644 index 0000000..5e049fd --- /dev/null +++ b/ckeditor.ckeditor.inc @@ -0,0 +1,212 @@ +') { + if (file_exists($_editor_path . '/plugins/tableresize/plugin.js')) { + $plugins['tableresize'] = array( + 'name' => 'tableresize', + 'desc' => t('Table Resize plugin'), + 'path' => $editor_path . '/plugins/tableresize/', + 'buttons' => FALSE, + 'default' => 't' + ); + } + + if (file_exists($_editor_path . '/plugins/autogrow/plugin.js')) { + $plugins['autogrow'] = array( + 'name' => 'autogrow', + 'desc' => t('Auto Grow plugin'), + 'path' => $editor_path . '/plugins/autogrow/', + 'buttons' => FALSE, + 'default' => 'f' + ); + } + + if (file_exists($_editor_path . '/plugins/stylesheetparser/plugin.js')) { + $plugins['stylesheetparser'] = array( + 'name' => 'stylesheetparser', + 'desc' => t('Stylesheet Parser plugin'), + 'path' => $editor_path . '/plugins/stylesheetparser/', + 'buttons' => FALSE, + 'default' => 'f' + ); + } + } + else { + $_editor_url = ckeditor_path('url'); + if (preg_match("/\/(standard|full)-all/", $_editor_url)) { + $plugins['tableresize'] = array( + 'name' => 'tableresize', + 'desc' => t('Table Resize plugin'), + 'path' => $_editor_url . '/plugins/tableresize/', + 'buttons' => FALSE, + 'default' => 't' + ); + $plugins['autogrow'] = array( + 'name' => 'autogrow', + 'desc' => t('Auto Grow plugin'), + 'path' => $_editor_url . '/plugins/autogrow/', + 'buttons' => FALSE, + 'default' => 'f' + ); + $plugins['stylesheetparser'] = array( + 'name' => 'stylesheetparser', + 'desc' => t('Stylesheet Parser plugin'), + 'path' => $_editor_url . '/plugins/stylesheetparser/', + 'buttons' => FALSE, + 'default' => 'f' + ); + } + } + + /* + * CKEditor module plugins + */ + $_plugin_dir = ckeditor_module_path('local') . '/plugins/'; + if ($handle = opendir($_plugin_dir)) { + while (false !== ($file = readdir($handle))) { + if (is_dir($_plugin_dir . $file) && file_exists($_plugin_dir . $file . '/plugin.js')) { + $source = file_get_contents($_plugin_dir . $file . '/plugin.js'); + $buttons = array(); + if (preg_match_all($pattern, $source, $matches)) { + foreach ($matches[1] as $i => $button_name) { + if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$i], $matches2)) { + $buttons[$button_name] = array(); + $buttons[$button_name]['label'] = $button_name; + $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]); + $buttons[$button_name]['icon'] = trim($matches2[2]); + } + } + } + if (preg_match('#@file ([^\n\r]*)#', $source, $matches)) { + $plugins[$file] = array( + 'name' => $file, + 'desc' => t($matches[1]), + 'path' => $plugin_dir . $file . '/', + 'buttons' => (count($buttons) > 0) ? $buttons : FALSE, + 'default' => 'f' + ); + } + else { + $plugins[$file] = array( + 'name' => $file, + 'desc' => t('Plugin file: ' . $file), + 'path' => $plugin_dir . $file . '/', + 'buttons' => (count($buttons) > 0) ? $buttons : FALSE, + 'default' => 'f' + ); + } + } + } + closedir($handle); + } + + /* + * CKEditor module plugins - additional directory + */ + $_plugin_dir_additional = ckeditor_plugins_path('local') . '/'; + if ($_plugin_dir != $_plugin_dir_additional && is_dir($_plugin_dir_additional) && $handle = opendir($_plugin_dir_additional)) { + while (false !== ($file = readdir($handle))) { + if (is_dir($_plugin_dir_additional . $file) && file_exists($_plugin_dir_additional . $file . '/plugin.js')) { + $source = file_get_contents($_plugin_dir_additional . $file . '/plugin.js'); + $buttons = array(); + if (preg_match_all($pattern, $source, $matches)) { + foreach ($matches[1] as $i => $button_name) { + if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$i], $matches2)) { + $buttons[$button_name] = array(); + $buttons[$button_name]['label'] = $button_name; + $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]); + $buttons[$button_name]['icon'] = trim($matches2[2]); + } + } + } + if (preg_match('#@file ([^\n\r]*)#', $source, $matches)) { + $plugins[$file] = array( + 'name' => $file, + 'desc' => t($matches[1]), + 'path' => $plugin_dir_additional . $file . '/', + 'buttons' => (count($buttons) > 0) ? $buttons : FALSE, + 'default' => 'f' + ); + } + else { + $plugins[$file] = array( + 'name' => $file, + 'desc' => t('Plugin file: ' . $file), + 'path' => $plugin_dir_additional . $file . '/', + 'buttons' => (count($buttons) > 0) ? $buttons : FALSE, + 'default' => 'f' + ); + } + } + } + + closedir($handle); + } + + return $plugins; +} + +/** + * Implements hook_ckeditor_plugin_alter(). + */ +function ckeditor_ckeditor_plugin_alter(&$plugins) { + if (isset($plugins['media']) && module_exists('media') == FALSE) { + unset($plugins['media']); + } + + if (isset($plugins['imce']) && module_exists('imce') == FALSE) { + unset($plugins['imce']); + } + //remove page break button if there is no module to do this + if (isset($plugins['drupalbreaks']['buttons']['DrupalPageBreak']) && !module_exists('paging') && !module_exists('pagebreak')) { + unset($plugins['drupalbreaks']['buttons']['DrupalPageBreak']); + } + + if (isset($plugins['drupalbreaks'])) { + $plugins['drupalbreaks']['default'] = 't'; + } + + /* + * External plugins - complete hook info and adjust path + * Workaround, until modules have adapted their hook implementations. + * @see https://www.drupal.org/node/2159403#comment-9019373 + * @see https://www.drupal.org/node/2217579 + */ + $base_path = '%base_path%'; + + if (isset($plugins['ckeditor_swf'])) { + $plugins['ckeditor_swf']['default'] = 't'; + $plugins['ckeditor_swf']['path'] = '%base_path%' . $plugins['ckeditor_swf']['path']; + } + + if (isset($plugins['ckeditor_link'])) { + $plugins['ckeditor_link']['default'] = 't'; + $plugins['ckeditor_link']['path'] = '%base_path%' . $plugins['ckeditor_link']['path']; + } + + if (isset($plugins['linkit'])) { + $plugins['linkit']['default'] = 't'; + $plugins['linkit']['path'] = '%base_path%' . $plugins['linkit']['path']; + } +} diff --git a/ckeditor.install b/ckeditor.install index 4c8447b..2c401dc 100644 --- a/ckeditor.install +++ b/ckeditor.install @@ -583,6 +583,39 @@ function ckeditor_update_7005() { } /** + * Move support for the Media module to media_wysiwyg. + */ +function ckeditor_update_7006() { + module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib'); + + $available_plugins = ckeditor_load_plugins(); + $profiles = ckeditor_profile_load(); + + // Media wysiwyg now supplies the media plugin, as it has been removed from + // CKeditor. + $media_wysiwyg_enabled = isset($available_plugins['media']); + + foreach ($profiles as $profile) { + if (isset($profile->settings['loadPlugins'], $profile->settings['loadPlugins']['media'])) { + if ($media_wysiwyg_enabled) { + $profile->settings['loadPlugins']['media'] = $available_plugins['media']; + } + else { + throw new DrupalUpdateException(t('The "@profile" CKEdtior profile is using the media plugin. Support for the media module has now moved to media wysiwyg, please enable it to continue.', array('@profile' => $profile->name))); + } + + db_update('ckeditor_settings') + ->fields(array( + 'settings' => serialize($profile->settings), + )) + ->condition('name', $profile->name, '=') + ->execute(); + } + } + +} + +/** * Adapts D6 table structure to D7 schema. */ function _ckeditor_d6_to_d7_migration() { diff --git a/ckeditor.module b/ckeditor.module index 630714d..da64f3e 100644 --- a/ckeditor.module +++ b/ckeditor.module @@ -51,6 +51,21 @@ $_ckeditor_configuration = array(); $_ckeditor_ids = array(); /** + * Implements hook_hook_info(). + */ +function ckeditor_hook_info() { + $hooks = array( + 'ckeditor_plugin', + 'ckeditor_plugin_alter', + 'ckeditor_security_filter', + 'ckeditor_security_filter_alter', + 'ckeditor_settings_alter', + ); + + return array_fill_keys($hooks, array('group' => 'ckeditor')); +} + +/** * Implementation of hook_menu(). */ function ckeditor_menu() { diff --git a/includes/ckeditor.lib.inc b/includes/ckeditor.lib.inc index 892e663..d764fd0 100644 --- a/includes/ckeditor.lib.inc +++ b/includes/ckeditor.lib.inc @@ -330,286 +330,17 @@ function ckeditor_scayt_langcode($lang) { * @return array */ function ckeditor_load_plugins($render = FALSE) { - $arr = array(); - $base_path = '%base_path%'; - $editor_path = '%editor_path%'; - $plugin_dir = '%plugin_dir%'; - $plugin_dir_additional = '%plugin_dir_extra%'; - $pattern = '#\.addButton\([\s]*[\'"](.*?)[\'"][\s]*\,[\s]*\{[\s]*(.*?)[\s]*\}#s'; - - /* - * External plugins - */ - if (module_exists('ckeditor_swf') && file_exists(drupal_get_path('module', 'ckeditor_swf') . '/plugins/swf/plugin.js')) { - $arr['ckeditor_swf'] = array( - 'name' => 'swf', - 'desc' => t('Support for the CKEditor SWF module'), - 'path' => $base_path . drupal_get_path('module', 'ckeditor_swf') . '/plugins/swf/', - 'buttons' => FALSE, - 'default' => 't' - ); - } - - if (module_exists('ckeditor_link') && file_exists(drupal_get_path('module', 'ckeditor_link') . '/plugins/link/plugin.js')) { - $arr['ckeditor_link'] = array( - 'name' => 'drupal_path', - 'desc' => t('Support for the CKEditor Link module'), - 'path' => $base_path . drupal_get_path('module', 'ckeditor_link') . '/plugins/link/', - 'buttons' => FALSE, - 'default' => 't' - ); - } - - if (module_exists('linkit') && file_exists(drupal_get_path('module', 'linkit') . '/editors/ckeditor/plugin.js')) { - $arr['linkit'] = array( - 'name' => 'Linkit', - 'desc' => t('Support for the Linkit module (buttons: Linkit)'), - 'path' => $base_path . drupal_get_path('module', 'linkit') . '/editors/ckeditor/', - 'buttons' => array( - 'Linkit' => array( - 'title' => 'Linkit', - 'icon' => $base_path . drupal_get_path('module', 'linkit') . '/editors/ckeditor/linkit.png' - ) - ), - 'default' => 't' - ); - } - - /* - * CKEditor build-in plugins - */ - $_editor_path = ckeditor_path('local'); - //die($editor_path); - if ($_editor_path != '') { - if (file_exists($_editor_path . '/plugins/tableresize/plugin.js')) { - $arr['tableresize'] = array( - 'name' => 'tableresize', - 'desc' => t('Table Resize plugin'), - 'path' => $editor_path . '/plugins/tableresize/', - 'buttons' => FALSE, - 'default' => 't' - ); - } - - if (file_exists($_editor_path . '/plugins/autogrow/plugin.js')) { - $arr['autogrow'] = array( - 'name' => 'autogrow', - 'desc' => t('Auto Grow plugin'), - 'path' => $editor_path . '/plugins/autogrow/', - 'buttons' => FALSE, - 'default' => 'f' - ); - } - - if (file_exists($_editor_path . '/plugins/stylesheetparser/plugin.js')) { - $arr['stylesheetparser'] = array( - 'name' => 'stylesheetparser', - 'desc' => t('Stylesheet Parser plugin'), - 'path' => $editor_path . '/plugins/stylesheetparser/', - 'buttons' => FALSE, - 'default' => 'f' - ); - } - } - else { - $_editor_url = ckeditor_path('url'); - if (preg_match("/\/(standard|full)-all/", $_editor_url)) { - $arr['tableresize'] = array( - 'name' => 'tableresize', - 'desc' => t('Table Resize plugin. See !link for more details.', array( - '!link' => l(t('addon page'), 'http://ckeditor.com/addon/tableresize') - )), - 'path' => $_editor_url . '/plugins/tableresize/', - 'buttons' => FALSE, - 'default' => 't' - ); - $arr['autogrow'] = array( - 'name' => 'autogrow', - 'desc' => t('Auto Grow plugin. See !link for more details.', array( - '!link' => l(t('addon page'), 'http://ckeditor.com/addon/autogrow') - )), - 'path' => $_editor_url . '/plugins/autogrow/', - 'buttons' => FALSE, - 'default' => 'f' - ); - $arr['stylesheetparser'] = array( - 'name' => 'stylesheetparser', - 'desc' => t('Stylesheet Parser plugin. See !link for more details.', array( - '!link' => l(t('addon page'), 'http://ckeditor.com/addon/stylesheetparser') - )), - 'path' => $_editor_url . '/plugins/stylesheetparser/', - 'buttons' => FALSE, - 'default' => 'f' - ); - $arr['codesnippet'] = array( - 'name' => 'codesnippet', - 'desc' => t('Plugin for inserting Code Snippets. See !link for more details. See !help for additional instructions.', array( - '!link' => l(t('addon page'), 'http://ckeditor.com/addon/codesnippet'), - '!help' => l(t('help'), 'admin/help/ckeditor', array('fragment' => 'codesnippet')) - )), - 'path' => $_editor_url . '/plugins/codesnippet/', - 'buttons' => array( - 'CodeSnippet' => array( - 'icon' => 'icons/codesnippet.png', - 'label' => 'Insert Code Snippet', - ) - ), - 'default' => 'f' - ); - $arr['mathjax'] = array( - 'name' => 'mathjax', - 'desc' => t('Plugin for inserting Mathematical Formula (MathJax). See !link for more details. See !help for additional instructions.', array( - '!link' => l(t('addon page'), 'http://ckeditor.com/addon/mathjax'), - '!help' => l(t('help'), 'admin/help/ckeditor', array('fragment' => 'mathjax')) - )), - 'path' => $_editor_url . '/plugins/mathjax/', - 'buttons' => array( - 'Mathjax' => array( - 'icon' => 'icons/mathjax.png', - 'label' => 'Insert Mathematical Formulas', - ) - ), - 'default' => 'f' - ); - } - } - - /* - * CKEditor module plugins - */ - $_plugin_dir = ckeditor_module_path('local') . '/plugins/'; - if ($handle = opendir($_plugin_dir)) { - while (false !== ($file = readdir($handle))) { - if (is_dir($_plugin_dir . $file) && file_exists($_plugin_dir . $file . '/plugin.js')) { - $source = file_get_contents($_plugin_dir . $file . '/plugin.js'); - $buttons = array(); - if (preg_match_all($pattern, $source, $matches)) { - foreach ($matches[1] as $i => $button_name) { - if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$i], $matches2)) { - $buttons[$button_name] = array(); - $buttons[$button_name]['label'] = $button_name; - $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]); - $buttons[$button_name]['icon'] = trim($matches2[2]); - } - } - } - if (preg_match('#@file ([^\n\r]*)#', $source, $matches)) { - $arr[$file] = array( - 'name' => $file, - 'desc' => t($matches[1]), - 'path' => $plugin_dir . $file . '/', - 'buttons' => (count($buttons) > 0) ? $buttons : FALSE, - 'default' => 'f' - ); - } - else { - $arr[$file] = array( - 'name' => $file, - 'desc' => t('Plugin file: ' . $file), - 'path' => $plugin_dir . $file . '/', - 'buttons' => (count($buttons) > 0) ? $buttons : FALSE, - 'default' => 'f' - ); - } - } - } - closedir($handle); - } - - /* - * CKEditor module plugins - additional directory - */ - $_plugin_dir_additional = ckeditor_plugins_path('local') . '/'; - if ($_plugin_dir != $_plugin_dir_additional && is_dir($_plugin_dir_additional) && $handle = opendir($_plugin_dir_additional)) { - while (false !== ($file = readdir($handle))) { - if (is_dir($_plugin_dir_additional . $file) && file_exists($_plugin_dir_additional . $file . '/plugin.js')) { - $source = file_get_contents($_plugin_dir_additional . $file . '/plugin.js'); - $buttons = array(); - if (preg_match_all($pattern, $source, $matches)) { - foreach ($matches[1] as $i => $button_name) { - if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$i], $matches2)) { - $buttons[$button_name] = array(); - $buttons[$button_name]['label'] = $button_name; - $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]); - $buttons[$button_name]['icon'] = trim($matches2[2]); - } - } - } - if (preg_match('#@file ([^\n\r]*)#', $source, $matches)) { - $arr[$file] = array( - 'name' => $file, - 'desc' => t($matches[1]), - 'path' => $plugin_dir_additional . $file . '/', - 'buttons' => (count($buttons) > 0) ? $buttons : FALSE, - 'default' => 'f' - ); - } - else { - $arr[$file] = array( - 'name' => $file, - 'desc' => t('Plugin file: ' . $file), - 'path' => $plugin_dir_additional . $file . '/', - 'buttons' => (count($buttons) > 0) ? $buttons : FALSE, - 'default' => 'f' - ); - } - } - } - - closedir($handle); - } - - /* - * CKEditor plugins registered by hook - */ $plugins = module_invoke_all('ckeditor_plugin'); - foreach ($plugins as $i => $plugin) { - if (file_exists($plugin['path'] . 'plugin.js')) { - $source = file_get_contents($plugin['path'] . 'plugin.js'); - $plugins[$i]['path'] = $base_path . $plugin['path']; - if (!isset($plugin['buttons']) || count($plugin['buttons']) == 0) { - $buttons = array(); - if (preg_match_all($pattern, $source, $matches)) { - foreach ($matches[1] as $j => $button_name) { - if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$j], $matches2)) { - $buttons[$button_name] = array(); - $buttons[$button_name]['label'] = $button_name; - $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]); - $buttons[$button_name]['icon'] = trim($matches2[2]); - } - } - } - $plugins[$i]['buttons'] = (count($buttons) > 0) ? $buttons : FALSE; - } - } - else { - unset($plugins[$i]); - } - } - $arr = array_merge($arr, $plugins); - - if (isset($arr['media']) && module_exists('media') == FALSE) { - unset($arr['media']); - } - - if (isset($arr['imce']) && module_exists('imce') == FALSE) { - unset($arr['imce']); - } - //remove page break button if there is no module to do this - if (isset($arr['drupalbreaks']['buttons']['DrupalPageBreak']) && !module_exists('paging') && !module_exists('pagebreak') && !module_exists('smart_paging')) { - unset($arr['drupalbreaks']['buttons']['DrupalPageBreak']); - } + drupal_alter('ckeditor_plugin', $plugins); - if (isset($arr['drupalbreaks'])) { - $arr['drupalbreaks']['default'] = 't'; - } + ksort($plugins); - ksort($arr); if ($render === TRUE) { - $arr = ckeditor_plugins_render($arr); + $plugins = ckeditor_plugins_render($plugins); } - return $arr; + + return $plugins; } /** @@ -888,16 +619,13 @@ function ckeditor_profile_settings_compile($global_profile, $profile) { if (isset($conf['loadPlugins'])) { $settings['loadPlugins'] = ckeditor_plugins_render($conf['loadPlugins']); - if (array_key_exists('media', $settings['loadPlugins']) && module_exists('media')) { - module_load_include('inc', 'media', 'includes/media.browser'); - $javascript = media_browser_js(); - foreach ($javascript as $key => $definitions) { - foreach ($definitions as $definition) { - $function = 'drupal_add_' . $key; - call_user_func_array($function, $definition); - } + // TODO This should be done by the media module, not us. + if (array_key_exists('media', $settings['loadPlugins']) && module_exists('media_wysiwyg')) { + if (module_exists('media_wysiwyg')) { + media_wysiwyg_include_browser_js(); + drupal_add_js(drupal_get_path('module', 'media_wysiwyg') . '/js/media_wysiwyg.filter.js'); + drupal_add_js(drupal_get_path('module', 'media_wysiwyg') . '/wysiwyg_plugins/media_ckeditor/library.js', array('scope' => 'footer', 'weight' => -20)); } - drupal_add_js(drupal_get_path('module', 'ckeditor') . '/plugins/media/library.js', array('scope' => 'footer', 'weight' => -20)); } } else { diff --git a/plugins/media/images/icon.gif b/plugins/media/images/icon.gif deleted file mode 100644 index bf9b501c3dd5a10dcbc33ce2491afe1ea55fb737..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 126 zcmZ?wbhEHb6krfwSj52a|NsAk55FHcaG;@~fdR|~l0cyNlZBC;ft5iA!~v;gV0Mn! zb;sM_)DNZ&KjMOxwKKS-').append( element.eq(0).clone() ).html(); - }, - - addImageAttributes: function (imgElement, fid, view_mode, additional) { - imgElement.addClass('media-image'); - - this.forceAttributesIntoClass(imgElement, fid, view_mode, additional); - }, - - /** - * Due to problems handling wrapping divs in ckeditor, this is needed. - * - * Going forward, if we don't care about supporting other editors - * we can use the fakeobjects plugin to ckeditor to provide cleaner - * transparency between what Drupal will output
- * instead of just , for now though, we're going to remove all the stuff surrounding the images. - * - * @param String formattedMedia - * Element containing the image - * - * @return HTML of tag inside formattedMedia - */ - stripDivs: function (formattedMedia) { - // Check to see if the image tag has divs to strip - var stripped = null; - if ($(formattedMedia).is('img')) { - stripped = this.outerHTML($(formattedMedia)); - } else { - stripped = this.outerHTML($('img', $(formattedMedia))); - } - // This will fail if we pass the img tag without anything wrapping it, like we do when re-enabling ckeditor - return stripped; - }, - - /** - * Attach function, called when a rich text editor loads. - * This finds all [[tags]] and replaces them with the html - * that needs to show in the editor. - * - */ - attach: function (content, settings, instanceId) { - var matches = content.match(/\[\[.*?\]\]/g); - this.initializeTagMap(); - var tagmap = Drupal.settings.tagmap; - if (matches) { - var inlineTag = ""; - for (i = 0; i < matches.length; i++) { - inlineTag = matches[i]; - if (tagmap[inlineTag]) { - // This probably needs some work... - // We need to somehow get the fid propogated here. - // We really want to - var tagContent = tagmap[inlineTag]; - var mediaMarkup = this.stripDivs(tagContent); // THis is
.. - - var _tag = inlineTag; - _tag = _tag.replace('[[',''); - _tag = _tag.replace(']]',''); - mediaObj = JSON.parse(_tag); - - var imgElement = $(mediaMarkup); - this.addImageAttributes(imgElement, mediaObj.fid, mediaObj.view_mode); - var toInsert = this.outerHTML(imgElement); - content = content.replace(inlineTag, toInsert); - } - else { - debug.debug("Could not find content for " + inlineTag); - } - } - } - return content; - }, - - /** - * Detach function, called when a rich text editor detaches - */ - detach: function (content, settings, instanceId) { - var content = $('
' + content + '
'); - $('img.media-image',content).each(function (elem) { - var tag = Drupal.settings.ckeditor.plugins['media'].createTag($(this)); - $(this).replaceWith(tag); - var newContent = content.html(); - var tagContent = $('
').append($(this)).html(); - Drupal.settings.tagmap[tag] = tagContent; - }); - return content.html(); - }, - - /** - * @param jQuery imgNode - * Image node to create tag from - */ - createTag: function (imgNode) { - // Currently this is the itself - // Collect all attribs to be stashed into tagContent - var mediaAttributes = {}; - var imgElement = imgNode[0]; - var sorter = []; - - // @todo: this does not work in IE, width and height are always 0. - for (i=0; i< imgElement.attributes.length; i++) { - var attr = imgElement.attributes[i]; - if (attr.specified == true) { - if (attr.name !== 'class') { - sorter.push(attr); - } - else { - // Exctract expando properties from the class field. - var attributes = this.getAttributesFromClass(attr.value); - for (var name in attributes) { - if (attributes.hasOwnProperty(name)) { - var value = attributes[name]; - if (value.type && value.type === 'attr') { - sorter.push(value); - } - } - } - } - } - } - - sorter.sort(this.sortAttributes); - - for (var prop in sorter) { - mediaAttributes[sorter[prop].name] = sorter[prop].value; - } - - // The following 5 ifs are dedicated to IE7 - // If the style is null, it is because IE7 can't read values from itself - if (jQuery.browser.msie && jQuery.browser.version == '7.0') { - if (mediaAttributes.style === "null") { - var imgHeight = imgNode.css('height'); - var imgWidth = imgNode.css('width'); - mediaAttributes.style = { - height: imgHeight, - width: imgWidth - } - if (!mediaAttributes['width']) { - mediaAttributes['width'] = imgWidth; - } - if (!mediaAttributes['height']) { - mediaAttributes['height'] = imgHeight; - } - } - // If the attribute width is zero, get the CSS width - if (Number(mediaAttributes['width']) === 0) { - mediaAttributes['width'] = imgNode.css('width'); - } - // IE7 does support 'auto' as a value of the width attribute. It will not - // display the image if this value is allowed to pass through - if (mediaAttributes['width'] === 'auto') { - delete mediaAttributes['width']; - } - // If the attribute height is zero, get the CSS height - if (Number(mediaAttributes['height']) === 0) { - mediaAttributes['height'] = imgNode.css('height'); - } - // IE7 does support 'auto' as a value of the height attribute. It will not - // display the image if this value is allowed to pass through - if (mediaAttributes['height'] === 'auto') { - delete mediaAttributes['height']; - } - } - - // Remove elements from attribs using the blacklist - for (var blackList in Drupal.settings.media.blacklist) { - delete mediaAttributes[Drupal.settings.media.blacklist[blackList]]; - } - tagContent = { - "type": 'media', - // @todo: This will be selected from the format form - "view_mode": attributes['view_mode'].value, - "fid" : attributes['fid'].value, - "attributes": mediaAttributes - }; - return '[[' + JSON.stringify(tagContent) + ']]'; - }, - - /** - * Forces custom attributes into the class field of the specified image. - * - * Due to a bug in some versions of Firefox - * (http://forums.mozillazine.org/viewtopic.php?f=9&t=1991855), the - * custom attributes used to share information about the image are - * being stripped as the image markup is set into the rich text - * editor. Here we encode these attributes into the class field so - * the data survives. - * - * @param imgElement - * The image - * @fid - * The file id. - * @param view_mode - * The view mode. - * @param additional - * Additional attributes to add to the image. - */ - forceAttributesIntoClass: function (imgElement, fid, view_mode, additional) { - var wysiwyg = imgElement.attr('wysiwyg'); - if (wysiwyg) { - imgElement.addClass('attr__wysiwyg__' + wysiwyg); - } - var format = imgElement.attr('format'); - if (format) { - imgElement.addClass('attr__format__' + format); - } - var typeOf = imgElement.attr('typeof'); - if (typeOf) { - imgElement.addClass('attr__typeof__' + typeOf); - } - if (fid) { - imgElement.addClass('img__fid__' + fid); - } - if (view_mode) { - imgElement.addClass('img__view_mode__' + view_mode); - } - if (additional) { - for (var name in additional) { - if (additional.hasOwnProperty(name)) { - if (name !== 'alt') { - imgElement.addClass('attr__' + name + '__' + additional[name]); - } - } - } - } - }, - - /** - * Retrieves encoded attributes from the specified class string. - * - * @param classString - * A string containing the value of the class attribute. - * @return - * An array containing the attribute names as keys, and an object - * with the name, value, and attribute type (either 'attr' or - * 'img', depending on whether it is an image attribute or should - * be it the attributes section) - */ - getAttributesFromClass: function (classString) { - var actualClasses = []; - var otherAttributes = []; - var classes = classString.split(' '); - var regexp = new RegExp('^(attr|img)__([^\S]*)__([^\S]*)$'); - for (var index = 0; index < classes.length; index++) { - var matches = classes[index].match(regexp); - if (matches && matches.length === 4) { - otherAttributes[matches[2]] = { - name: matches[2], - value: matches[3], - type: matches[1] - }; - } - else { - actualClasses.push(classes[index]); - } - } - if (actualClasses.length > 0) { - otherAttributes['class'] = { - name: 'class', - value: actualClasses.join(' '), - type: 'attr' - }; - } - return otherAttributes; - }, - - sortAttributes: function (a, b) { - var nameA = a.name.toLowerCase(); - var nameB = b.name.toLowerCase(); - if (nameA < nameB) { - return -1; - } - if (nameA > nameB) { - return 1; - } - return 0; - } - }; - -})(jQuery); diff --git a/plugins/media/plugin.js b/plugins/media/plugin.js deleted file mode 100644 index a575006..0000000 --- a/plugins/media/plugin.js +++ /dev/null @@ -1,53 +0,0 @@ -/* -Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved. -For licensing, see LICENSE.html or http://ckeditor.com/license -*/ - -/** - * @file Plugin for inserting images from Drupal media module - */ -( function() { - CKEDITOR.plugins.add( 'media', - { - // Wrap Drupal plugin in a proxy plugin. - init: function(editor) - { - var pluginCommand = { - exec: function (editor) { - var data = { - format: 'html', - node: null, - content: '' - }; - var selection = editor.getSelection(); - - if (selection) { - data.node = selection.getSelectedElement(); - if (data.node) { - data.node = data.node.$; - } - if (selection.getType() == CKEDITOR.SELECTION_TEXT) { - data.content = selection.getSelectedText(); - } - else if (data.node) { - // content is supposed to contain the "outerHTML". - data.content = data.node.parentNode.innerHTML; - } - } - Drupal.settings.ckeditor.plugins['media'].invoke(data, Drupal.settings.ckeditor.plugins['media'], editor.name); - } - }; - editor.addCommand( 'media', pluginCommand ); - - editor.ui.addButton( 'Media', - { - label: 'Add media', - command: 'media', - icon: this.path + 'images/icon.gif' - }); - } - }); - -} )(); - -