Skip to content

Commit

Permalink
Convert the project colors to RGB and use them in the CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenwalker committed Apr 19, 2019
1 parent c0e9c55 commit 872a4f6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/css/metacatui-common.css
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,7 @@ img[src*="googleapis.com/"].georegion-map{
}
.project-display-text{
box-sizing: border-box;
background-color: rgba(0,0,0,.5);
background-color: var(--project-primary-color-transparent);
padding: 20px;
}
.logo-container{
Expand Down
29 changes: 26 additions & 3 deletions src/js/models/ProjectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ define(["jquery",
//The MapModel
mapModel: gmaps ? new MapModel() : null,
//Project view colors, as specified in the project document options
primaryColor: "#333",
secondaryColor: "#333",
accentColor: "#333"
primaryColor: "",
secondaryColor: "",
accentColor: "",
primaryColorRGB: null,
secondaryColorRGB: null,
accentColorRGB: null,
});
},

Expand Down Expand Up @@ -199,6 +202,17 @@ define(["jquery",

});

//Convert all the hex colors to rgb
if(modelJSON.primaryColor){
modelJSON.primaryColorRGB = this.hexToRGB(modelJSON.primaryColor);
}
if(modelJSON.secondaryColor){
modelJSON.secondaryColorRGB = this.hexToRGB(modelJSON.secondaryColor);
}
if(modelJSON.accentColor){
modelJSON.accentColorRGB = this.hexToRGB(modelJSON.accentColor);
}

if (gmaps) {
//Create a MapModel with all the map options
modelJSON.mapModel = new MapModel();
Expand Down Expand Up @@ -286,6 +300,15 @@ define(["jquery",
});

return filters;
},

hexToRGB: function(hex){
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}

});
Expand Down
4 changes: 4 additions & 0 deletions src/js/templates/project/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
--project-primary-color: <%=primaryColor%>;
--project-secondary-color: <%=secondaryColor%>;
--project-accent-color: <%=accentColor%>;
--project-primary-color-transparent: <%=primaryColorTransparent%>;
--project-secondary-color-transparent: <%=secondaryColorTransparent%>;
--project-accent-color-transparent: <%=accentColorTransparent%>;

}
</style>
</div>
16 changes: 15 additions & 1 deletion src/js/views/project/ProjectView.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,22 @@ define(["jquery",

renderProject: function() {

//Make the JSON to send to the template
var templateVariables = this.model.toJSON();

//Make the color rgba string
templateVariables.primaryColorTransparent = "rgba(" + this.model.get("primaryColorRGB").r +
"," + this.model.get("primaryColorRGB").g + "," + this.model.get("primaryColorRGB").b +
", .5)";
templateVariables.secondaryColorTransparent = "rgba(" + this.model.get("secondaryColorRGB").r +
"," + this.model.get("secondaryColorRGB").g + "," + this.model.get("secondaryColorRGB").b +
", .5)";
templateVariables.accentColorTransparent = "rgba(" + this.model.get("accentColorRGB").r +
"," + this.model.get("accentColorRGB").g + "," + this.model.get("accentColorRGB").b +
", .5)";

// Insert the overall project template
this.$el.html(this.template(this.model.toJSON()));
this.$el.html(this.template(templateVariables));

//Render the header view
this.headerView = new ProjectHeaderView({
Expand Down

0 comments on commit 872a4f6

Please sign in to comment.