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 if ($tour.find('li').length) {
69 postRideCallback: function postRideCallback() {
70 that.model.set('isActive', false);
74 link: '<a href=\"#close\" class=\"joyride-close-tip\">×</a>',
75 button: '<a href=\"#\" class=\"button button--primary joyride-next-tip\"></a>'
78 this.model.set({ isActive: true, activeTour: $tour });
81 this.model.get('activeTour').joyride('destroy');
82 this.model.set({ isActive: false, activeTour: [] });
85 onClick: function onClick(event) {
86 this.model.set('isActive', !this.model.get('isActive'));
87 event.preventDefault();
88 event.stopPropagation();
90 _getTour: function _getTour() {
91 return this.model.get('tour');
93 _getDocument: function _getDocument() {
96 _removeIrrelevantTourItems: function _removeIrrelevantTourItems($tour, $document) {
98 var tips = /tips=([^&]+)/.exec(queryString);
99 $tour.find('li').each(function () {
101 var itemId = $this.attr('data-id');
102 var itemClass = $this.attr('data-class');
104 if (tips && !$(this).hasClass(tips[1])) {
110 if (!itemId && !itemClass || itemId && $document.find('#' + itemId).length || itemClass && $document.find('.' + itemClass).length) {
118 var total = $tour.find('li').length;
120 this.model.set({ tour: [] });
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'));
130 })(jQuery, Backbone, Drupal, document);