2012-08-22 07:48:46 +00:00
( function ( $ , window ) {
2007-11-14 09:50:00 +00:00
2012-05-08 02:57:33 +00:00
"use strict" ;
2009-12-07 21:16:31 +00:00
/ * *
* Provide the summary information for the block settings vertical tabs .
* /
Drupal . behaviors . blockSettingsSummary = {
2012-06-12 01:39:50 +00:00
attach : function ( ) {
2010-04-09 12:24:53 +00:00
// The drupalSetSummary method required for this behavior is not available
2009-12-21 08:14:12 +00:00
// on the Blocks administration page, so we need to make sure this
2010-04-09 12:24:53 +00:00
// behavior is processed only if drupalSetSummary is defined.
2012-06-23 16:50:41 +00:00
if ( typeof jQuery . fn . drupalSetSummary === 'undefined' ) {
2009-12-21 08:14:12 +00:00
return ;
}
2012-06-12 01:39:50 +00:00
function checkboxesSummary ( context ) {
2009-12-07 21:16:31 +00:00
var vals = [ ] ;
2012-06-12 01:39:50 +00:00
var $checkboxes = $ ( context ) . find ( 'input[type="checkbox"]:checked + label' ) ;
for ( var i = 0 , il = $checkboxes . length ; i < il ; i += 1 ) {
vals . push ( $ ( $checkboxes [ i ] ) . text ( ) ) ;
2009-12-07 21:16:31 +00:00
}
2012-04-19 17:45:46 +00:00
if ( ! vals . length ) {
vals . push ( Drupal . t ( 'Not restricted' ) ) ;
}
2012-06-12 01:39:50 +00:00
return $ . map ( vals , $ . trim ) . join ( ', ' ) ;
}
2012-04-19 17:45:46 +00:00
2012-06-12 01:39:50 +00:00
$ ( '#edit-node-type' ) . drupalSetSummary ( checkboxesSummary ) ;
$ ( '#edit-language' ) . drupalSetSummary ( checkboxesSummary ) ;
$ ( '#edit-role' ) . drupalSetSummary ( checkboxesSummary ) ;
2012-04-19 17:45:46 +00:00
2012-06-12 01:39:50 +00:00
$ ( '#edit-path' ) . drupalSetSummary ( function ( context ) {
var $pages = $ ( context ) . find ( 'textarea[name="pages"]' ) ;
if ( ! $pages . val ( ) ) {
return Drupal . t ( 'Not restricted' ) ;
}
else {
return Drupal . t ( 'Restricted to certain pages' ) ;
2009-12-07 21:16:31 +00:00
}
} ) ;
2012-06-12 01:39:50 +00:00
$ ( '#edit-user' ) . drupalSetSummary ( function ( context ) {
2012-04-07 07:19:30 +00:00
var $radio = $ ( context ) . find ( 'input[name="custom"]:checked' ) ;
2012-06-23 16:50:41 +00:00
if ( $radio . val ( ) === 0 ) {
2009-12-07 21:16:31 +00:00
return Drupal . t ( 'Not customizable' ) ;
}
else {
return $radio . next ( 'label' ) . text ( ) ;
}
} ) ;
}
} ;
2007-11-14 09:50:00 +00:00
/ * *
* Move a block in the blocks table from one region to another via select list .
*
* This behavior is dependent on the tableDrag behavior , since it uses the
* objects initialized in that behavior to update the row .
* /
2008-10-29 10:01:28 +00:00
Drupal . behaviors . blockDrag = {
2009-04-27 20:19:38 +00:00
attach : function ( context , settings ) {
2010-05-09 13:57:59 +00:00
// tableDrag is required and we should be on the blocks admin page.
2012-06-23 16:50:41 +00:00
if ( typeof Drupal . tableDrag === 'undefined' || typeof Drupal . tableDrag . blocks === 'undefined' ) {
2009-12-07 21:16:31 +00:00
return ;
}
2012-06-12 01:39:50 +00:00
var table = $ ( '#blocks' ) ;
2008-10-29 10:01:28 +00:00
var tableDrag = Drupal . tableDrag . blocks ; // Get the blocks tableDrag object.
2007-11-14 09:50:00 +00:00
2008-10-29 10:01:28 +00:00
// Add a handler for when a row is swapped, update empty regions.
2009-04-27 20:19:38 +00:00
tableDrag . row . prototype . onSwap = function ( swappedRow ) {
2008-10-29 10:01:28 +00:00
checkEmptyRegions ( table , this ) ;
} ;
2007-11-14 09:50:00 +00:00
2008-10-29 10:01:28 +00:00
// A custom message for the blocks page specifically.
2009-04-27 20:19:38 +00:00
Drupal . theme . tableDragChangedWarning = function ( ) {
2010-02-15 19:06:21 +00:00
return '<div class="messages warning">' + Drupal . theme ( 'tableDragChangedMarker' ) + ' ' + Drupal . t ( 'The changes to these blocks will not be saved until the <em>Save blocks</em> button is clicked.' ) + '</div>' ;
2008-10-29 10:01:28 +00:00
} ;
2007-11-14 09:50:00 +00:00
2008-10-29 10:01:28 +00:00
// Add a handler so when a row is dropped, update fields dropped into new regions.
2009-04-27 20:19:38 +00:00
tableDrag . onDrop = function ( ) {
2012-04-07 07:19:30 +00:00
var dragObject = this ;
var $rowElement = $ ( dragObject . rowObject . element ) ;
2009-08-04 06:26:52 +00:00
// Use "region-message" row instead of "region" row because
// "region-{region_name}-message" is less prone to regexp match errors.
2012-04-07 07:19:30 +00:00
var regionRow = $rowElement . prevAll ( 'tr.region-message' ) . get ( 0 ) ;
2009-05-21 21:12:25 +00:00
var regionName = regionRow . className . replace ( /([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/ , '$2' ) ;
2012-04-07 07:19:30 +00:00
var regionField = $rowElement . find ( 'select.block-region-select' ) ;
2009-05-21 21:12:25 +00:00
// Check whether the newly picked region is available for this block.
2012-06-23 16:50:41 +00:00
if ( regionField . find ( 'option[value=' + regionName + ']' ) . length === 0 ) {
2009-05-21 21:12:25 +00:00
// If not, alert the user and keep the block in its old region setting.
2012-08-22 07:48:46 +00:00
window . alert ( Drupal . t ( 'The block cannot be placed in this region.' ) ) ;
2009-05-21 21:12:25 +00:00
// Simulate that there was a selected element change, so the row is put
// back to from where the user tried to drag it.
regionField . change ( ) ;
}
2012-04-07 07:19:30 +00:00
else if ( $rowElement . prev ( 'tr' ) . is ( '.region-message' ) ) {
var weightField = $rowElement . find ( 'select.block-weight' ) ;
2008-10-29 10:01:28 +00:00
var oldRegionName = weightField [ 0 ] . className . replace ( /([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/ , '$2' ) ;
2007-11-14 09:50:00 +00:00
2009-04-26 19:18:46 +00:00
if ( ! regionField . is ( '.block-region-' + regionName ) ) {
2008-10-29 10:01:28 +00:00
regionField . removeClass ( 'block-region-' + oldRegionName ) . addClass ( 'block-region-' + regionName ) ;
weightField . removeClass ( 'block-weight-' + oldRegionName ) . addClass ( 'block-weight-' + regionName ) ;
regionField . val ( regionName ) ;
}
2007-11-14 09:50:00 +00:00
}
2008-10-29 10:01:28 +00:00
} ;
2007-11-14 09:50:00 +00:00
2008-10-29 10:01:28 +00:00
// Add the behavior to each region select list.
2012-04-07 07:19:30 +00:00
$ ( context ) . find ( 'select.block-region-select' ) . once ( 'block-region-select' , function ( ) {
2009-04-27 20:19:38 +00:00
$ ( this ) . change ( function ( event ) {
2008-10-29 10:01:28 +00:00
// Make our new row and select field.
2012-01-24 18:54:39 +00:00
var row = $ ( this ) . closest ( 'tr' ) ;
2008-10-29 10:01:28 +00:00
var select = $ ( this ) ;
tableDrag . rowObject = new tableDrag . row ( row ) ;
2007-11-14 09:50:00 +00:00
2012-04-24 01:51:14 +00:00
// Find the correct region and insert the row as the last in the region.
table . find ( '.region-' + select [ 0 ] . value + '-message' ) . nextUntil ( '.region-message' ) . last ( ) . before ( row ) ;
2007-11-14 09:50:00 +00:00
2008-10-29 10:01:28 +00:00
// Modify empty regions with added or removed fields.
checkEmptyRegions ( table , row ) ;
// Remove focus from selectbox.
select . get ( 0 ) . blur ( ) ;
} ) ;
2007-11-14 09:50:00 +00:00
} ) ;
2009-04-27 20:19:38 +00:00
var checkEmptyRegions = function ( table , rowObject ) {
2012-04-07 07:19:30 +00:00
table . find ( 'tr.region-message' ) . each ( function ( ) {
var $this = $ ( this ) ;
2008-10-29 10:01:28 +00:00
// If the dragged row is in this region, but above the message row, swap it down one space.
2012-06-23 16:50:41 +00:00
if ( $this . prev ( 'tr' ) . get ( 0 ) === rowObject . element ) {
2008-10-29 10:01:28 +00:00
// Prevent a recursion problem when using the keyboard to move rows up.
2012-06-23 16:50:41 +00:00
if ( ( rowObject . method !== 'keyboard' || rowObject . direction === 'down' ) ) {
2008-10-29 10:01:28 +00:00
rowObject . swap ( 'after' , this ) ;
}
2007-11-14 09:50:00 +00:00
}
2008-10-29 10:01:28 +00:00
// This region has become empty.
2012-06-23 16:50:41 +00:00
if ( $this . next ( 'tr' ) . is ( ':not(.draggable)' ) || $this . next ( 'tr' ) . length === 0 ) {
2012-04-07 07:19:30 +00:00
$this . removeClass ( 'region-populated' ) . addClass ( 'region-empty' ) ;
2008-10-29 10:01:28 +00:00
}
// This region has become populated.
2012-04-07 07:19:30 +00:00
else if ( $this . is ( '.region-empty' ) ) {
$this . removeClass ( 'region-empty' ) . addClass ( 'region-populated' ) ;
2008-10-29 10:01:28 +00:00
}
} ) ;
} ;
}
2007-11-14 09:50:00 +00:00
} ;
2009-02-18 13:46:55 +00:00
2012-08-22 07:48:46 +00:00
} ) ( jQuery , window ) ;