diff --git a/source/index.html.erb b/source/index.html.erb index 050d667..10621d3 100644 --- a/source/index.html.erb +++ b/source/index.html.erb @@ -5,6 +5,6 @@ title: Slack Themes <% themes.each do |theme| %> <% end %> diff --git a/source/javascripts/all.js b/source/javascripts/all.js deleted file mode 100644 index cd23351..0000000 --- a/source/javascripts/all.js +++ /dev/null @@ -1,18 +0,0 @@ -//= require_tree . - -angular.module('theme', []) - .controller('ThemeController', ['$scope', function($scope) { - $scope.$watch( - function() { return $scope.theme; }, - function(theme) { - parts = theme.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]; - }); - }]); diff --git a/source/javascripts/all.js.erb b/source/javascripts/all.js.erb new file mode 100644 index 0000000..e97b870 --- /dev/null +++ b/source/javascripts/all.js.erb @@ -0,0 +1,48 @@ +//= require_tree . + +var app = angular.module('theme', ['ui.router']); + +app.config(['$stateProvider', + function($stateProvider) { + $stateProvider + .state('theme', { + url: "/{slug}", + controller: 'ThemeController' + }); + }]); + +app.controller('ThemeController', ['$scope', '$stateParams', '$state', + function($scope, $stateParams, $state) { + var colors = { + <%= themes.map do |theme| + "'#{theme.slug}': '#{theme.colors}'" + end.join ",\n" %> + }; + + $scope.$on('$stateChangeSuccess', function() { + $scope.slug = $stateParams.slug; + }); + + $scope.$watch('slug', function(slug) { + if (!slug) { + return; + } + $scope.colors = colors[$scope.slug] + $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]; + }); + }]); diff --git a/source/layouts/layout.erb b/source/layouts/layout.erb index 82dbfb6..81987c8 100644 --- a/source/layouts/layout.erb +++ b/source/layouts/layout.erb @@ -10,6 +10,7 @@