48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
var AmiStyles = function() {
|
|
var styles = new Map,
|
|
defaultStyle = undefined;
|
|
|
|
var createStyle = function(name, title, setDefault) {
|
|
if(setDefault)
|
|
defaultStyle = name;
|
|
|
|
return {
|
|
getName: function() { return name; },
|
|
getTitle: function() { return title; },
|
|
isDefault: function() { return name === defaultStyle; },
|
|
getBodyClass: function() { return 'ami-theme-' + name; },
|
|
getOptionClass: function() { return 'ami-themeOpt-' + name; },
|
|
};
|
|
};
|
|
|
|
var apply = function(name) {
|
|
var style = styles.get(name);
|
|
if(style === undefined)
|
|
throw 'this style has not been registered';
|
|
document.body.className = style.getBodyClass();
|
|
};
|
|
|
|
return {
|
|
register: function(name, title, setDefault) {
|
|
if(styles.has(name))
|
|
throw 'a style with this name has already been registered';
|
|
var styleInfo = createStyle(name, title, setDefault);
|
|
styles.set(styleInfo.getName(), styleInfo);
|
|
return styleInfo;
|
|
},
|
|
get: function(name) {
|
|
var style = styles.get(name);
|
|
if(style === undefined)
|
|
throw 'this style has not been registered';
|
|
return styles.get(name);
|
|
},
|
|
forEach: function(body) {
|
|
styles.forEach(body);
|
|
},
|
|
apply: apply,
|
|
setDefault: function() {
|
|
apply(defaultStyle);
|
|
},
|
|
};
|
|
};
|