editor themes

This commit is contained in:
Mo Bitar
2017-04-20 09:42:59 -05:00
parent 0fcd439736
commit ad92c0894d
2 changed files with 42 additions and 6 deletions

View File

@@ -23,7 +23,11 @@ angular.module('app.frontend')
}
}
})
.controller('EditorCtrl', function ($sce, $timeout, authManager, $rootScope, extensionManager, syncManager, modelManager, editorManager) {
.controller('EditorCtrl', function ($sce, $timeout, authManager, $rootScope, extensionManager, syncManager, modelManager, editorManager, themeManager) {
$rootScope.$on("theme-changed", function(){
this.postThemeToExternalEditor();
}.bind(this))
window.addEventListener("message", function(event){
if(event.data.status) {
@@ -118,13 +122,33 @@ angular.module('app.frontend')
return _.find(editors, {default: true});
}
this.postNoteToExternalEditor = function() {
this.postDataToExternalEditor = function(data) {
var externalEditorElement = document.getElementById("editor-iframe");
if(externalEditorElement) {
externalEditorElement.contentWindow.postMessage({text: this.note.text, data: this.editor.dataForKey(this.note.uuid), id: this.note.uuid}, '*');
externalEditorElement.contentWindow.postMessage(data, '*');
}
}
function themeData() {
return {
themes: [themeManager.currentTheme ? themeManager.currentTheme.url : null]
}
}
this.postThemeToExternalEditor = function() {
this.postDataToExternalEditor(themeData())
}
this.postNoteToExternalEditor = function() {
var data = {
text: this.note.text,
data: this.editor.dataForKey(this.note.uuid),
id: this.note.uuid,
}
_.merge(data, themeData());
this.postDataToExternalEditor(data);
}
this.hasAvailableExtensions = function() {
return extensionManager.extensionsInContextOfItem(this.note).length > 0;
}

View File

@@ -1,14 +1,20 @@
class ThemeManager {
constructor(modelManager, syncManager) {
this.syncManager = syncManager;
this.modelManager = modelManager;
constructor(modelManager, syncManager, $rootScope) {
this.syncManager = syncManager;
this.modelManager = modelManager;
this.$rootScope = $rootScope;
}
get themes() {
return this.modelManager.itemsForContentType("SN|Theme");
}
/*
activeTheme: computed property that returns saved theme
currentTheme: stored variable that allows other classes to watch changes
*/
get activeTheme() {
var activeThemeId = localStorage.getItem("activeTheme");
if(!activeThemeId) {
@@ -48,6 +54,9 @@ class ThemeManager {
link.id = theme.uuid;
document.getElementsByTagName("head")[0].appendChild(link);
localStorage.setItem("activeTheme", theme.uuid);
this.currentTheme = theme;
this.$rootScope.$broadcast("theme-changed");
}
deactivateTheme(theme) {
@@ -57,6 +66,9 @@ class ThemeManager {
element.disabled = true;
element.parentNode.removeChild(element);
}
this.currentTheme = null;
this.$rootScope.$broadcast("theme-changed");
}
isThemeActive(theme) {