2007-12-16 10:36:53 +00:00
// $Id$
2009-04-27 20:19:38 +00:00
( function ( $ ) {
2007-11-14 09:50:00 +00:00
2009-12-07 21:16:31 +00:00
/ * *
* Provide the summary information for the block settings vertical tabs .
* /
Drupal . behaviors . blockSettingsSummary = {
attach : function ( context ) {
2009-12-21 08:14:12 +00:00
// The setSummary method required for this behavior is not available
// on the Blocks administration page, so we need to make sure this
// behavior is processed only if setSummary is defined.
if ( typeof jQuery . fn . setSummary == 'undefined' ) {
return ;
}
2009-12-07 21:16:31 +00:00
$ ( 'fieldset#edit-path' , context ) . setSummary ( function ( context ) {
if ( ! $ ( 'textarea[name="pages"]' , context ) . val ( ) ) {
return Drupal . t ( 'Not restricted' ) ;
}
else {
return Drupal . t ( 'Restricted to certain pages' ) ;
}
} ) ;
$ ( 'fieldset#edit-node-type' , context ) . setSummary ( function ( context ) {
var vals = [ ] ;
$ ( 'input[type="checkbox"]:checked' , context ) . each ( function ( ) {
vals . push ( $ . trim ( $ ( this ) . next ( 'label' ) . text ( ) ) ) ;
} ) ;
if ( ! vals . length ) {
vals . push ( Drupal . t ( 'Not restricted' ) ) ;
}
return vals . join ( ', ' ) ;
} ) ;
$ ( 'fieldset#edit-role' , context ) . setSummary ( function ( context ) {
var vals = [ ] ;
$ ( 'input[type="checkbox"]:checked' , context ) . each ( function ( ) {
vals . push ( $ . trim ( $ ( this ) . next ( 'label' ) . text ( ) ) ) ;
} ) ;
if ( ! vals . length ) {
vals . push ( Drupal . t ( 'Not restricted' ) ) ;
}
return vals . join ( ', ' ) ;
} ) ;
$ ( 'fieldset#edit-user' , context ) . setSummary ( function ( context ) {
var $radio = $ ( 'input[name="custom"]:checked' , context ) ;
if ( $radio . val ( ) == 0 ) {
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 ) {
2009-12-07 21:16:31 +00:00
// tableDrag is required for this behavior.
if ( typeof Drupal . tableDrag == 'undefined' ) {
return ;
}
2008-10-29 10:01:28 +00:00
var table = $ ( 'table#blocks' ) ;
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 ( ) {
2009-04-26 19:18:46 +00:00
return '<div class="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 ( ) {
2008-10-29 10:01:28 +00:00
dragObject = this ;
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.
var regionRow = $ ( dragObject . rowObject . element ) . prevAll ( 'tr.region-message' ) . get ( 0 ) ;
2009-05-21 21:12:25 +00:00
var regionName = regionRow . className . replace ( /([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/ , '$2' ) ;
var regionField = $ ( 'select.block-region-select' , dragObject . rowObject . element ) ;
// Check whether the newly picked region is available for this block.
if ( $ ( 'option[value=' + regionName + ']' , regionField ) . length == 0 ) {
// If not, alert the user and keep the block in its old region setting.
alert ( Drupal . t ( 'The block cannot be placed in this region.' ) ) ;
// 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 ( ) ;
}
else if ( $ ( dragObject . rowObject . element ) . prev ( 'tr' ) . is ( '.region-message' ) ) {
2008-10-29 10:01:28 +00:00
var weightField = $ ( 'select.block-weight' , dragObject . rowObject . element ) ;
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.
2009-08-31 05:51:08 +00:00
$ ( 'select.block-region-select' , context ) . 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.
var row = $ ( this ) . parents ( 'tr:first' ) ;
var select = $ ( this ) ;
tableDrag . rowObject = new tableDrag . row ( row ) ;
2007-11-14 09:50:00 +00:00
2008-10-29 10:01:28 +00:00
// Find the correct region and insert the row as the first in the region.
2009-04-27 20:19:38 +00:00
$ ( 'tr.region-message' , table ) . each ( function ( ) {
2008-10-29 10:01:28 +00:00
if ( $ ( this ) . is ( '.region-' + select [ 0 ] . value + '-message' ) ) {
// Add the new row and remove the old one.
$ ( this ) . after ( row ) ;
// Manually update weights and restripe.
tableDrag . updateFields ( row . get ( 0 ) ) ;
tableDrag . rowObject . changed = true ;
if ( tableDrag . oldRowElement ) {
$ ( tableDrag . oldRowElement ) . removeClass ( 'drag-previous' ) ;
}
tableDrag . oldRowElement = row . get ( 0 ) ;
tableDrag . restripeTable ( ) ;
tableDrag . rowObject . markChanged ( ) ;
tableDrag . oldRowElement = row ;
$ ( row ) . addClass ( 'drag-previous' ) ;
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
// 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 ) {
$ ( 'tr.region-message' , table ) . each ( function ( ) {
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.
if ( $ ( this ) . prev ( 'tr' ) . get ( 0 ) == rowObject . element ) {
// Prevent a recursion problem when using the keyboard to move rows up.
if ( ( rowObject . method != 'keyboard' || rowObject . direction == 'down' ) ) {
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.
if ( $ ( this ) . next ( 'tr' ) . is ( ':not(.draggable)' ) || $ ( this ) . next ( 'tr' ) . size ( ) == 0 ) {
$ ( this ) . removeClass ( 'region-populated' ) . addClass ( 'region-empty' ) ;
}
// This region has become populated.
else if ( $ ( this ) . is ( '.region-empty' ) ) {
$ ( this ) . removeClass ( 'region-empty' ) . addClass ( 'region-populated' ) ;
}
} ) ;
} ;
}
2007-11-14 09:50:00 +00:00
} ;
2009-02-18 13:46:55 +00:00
} ) ( jQuery ) ;