From f69675556d1a277ef1daade833f829123c4a1a45 Mon Sep 17 00:00:00 2001
From: michal <michal_cksource@922884.no-reply.drupal.org>
Date: Tue, 23 Aug 2011 12:51:31 +0200
Subject: [PATCH 2/2] Add loading sample toolbar in profile config.

---
 ckeditor.config.js          |   46 +++++++++++++++++++-
 includes/ckeditor.admin.inc |   17 ++++----
 includes/ckeditor.admin.js  |   99 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 152 insertions(+), 10 deletions(-)

diff --git a/ckeditor.config.js b/ckeditor.config.js
index 779c61f..8c229cc 100644
--- a/ckeditor.config.js
+++ b/ckeditor.config.js
@@ -28,7 +28,7 @@ CKEDITOR.editorConfig = function(config) {
 
     /*
    * Append here extra CSS rules that should be applied into the editing area.
-   * Example: 
+   * Example:
    * config.extraCss = 'body {color:#FF0000;}';
    */
     config.extraCss = '';
@@ -57,4 +57,46 @@ CKEDITOR.editorConfig = function(config) {
         config.bodyClass = 'singlepage';
         config.bodyId = 'primary';
     }
-}
\ No newline at end of file
+}
+
+/*
+* DrupalBasic toolbar definition for basic buttons
+*/
+Drupal.settings.cke_toolbar_DrupalBasic = [ [ 'Format', 'Bold', 'Italic', '-', 'NumberedList','BulletedList', '-', 'Link', 'Unlink', 'Image' ] ];
+
+//Toolbar definition for Advanced buttons
+Drupal.settings.cke_toolbar_DrupalAdvanced = [
+  ['Source'],
+  ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
+  ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
+  ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
+  ['Maximize', 'ShowBlocks'],
+  '/',
+  ['Format'],
+  ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
+  ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
+  ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiRtl','BidiLtr'],
+  ['Link','Unlink','Anchor','Linkit','LinkToNode','LinkToMenu'],
+  ['DrupalBreak', 'DrupalPageBreak']
+ ];
+
+
+/*
+ * Toolbar definiton for all buttons
+ */
+Drupal.settings.cke_toolbar_DrupalFull = [
+    ['Source'],
+    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','SpellChecker', 'Scayt'],
+    ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
+    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar'],
+    '/',
+    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
+    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
+    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiRtl','BidiLtr'],
+    ['Link','Unlink','Anchor','Linkit','LinkToNode', 'LinkToMenu'],
+    '/',
+    ['Format','Font','FontSize'],
+    ['TextColor','BGColor'],
+    ['Maximize', 'ShowBlocks'],
+    ['DrupalBreak', 'DrupalPageBreak']
+   ];
\ No newline at end of file
diff --git a/includes/ckeditor.admin.inc b/includes/ckeditor.admin.inc
index d662196..c72cb90 100644
--- a/includes/ckeditor.admin.inc
+++ b/includes/ckeditor.admin.inc
@@ -38,7 +38,7 @@ function ckeditor_admin_main() {
     module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
     $editor_path = ckeditor_path(TRUE);
     $ckconfig_file = $editor_path . '/config.js';
-    
+
     //check if CKEditor plugin is installed
     if (!_ckeditor_requirements_isinstalled()) {
         drupal_set_message(t('Checking for %filename or %file.', array('%filename' => $ckconfig_file, '%file' => 'sites/all/libraries/ckeditor/ckeditor.js')));
@@ -333,7 +333,7 @@ function ckeditor_admin_profile_form($form, $form_state, $profile = NULL) {
         $profile->input_formats = array();
         $used_formats = db_select('ckeditor_input_format', 'f')->fields('f', array("format"))->distinct()->execute()->fetchAllAssoc('format');
     }
-    
+
     $formats = array();
     foreach ($orig_formats AS $format) {
         if ( (arg(4) == 'edit' && !empty($profile->input_formats) && array_key_exists($format->format, $profile->input_formats)) || !array_key_exists($format->format, $used_formats) ) {
@@ -482,6 +482,7 @@ function ckeditor_admin_profile_form($form, $form_state, $profile = NULL) {
     $module_drupal_path = drupal_get_path('module', 'ckeditor');
     drupal_add_js('window.CKEDITOR_BASEPATH = "' . base_path() . $editor_path . '/"', array('type' => 'inline', 'weight' => -100));
     drupal_add_js($editor_path . '/ckeditor.js', array('type' => 'file', 'preprocess' => FALSE));
+    drupal_add_js($module_drupal_path . '/ckeditor.config.js', 'file');
     drupal_add_js($module_drupal_path . '/includes/ckeditor.admin.js', 'file');
 
     $form['appearance']['uicolor'] = array(
@@ -511,11 +512,11 @@ function ckeditor_admin_profile_form($form, $form_state, $profile = NULL) {
         '#type' => 'textarea',
         '#title' => t('Toolbar'),
         '#default_value' => !empty($profile->settings['toolbar']) ? $profile->settings['toolbar'] : '',
-        '#description' => t('Set the toolbar definition. The instruction is available in the <a href="http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Toolbar" target="_blank">CKEditor documentation</a>.'),
+        '#description' => t('Set the toolbar definition. The instruction is available in the <a href="http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Toolbar" target="_blank">CKEditor documentation</a>.<br /> Load sample toolbar: <a href="#" id="ckeditor_toolbar_basic">Basic</a> | <a href="#" id="ckeditor_toolbar_advanced">Advanced</a> | <a href="#" id="ckeditor_toolbar_full">Full</a>'),
         '#wysiwyg' => FALSE,
         '#rows' => 15
     );
-    
+
     $pluginList = ckeditor_load_plugins();
     $plugins = array();
     if (isset($profile->settings['loadPlugins'])){
@@ -770,8 +771,8 @@ function ckeditor_admin_profile_form($form, $form_state, $profile = NULL) {
     }
 
    if (module_exists('elfinder')) {
-	$filebrowsers['elfinder'] = t('elFinder');
-	$filebrowsers_dialogs['elfinder'] = t('elFinder');
+  $filebrowsers['elfinder'] = t('elFinder');
+  $filebrowsers_dialogs['elfinder'] = t('elFinder');
     }
 
     /* MODULES NOT PORTED TO D7
@@ -1101,7 +1102,7 @@ function ckeditor_admin_profile_clone_form_submit($form, &$form_state) {
             }
         }
     }
-    
+
     $form_state['redirect'] = 'admin/config/content/ckeditor';
 }
 
@@ -1160,7 +1161,7 @@ function ckeditor_admin_values_to_settings($values) {
         $plugins = $values['loadPlugins'];
     }
     unset($values['name'], $values['input_formats'], $values['_profile'], $values['op'], $values['submit'], $values['form_build_id'], $values['form_token'], $values['form_id'], $values['loadPlugins']);
-    
+
     module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
     $pluginList = ckeditor_load_plugins();
     $values['loadPlugins'] = array();
diff --git a/includes/ckeditor.admin.js b/includes/ckeditor.admin.js
index 9c4c259..3bf4f6b 100644
--- a/includes/ckeditor.admin.js
+++ b/includes/ckeditor.admin.js
@@ -122,5 +122,104 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                 }
             }
         });
+
+        $("#ckeditor_toolbar_basic").click(function(){
+            var buttons = Drupal.settings.cke_toolbar_DrupalBasic;
+            var text = "[\n";
+            for(i in buttons)
+            {
+             text = text + "    [";
+             max = buttons[i].length - 1;
+             rows = buttons.length - 1;
+             for (j in buttons[i])
+             {
+              if (j < max)
+              {
+                text = text + "'" + buttons[i][j] + "',";
+              }else
+              {
+                text = text + "'" + buttons[i][j] + "'";
+              }
+             }
+             if (i < rows)
+             {
+               text = text + "],\n";
+             }else
+             {
+               text = text + "]\n";
+             }
+            }
+
+            text = text + "]";
+            text = text.replace(/\['\/'\]/g,"'/'");
+            $("#edit-toolbar").attr('value',text);
+            return false;
+          });
+
+        $("#ckeditor_toolbar_advanced").click(function(){
+          var buttons = Drupal.settings.cke_toolbar_DrupalAdvanced;
+          var text = "[\n";
+          for(i in buttons)
+          {
+           text = text + "    [";
+           max = buttons[i].length - 1;
+           rows = buttons.length - 1;
+           for (j in buttons[i])
+           {
+            if (j < max)
+            {
+              text = text + "'" + buttons[i][j] + "',";
+            }else
+            {
+              text = text + "'" + buttons[i][j] + "'";
+            }
+           }
+           if (i < rows)
+           {
+             text = text + "],\n";
+           }else
+           {
+             text = text + "]\n";
+           }
+          }
+
+          text = text + "]";
+          text = text.replace(/\['\/'\]/g,"'/'");
+          $("#edit-toolbar").attr('value',text);
+          return false;
+        });
+
+        $("#ckeditor_toolbar_full").click(function(){
+            var buttons = Drupal.settings.cke_toolbar_DrupalFull;
+            var text = "[\n";
+            for(i in buttons)
+            {
+             text = text + "    [";
+             max = buttons[i].length - 1;
+             rows = buttons.length - 1;
+             for (j in buttons[i])
+             {
+              if (j < max)
+              {
+                text = text + "'" + buttons[i][j] + "',";
+              }else
+              {
+                text = text + "'" + buttons[i][j] + "'";
+              }
+             }
+             if (i < rows)
+             {
+               text = text + "],\n";
+             }else
+             {
+               text = text + "]\n";
+             }
+            }
+
+            text = text + "]";
+            text = text.replace(/\['\/'\]/g,"'/'");
+            $("#edit-toolbar").attr('value',text);
+            return false;
+          });
     });
 })(jQuery);
\ No newline at end of file
-- 
1.7.4.msysgit.0

