Files
slackthemes/source/javascripts/all.js.erb
T

72 lines
2.2 KiB
ERB
Raw Normal View History

2015-03-17 01:24:29 +02:00
//= require_tree .
var app = angular.module('theme', ['ui.router']);
2015-03-17 02:01:28 +02:00
app.config(['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
2015-03-17 01:24:29 +02:00
$stateProvider
.state('theme', {
2015-03-17 02:01:28 +02:00
url: "/:slug",
controller: 'ThemeController',
params: {
slug: { value: '<%= themes.first.slug %>' }
}
2015-03-17 01:24:29 +02:00
});
2015-03-17 02:01:28 +02:00
$urlRouterProvider.otherwise('/<%= themes.first.slug %>');
2015-03-17 01:24:29 +02:00
}]);
app.controller('ThemeController', ['$scope', '$stateParams', '$state', '$location',
function($scope, $stateParams, $state, $location) {
var themes = {
2015-03-17 01:24:29 +02:00
<%= themes.map do |theme|
"'#{theme.slug}': '#{theme.colors}'"
end.join ",\n" %>
};
$scope.$on('$stateChangeSuccess', function() {
2015-03-31 20:34:04 -04:00
$scope.slug = $stateParams.slug;
2015-03-17 01:24:29 +02:00
});
$scope.$watch('slug', function(slug) {
if (!slug) {
return;
}
if (slug === 'custom') {
$scope.colors = $location.hash().split(',').map(function(part) {
return '#' + part;
}).join(',');
return;
}
$scope.colors = themes[$scope.slug];
2015-03-17 01:24:29 +02:00
$state.go('theme', { slug: slug });
});
$scope.$watch('colors', function(colors) {
if (!colors) {
return;
}
var parts = colors.split(',');
$scope.column_bg = parts[0];
$scope.menu_bg = parts[1];
$scope.active_item = parts[2];
$scope.active_item_text = parts[3];
$scope.hover_item = parts[4];
$scope.text_color = parts[5];
$scope.active_presence = parts[6];
$scope.mention_badge = parts[7];
function updateHash() {
$location.hash(parts.map(function(part) {
return part.replace('#', '');
}));
}
if ($scope.slug === 'custom') {
updateHash();
} else if (colors !== themes[$scope.slug]) {
$state.go('theme', { slug: 'custom' }).then(updateHash);
}
2015-03-17 01:24:29 +02:00
});
}]);