From 88cd593d10e347698df64ecb293f7f7a003a44ce Mon Sep 17 00:00:00 2001 From: michal Date: Wed, 28 Sep 2011 15:48:23 +0200 Subject: [PATCH] [#1288664] CKeditor is not working in Views header and footer text areas --- ckeditor.module | 61 +++++++++++++++++++++++++++++++++++++++---- includes/ckeditor.utils.js | 41 ++++++++++++++++++++--------- 2 files changed, 83 insertions(+), 19 deletions(-) diff --git a/ckeditor.module b/ckeditor.module index 98f7786..611d6cb 100644 --- a/ckeditor.module +++ b/ckeditor.module @@ -234,7 +234,6 @@ function ckeditor_process_form(&$form) { } drupal_add_js(array('ckeditor' => $arr), 'setting'); } - return $form; } @@ -341,6 +340,14 @@ function ckeditor_menu() { 'type' => MENU_CALLBACK, ); + $items['admin/ckeditor/get_settings'] = array( + 'title' => 'Get settings for ckeditor instance', + 'description' => 'Get settings for ckeditor instance', + 'page callback' => 'ckeditor_get_settings', + 'access arguments' => array('access ckeditor'), + 'type' => MENU_CALLBACK, + ); + return $items; } @@ -349,6 +356,16 @@ function ckeditor_menu() { */ function ckeditor_init() { drupal_add_css(drupal_get_path('module', 'ckeditor') .'/ckeditor.css'); + + // Added for support [#1288664] Views + if (module_exists('views') && preg_match('/admin\/build\/views/', $_GET['q'])) + { + $module_drupal_path = drupal_get_path('module', 'ckeditor'); + $editor_local_path = ckeditor_path(TRUE); + drupal_add_js($editor_local_path . '/ckeditor.js?I', 'module', 'footer', FALSE, TRUE, FALSE); + drupal_add_js($module_drupal_path .'/includes/ckeditor.utils.js', 'module', 'footer' ); + drupal_add_js(array('ckeditor' => array('settings' =>array('edit-footer','edit-header'))), 'setting'); + } } /** @@ -432,7 +449,6 @@ function ckeditor_process_textarea($element) { if (isset($element['#access']) && !$element['#access']) { return $element; } - //skip this one, surely nobody wants WYSIWYG here switch ($element['#id']) { case 'edit-log': @@ -473,7 +489,6 @@ function ckeditor_process_textarea($element) { $enabled = ckeditor_is_enabled(empty($global_conf['excl_mode']) ? '0' : $global_conf['excl_mode'], empty($global_conf['excl_regex']) ? '' : $global_conf['excl_regex'], $element['#id'], $_GET['q']); } } - if ($enabled) { $profile = ckeditor_user_get_profile($user, $element['#id']); if ($profile) { @@ -514,7 +529,6 @@ function ckeditor_process_textarea($element) { $class = 'ckeditor-mod'; $_ckeditor_ids[] = $textarea_id; $ckeditor_on = ($conf['default']=='t') ? 1 : 0 ; - $xss_check = 0; //it's not a problem when adding new content/comment if (arg(1) != "add" && arg(1) != "reply") { @@ -1035,6 +1049,7 @@ function ckeditor_process_textarea($element) { drupal_add_js(array('ckeditor' => array( 'theme' => $theme )), 'setting'); if (!empty($settings)) { + $_SESSION['cke_get_settings'] = $settings; drupal_add_js(array('ckeditor' => array('settings' => $settings)), 'setting'); } if (!empty($autostart)) { @@ -1070,7 +1085,6 @@ function ckeditor_process_textarea($element) { $element['#attributes']['class'] .= ' '. $class; } //hack with patch jquery-ui dialog - return $element; } @@ -1096,7 +1110,6 @@ function ckeditor_path($local = FALSE, $refresh = FALSE) { //default: path to ckeditor subdirectory in the ckeditor module directory (relative to index.php) //e.g.: sites/all/modules/ckeditor/ckeditor $cke_local_path = $mod_path .'/ckeditor'; - if ($global_profile) { $gs = $global_profile->settings; @@ -1293,3 +1306,39 @@ function _ckeditor_scayt_langcode($lang) { return 'en_US'; } +/* + * Get settings for ckeditor + * Added for support [#1288664] Views + */ +function ckeditor_get_settings() +{ + global $user; + module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib'); + if (empty($_POST['id'])) echo json_encode(array()); + unset($_SESSION['cke_get_settings']); + $enabled = FALSE; + + $global_profile = ckeditor_profile_load('CKEditor Global Profile'); + if ($global_profile) { + $global_conf = $global_profile->settings; + if ($global_conf) { + $enabled = ckeditor_is_enabled(empty($global_conf['excl_mode']) ? '0' : $global_conf['excl_mode'], empty($global_conf['excl_regex']) ? '' : $global_conf['excl_regex'], $_POST['id'], 'admin/build/views'); + } + } + if ($enabled) { + $profile = ckeditor_user_get_profile($user, $_POST['#id']); + if ($profile) { + $conf = array(); + $conf = $profile->settings; + $enabled = ckeditor_is_enabled(empty($conf['excl_mode']) ? '0' : $conf['excl_mode'], empty($conf['excl_regex']) ? '' : $conf['excl_regex'], $_POST['id'], 'admin/build/views'); + } + else { + $enabled = FALSE; + } + } + if (!$enabled) echo json_encode(array()); + $element = ckeditor_process_textarea(array('#id' => $_POST['id'])); + if (empty($_SESSION['cke_get_settings'][$_POST['id']])) echo json_encode(array()); + echo json_encode($_SESSION['cke_get_settings'][$_POST['id']]); + die(); +} \ No newline at end of file diff --git a/includes/ckeditor.utils.js b/includes/ckeditor.utils.js index 71e93ff..d06a6d1 100644 --- a/includes/ckeditor.utils.js +++ b/includes/ckeditor.utils.js @@ -3,7 +3,6 @@ Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ Drupal.ckeditor = (typeof(CKEDITOR) != 'undefined'); - // this object will store teaser information Drupal.ckeditorTeaser = { lookup: {}, @@ -54,7 +53,7 @@ Drupal.ckeditorOn = function(textarea_id) { if (teaser.button.attr('value') != Drupal.t('Split summary at cursor')) { try { teaser.button.click(); - } + } catch (e) { teaser.button.val(Drupal.t('Split summary at cursor')); } @@ -98,7 +97,7 @@ Drupal.ckeditorOn = function(textarea_id) { var dtd = CKEDITOR.dtd; for ( var e in CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) { ev.editor.dataProcessor.writer.setRules( e, textarea_settings.custom_formatting); - } + } ev.editor.dataProcessor.writer.setRules( 'pre', { indent: textarea_settings.output_pre_indent @@ -163,7 +162,7 @@ Drupal.ckeditorOff = function(textarea_id) { if (teaser.button.attr('value') != Drupal.t('Join summary')) { try { teaser.button.click(); - } + } catch (e) { teaser.button.val(Drupal.t('Join summary')); } @@ -178,7 +177,7 @@ Drupal.ckeditorOff = function(textarea_id) { if (teaser.button.attr('value') != Drupal.t('Split summary at cursor')) { try { teaser.button.click(); - } + } catch (e) { teaser.button.val(Drupal.t('Split summary at cursor')); } @@ -196,7 +195,6 @@ Drupal.ckeditorOff = function(textarea_id) { */ function ckeditorOpenPopup(jsID, textareaID, width){ popupUrl = Drupal.settings.ckeditor.module_path + '/includes/ckeditor.popup.html?var=' + jsID + '&el=' + textareaID; - var percentPos = width.indexOf('%'); if (percentPos != -1) { width = width.substr(0, percentPos); @@ -239,7 +237,6 @@ Drupal.ckeditorTeaserInfo = function(taid) { if (Drupal.ckeditorTeaser.cache[taid]) { return Drupal.ckeditorTeaser.cache[taid]; } - // build a lookup table if (!Drupal.ckeditorTeaser.lookupSetup) { Drupal.ckeditorTeaser.lookupSetup = true; @@ -247,7 +244,6 @@ Drupal.ckeditorTeaserInfo = function(taid) { Drupal.ckeditorTeaser.lookup[Drupal.settings.teaser[x]] = x; } } - // find the elements if (Drupal.ckeditorTeaser.lookup[taid]) { var obj; @@ -262,19 +258,16 @@ Drupal.ckeditorTeaserInfo = function(taid) { checkbox: $('#' + Drupal.settings.teaserCheckbox[Drupal.ckeditorTeaser.lookup[taid]]) }; } - obj.textareaContainer = obj.textarea.parent(); obj.checkboxContainer = obj.checkbox.parent(); - obj.button = $('input.teaser-button', obj.checkbox.parents('div.teaser-checkbox').get(0)); obj.buttonContainer = obj.button.parent(); - Drupal.ckeditorTeaser.cache[taid] = obj; } else { Drupal.ckeditorTeaser.cache[taid] = null; } - + return Drupal.ckeditorTeaser.cache[taid]; }; @@ -368,6 +361,28 @@ Drupal.behaviors.ckeditor = function (context) { Drupal.behaviors.textarea(context); } + //Added for support [#1288664] Views + if ($(context).attr('id') === 'views-ajax-pad') + { + views_textarea_id = $("textarea", $(context)).attr('id'); + if (views_textarea_id) + { + path = document.location.href.replace(document.location.pathname, ''); + $.ajax({ + url: path + '/admin/ckeditor/get_settings', + dataType: 'json', + data: { 'id': views_textarea_id }, + type: 'POST', + success: function( data ) { + Drupal.settings.ckeditor.settings[views_textarea_id] = data; + Drupal.ckeditorOff(views_textarea_id); + Drupal.ckeditorOn(views_textarea_id); + }, + error: function(xhr) { } + }); + } + } + // Support for Panels [#679976] if ($(context).attr('id') == 'modal-content') { if (CKEDITOR.instances['edit-body'] != 'undefined') { @@ -385,7 +400,7 @@ Drupal.behaviors.ckeditor = function (context) { $('body').unbind('keypress'); }; }); - } + } $("textarea.ckeditor-mod:not(.ckeditor-processed)").each(function () { var ta_id=$(this).attr("id"); -- 1.7.4.msysgit.0