2015-08-17 17:00:26 -07:00
/ * *
2018-11-23 12:29:20 +00:00
* DO NOT EDIT THIS FILE .
* See the following change record for more information ,
* https : //www.drupal.org/node/2815083
* @ preserve
* * /
2015-08-17 17:00:26 -07:00
( function ( $ , Backbone , Drupal , document ) {
var queryString = decodeURI ( window . location . search ) ;
Drupal . behaviors . tour = {
2018-11-23 12:29:20 +00:00
attach : function attach ( context ) {
2015-08-17 17:00:26 -07:00
$ ( 'body' ) . once ( 'tour' ) . each ( function ( ) {
var model = new Drupal . tour . models . StateModel ( ) ;
new Drupal . tour . views . ToggleTourView ( {
el : $ ( context ) . find ( '#toolbar-tab-tour' ) ,
model : model
} ) ;
2018-11-23 12:29:20 +00:00
model . on ( 'change:isActive' , function ( model , isActive ) {
$ ( document ) . trigger ( isActive ? 'drupalTourStarted' : 'drupalTourStopped' ) ;
} ) . set ( 'tour' , $ ( context ) . find ( 'ol#tour' ) ) ;
2015-08-17 17:00:26 -07:00
if ( /tour=?/i . test ( queryString ) ) {
model . set ( 'isActive' , true ) ;
}
} ) ;
}
} ;
Drupal . tour = Drupal . tour || {
models : { } ,
views : { }
} ;
2018-11-23 12:29:20 +00:00
Drupal . tour . models . StateModel = Backbone . Model . extend ( {
defaults : {
2015-08-17 17:00:26 -07:00
tour : [ ] ,
isActive : false ,
activeTour : [ ]
}
} ) ;
2018-11-23 12:29:20 +00:00
Drupal . tour . views . ToggleTourView = Backbone . View . extend ( {
events : { click : 'onClick' } ,
2015-08-17 17:00:26 -07:00
2018-11-23 12:29:20 +00:00
initialize : function initialize ( ) {
2015-08-17 17:00:26 -07:00
this . listenTo ( this . model , 'change:tour change:isActive' , this . render ) ;
this . listenTo ( this . model , 'change:isActive' , this . toggleTour ) ;
} ,
2018-11-23 12:29:20 +00:00
render : function render ( ) {
2015-08-17 17:00:26 -07:00
this . $el . toggleClass ( 'hidden' , this . _getTour ( ) . length === 0 ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
var isActive = this . model . get ( 'isActive' ) ;
2018-11-23 12:29:20 +00:00
this . $el . find ( 'button' ) . toggleClass ( 'is-active' , isActive ) . prop ( 'aria-pressed' , isActive ) ;
2015-08-17 17:00:26 -07:00
return this ;
} ,
2018-11-23 12:29:20 +00:00
toggleTour : function toggleTour ( ) {
2015-08-17 17:00:26 -07:00
if ( this . model . get ( 'isActive' ) ) {
var $tour = this . _getTour ( ) ;
this . _removeIrrelevantTourItems ( $tour , this . _getDocument ( ) ) ;
var that = this ;
2018-11-23 12:29:20 +00:00
var close = Drupal . t ( 'Close' ) ;
2015-08-17 17:00:26 -07:00
if ( $tour . find ( 'li' ) . length ) {
$tour . joyride ( {
autoStart : true ,
2018-11-23 12:29:20 +00:00
postRideCallback : function postRideCallback ( ) {
that . model . set ( 'isActive' , false ) ;
} ,
2015-08-17 17:00:26 -07:00
template : {
2018-11-23 12:29:20 +00:00
link : '<a href="#close" class="joyride-close-tip" aria-label="' + close + '">×</a>' ,
button : '<a href="#" class="button button--primary joyride-next-tip"></a>'
2015-08-17 17:00:26 -07:00
}
} ) ;
2018-11-23 12:29:20 +00:00
this . model . set ( { isActive : true , activeTour : $tour } ) ;
2015-08-17 17:00:26 -07:00
}
2018-11-23 12:29:20 +00:00
} else {
2015-08-17 17:00:26 -07:00
this . model . get ( 'activeTour' ) . joyride ( 'destroy' ) ;
2018-11-23 12:29:20 +00:00
this . model . set ( { isActive : false , activeTour : [ ] } ) ;
2015-08-17 17:00:26 -07:00
}
} ,
2018-11-23 12:29:20 +00:00
onClick : function onClick ( event ) {
2015-08-17 17:00:26 -07:00
this . model . set ( 'isActive' , ! this . model . get ( 'isActive' ) ) ;
event . preventDefault ( ) ;
event . stopPropagation ( ) ;
} ,
2018-11-23 12:29:20 +00:00
_getTour : function _getTour ( ) {
2015-08-17 17:00:26 -07:00
return this . model . get ( 'tour' ) ;
} ,
2018-11-23 12:29:20 +00:00
_getDocument : function _getDocument ( ) {
2015-08-17 17:00:26 -07:00
return $ ( document ) ;
} ,
2018-11-23 12:29:20 +00:00
_removeIrrelevantTourItems : function _removeIrrelevantTourItems ( $tour , $document ) {
2015-08-17 17:00:26 -07:00
var removals = false ;
var tips = /tips=([^&]+)/ . exec ( queryString ) ;
2018-11-23 12:29:20 +00:00
$tour . find ( 'li' ) . each ( function ( ) {
var $this = $ ( this ) ;
var itemId = $this . attr ( 'data-id' ) ;
var itemClass = $this . attr ( 'data-class' ) ;
if ( tips && ! $ ( this ) . hasClass ( tips [ 1 ] ) ) {
2015-08-17 17:00:26 -07:00
removals = true ;
$this . remove ( ) ;
2018-11-23 12:29:20 +00:00
return ;
}
if ( ! itemId && ! itemClass || itemId && $document . find ( '#' + itemId ) . length || itemClass && $document . find ( '.' + itemClass ) . length ) {
return ;
}
removals = true ;
$this . remove ( ) ;
} ) ;
2015-08-17 17:00:26 -07:00
if ( removals ) {
var total = $tour . find ( 'li' ) . length ;
if ( ! total ) {
2018-11-23 12:29:20 +00:00
this . model . set ( { tour : [ ] } ) ;
2015-08-17 17:00:26 -07:00
}
2018-11-23 12:29:20 +00:00
$tour . find ( 'li' ) . each ( function ( index ) {
var progress = Drupal . t ( '!tour_item of !total' , {
'!tour_item' : index + 1 ,
'!total' : total
} ) ;
$ ( this ) . find ( '.tour-progress' ) . text ( progress ) ;
} ) . eq ( - 1 ) . attr ( 'data-text' , Drupal . t ( 'End tour' ) ) ;
2015-08-17 17:00:26 -07:00
}
}
} ) ;
2018-11-23 12:29:20 +00:00
} ) ( jQuery , Backbone , Drupal , document ) ;