Skip to content

Instantly share code, notes, and snippets.

@BatJan
Created October 25, 2018 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BatJan/66b105d39636f65a90821e4053f81a15 to your computer and use it in GitHub Desktop.
Save BatJan/66b105d39636f65a90821e4053f81a15 to your computer and use it in GitHub Desktop.
function EditorThemeColorPickerController($scope,localizationService, contentResource){
var contentId;
//Figure out whether we're working locally or live...surely this can be done a better way? But does not seem that it's possible to lookup aliases using the API's currently :-/
if(location.hostname.indexOf('localhost') === 0){
contentId = 1920;
} else{
contentId = 2123;
}
//Setup array to hold color themes
$scope.colorThemes = []
//Get colors
contentResource.getChildren(contentId).then(function(contentArray){
var colorItems = contentArray.items;
for (var i = 0; i < colorItems.length; i++) {
var colorItem = colorItems[i],
colorTheme = colorItem.properties[0].value;
$scope.colorThemes.push(colorTheme);
}
//Let's initialize the model with a default value
if(!angular.isObject($scope.model.value)){
var colorThemeObj = {
backgroundColor: $scope.colorThemes[0].backgroundColor,
textColor: $scope.colorThemes[0].textColor,
isDefault: true,
id:0
}
$scope.model.value = colorThemeObj;
}
$scope.selectTheme = function(idx){
$scope.model.value.backgroundColor = $scope.colorThemes[idx].backgroundColor;
$scope.model.value.textColor = $scope.colorThemes[idx].textColor;
$scope.model.value.isDefault = true;
$scope.model.value.id = idx;
}
});
}
//Inject the controller into the umbraco context
angular.module("umbraco").controller("Our.Umbraco.EditorThemeColorPickerController", EditorThemeColorPickerController);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment