editor themes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user