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
2016-04-20 09:56:34 -07:00
( function ( $ , window , Drupal ) {
2015-08-17 17:00:26 -07:00
Drupal . behaviors . blockSettingsSummary = {
2018-11-23 12:29:20 +00:00
attach : function attach ( ) {
2016-04-20 09:56:34 -07:00
if ( typeof $ . fn . drupalSetSummary === 'undefined' ) {
2015-08-17 17:00:26 -07:00
return ;
}
function checkboxesSummary ( context ) {
var vals = [ ] ;
var $checkboxes = $ ( context ) . find ( 'input[type="checkbox"]:checked + label' ) ;
var il = $checkboxes . length ;
for ( var i = 0 ; i < il ; i ++ ) {
2015-08-27 12:03:05 -07:00
vals . push ( $ ( $checkboxes [ i ] ) . html ( ) ) ;
2015-08-17 17:00:26 -07:00
}
if ( ! vals . length ) {
vals . push ( Drupal . t ( 'Not restricted' ) ) ;
}
return vals . join ( ', ' ) ;
}
$ ( '[data-drupal-selector="edit-visibility-node-type"], [data-drupal-selector="edit-visibility-language"], [data-drupal-selector="edit-visibility-user-role"]' ) . drupalSetSummary ( checkboxesSummary ) ;
$ ( '[data-drupal-selector="edit-visibility-request-path"]' ) . drupalSetSummary ( function ( context ) {
var $pages = $ ( context ) . find ( 'textarea[name="visibility[request_path][pages]"]' ) ;
if ( ! $pages . val ( ) ) {
return Drupal . t ( 'Not restricted' ) ;
}
2018-11-23 12:29:20 +00:00
return Drupal . t ( 'Restricted to certain pages' ) ;
2015-08-17 17:00:26 -07:00
} ) ;
}
} ;
Drupal . behaviors . blockDrag = {
2018-11-23 12:29:20 +00:00
attach : function attach ( context , settings ) {
2015-08-17 17:00:26 -07:00
if ( typeof Drupal . tableDrag === 'undefined' || typeof Drupal . tableDrag . blocks === 'undefined' ) {
return ;
}
2016-04-20 09:56:34 -07:00
function checkEmptyRegions ( table , rowObject ) {
table . find ( 'tr.region-message' ) . each ( function ( ) {
var $this = $ ( this ) ;
2018-11-23 12:29:20 +00:00
2016-04-20 09:56:34 -07:00
if ( $this . prev ( 'tr' ) . get ( 0 ) === rowObject . element ) {
2018-11-23 12:29:20 +00:00
if ( rowObject . method !== 'keyboard' || rowObject . direction === 'down' ) {
2016-04-20 09:56:34 -07:00
rowObject . swap ( 'after' , this ) ;
}
}
2018-11-23 12:29:20 +00:00
2016-04-20 09:56:34 -07:00
if ( $this . next ( 'tr' ) . is ( ':not(.draggable)' ) || $this . next ( 'tr' ) . length === 0 ) {
$this . removeClass ( 'region-populated' ) . addClass ( 'region-empty' ) ;
2018-11-23 12:29:20 +00:00
} else if ( $this . is ( '.region-empty' ) ) {
$this . removeClass ( 'region-empty' ) . addClass ( 'region-populated' ) ;
}
2016-04-20 09:56:34 -07:00
} ) ;
}
function updateLastPlaced ( table , rowObject ) {
table . find ( '.color-success' ) . removeClass ( 'color-success' ) ;
var $rowObject = $ ( rowObject ) ;
if ( ! $rowObject . is ( '.drag-previous' ) ) {
table . find ( '.drag-previous' ) . removeClass ( 'drag-previous' ) ;
$rowObject . addClass ( 'drag-previous' ) ;
}
}
function updateBlockWeights ( table , region ) {
var weight = - Math . round ( table . find ( '.draggable' ) . length / 2 ) ;
2018-11-23 12:29:20 +00:00
table . find ( '.region-' + region + '-message' ) . nextUntil ( '.region-title' ) . find ( 'select.block-weight' ) . val ( function ( ) {
return ++ weight ;
} ) ;
2016-04-20 09:56:34 -07:00
}
2015-08-17 17:00:26 -07:00
var table = $ ( '#blocks' ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
var tableDrag = Drupal . tableDrag . blocks ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
tableDrag . row . prototype . onSwap = function ( swappedRow ) {
checkEmptyRegions ( table , this ) ;
2015-10-08 11:40:12 -07:00
updateLastPlaced ( table , this ) ;
2015-08-17 17:00:26 -07:00
} ;
tableDrag . onDrop = function ( ) {
var dragObject = this ;
var $rowElement = $ ( dragObject . rowObject . element ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
var regionRow = $rowElement . prevAll ( 'tr.region-message' ) . get ( 0 ) ;
var regionName = regionRow . className . replace ( /([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/ , '$2' ) ;
var regionField = $rowElement . find ( 'select.block-region-select' ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
if ( regionField . find ( 'option[value=' + regionName + ']' ) . length === 0 ) {
window . alert ( Drupal . t ( 'The block cannot be placed in this region.' ) ) ;
2018-11-23 12:29:20 +00:00
2015-08-17 17:00:26 -07:00
regionField . trigger ( 'change' ) ;
}
2015-09-04 13:20:09 -07:00
if ( ! regionField . is ( '.block-region-' + regionName ) ) {
2015-08-17 17:00:26 -07:00
var weightField = $rowElement . find ( 'select.block-weight' ) ;
var oldRegionName = weightField [ 0 ] . className . replace ( /([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/ , '$2' ) ;
2015-09-04 13:20:09 -07:00
regionField . removeClass ( 'block-region-' + oldRegionName ) . addClass ( 'block-region-' + regionName ) ;
weightField . removeClass ( 'block-weight-' + oldRegionName ) . addClass ( 'block-weight-' + regionName ) ;
regionField . val ( regionName ) ;
2015-08-17 17:00:26 -07:00
}
2015-09-04 13:20:09 -07:00
updateBlockWeights ( table , regionName ) ;
2015-08-17 17:00:26 -07:00
} ;
2018-11-23 12:29:20 +00:00
$ ( context ) . find ( 'select.block-region-select' ) . once ( 'block-region-select' ) . on ( 'change' , function ( event ) {
var row = $ ( this ) . closest ( 'tr' ) ;
var select = $ ( this ) ;
tableDrag . rowObject = new tableDrag . row ( row [ 0 ] ) ;
var regionMessage = table . find ( '.region-' + select [ 0 ] . value + '-message' ) ;
var regionItems = regionMessage . nextUntil ( '.region-message, .region-title' ) ;
if ( regionItems . length ) {
regionItems . last ( ) . after ( row ) ;
} else {
regionMessage . after ( row ) ;
2016-04-07 11:19:57 -07:00
}
2018-11-23 12:29:20 +00:00
updateBlockWeights ( table , select [ 0 ] . value ) ;
checkEmptyRegions ( table , tableDrag . rowObject ) ;
updateLastPlaced ( table , row ) ;
if ( ! tableDrag . changed ) {
$ ( Drupal . theme ( 'tableDragChangedWarning' ) ) . insertBefore ( tableDrag . table ) . hide ( ) . fadeIn ( 'slow' ) ;
tableDrag . changed = true ;
}
select . trigger ( 'blur' ) ;
} ) ;
2015-08-17 17:00:26 -07:00
}
} ;
2018-11-23 12:29:20 +00:00
} ) ( jQuery , window , Drupal ) ;