Last active
December 17, 2017 14:51
-
-
Save vegarringdal/96d86a621c8e692612bb3fad6a7a3321 to your computer and use it in GitHub Desktop.
Aurelia custom attribute :tiny-mce
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
<template> | |
<textarea onsave.delegate="printToConsole($event.detail)" value.bind="myText" tiny-mce></textarea> | |
</template> |
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
export class BasicUse { | |
//helper for dummy data | |
constructor() { | |
this.myText = "This is my text set from app.js" | |
} | |
printToConsole(value){ | |
console.log(value) | |
} | |
} |
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
<!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> |
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
export function configure(aurelia) { | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging() | |
.globalResources('tiny-mce-attribute'); | |
aurelia.start().then(a => a.setRoot()); | |
} |
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
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