Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / tour / js / tour.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 (function ($, Backbone, Drupal, document) {
9   var queryString = decodeURI(window.location.search);
10
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'),
17           model: model
18         });
19
20         model.on('change:isActive', function (model, isActive) {
21           $(document).trigger(isActive ? 'drupalTourStarted' : 'drupalTourStopped');
22         }).set('tour', $(context).find('ol#tour'));
23
24         if (/tour=?/i.test(queryString)) {
25           model.set('isActive', true);
26         }
27       });
28     }
29   };
30
31   Drupal.tour = Drupal.tour || {
32     models: {},
33
34     views: {}
35   };
36
37   Drupal.tour.models.StateModel = Backbone.Model.extend({
38     defaults: {
39       tour: [],
40
41       isActive: false,
42
43       activeTour: []
44     }
45   });
46
47   Drupal.tour.views.ToggleTourView = Backbone.View.extend({
48     events: { click: 'onClick' },
49
50     initialize: function initialize() {
51       this.listenTo(this.model, 'change:tour change:isActive', this.render);
52       this.listenTo(this.model, 'change:isActive', this.toggleTour);
53     },
54     render: function render() {
55       this.$el.toggleClass('hidden', this._getTour().length === 0);
56
57       var isActive = this.model.get('isActive');
58       this.$el.find('button').toggleClass('is-active', isActive).prop('aria-pressed', isActive);
59       return this;
60     },
61     toggleTour: function toggleTour() {
62       if (this.model.get('isActive')) {
63         var $tour = this._getTour();
64         this._removeIrrelevantTourItems($tour, this._getDocument());
65         var that = this;
66         if ($tour.find('li').length) {
67           $tour.joyride({
68             autoStart: true,
69             postRideCallback: function postRideCallback() {
70               that.model.set('isActive', false);
71             },
72
73             template: {
74               link: '<a href=\"#close\" class=\"joyride-close-tip\">&times;</a>',
75               button: '<a href=\"#\" class=\"button button--primary joyride-next-tip\"></a>'
76             }
77           });
78           this.model.set({ isActive: true, activeTour: $tour });
79         }
80       } else {
81         this.model.get('activeTour').joyride('destroy');
82         this.model.set({ isActive: false, activeTour: [] });
83       }
84     },
85     onClick: function onClick(event) {
86       this.model.set('isActive', !this.model.get('isActive'));
87       event.preventDefault();
88       event.stopPropagation();
89     },
90     _getTour: function _getTour() {
91       return this.model.get('tour');
92     },
93     _getDocument: function _getDocument() {
94       return $(document);
95     },
96     _removeIrrelevantTourItems: function _removeIrrelevantTourItems($tour, $document) {
97       var removals = false;
98       var tips = /tips=([^&]+)/.exec(queryString);
99       $tour.find('li').each(function () {
100         var $this = $(this);
101         var itemId = $this.attr('data-id');
102         var itemClass = $this.attr('data-class');
103
104         if (tips && !$(this).hasClass(tips[1])) {
105           removals = true;
106           $this.remove();
107           return;
108         }
109
110         if (!itemId && !itemClass || itemId && $document.find('#' + itemId).length || itemClass && $document.find('.' + itemClass).length) {
111           return;
112         }
113         removals = true;
114         $this.remove();
115       });
116
117       if (removals) {
118         var total = $tour.find('li').length;
119         if (!total) {
120           this.model.set({ tour: [] });
121         }
122
123         $tour.find('li').each(function (index) {
124           var progress = Drupal.t('!tour_item of !total', { '!tour_item': index + 1, '!total': total });
125           $(this).find('.tour-progress').text(progress);
126         }).eq(-1).attr('data-text', Drupal.t('End tour'));
127       }
128     }
129   });
130 })(jQuery, Backbone, Drupal, document);