-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a rich text editor cell editor for source html. Made this…
… testable on Expedia and through a new site adapter for Blogger.
- Loading branch information
1 parent
1fd4a2a
commit be106c4
Showing
8 changed files
with
143 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#open-apps-rich-text-editor-container { | ||
background-color: white; | ||
padding: 20px; | ||
position: fixed; | ||
height: 500px; | ||
width: 700px; | ||
bottom: 100px; | ||
right: 50px; | ||
z-index: 1000; | ||
} | ||
|
||
.cke_show_borders { | ||
overflow: scroll; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import Handsontable from 'handsontable'; | ||
import ClassicEditor from '@ckeditor/ckeditor5-build-classic'; | ||
|
||
import './richTextEditor.css' | ||
|
||
let TEXTAREA_ID = "open-apps-rich-text-editor"; | ||
|
||
function htmlToElement(html) { | ||
var template = document.createElement('template'); | ||
html = html.trim(); | ||
template.innerHTML = html; | ||
return template.content.firstChild; | ||
} | ||
|
||
class RichTextEditor extends Handsontable.editors.BaseEditor { | ||
constructor(hotInstance) { | ||
super(hotInstance); | ||
} | ||
|
||
init(){ | ||
this.text = this.originalValue; | ||
this.initializeHTML(); | ||
} | ||
|
||
getValue(){ | ||
return this.editor.getData(); | ||
} | ||
|
||
setValue(newValue){ | ||
this.text = newValue; | ||
} | ||
|
||
open(){ | ||
let oldValue = document.getElementById(TEXTAREA_ID).value; | ||
|
||
//Has to update the textarea for the rich text editor api to update as well | ||
if(this.text !== oldValue){ | ||
this.destroyEditor(); | ||
document.getElementById(TEXTAREA_ID).value = this.text; | ||
this.createEditor(); | ||
} | ||
|
||
this.textEditorDiv.style.display = ''; | ||
} | ||
|
||
initializeHTML(){ | ||
this.textEditorDiv = htmlToElement(`<div id="open-apps-rich-text-editor-container"><textarea id=${TEXTAREA_ID}>${this.text}</textarea></div>`); | ||
document.body.appendChild(this.textEditorDiv); | ||
|
||
this.createEditor(); | ||
|
||
this.textEditorDiv.style.display = "none"; | ||
this.textEditorDiv.addEventListener('mousedown', e => { | ||
event.stopPropagation(); | ||
}); | ||
} | ||
|
||
createEditor(){ | ||
this.richTextEditor = ClassicEditor.create( document.querySelector(`#${TEXTAREA_ID}`)) | ||
.then( newEditor => { | ||
this.editor = newEditor; | ||
}) | ||
.catch( error => { | ||
console.error(error); | ||
}); | ||
} | ||
|
||
destroyEditor(){ | ||
this.editor.destroy() | ||
.catch( error => { | ||
console.log( error ); | ||
}); | ||
} | ||
|
||
close(){ | ||
this.textEditorDiv.style.display = 'none'; | ||
} | ||
|
||
focus(){ | ||
this.textEditorDiv.focus(); | ||
} | ||
} | ||
|
||
export {RichTextEditor}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { RichTextEditor } from '../cell_editors/richTextEditor.js' | ||
|
||
export const BloggerAdapter = { | ||
name: "Blogger", | ||
urlPattern: "blogger.com", | ||
colSpecs: [ | ||
{ name: "id", type: "text", hidden: true }, | ||
{ name: "document", editable: true, renderer: 'html', type: "text", editor: RichTextEditor }, | ||
{ name: "source", editable: true, renderer: 'html', type: "text", editor: RichTextEditor }, | ||
], | ||
getDataRows: () => { | ||
let container = document.getElementById("blogger-app"); | ||
console.log(container); | ||
let container2 : HTMLElement = container; | ||
return [ | ||
{ | ||
el: container2, | ||
dataValues: { | ||
id: 1, // only one row so we can just hardcode an ID | ||
document: container.querySelector("#postingComposeBox"), | ||
source: container.querySelector("#postingHtmlBox"), | ||
} | ||
} | ||
] | ||
}, | ||
// Reload data anytime there's a click or keypress on the page | ||
setupReloadTriggers: (reload) => { | ||
document.addEventListener("click", (e) => { reload() }); | ||
document.addEventListener("keydown", (e) => { reload() }); | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters