-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy paththemeroller.js
98 lines (88 loc) · 3.77 KB
/
themeroller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var _ = require( "underscore" ),
config = require( "./config" ),
fs = require( "fs" ),
Handlebars = require( "handlebars" ),
querystring = require( "querystring" ),
textures = require( "./lib/themeroller.textures" ),
themeGallery = require( "./lib/themeroller.themegallery" ),
ThemeRoller = require( "./lib/themeroller" );
// Returns 'selected="selected"' if param == value
Handlebars.registerHelper( "selected", function( param, value ) {
return param == value ? "selected=\"selected\"" : "";
});
// Returns select options with textures - configured to each theme group
Handlebars.registerHelper( "textureOptions", function( select, panel ) {
var optSet = "";
textures.forEach(function( texture ) {
var name = texture.file.split( "." )[ 0 ].split( "_" ).slice( 1 ).join( " " ),
selected = texture.file == select ? " selected=\"selected\"" : "",
texturedims = [ texture.width, texture.height ];
// large images need hard coded icon sizes to be useful
if ( texture.width * texture.height >= 360000 ) {
texturedims = [ 16, 16 ];
}
// tall panel element (content, overlay, shadow, etc), don't allow glass texture
if ( panel === "true" ) {
if( texture.file != "02_glass.png" ) {
optSet += "<option value=\"" + texture.file + "\"" + selected + " data-texturewidth=\"" + texturedims[0] + "\" data-textureheight=\"" + texturedims[1] + "\">" + name + "</option>";
}
} else {
optSet += "<option value=\"" + texture.file + "\"" + selected + " data-texturewidth=\"" + texturedims[0] + "\" data-textureheight=\"" + texturedims[1] + "\">" + name + "</option>";
}
});
return optSet;
});
Handlebars.registerHelper( "themeParams", function( serializedVars ) {
return serializedVars.length > 0 ? "?themeParams=" + escape( serializedVars ) : "";
});
var appinterfaceTemplate = Handlebars.compile( fs.readFileSync( __dirname + "/template/themeroller/appinterface.html", "utf8" ) ),
helpTemplate = Handlebars.compile( fs.readFileSync( __dirname + "/template/themeroller/help.html", "utf8" ) ),
indexTemplate = Handlebars.compile( fs.readFileSync( __dirname + "/template/themeroller/index.html", "utf8" ) ),
jsonpTemplate = Handlebars.compile( fs.readFileSync( __dirname + "/template/jsonp.js", "utf8" ) ),
rollyourownTemplate = Handlebars.compile( fs.readFileSync( __dirname + "/template/themeroller/rollyourown.html", "utf8" ) ),
themegalleryTemplate = Handlebars.compile( fs.readFileSync( __dirname + "/template/themeroller/themegallery.html", "utf8" ) ),
wrapTemplate = Handlebars.compile( fs.readFileSync( __dirname + "/template/themeroller/wrap.html", "utf8" ) );
var Frontend = function( args ) {
_.extend( this, args );
};
Frontend.prototype = {
index: function( vars, options ) {
var theme = new ThemeRoller( vars );
options = options || {};
if ( options.wrap ) {
options = _.defaults( { wrap: false }, options );
return wrapTemplate({
body: this.index( vars, options ),
resources: this.resources
});
}
return indexTemplate({
appinterface: appinterfaceTemplate({
help: helpTemplate(),
rollyourown: rollyourownTemplate( theme ),
themegallery: themegalleryTemplate({
themeGallery: themeGallery
})
}),
baseVars: themeGallery[ 2 ].serializedVars,
host: this.host,
imageGeneratorUrl: "http://" + config.imageGeneratorHost + config.imageGeneratorPath + "/",
resources: this.resources
});
},
css: function( vars ) {
var theme = new ThemeRoller( _.extend( { dynamicImage: true }, vars ) );
return theme.css();
},
gallery: function() {
return themeGallery;
},
rollYourOwn: function( params ) {
var theme = new ThemeRoller( querystring.parse( unescape( params.themeParams ) ) );
return jsonpTemplate({
callback: params.callback,
data: JSON.stringify( rollyourownTemplate( theme ) )
});
}
};
module.exports = Frontend;