2017-05-19 22:12:53 +00:00
/ * *
* @ file
* Locale admin behavior .
* /
( function ( $ , Drupal ) {
/ * *
* Marks changes of translations .
*
* @ type { Drupal ~ behavior }
*
* @ prop { Drupal ~ behaviorAttach } attach
* Attaches behavior to show the user if translations has changed .
* @ prop { Drupal ~ behaviorDetach } detach
* Detach behavior to show the user if translations has changed .
* /
Drupal . behaviors . localeTranslateDirty = {
2017-07-06 06:21:40 +00:00
attach ( ) {
const $form = $ ( '#locale-translate-edit-form' ) . once ( 'localetranslatedirty' ) ;
2017-05-19 22:12:53 +00:00
if ( $form . length ) {
// Display a notice if any row changed.
$form . one ( 'formUpdated.localeTranslateDirty' , 'table' , function ( ) {
2017-07-06 06:21:40 +00:00
const $marker = $ ( Drupal . theme ( 'localeTranslateChangedWarning' ) ) . hide ( ) ;
2017-05-19 22:12:53 +00:00
$ ( this ) . addClass ( 'changed' ) . before ( $marker ) ;
$marker . fadeIn ( 'slow' ) ;
} ) ;
// Highlight changed row.
$form . on ( 'formUpdated.localeTranslateDirty' , 'tr' , function ( ) {
2017-07-06 06:21:40 +00:00
const $row = $ ( this ) ;
const $rowToMark = $row . once ( 'localemark' ) ;
const marker = Drupal . theme ( 'localeTranslateChangedMarker' ) ;
2017-05-19 22:12:53 +00:00
$row . addClass ( 'changed' ) ;
// Add an asterisk only once if row changed.
if ( $rowToMark . length ) {
$rowToMark . find ( 'td:first-child .js-form-item' ) . append ( marker ) ;
}
} ) ;
}
} ,
2017-07-06 06:21:40 +00:00
detach ( context , settings , trigger ) {
2017-05-19 22:12:53 +00:00
if ( trigger === 'unload' ) {
2017-07-06 06:21:40 +00:00
const $form = $ ( '#locale-translate-edit-form' ) . removeOnce ( 'localetranslatedirty' ) ;
2017-05-19 22:12:53 +00:00
if ( $form . length ) {
$form . off ( 'formUpdated.localeTranslateDirty' ) ;
}
}
2017-07-06 06:21:40 +00:00
} ,
2017-05-19 22:12:53 +00:00
} ;
/ * *
* Show / hide the description details on Available translation updates page .
*
* @ type { Drupal ~ behavior }
*
* @ prop { Drupal ~ behaviorAttach } attach
* Attaches behavior for toggling details on the translation update page .
* /
Drupal . behaviors . hideUpdateInformation = {
2017-07-06 06:21:40 +00:00
attach ( context , settings ) {
const $table = $ ( '#locale-translation-status-form' ) . once ( 'expand-updates' ) ;
2017-05-19 22:12:53 +00:00
if ( $table . length ) {
2017-07-06 06:21:40 +00:00
const $tbodies = $table . find ( 'tbody' ) ;
2017-05-19 22:12:53 +00:00
// Open/close the description details by toggling a tr class.
$tbodies . on ( 'click keydown' , '.description' , function ( e ) {
if ( e . keyCode && ( e . keyCode !== 13 && e . keyCode !== 32 ) ) {
return ;
}
e . preventDefault ( ) ;
2017-07-06 06:21:40 +00:00
const $tr = $ ( this ) . closest ( 'tr' ) ;
2017-05-19 22:12:53 +00:00
$tr . toggleClass ( 'expanded' ) ;
// Change screen reader text.
2017-07-06 06:21:40 +00:00
$tr . find ( '.locale-translation-update__prefix' ) . text ( ( ) => {
2017-05-19 22:12:53 +00:00
if ( $tr . hasClass ( 'expanded' ) ) {
return Drupal . t ( 'Hide description' ) ;
}
2017-07-06 06:21:40 +00:00
return Drupal . t ( 'Show description' ) ;
2017-05-19 22:12:53 +00:00
} ) ;
} ) ;
$table . find ( '.requirements, .links' ) . hide ( ) ;
}
2017-07-06 06:21:40 +00:00
} ,
2017-05-19 22:12:53 +00:00
} ;
$ . extend ( Drupal . theme , /** @lends Drupal.theme */ {
/ * *
* Creates markup for a changed translation marker .
*
* @ return { string }
* Markup for the marker .
* /
2017-07-06 06:21:40 +00:00
localeTranslateChangedMarker ( ) {
return ` <abbr class="warning ajax-changed" title=" ${ Drupal . t ( 'Changed' ) } ">*</abbr> ` ;
2017-05-19 22:12:53 +00:00
} ,
/ * *
* Creates markup for the translation changed warning .
*
* @ return { string }
* Markup for the warning .
* /
2017-07-06 06:21:40 +00:00
localeTranslateChangedWarning ( ) {
return ` <div class="clearfix messages messages--warning"> ${ Drupal . theme ( 'localeTranslateChangedMarker' ) } ${ Drupal . t ( 'Changes made in this table will not be saved until the form is submitted.' ) } </div> ` ;
} ,
2017-05-19 22:12:53 +00:00
} ) ;
2017-07-06 06:21:40 +00:00
} ( jQuery , Drupal ) ) ;