A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.1 KiB

  1. extends layout
  2. block content
  3. div.uk-grid
  4. br
  5. br
  6. div.uk-width-1-1
  7. div.uk-panel.uk-panel-box
  8. div.uk-badge.uk-float-right
  9. form.uk-search
  10. input(class='uk-search-field', type='search', placeholder='Search...')
  11. button(class='uk-close', type='reset')
  12. table.uk-table.uk-table-hover.uk-table-striped
  13. caption Potato Farmer Ladder Rankings
  14. thead
  15. tr
  16. th Rank
  17. th Viewer
  18. th Potatoes
  19. tbody
  20. ul.uk-pagination
  21. block postscript
  22. script.
  23. var perPage = 20,
  24. data = !{JSON.stringify(rows)};
  25. $(document).ready(function(){
  26. // Live search of the ladder listings
  27. $('.uk-search-field').keyup(function() {
  28. var query = $(this).val();
  29. if(query.length > 2) {
  30. var temp = $('.uk-active').attr('page');
  31. $('.uk-active').removeClass('uk-active').empty().append('<a>'+temp+'</a>');
  32. $('table > tbody').empty();
  33. data.forEach(function(element, index, array) {
  34. if(element.user.search(new RegExp(query, 'i')) != -1) {
  35. $('table > tbody').append($('<tr></tr>').append('<td>'+index+'</td><td>'+element.user+'</td><td>'+element.points+'</td>'));
  36. }
  37. });
  38. }
  39. });
  40. // Create pagination buttons
  41. for(var i = 1; i <= Math.ceil(data.length/perPage); i++) {
  42. var button = $('<li page='+i+'></li>').append('<a>'+i+'</a>');
  43. button.on('click', function(){
  44. //get page
  45. var z = $(this).attr('page');
  46. // cleanup
  47. var temp = $('.uk-active').attr('page');
  48. $('.uk-active').removeClass('uk-active').empty().append('<a>'+temp+'</a>');
  49. $('table > tbody').empty();
  50. $(this).addClass('uk-active').empty().append('<span>'+z+'</span>');
  51. // slice(a, b): a = (n*(x-1))+1, b = n*x where n = perPage and x=curerntPage (skip +1 at end of a for splice)
  52. var a = (perPage*(z-1)),
  53. b = perPage*z;
  54. data.slice(a, b).forEach(function(element, index, array){
  55. $('table > tbody').append($('<tr></tr>').append('<td>'+(a+index+1)+'</td><td>'+element.user+'</td><td>'+element.points+'</td>'));
  56. });
  57. });
  58. $('.uk-pagination').append(button);
  59. }
  60. // When search input is cleared, go back to first page
  61. $('.uk-close').on('click', function(){
  62. $('ul.uk-pagination > li').first().click();
  63. });
  64. // Show the first page when we load up
  65. $('ul.uk-pagination > li').first().click();
  66. });