switch_profile_guide.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. (function() {
  2. $script('lib/tether/tether.js', function() {
  3. return $script('lib/shepherd.js/shepherd.min.js', function() {
  4. var conditionTypeStep, defaultStep, tour, tr, _ref;
  5. if (jQuery('.switch-rule-row').length === 0) {
  6. return;
  7. }
  8. jQuery('html, body').scrollTop(0);
  9. tr = chrome.i18n.getMessage.bind(chrome.i18n);
  10. tour = new Shepherd.Tour({
  11. defaults: {
  12. classes: 'shepherd-theme-arrows'
  13. }
  14. });
  15. tour.addStep('condition-step', {
  16. text: tr('options_guide_conditionStep'),
  17. attachTo: '.switch-rule-row bottom',
  18. buttons: [
  19. {
  20. text: tr('options_guideSkip'),
  21. action: tour.cancel,
  22. classes: 'shepherd-button-secondary'
  23. }, {
  24. text: tr('options_guideNext'),
  25. action: tour.next
  26. }
  27. ]
  28. });
  29. conditionTypeStep = tour.addStep('condition-type-step', {
  30. text: tr('options_guide_conditionTypeStep'),
  31. attachTo: '.condition-type-th bottom',
  32. advanceOn: {
  33. selector: '.close-condition-help',
  34. event: 'click'
  35. },
  36. buttons: [
  37. {
  38. text: tr('options_guideNext'),
  39. action: tour.next
  40. }
  41. ]
  42. });
  43. conditionTypeStep.on('show', function() {
  44. return jQuery('.toggle-condition-help').one('click', function() {
  45. if (!conditionTypeStep.isOpen()) {
  46. return;
  47. }
  48. jQuery('.shepherd-step.shepherd-enabled').hide();
  49. return jQuery('.toggle-condition-help, .close-condition-help').one('click', function() {
  50. return tour.next();
  51. });
  52. });
  53. });
  54. tour.addStep('condition-profile-step', {
  55. text: tr('options_guide_conditionProfileStep'),
  56. attachTo: '.switch-rule-row-target bottom',
  57. buttons: [
  58. {
  59. text: tr('options_guideNext'),
  60. action: tour.next
  61. }
  62. ]
  63. });
  64. defaultStep = tour.addStep('switch-default-step', {
  65. text: tr('options_guide_switchDefaultStep'),
  66. attachTo: '.switch-default-row top',
  67. buttons: [
  68. {
  69. text: tr('options_guideNext'),
  70. action: tour.next
  71. }
  72. ]
  73. });
  74. defaultStep.on('show', function() {
  75. var row, scrollTop;
  76. row = jQuery('.switch-default-row');
  77. scrollTop = row.offset().top + row.height() - $(window).height();
  78. if (scrollTop < 0) {
  79. scrollTop = 0;
  80. }
  81. return jQuery('html, body').animate({
  82. scrollTop: scrollTop
  83. });
  84. });
  85. tour.addStep('apply-switch-profile-step', {
  86. text: tr('options_guide_applySwitchProfileStep'),
  87. attachTo: 'body top',
  88. scrollTo: false,
  89. classes: 'shepherd-theme-arrows fixed-top-right',
  90. buttons: [
  91. {
  92. text: tr('options_guideDone'),
  93. action: tour.next
  94. }
  95. ]
  96. });
  97. if ((_ref = Shepherd.activeTour) != null) {
  98. _ref.cancel();
  99. }
  100. return tour.start();
  101. });
  102. });
  103. }).call(this);