el-header-and-footer 0.0.54 → 0.0.55

Sign up to get free protection for your applications and to get access to all the features.
@@ -1013,6 +1013,25 @@ class ElHeaderAndFooterComponent {
1013
1013
  }
1014
1014
  }
1015
1015
  }
1016
+ // getToday() {
1017
+ // const currentDate = new Date();
1018
+ // const day = currentDate.getDate() ;
1019
+ // const month = currentDate.getMonth() + 1;
1020
+ // const year = currentDate.getFullYear();
1021
+ // const formattedDate = `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;
1022
+ // this.today = formattedDate;
1023
+ // // const label = `{(${this.today})}`;
1024
+ // const label = `{(date)}`;
1025
+ // const htmlContent = ` ${label} `;
1026
+ // const editor = document.getElementById(this.editorId);
1027
+ // if (editor) {
1028
+ // this.editorText += `<div> ${htmlContent} </div>`;
1029
+ // this.sanitizedContent = this.editorText;
1030
+ // } else {
1031
+ // this.editorText += `<div> ${htmlContent} </div>`;
1032
+ // this.sanitizedContent = this.editorText;
1033
+ // }
1034
+ // }
1016
1035
  getToday() {
1017
1036
  const currentDate = new Date();
1018
1037
  const day = currentDate.getDate();
@@ -1024,13 +1043,43 @@ class ElHeaderAndFooterComponent {
1024
1043
  const label = `{(date)}`;
1025
1044
  const htmlContent = ` ${label} `;
1026
1045
  const editor = document.getElementById(this.editorId);
1027
- if (editor) {
1028
- this.editorText += `<div> ${htmlContent} </div>`;
1029
- this.sanitizedContent = this.editorText;
1030
- }
1031
- else {
1032
- this.editorText += `<div> ${htmlContent} </div>`;
1033
- this.sanitizedContent = this.editorText;
1046
+ this.insertAtCaret(htmlContent);
1047
+ // if (editor) {
1048
+ // this.editorText += `<div> ${htmlContent} </div>`;
1049
+ // this.sanitizedContent = this.editorText;
1050
+ // } else {
1051
+ // this.editorText += `<div> ${htmlContent} </div>`;
1052
+ // this.sanitizedContent = this.editorText;
1053
+ // }
1054
+ }
1055
+ insertAtCaret(newData) {
1056
+ const selection = window.getSelection();
1057
+ if (selection && selection.rangeCount > 0) {
1058
+ // Get the current range (caret position)
1059
+ const range = selection.getRangeAt(0);
1060
+ // Create a document fragment to insert (allows handling HTML strings)
1061
+ const fragment = document.createDocumentFragment();
1062
+ const tempDiv = document.createElement('div');
1063
+ tempDiv.innerHTML = newData;
1064
+ // Append the new data to the fragment (supports HTML insertion)
1065
+ while (tempDiv.firstChild) {
1066
+ fragment.appendChild(tempDiv.firstChild);
1067
+ }
1068
+ // Insert the fragment at the caret position
1069
+ range.deleteContents(); // Remove any selected content if applicable
1070
+ range.insertNode(fragment);
1071
+ // Move the caret after the inserted content
1072
+ const lastChild = fragment.lastChild;
1073
+ if (lastChild) {
1074
+ range.setStartAfter(lastChild);
1075
+ range.setEndAfter(lastChild);
1076
+ selection.removeAllRanges();
1077
+ selection.addRange(range);
1078
+ }
1079
+ let editor = document.getElementById('editor');
1080
+ if (editor) {
1081
+ this.moveCaretToEnd(editor);
1082
+ }
1034
1083
  }
1035
1084
  }
1036
1085
  insertPageNumber() {