SC.loadPackage({ 'TextEditor': { comment: 'I am the TextEditor for TextElements.', sharedProperties: { editGroupFontFamily: { initValue: '' }, editGroupFontSize: { initValue: ' ' }, editGroupFontStyle: { initValue: '' }, editGroupFontColor: { initValue: ' 
' }, editGroupLists: { initValue: '' }, editGroupIndention: { initValue: '' }, editGroupAlignment: { initValue: '' }, editGroupHyperlink: { initValue: '' }, //editGroupHyperlink: { initValue: ' ' }, activeEditGroups: { initValue: ['editGroupIndention', 'editGroupAlignment', 'editGroupFontSize', 'editGroupFontFamily', 'editGroupFontColor', 'editGroupHyperlink', 'editGroupFontStyle', 'editGroupLists'] }, activeFonts: { initValue: ['Serif', 'Sans', 'Arial', 'Arial Black', 'Courier', 'Courier New', 'Comic Sans MS','Dosis', 'Helvetica', 'Impact', 'Lucida Grande', 'Lucida Sans', 'Montserrat', 'Tahoma', 'Times', 'Times New Roman', 'TitilliumWeb', 'Verdana'] }, activeFontSizes: { initValue: ['8px', '9px', '10px', '11px', '12px', '13px', '14px', '15px', '16px', '17px', '18px', '20px', '22px', '26px', '28px', '30px', '32px', '34px', '36px', '38px', '40px', '46px', '50px', '60px', '70px'] } }, properties: { originalElementNode: { comment: 'I store the original TextElement\'s DOM node.' }, originalSelection: { comment: 'I store the selection to restore it on unloading of the editor.' }, textEditor: { comment: 'I store the TextEditor\'s DOM node.' }, textEditorContainer: { comment: 'I store the textEditorContainer\'s DOM node.' }, textEditorToolbar: { comment: 'I store the textEditorToolbar\'s DOM node.' }, colorpicker: { comment: 'I store a reference to my colorpicker' } }, methods: { init: { comment: 'method comment', code: function(aTextElement){ var self = this, originalElementNode = aTextElement.get('node'), textEditor = document.createElement('textarea'), textEditorContainer = document.createElement('div'); this.set({ originalElementNode: originalElementNode, originalSelection: SuperGlue.get('selection').get('elements'), textEditor: textEditor, textEditorContainer: textEditorContainer }); SuperGlue.get('selection').do('clearAll'); (function(elementNode){ var textContent = elementNode.innerHTML; SuperGlue.get('history').do('actionHasStarted', function(){ elementNode.innerHTML = textContent; }) }).call(this, this.get('originalElementNode')); // Prepare textEditor's div /* textEditor.setAttribute('id', 'sg-editing-textEditor'); textEditor.style.width = originalElementNode.style.width; textEditor.style.height = originalElementNode.style.height; textEditor.style.padding = originalElementNode.style.padding; textEditor.style.border = originalElementNode.style.border; textEditor.style.borderRadius = originalElementNode.style.borderRadius; */ // Add textarea textEditor.setAttribute('id', 'currentEditor'); textEditor.style.borderWidth = originalElementNode.style.borderWidth; textEditor.style.borderColor = originalElementNode.style.borderColor; textEditor.style.borderRadius = originalElementNode.style.borderRadius; textEditor.style.backgroundColor = originalElementNode.style.backgroundColor; textEditor.style.backgroundRepeat = originalElementNode.style.backgroundRepeat; textEditor.style.backgroundImage = originalElementNode.style.backgroundImage; textEditor.style.padding = originalElementNode.style.padding; textEditor.style.boxSizing = 'border-box'; textEditor.style.borderStyle = 'solid'; textEditor.style.position = 'absolute'; textEditor.style.width = this.get('originalElementNode').offsetWidth + 'px'; textEditor.style.height = this.get('originalElementNode').offsetHeight + 'px'; textEditor.style.outline = '1px dashed rgb(255, 41, 61)'; this.do('updateEditorDimensions'); /* textEditor.style.top = this.get('originalElementNode').clientTop - this.get('originalElementNode').scrollTop + 'px'; textEditor.style.left = this.get('originalElementNode').clientLeft - this.get('originalElementNode').scrollLeft + 'px'; textEditor.style.width = this.get('originalElementNode').offsetWidth + 'px'; textEditor.style.height = this.get('originalElementNode').offsetHeight + 'px'; */ this.get('textEditorContainer').appendChild(textEditor); window.addEventListener('resize', function(){ self.do('updateEditorDimensions', textEditor) }, false); // Prepare container textEditorContainer.setAttribute('id', 'sg-editing-textEditor-container'); this.do('updateContainerDimensions', textEditorContainer); window.addEventListener('resize', function(){ self.do('updateContainerDimensions', textEditorContainer) }, false); textEditor.innerHTML = originalElementNode.innerHTML; originalElementNode.style.display = 'none'; textEditorContainer.appendChild(textEditor); // Add eventListener on the container textEditorContainer.addEventListener('mouseover', function(evt){ evt.stopPropagation(); }, false); textEditorContainer.addEventListener('mouseout', function(evt){ evt.stopPropagation(); }, false); textEditorContainer.addEventListener('mouseup', function(evt){ self.do('closeTextEditor'); evt.stopPropagation(); }, false); textEditorContainer.addEventListener('mousedown', function(evt){ evt.stopPropagation(); }, false); document.body.insertBefore( textEditorContainer, SuperGlue.get('document').get('editingContainer').nextElementSibling ); // Append text editing toolbar var textShapeToolbar = document.createElement('div'); textShapeToolbar.setAttribute('id', 'textShapeToolbar'); textShapeToolbar.setAttribute('data-role', 'editor-toolbar'); textShapeToolbar.setAttribute('data-target', '#currentEditor'); textShapeToolbar.style.display = 'block'; textShapeToolbar.style.top = this.get('textEditor').offsetTop - 85 + 'px'; textShapeToolbar.style.left = this.get('textEditor').offsetLeft + this.get('textEditor').offsetWidth - 300 + 'px'; var editGroups = this.class.get('activeEditGroups'); for ( i=0; i < editGroups.length; i++ ) { var htmlString = this.class.get(editGroups[i]); var currentGroup = document.createElement('div'); currentGroup.setAttribute('class', 'btn-group'); currentGroup.innerHTML = htmlString; textShapeToolbar.appendChild(currentGroup); } textShapeToolbar.addEventListener('mousedown', function(evt) { evt.stopPropagation(); }); this.get('textEditorContainer').appendChild(textShapeToolbar); this.set({ textEditorToolbar: textShapeToolbar }); this.do('initToolbarBindings'); textEditor.style.display = 'none'; // Initialize Editor window.editor = new wysihtml5.Editor("currentEditor", { // id of textarea element toolbar: "textShapeToolbar", // id of toolbar element style: false, useLineBreaks: false, parserRules: wysihtml5ParserRules, // defined in parser rules set cleanUp: true, stylesheets: ["../resources/css/SuperGlue.css"] }).on('load', function() { document.querySelector('.wysihtml5-sandbox').addEventListener('mouseenter', function() { // Hide open dropdown menus var dropdownMenuContainers = document.querySelectorAll('.dropdown-menu'); var dropdownMenus = document.querySelectorAll('.dropdown-toggle'); for (var i=0; i (window.innerWidth - 20) ? maxWidth : (window.innerWidth - 20); maxHeight = maxHeight > (window.innerHeight - 20) ? maxHeight : (window.innerHeight - 20); textEditorContainer.style.width = maxWidth + 'px'; textEditorContainer.style.height = maxHeight + 'px'; } }, initToolbarBindings: { comment: 'I initialize event bindings for the textShapeToolbar before wysihtml5 is executed.', params: {}, code: function() { var self = this; var fonts = this.class.get('activeFonts'); var fontTarget = document.querySelector('[title="Font"]').parentNode.querySelector('.dropdown-menu'); for (var i=0; i'+ fontName + ''; fontTarget.appendChild(fontBtn); } var fontSizes = this.class.get('activeFontSizes'), fontSizeTarget = document.querySelector('[title="Font Size"]').parentNode.querySelector('.dropdown-menu'); for (var s=0; s'+ fontSize + ''; fontSizeTarget.appendChild(fontSizeBtn); } document.querySelector('.hyperlink-dropdown input.text').addEventListener('keyup', function (evt) { evt.stopPropagation(); evt.preventDefault(); }); self.get('textEditorToolbar').querySelector('.hyperlink').addEventListener('click', function() { var dropdownToggleBtns = self.get('textEditorToolbar').querySelectorAll('.dropdown-toggle'); for (var i=0; i b.count) return -1; return 0; } frequencyArray.sort(compare); if ( frequencyArray.length > 5 ) { frequencyArray.slice(0, 5); } return frequencyArray; } if ( !colorpickerContainer.querySelector('.sg-colorpicker') ) { var initialColor = undefined; start(); } else if ( colorPickerConfig.initialColor ) { var initialColor = rgbString2Hex(colorPickerConfig.initialColor); updatePicker(initialColor); } // End from flexicolorPicker } } } }});