Advertisement
Guest User

Untitled

a guest
May 2nd, 2015
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ga('send', 'pageview', '/index.html');
  2.  
  3. $(document).ready(function() {
  4.   $('#new-task').on('click', function(e) {
  5.     return ga('send', 'event', 'New task focused', 'click');
  6.   });
  7.   $('#add-link').on('click', function(e) {
  8.     return ga('send', 'event', 'Add link button', 'click');
  9.   });
  10.   $('#task-submit').on('click', function(e) {
  11.     return ga('send', 'event', 'Add task button', 'click');
  12.   });
  13.   $('#clear-completed').on('click', function(e) {
  14.     return ga('send', 'event', 'Clear completed', 'click');
  15.   });
  16.   return $('#export-tasks').on('click', function(e) {
  17.     return ga('send', 'event', 'Export tasks', 'click');
  18.   });
  19. });
  20.  
  21. document.querySelector('#task-list').addEventListener('slip:reorder', function(e) {
  22.   return ga('send', 'event', 'Reorder', 'click');
  23. });
  24.  
  25. $(document).on('click', '.drag-handle', function() {
  26.   return ga('send', 'event', 'Reorder with handle', 'click');
  27. });
  28.  
  29. $(document).on('click', '.priority', function() {
  30.   return ga('send', 'event', 'Priority', 'click');
  31. });
  32.  
  33. $(document).on('mousedown', '.task > label', function() {
  34.   return ga('send', 'event', 'Complete task', 'click');
  35. });
  36.  
  37. $(document).on('click', '.task-link', function() {
  38.   return ga('send', 'event', 'Task link', 'click');
  39. });
  40.  
  41. $(document).on('click', '#whats-new-close', function() {
  42.   return ga('send', 'event', 'Close Whats New', 'click');
  43. });
  44.  
  45. $(document).on('click', '#tour-bus-1', function() {
  46.   return ga('send', 'event', 'Onboarding', 'click', 'Step 1', 33);
  47. });
  48.  
  49. $(document).on('click', '#tour-bus-2', function() {
  50.   return ga('send', 'event', 'Onboarding', 'click', 'Step 2', 33);
  51. });
  52.  
  53. $(document).on('click', '#tour-bus-3', function() {
  54.   return ga('send', 'event', 'Onboarding', 'click', 'Step 3', 33);
  55. });
  56.  
  57. var checkOnline, checkStorageMethod, setPopupClass, standardLog;
  58.  
  59. setPopupClass = function() {
  60.   var isPopup;
  61.   isPopup = Utils.getUrlParameter('popup') === 'true';
  62.   if (isPopup) {
  63.     $('body').addClass('popup');
  64.     return $('#expand').show();
  65.   }
  66. };
  67.  
  68. checkStorageMethod = function() {
  69.   if (!!window.chrome && chrome.storage) {
  70.     console.log('Using chrome.storage.sync to save');
  71.     return window.storageType = ChromeStorage;
  72.   } else {
  73.     console.log('Using localStorage to save');
  74.     return window.storageType = LocalStorage;
  75.   }
  76. };
  77.  
  78. checkOnline = function() {
  79.   var online;
  80.   online = navigator.onLine;
  81.   if (online === true) {
  82.     console.log('Connected to the internet');
  83.     return setTimeout((function() {
  84.       return $('#empty-state-image').css('background-image', 'url("https://unsplash.it/680/440/?random")');
  85.     }), 0);
  86.   } else {
  87.     return console.log('Disconnected from the internet');
  88.   }
  89. };
  90.  
  91. standardLog = function() {
  92.   console.log('Super Simple Tasks v2.0.5');
  93.   return console.log('Like looking under the hood? Feel free to help make Super Simple Tasks better at https://github.com/humphreybc/super-simple-tasks');
  94. };
  95.  
  96. $(document).ready(function() {
  97.   var $link_input, $new_task_input, KeyPress, addLinkTriggered, addTaskTriggered, initialize, nextTourBus, tour;
  98.   setPopupClass();
  99.   standardLog();
  100.   checkStorageMethod();
  101.   checkOnline();
  102.   $new_task_input = $('#new-task');
  103.   $link_input = $('#add-link-input');
  104.   window.tourRunning = false;
  105.   tour = $('#tour').tourbus({
  106.     onStop: Views.finishTour,
  107.     onLegStart: function(leg, bus) {
  108.       window.tourRunning = bus.running;
  109.       return leg.$el.addClass('animated fadeInDown');
  110.     }
  111.   });
  112.   initialize = function() {
  113.     return window.storageType.get(DB.db_key, function(allTasks) {
  114.       if (allTasks === null) {
  115.         allTasks = Arrays.default_data;
  116.         window.storageType.set(DB.db_key, allTasks);
  117.       }
  118.       ga('send', {
  119.         'hitType': 'event',
  120.         'eventCategory': 'Data',
  121.         'eventAction': 'Task count',
  122.         'eventValue': allTasks.length
  123.       });
  124.       Migrations.run(allTasks);
  125.       Views.showTasks(allTasks);
  126.       $new_task_input.focus();
  127.       Views.checkOnboarding(allTasks, tour);
  128.       Views.checkWhatsNew();
  129.       return setTimeout((function() {
  130.         return $('#main-content').addClass('content-show');
  131.       }), 150);
  132.     });
  133.   };
  134.   nextTourBus = function() {
  135.     if (window.tourRunning) {
  136.       return tour.trigger('next.tourbus');
  137.     }
  138.   };
  139.   $('#whats-new-close').click(function(e) {
  140.     $('.whats-new').hide();
  141.     return Views.closeWhatsNew();
  142.   });
  143.   addTaskTriggered = function() {
  144.     var link, name;
  145.     nextTourBus();
  146.     name = $new_task_input.val();
  147.     if (name !== '') {
  148.       $('#task-submit').removeClass('task-submit-button');
  149.       $('#task-submit').addClass('task-submitted');
  150.       setTimeout((function() {
  151.         $('#task-submit').removeClass('task-submitted');
  152.         return $('#task-submit').addClass('task-submit-button');
  153.       }), 1000);
  154.       link = $link_input.val();
  155.       Task.setNewTask(name, link);
  156.       $new_task_input.val('');
  157.       $link_input.val('');
  158.     }
  159.     return $new_task_input.focus();
  160.   };
  161.   addLinkTriggered = function() {
  162.     if ($('#add-link').hasClass('link-active')) {
  163.       $('#add-link').removeClass('link-active');
  164.       $('#add-link-input-wrapper').css('opacity', '0');
  165.       setTimeout((function() {
  166.         return $('#task-list').css('margin-top', '-40px');
  167.       }), 150);
  168.       return $new_task_input.focus();
  169.     } else {
  170.       $('#add-link').addClass('link-active');
  171.       $('#task-list').css('margin-top', '0px');
  172.       setTimeout((function() {
  173.         return $('#add-link-input-wrapper').css('opacity', '1');
  174.       }), 150);
  175.       return $link_input.focus();
  176.     }
  177.   };
  178.   $('#task-submit').click(addTaskTriggered);
  179.   $('#add-link').click(addLinkTriggered);
  180.   KeyPress = function(e) {
  181.     var evtobj;
  182.     evtobj = window.event ? event : e;
  183.     if (evtobj.keyCode === 13) {
  184.       addTaskTriggered();
  185.       ga('send', 'event', 'Add task shortcut', 'shortcut');
  186.     }
  187.     if (evtobj.ctrlKey && evtobj.keyCode === 76) {
  188.       addLinkTriggered();
  189.       return ga('send', 'event', 'Add link shortcut', 'shortcut');
  190.     }
  191.   };
  192.   document.onkeydown = KeyPress;
  193.   $(document).on('click', '.task > label', function(e) {
  194.     return e.preventDefault();
  195.   });
  196.   $(document).on('mousedown', '.task > label', function() {
  197.     var holding;
  198.     holding = false;
  199.     setTimeout((function() {
  200.       return holding = true;
  201.     }), 250);
  202.     return $(this).one('mouseup', function() {
  203.       var checkbox, li;
  204.       checkbox = void 0;
  205.       if (!holding) {
  206.         li = $(this).closest('li');
  207.         checkbox = $('input', this);
  208.         if (checkbox.prop('checked')) {
  209.           Task.updateAttr(Views.getId(li), 'isDone', false);
  210.         } else {
  211.           Task.updateAttr(Views.getId(li), 'isDone', true);
  212.         }
  213.         checkbox.prop('checked', !checkbox.prop('checked'));
  214.         return nextTourBus();
  215.       }
  216.     });
  217.   });
  218.   $(document).on('click', '.priority', function(e) {
  219.     var li, type_attr, value;
  220.     e.preventDefault();
  221.     nextTourBus();
  222.     type_attr = $(e.currentTarget).attr('type');
  223.     value = $(this).attr(type_attr);
  224.     li = $(this).closest('li');
  225.     return Task.cycleAttr(li, type_attr, value);
  226.   });
  227.   $('#clear-completed').click(function(e) {
  228.     e.preventDefault();
  229.     return window.storageType.get(DB.db_key, function(allTasks) {
  230.       if (allTasks.length !== 0) {
  231.         return Task.clearCompleted();
  232.       }
  233.     });
  234.   });
  235.   $('#export-tasks').click(function(e) {
  236.     e.preventDefault();
  237.     return window.storageType.get(DB.db_key, function(allTasks) {
  238.       return Exporter(allTasks, 'super simple tasks backup');
  239.     });
  240.   });
  241.   $(document).on({
  242.     mouseenter: function() {
  243.       return $new_task_input.blur();
  244.     }
  245.   }, '.drag-handle');
  246.   return initialize();
  247. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement