Browse Source

edit code-editor to include everything for settingsOption
switch custom HTML to new code-editor method

CauseFX 4 năm trước cách đây
mục cha
commit
100b8316f4
3 tập tin đã thay đổi với 29 bổ sung3 xóa
  1. 25 1
      api/functions/option-functions.php
  2. 1 1
      api/homepage/html.php
  3. 3 1
      js/functions.js

+ 25 - 1
api/functions/option-functions.php

@@ -278,11 +278,35 @@ trait OptionsFunction
 				];
 				break;
 			case 'codeeditor':
+				$mode = strtolower($extras['mode'] ?? 'css');
+				switch ($mode) {
+					case 'html':
+					case 'javascript':
+						$mode = 'ace/mode/' . $mode;
+						break;
+					case 'js':
+						$mode = 'ace/mode/javascript';
+						break;
+					default:
+						$mode = 'ace/mode/css';
+						break;
+				}
 				$settingMerge = [
 					'type' => 'html',
 					'override' => 12,
 					'label' => 'Custom Code',
-					'html' => '<textarea data-changed="false" class="form-control hidden ' . $name . 'Textarea" name="' . $name . '" data-type="textbox" autocomplete="new-password"></textarea><div id="' . $name . 'Editor" style="height:300px">' . htmlentities($this->config[$name]) . '</div>'
+					'html' => '
+					<textarea data-changed="false" class="form-control hidden ' . $name . 'Textarea" name="' . $name . '" data-type="textbox" autocomplete="new-password"></textarea>
+					<div id="' . $name . 'Editor" style="height:300px">' . htmlentities($this->config[$name]) . '</div>
+					<script>
+						let mode = ace.require("' . $mode . '").Mode;
+						' . $name . ' = ace.edit("' . $name . 'Editor");
+						' . $name . '.session.setMode(new mode());
+						' . $name . '.setTheme("ace/theme/idle_fingers");
+						' . $name . '.setShowPrintMargin(false);
+						' . $name . '.session.on("change", function(delta) { $(".' . $name . 'Textarea").val(' . $name . '.getValue()) });
+					</script>
+					'
 				];
 				break;
 			// CALENDAR ITEMS

+ 1 - 1
api/homepage/html.php

@@ -29,7 +29,7 @@ trait HTMLHomepageItem
 				$this->settingsOption('enable', 'homepageCustomHTML' . $i . 'Enabled'),
 				$this->settingsOption('auth', 'homepageCustomHTML' . $i . 'Auth'),
 				//$this->settingsOption('pre-code-editor', 'customHTML' . $i), // possibly can remove this as we consolidated the type into one
-				$this->settingsOption('code-editor', 'customHTML' . $i, ['label' => 'Custom HTML Code']),
+				$this->settingsOption('code-editor', 'customHTML' . $i, ['label' => 'Custom HTML Code', 'mode' => 'html']),
 			);
 		}
 		return array_merge($homepageInformation, $homepageSettings);

+ 3 - 1
js/functions.js

@@ -1736,6 +1736,7 @@ function clearHomepageOriginal(){
 	$('#editHomepageItem').html('');
 }
 function completeHomepageLoad(item, data){
+	/*
 	if(item == 'CustomHTML'){
 		let iteration = 0;
 		$.each(data.settings, function(i,customItem) {
@@ -1749,11 +1750,12 @@ function completeHomepageLoad(item, data){
 			customHTMLEditorObject[iterationString].setShowPrintMargin(false);
 			customHTMLEditorObject[iterationString].session.on('change', function(delta) {
 				$('.' + customTextarea).val(customHTMLEditorObject[iterationString].getValue());
-				$('#homepage-CustomHTML-form-save').removeClass('hidden');
+				//$('#homepage-CustomHTML-form-save').removeClass('hidden');
 			});
 			iteration++;
 		});
 	}
+	*/
 	pageLoad();
 }
 function editHomepageItem(item){