switch_profile_guide.coffee 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. $script 'lib/tether/tether.js', ->
  2. $script 'lib/shepherd.js/shepherd.min.js', ->
  3. return if jQuery('.switch-rule-row').length == 0
  4. jQuery('html, body').scrollTop(0)
  5. tr = chrome.i18n.getMessage.bind(chrome.i18n)
  6. tour = new Shepherd.Tour
  7. defaults:
  8. classes: 'shepherd-theme-arrows'
  9. tour.addStep 'condition-step',
  10. text: tr('options_guide_conditionStep')
  11. attachTo: '.switch-rule-row bottom'
  12. buttons: [
  13. {
  14. text: tr('options_guideSkip')
  15. action: tour.cancel
  16. classes: 'shepherd-button-secondary'
  17. }
  18. {
  19. text: tr('options_guideNext')
  20. action: tour.next
  21. }
  22. ]
  23. conditionTypeStep = tour.addStep('condition-type-step',
  24. text: tr('options_guide_conditionTypeStep')
  25. attachTo: '.condition-type-th bottom'
  26. advanceOn:
  27. selector: '.close-condition-help'
  28. event: 'click'
  29. buttons: [
  30. text: tr('options_guideNext')
  31. action: tour.next
  32. ]
  33. )
  34. conditionTypeStep.on 'show', ->
  35. jQuery('.toggle-condition-help').one 'click', ->
  36. return unless conditionTypeStep.isOpen()
  37. jQuery('.shepherd-step.shepherd-enabled').hide()
  38. jQuery('.toggle-condition-help, .close-condition-help').one 'click', ->
  39. tour.next()
  40. tour.addStep 'condition-profile-step',
  41. text: tr('options_guide_conditionProfileStep')
  42. attachTo: '.switch-rule-row-target bottom'
  43. buttons: [
  44. text: tr('options_guideNext')
  45. action: tour.next
  46. ]
  47. defaultStep = tour.addStep 'switch-default-step',
  48. text: tr('options_guide_switchDefaultStep')
  49. attachTo: '.switch-default-row top'
  50. buttons: [
  51. text: tr('options_guideNext')
  52. action: tour.next
  53. ]
  54. defaultStep.on 'show', ->
  55. row = jQuery('.switch-default-row')
  56. scrollTop = row.offset().top + row.height() - $(window).height()
  57. scrollTop = 0 if scrollTop < 0
  58. jQuery('html, body').animate({scrollTop: scrollTop})
  59. tour.addStep 'apply-switch-profile-step',
  60. text: tr('options_guide_applySwitchProfileStep')
  61. attachTo: 'body top'
  62. scrollTo: false
  63. classes: 'shepherd-theme-arrows fixed-top-right'
  64. buttons: [
  65. text: tr('options_guideDone')
  66. action: tour.next
  67. ]
  68. Shepherd.activeTour?.cancel()
  69. tour.start()