Styled Rankings

This commit is contained in:
Nick Eyre
2014-06-04 23:17:38 -07:00
parent c1a4e4cce4
commit 9fdcac26e9
4 changed files with 138 additions and 26 deletions

View File

@@ -8,12 +8,15 @@ var app = angular
app.controller('RankingsController', ['$scope', 'Rankings', '$interval', function($scope, Rankings, $interval){
$scope.date = new Date();
// Load Rankings
init();
function init(){
Rankings.get().then(function(data){
$scope.rankingsOld = data;
$scope.rankingsNew = data;
setTimeout(equalize, 0);
setTimeout(detectListSize, 0);
});
}
@@ -21,7 +24,7 @@ app.controller('RankingsController', ['$scope', 'Rankings', '$interval', functio
// Detect if List is Long Enough to Require Scrolling
function detectListSize(){
$('.new').hide();
if($(document).height() > $(window).height()){
if($('#container table').height() > $('#container').height()){
$('.new').show();
setTimeout(scrollToBottom, 0);
}
@@ -29,10 +32,11 @@ app.controller('RankingsController', ['$scope', 'Rankings', '$interval', functio
// Scroll to Bottom of List
function scrollToBottom(){
$('body').animate({scrollTop: $('.old').first().offset().top}, 0);
$scope.interval = $interval(loadNewData, 10);
var time = 500 * $scope.rankingsOld.length;
$('body').animate({scrollTop: $('.new').first().offset().top}, time, 'linear', scrollComplete);
var offset = $('#container').offset().top;
$('#container').animate({scrollTop: $('.old').first().offset().top - offset}, 0);
// $scope.interval = $interval(loadNewData, 10);
var time = 1000 * $scope.rankingsOld.length;
$('#container').animate({scrollTop: $('.new').first().offset().top - offset}, time, 'linear', scrollComplete);
}
// Go Back to Top
@@ -50,10 +54,30 @@ app.controller('RankingsController', ['$scope', 'Rankings', '$interval', functio
$scope.rankingsOld = $scope.rankingsNew;
$scope.rankingsNew = data;
$interval.cancel($scope.interval);
setTimeout(equalize, 0);
});
}
}
// Balance Column Widths
function equalize(){
var width = $('#container table').width();
var count = $('#container tr').first().children('td').length;
var offset = ($(window).width() - width) / (count + 1);
var widths = [];
$('#container tr').first().children('td').each(function(){
var width = $(this).width()+offset;
$(this).width(width);
widths.push(width);
});
$('#header').children('td').each(function(index){
$(this).width(widths[index]);
});
$('#container tr.new').children('td').each(function(index){
$(this).width(widths[index]);
});
}
}]);
app.factory('Rankings', ['$http', '$log', '$q', function($http, $log, $q){
@@ -62,7 +86,7 @@ app.factory('Rankings', ['$http', '$log', '$q', function($http, $log, $q){
var deferred = $q.defer();
$http.get('/reports/json/rankings').
success(function(data, status, headers, config) {
data[0]['TeamId'] = jQuery.now();
// data[0]['TeamId'] = jQuery.now();
deferred.resolve(data);
}).
error(function(data, status, headers, config) {
@@ -71,4 +95,4 @@ app.factory('Rankings', ['$http', '$log', '$q', function($http, $log, $q){
return deferred.promise;
}
};
}]);
}]);