Cleanup themeManager
This commit is contained in:
@@ -57,7 +57,6 @@ angular.module('app')
|
|||||||
authManager.loadInitialData();
|
authManager.loadInitialData();
|
||||||
syncManager.loadLocalItems(function(items) {
|
syncManager.loadLocalItems(function(items) {
|
||||||
$scope.allTag.didLoad = true;
|
$scope.allTag.didLoad = true;
|
||||||
themeManager.activateInitialTheme();
|
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
|
|
||||||
$rootScope.$broadcast("initial-data-loaded");
|
$rootScope.$broadcast("initial-data-loaded");
|
||||||
|
|||||||
@@ -20,10 +20,6 @@ class ComponentManager {
|
|||||||
|
|
||||||
this.handlers = [];
|
this.handlers = [];
|
||||||
|
|
||||||
// $rootScope.$on("theme-changed", function(){
|
|
||||||
// this.postThemeToAllComponents();
|
|
||||||
// }.bind(this))
|
|
||||||
|
|
||||||
window.addEventListener("message", function(event){
|
window.addEventListener("message", function(event){
|
||||||
if(this.loggingEnabled) {
|
if(this.loggingEnabled) {
|
||||||
console.log("Web app: received message", event);
|
console.log("Web app: received message", event);
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
class ThemeManager {
|
class ThemeManager {
|
||||||
|
|
||||||
constructor(modelManager, syncManager, $rootScope, storageManager, componentManager) {
|
constructor(componentManager) {
|
||||||
this.syncManager = syncManager;
|
|
||||||
this.modelManager = modelManager;
|
|
||||||
this.$rootScope = $rootScope;
|
|
||||||
this.storageManager = storageManager;
|
|
||||||
this.componentManager = componentManager;
|
this.componentManager = componentManager;
|
||||||
|
|
||||||
componentManager.registerHandler({identifier: "themeManager", areas: ["themes"], activationHandler: (component) => {
|
componentManager.registerHandler({identifier: "themeManager", areas: ["themes"], activationHandler: (component) => {
|
||||||
@@ -16,48 +12,8 @@ class ThemeManager {
|
|||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = this.storageManager.getItem("activeTheme");
|
|
||||||
// if(!activeThemeId) {
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// var theme = _.find(this.themes, {uuid: activeThemeId});
|
|
||||||
// return theme;
|
|
||||||
// }
|
|
||||||
|
|
||||||
activateInitialTheme() {
|
|
||||||
// var theme = this.activeTheme;
|
|
||||||
// if(theme) {
|
|
||||||
// this.activateTheme(theme);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
// submitTheme(url) {
|
|
||||||
// var name = this.displayNameForThemeFile(this.fileNameFromPath(url));
|
|
||||||
// var theme = this.modelManager.createItem({content_type: "SN|Theme", url: url, name: name});
|
|
||||||
// this.modelManager.addItem(theme);
|
|
||||||
// theme.setDirty(true);
|
|
||||||
// this.syncManager.sync();
|
|
||||||
// }
|
|
||||||
|
|
||||||
activateTheme(theme) {
|
activateTheme(theme) {
|
||||||
if(this.activeTheme && this.activeTheme !== theme) {
|
|
||||||
this.deactivateTheme(this.activeTheme);
|
|
||||||
}
|
|
||||||
|
|
||||||
var url = this.componentManager.urlForComponent(theme);
|
var url = this.componentManager.urlForComponent(theme);
|
||||||
|
|
||||||
var link = document.createElement("link");
|
var link = document.createElement("link");
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.type = "text/css";
|
link.type = "text/css";
|
||||||
@@ -65,42 +21,15 @@ class ThemeManager {
|
|||||||
link.media = "screen,print";
|
link.media = "screen,print";
|
||||||
link.id = theme.uuid;
|
link.id = theme.uuid;
|
||||||
document.getElementsByTagName("head")[0].appendChild(link);
|
document.getElementsByTagName("head")[0].appendChild(link);
|
||||||
this.storageManager.setItem("activeTheme", theme.uuid);
|
|
||||||
|
|
||||||
this.currentTheme = theme;
|
|
||||||
this.$rootScope.$broadcast("theme-changed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deactivateTheme(theme) {
|
deactivateTheme(theme) {
|
||||||
this.storageManager.removeItem("activeTheme");
|
|
||||||
var element = document.getElementById(theme.uuid);
|
var element = document.getElementById(theme.uuid);
|
||||||
if(element) {
|
if(element) {
|
||||||
element.disabled = true;
|
element.disabled = true;
|
||||||
element.parentNode.removeChild(element);
|
element.parentNode.removeChild(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.currentTheme = null;
|
|
||||||
this.$rootScope.$broadcast("theme-changed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileNameFromPath(filePath) {
|
|
||||||
return filePath.replace(/^.*[\\\/]/, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
capitalizeString(string) {
|
|
||||||
return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
|
|
||||||
}
|
|
||||||
|
|
||||||
displayNameForThemeFile(fileName) {
|
|
||||||
let fromParam = getParameterByName("name", fileName);
|
|
||||||
if(fromParam) {
|
|
||||||
return fromParam;
|
|
||||||
}
|
|
||||||
let name = fileName.split(".")[0];
|
|
||||||
let cleaned = name.split("-").join(" ");
|
|
||||||
return this.capitalizeString(cleaned);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
angular.module('app').service('themeManager', ThemeManager);
|
angular.module('app').service('themeManager', ThemeManager);
|
||||||
|
|||||||
Reference in New Issue
Block a user