1document.body.addEventListener("trix-initialize", function(event) { 2 //Trix.config.textAttributes.left = { style: { textAlign:"" } }; 3 Trix.config.textAttributes.center = { tagName: "center" }; 4 Trix.config.textAttributes.right = { tagName: "right" }; 5 var element = event.target; 6 var toolbarElement = element.toolbarElement; 7 var groupElement = toolbarElement.querySelector(".trix-button-group.trix-button-group--block-tools"); 8 //groupElement.insertAdjacentHTML("beforeend",'<button type="button" class="trix-button trix-button--icon trix-button--icon-align-left" data-trix-attribute="left"></button>'); 9 groupElement.insertAdjacentHTML("beforeend", '<button type="button" class="trix-button trix-button--icon trix-button--icon-align-center" data-trix-attribute="center"></button>'); 10 groupElement.insertAdjacentHTML("beforeend",'<button type="button" class="trix-button trix-button--icon trix-button--icon-align-right" data-trix-attribute="right"></button>'); 11 12 var editor = element.editor; 13 var selectedAttributes = new Set; 14 let upd = false; 15 function updateSelectedAttributes() { 16 selectedAttributes = new Set; 17 var selectedRange = editor.getSelectedRange() 18 if (selectedRange[0] === selectedRange[1]) { selectedRange[1]++ } 19 var selectedPieces = editor.getDocument().getDocumentAtRange(selectedRange).getPieces() 20 selectedPieces.forEach(function(piece) { 21 Object.keys(piece.getAttributes()).forEach(function(attribute) { 22 selectedAttributes.add(attribute); 23 }); 24 }); 25 if (upd === true) { 26 finishAttributes(); 27 upd = false; 28 } 29 } 30 function enforceExclusiveAttributes(e) { 31 upd = true; 32 if (editor.attributeIsActive("center") && selectedAttributes.has("right")) { 33 editor.deactivateAttribute("right"); 34 updateSelectedAttributes(); 35 } else if (editor.attributeIsActive("right") && selectedAttributes.has("center")) { 36 editor.deactivateAttribute("center"); 37 updateSelectedAttributes(); 38 }else if(editor.attributeIsActive("center") === true || editor.attributeIsActive("right") === true){ 39 updateSelectedAttributes(); 40 }else{ 41 upd = false; 42 finishAttributes(); 43 } 44 } 45 function finishAttributes(){ 46 // let elem = editor.element.parentElement.querySelector('input[type="hidden"]'); 47 // editor.element.innerHTML = elem.value; 48 // let str = elem.value; 49 // str = occ.replace(str, '<center>', '<div style="text-align:center;"></div>'); 50 // str = occ.replace(str, '<right>', '<div style="text-align:right;"></div>'); 51 // elem.value = str; 52 element.dispatchEvent(new Event('trix-change-occ')); 53 } 54 updateSelectedAttributes(); 55 element.addEventListener("trix-selection-change", updateSelectedAttributes); 56 element.addEventListener("trix-change", enforceExclusiveAttributes); 57})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.