2015-08-17 17:00:26 -07:00
/ * *
* @ file
* A Backbone View that provides a dynamic contextual link .
* /
( function ( $ , Backbone , Drupal ) {
2015-10-21 21:44:50 -07:00
'use strict' ;
2015-08-17 17:00:26 -07:00
Drupal . quickedit . ContextualLinkView = Backbone . View . extend ( /** @lends Drupal.quickedit.ContextualLinkView# */ {
/ * *
* Define all events to listen to .
*
* @ return { object }
2015-09-04 13:20:09 -07:00
* A map of events .
2015-08-17 17:00:26 -07:00
* /
events : function ( ) {
// Prevents delay and simulated mouse events.
function touchEndToClick ( event ) {
event . preventDefault ( ) ;
event . target . click ( ) ;
}
return {
'click a' : function ( event ) {
event . preventDefault ( ) ;
this . model . set ( 'state' , 'launching' ) ;
} ,
'touchEnd a' : touchEndToClick
} ;
} ,
/ * *
2015-09-04 13:20:09 -07:00
* Create a new contextual link view .
*
2015-08-17 17:00:26 -07:00
* @ constructs
*
* @ augments Backbone . View
*
* @ param { object } options
* An object with the following keys :
* @ param { Drupal . quickedit . EntityModel } options . model
* The associated entity ' s model .
* @ param { Drupal . quickedit . AppModel } options . appModel
* The application state model .
* @ param { object } options . strings
* The strings for the "Quick edit" link .
* /
initialize : function ( options ) {
// Insert the text of the quick edit toggle.
this . $el . find ( 'a' ) . text ( options . strings . quickEdit ) ;
// Initial render.
this . render ( ) ;
// Re-render whenever this entity's isActive attribute changes.
this . listenTo ( this . model , 'change:isActive' , this . render ) ;
} ,
/ * *
2015-09-04 13:20:09 -07:00
* Render function for the contextual link view .
2015-08-17 17:00:26 -07:00
*
* @ param { Drupal . quickedit . EntityModel } entityModel
2015-09-04 13:20:09 -07:00
* The associated ` EntityModel ` .
2015-08-17 17:00:26 -07:00
* @ param { bool } isActive
2015-09-04 13:20:09 -07:00
* Whether the in - place editor is active or not .
2015-08-17 17:00:26 -07:00
*
* @ return { Drupal . quickedit . ContextualLinkView }
2015-09-04 13:20:09 -07:00
* The ` ContextualLinkView ` in question .
2015-08-17 17:00:26 -07:00
* /
render : function ( entityModel , isActive ) {
this . $el . find ( 'a' ) . attr ( 'aria-pressed' , isActive ) ;
// Hides the contextual links if an in-place editor is active.
this . $el . closest ( '.contextual' ) . toggle ( ! isActive ) ;
return this ;
}
} ) ;
} ) ( jQuery , Backbone , Drupal ) ;