Skip to content

Instantly share code, notes, and snippets.

@ryanlntn
Created May 25, 2017 07:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanlntn/ac346d361d9e10a8f1888bf59cea0e37 to your computer and use it in GitHub Desktop.
Save ryanlntn/ac346d361d9e10a8f1888bf59cea0e37 to your computer and use it in GitHub Desktop.
Custom Thesis HTML Editor Example
import $ from 'jquery'
import './vendor/trumbowyg.min'
class CustomEditor {
constructor (opts) {
this.editors = document.querySelectorAll('.thesis-content-html')
this.enabled = false
this.onChange = opts.onChange
this.changedHtmlEditor = this.changedHtmlEditor.bind(this)
}
enable () {
if (this.enabled) return
if (this.editors.length > 0) {
$(this.editors).trumbowyg({
btns: [
['viewHTML'],
'btnGrp-design',
['formatting'],
['link'],
['justifyLeft', 'justifyCenter', 'justifyRight'],
'btnGrp-lists',
['removeformat'],
['fullscreen']
]
})
$('.trumbowyg-box').css('z-index', 9999)
$(this.editors).on('tbwchange', this.changedHtmlEditor)
}
this.enabled = true
}
disable () {
if (!this.enabled) return
$(this.editors).trumbowyg('destroy')
this.enabled = false
}
content (ed) {
return ed.innerHTML
}
set (name, data) {
const ed = document.querySelector(`[data-thesis-content-id='${name}']`)
if (!ed) return
ed.innerHTML = data.content
ed.classList.add('modified')
}
changedHtmlEditor (event) {
event.target.classList.add('modified')
this.onChange()
}
}
window.CustomEditor = CustomEditor
export default CustomEditor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment