Skip to content

Instantly share code, notes, and snippets.

@vegarringdal
Last active December 17, 2017 14:51
Show Gist options
  • Save vegarringdal/96d86a621c8e692612bb3fad6a7a3321 to your computer and use it in GitHub Desktop.
Save vegarringdal/96d86a621c8e692612bb3fad6a7a3321 to your computer and use it in GitHub Desktop.
Aurelia custom attribute :tiny-mce
<template>
<textarea onsave.delegate="printToConsole($event.detail)" value.bind="myText" tiny-mce></textarea>
</template>
export class BasicUse {
//helper for dummy data
constructor() {
this.myText = "This is my text set from app.js"
}
printToConsole(value){
console.log(value)
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="//cdn.tinymce.com/4/tinymce.min.js"></script>
</head>
<body aurelia-app="main">
<h1>Loading...</h1>
<script src="https://cdn.rawgit.com/vegarringdal/vGridGistRunJSPMBundle/v.1.0.7/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/vegarringdal/vGridGistRunJSPMBundle/v.1.0.7/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging()
.globalResources('tiny-mce-attribute');
aurelia.start().then(a => a.setRoot());
}
import {customAttribute} from 'aurelia-framework';
@customAttribute('tiny-mce')
export class TinyMceAttribute {
static inject = [Element]
valueChanged(newValue, oldValue) {
}
constructor(element) {
this.element = element;
}
attached() {
tinymce.init({
target: this.element,
toolbar: 'Save',
setup: (editor) => {
editor.addButton('Save', {
text: 'Save',
icon: false,
onclick: () => {
let content = editor.getContent();
this.fireEvent('onsave', content);
}
})
},
});
}
fireEvent(type, data) {
let event = new CustomEvent(type, {
detail: data,
bubbles: true
});
this.element.dispatchEvent(event);
}
detached() {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment