main.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. (function($) {
  2. $.fn.sorted = function(customOptions) {
  3. var options = {
  4. reversed: false,
  5. by: function(a) {
  6. return a.text();
  7. }
  8. };
  9. $.extend(options, customOptions);
  10. $data = $(this);
  11. arr = $data.get();
  12. arr.sort(function(a, b) {
  13. var valA = options.by($(a));
  14. var valB = options.by($(b));
  15. if (options.reversed) {
  16. return (valA < valB) ? 1 : (valA > valB) ? -1 : 0;
  17. } else {
  18. return (valA < valB) ? -1 : (valA > valB) ? 1 : 0;
  19. }
  20. });
  21. return $(arr);
  22. };
  23. })(jQuery);
  24. $(function() {
  25. var read_button = function(class_names) {
  26. var r = {
  27. selected: false,
  28. type: 0
  29. };
  30. for (var i=0; i < class_names.length; i++) {
  31. if (class_names[i].indexOf('selected-') == 0) {
  32. r.selected = true;
  33. }
  34. if (class_names[i].indexOf('segment-') == 0) {
  35. r.segment = class_names[i].split('-')[1];
  36. }
  37. };
  38. return r;
  39. };
  40. var determine_sort = function($buttons) {
  41. var $selected = $buttons.parent().filter('[class*="selected-"]');
  42. return $selected.find('a').attr('data-value');
  43. };
  44. var determine_kind = function($buttons) {
  45. var $selected = $buttons.parent().filter('[class*="selected-"]');
  46. return $selected.find('a').attr('data-value');
  47. };
  48. var $preferences = {
  49. duration: 800,
  50. easing: 'easeInOutQuad',
  51. adjustHeight: false
  52. };
  53. var $list = $('#list');
  54. var $data = $list.clone();
  55. var $controls = $('ul.splitter ul');
  56. $controls.each(function(i) {
  57. var $control = $(this);
  58. var $buttons = $control.find('a');
  59. $buttons.bind('click', function(e) {
  60. var $button = $(this);
  61. var $button_container = $button.parent();
  62. var button_properties = read_button($button_container.attr('class').split(' '));
  63. var selected = button_properties.selected;
  64. var button_segment = button_properties.segment;
  65. if (!selected) {
  66. $buttons.parent().removeClass('selected-0').removeClass('selected-1').removeClass('selected-2');
  67. $button_container.addClass('selected-' + button_segment);
  68. var sorting_type = determine_sort($controls.eq(1).find('a'));
  69. var sorting_kind = determine_kind($controls.eq(0).find('a'));
  70. if (sorting_kind == 'all') {
  71. var $filtered_data = $data.find('li');
  72. } else {
  73. var $filtered_data = $data.find('li.' + sorting_kind);
  74. }
  75. if (sorting_type == 'size') {
  76. var $sorted_data = $filtered_data.sorted({
  77. by: function(v) {
  78. return parseFloat($(v).find('span').text());
  79. }
  80. });
  81. } else {
  82. var $sorted_data = $filtered_data.sorted({
  83. by: function(v) {
  84. return $(v).find('strong').text().toLowerCase();
  85. }
  86. });
  87. }
  88. $list.quicksand($sorted_data, $preferences);
  89. }
  90. e.preventDefault();
  91. });
  92. });
  93. var high_performance = true;
  94. var $performance_container = $('#performance-toggle');
  95. var $original_html = $performance_container.html();
  96. $performance_container.find('a').live('click', function(e) {
  97. if (high_performance) {
  98. $preferences.useScaling = false;
  99. $performance_container.html('CSS3 scaling turned off. Try the demo again. <a href="#toggle">Reverse</a>.');
  100. high_performance = false;
  101. } else {
  102. $preferences.useScaling = true;
  103. $performance_container.html($original_html);
  104. high_performance = true;
  105. }
  106. e.preventDefault();
  107. });
  108. });