2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, Backbone, Drupal, document) {
9 var queryString = decodeURI(window.location.search);
11 Drupal.behaviors.tour = {
12 attach: function attach(context) {
13 $('body').once('tour').each(function () {
14 var model = new Drupal.tour.models.StateModel();
15 new Drupal.tour.views.ToggleTourView({
16 el: $(context).find('#toolbar-tab-tour'),
20 model.on('change:isActive', function (model, isActive) {
21 $(document).trigger(isActive ? 'drupalTourStarted' : 'drupalTourStopped');
22 }).set('tour', $(context).find('ol#tour'));
24 if (/tour=?/i.test(queryString)) {
25 model.set('isActive', true);
31 Drupal.tour = Drupal.tour || {
37 Drupal.tour.models.StateModel = Backbone.Model.extend({
47 Drupal.tour.views.ToggleTourView = Backbone.View.extend({
48 events: { click: 'onClick' },
50 initialize: function initialize() {
51 this.listenTo(this.model, 'change:tour change:isActive', this.render);
52 this.listenTo(this.model, 'change:isActive', this.toggleTour);
54 render: function render() {
55 this.$el.toggleClass('hidden', this._getTour().length === 0);
57 var isActive = this.model.get('isActive');
58 this.$el.find('button').toggleClass('is-active', isActive).prop('aria-pressed', isActive);
61 toggleTour: function toggleTour() {
62 if (this.model.get('isActive')) {
63 var $tour = this._getTour();
64 this._removeIrrelevantTourItems($tour, this._getDocument());
66 var close = Drupal.t('Close');
67 if ($tour.find('li').length) {
70 postRideCallback: function postRideCallback() {
71 that.model.set('isActive', false);
75 link: '<a href="#close" class="joyride-close-tip" aria-label="' + close + '">×</a>',
76 button: '<a href="#" class="button button--primary joyride-next-tip"></a>'
79 this.model.set({ isActive: true, activeTour: $tour });
82 this.model.get('activeTour').joyride('destroy');
83 this.model.set({ isActive: false, activeTour: [] });
86 onClick: function onClick(event) {
87 this.model.set('isActive', !this.model.get('isActive'));
88 event.preventDefault();
89 event.stopPropagation();
91 _getTour: function _getTour() {
92 return this.model.get('tour');
94 _getDocument: function _getDocument() {
97 _removeIrrelevantTourItems: function _removeIrrelevantTourItems($tour, $document) {
99 var tips = /tips=([^&]+)/.exec(queryString);
100 $tour.find('li').each(function () {
102 var itemId = $this.attr('data-id');
103 var itemClass = $this.attr('data-class');
105 if (tips && !$(this).hasClass(tips[1])) {
111 if (!itemId && !itemClass || itemId && $document.find('#' + itemId).length || itemClass && $document.find('.' + itemClass).length) {
119 var total = $tour.find('li').length;
121 this.model.set({ tour: [] });
124 $tour.find('li').each(function (index) {
125 var progress = Drupal.t('!tour_item of !total', { '!tour_item': index + 1, '!total': total });
126 $(this).find('.tour-progress').text(progress);
127 }).eq(-1).attr('data-text', Drupal.t('End tour'));
131 })(jQuery, Backbone, Drupal, document);