settings.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Generated by CoffeeScript 1.3.3
  2. (function() {
  3. var STORAGE_NAME, setall, visible;
  4. STORAGE_NAME = 'tvgids-channels';
  5. visible = localStorage.hasOwnProperty(STORAGE_NAME) ? localStorage.getItem(STORAGE_NAME).split(';') : _.pluck(CHANNELS, 'id');
  6. _.each(CHANNELS, function(channel) {
  7. var elem, input, is_visible;
  8. is_visible = _.contains(visible, channel.id);
  9. input = $('<input type="checkbox" name="channels[]" value="' + channel.id + '">');
  10. input.attr('checked', is_visible);
  11. input.change(function() {
  12. return $(this).parent().toggleClass('disabled', !$(this).is(':checked'));
  13. });
  14. input.change(function() {
  15. return $('#select-channels').submit();
  16. });
  17. elem = $('<label/>').html(channel.name);
  18. elem.prepend(input);
  19. elem.toggleClass('disabled', !is_visible);
  20. return elem.appendTo('#select-channels .options');
  21. });
  22. $('#select-channels').submit(function(e) {
  23. var i, selected;
  24. e.preventDefault();
  25. selected = (function() {
  26. var _i, _len, _ref, _results;
  27. _ref = $('input', this);
  28. _results = [];
  29. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  30. i = _ref[_i];
  31. if ($(i).is(':checked')) {
  32. _results.push($(i).val());
  33. }
  34. }
  35. return _results;
  36. }).call(this);
  37. return localStorage.setItem(STORAGE_NAME, selected.join(';'));
  38. });
  39. setall = function(c) {
  40. return $('#select-channels input').prop('checked', c).change();
  41. };
  42. $('#select-all').click(function() {
  43. return setall(true);
  44. });
  45. $('#select-none').click(function() {
  46. return setall(false);
  47. });
  48. }).call(this);