From 0bdb9aac314c19a6953dabeb2a0cf973df37fe41 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Mon, 27 Aug 2012 13:07:25 +0200
Subject: [PATCH] Fix condition of usage of ckeditor

---
 htdocs/core/lib/ajax.lib.php           | 19 +++++++++++--------
 htdocs/core/tpl/objectline_add.tpl.php | 25 +++++++++++++++----------
 2 files changed, 26 insertions(+), 18 deletions(-)

diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php
index 8b0614a1b42..3d099d59442 100644
--- a/htdocs/core/lib/ajax.lib.php
+++ b/htdocs/core/lib/ajax.lib.php
@@ -135,14 +135,17 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
     							});
     						}
     						if (ui.item.textarea) {
-    							$.each(ui.item.textarea, function(key, value) {
-    								if (typeof CKEDITOR == "object") {
-    									CKEDITOR.instances[key].setData(value);
-    									CKEDITOR.instances[key].focus();
-    								} else {
-    									$("#" + key).html(value);
-    									$("#" + key).focus();
-									}
+    							$.each(ui.item.textarea, function(key, value) {';
+								if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) {
+								$script.= '					// We use CKEditor
+															CKEDITOR.instances[key].setData(value);
+    														CKEDITOR.instances[key].focus();';
+								} else {
+    							$script.= '					// We use a simple textarea
+    														$("#" + key).html(value);
+    														$("#" + key).focus();';
+								}
+								$script.='
     							});
     						}
     					}
diff --git a/htdocs/core/tpl/objectline_add.tpl.php b/htdocs/core/tpl/objectline_add.tpl.php
index a1f8ecbda40..e9ff02a8ac1 100644
--- a/htdocs/core/tpl/objectline_add.tpl.php
+++ b/htdocs/core/tpl/objectline_add.tpl.php
@@ -211,7 +211,6 @@ if (! empty($conf->margin->enabled)) {
 <?php } ?>
 
 </form>
-
 <script type="text/javascript">
 $(document).ready(function() {
 
@@ -220,11 +219,13 @@ $(document).ready(function() {
 	$('#idprod').change(function() {
 		if ($(this).val().length > 0)
 	    {
-			if (typeof CKEDITOR == 'object') {
+			<?php if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
+				// We use CKEditor
 				CKEDITOR.instances['product_desc'].focus();
-			} else {
+			<?php } else { ?>
+				// We use a simple textarea
 				$('#product_desc').focus();
-			}
+			<?php } ?>
 
 	    } else {
 	    	$('#update_desc_checkbox').removeAttr('checked').trigger('change');
@@ -336,19 +337,21 @@ $(document).ready(function() {
 
 			var origin_desc = $('#origin_desc_cache').val();
 
-			if (typeof CKEDITOR == 'object') {
+			<?php if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
+				// We use CKEditor
 				var freecontent = CKEDITOR.instances['product_desc'].getData();
 				if (origin_desc.length > 0)
 					var content = origin_desc + '<br />' + freecontent;
 				else
 					var content = freecontent;
-			} else {
+			<?php } else { ?>
+				// We use a simple textarea
 				var freecontent = $('#product_desc').html();
 				if (origin_desc.length > 0)
 					var content = origin_desc + '\r\n' + freecontent;
 				else
 					var content = freecontent;
-			}
+			<?php } ?>
 
 			$('#free_desc_cache').val(freecontent);
 
@@ -356,11 +359,13 @@ $(document).ready(function() {
 			var content = $('#free_desc_cache').val();
 		}
 
-		if (typeof CKEDITOR == 'object') {
+		<?php if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
+			// We use CKEditor
 			CKEDITOR.instances['product_desc'].setData(content);
-		} else {
+		<?php } else { ?>
+			// We use a simple textarea
 			$('#product_desc').html(content);
-		}
+		<?php } ?>
 	});
 
 	$('#price_ht').focusin(function() {
-- 
GitLab