Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
/ * *
* DO NOT EDIT THIS FILE .
* See the following change record for more information ,
* https : //www.drupal.org/node/2815083
* @ preserve
* * /
2019-02-07 10:30:04 +00:00
( function ( $ , Drupal ) {
var ajax = Drupal . ajax ,
behaviors = Drupal . behaviors ,
debounce = Drupal . debounce ,
announce = Drupal . announce ,
formatPlural = Drupal . formatPlural ;
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
2019-02-07 10:30:04 +00:00
var layoutBuilderBlocksFiltered = false ;
behaviors . layoutBuilderBlockFilter = {
attach : function attach ( context ) {
var $categories = $ ( '.js-layout-builder-categories' , context ) ;
var $filterLinks = $categories . find ( '.js-layout-builder-block-link' ) ;
var filterBlockList = function filterBlockList ( e ) {
var query = $ ( e . target ) . val ( ) . toLowerCase ( ) ;
var toggleBlockEntry = function toggleBlockEntry ( index , link ) {
var $link = $ ( link ) ;
var textMatch = $link . text ( ) . toLowerCase ( ) . indexOf ( query ) !== - 1 ;
$link . toggle ( textMatch ) ;
} ;
if ( query . length >= 2 ) {
$categories . find ( '.js-layout-builder-category:not([open])' ) . attr ( 'remember-closed' , '' ) ;
$categories . find ( '.js-layout-builder-category' ) . attr ( 'open' , '' ) ;
$filterLinks . each ( toggleBlockEntry ) ;
$categories . find ( '.js-layout-builder-category:not(:has(.js-layout-builder-block-link:visible))' ) . hide ( ) ;
announce ( formatPlural ( $categories . find ( '.js-layout-builder-block-link:visible' ) . length , '1 block is available in the modified list.' , '@count blocks are available in the modified list.' ) ) ;
layoutBuilderBlocksFiltered = true ;
} else if ( layoutBuilderBlocksFiltered ) {
layoutBuilderBlocksFiltered = false ;
$categories . find ( '.js-layout-builder-category[remember-closed]' ) . removeAttr ( 'open' ) . removeAttr ( 'remember-closed' ) ;
$categories . find ( '.js-layout-builder-category' ) . show ( ) ;
$filterLinks . show ( ) ;
announce ( Drupal . t ( 'All available blocks are listed.' ) ) ;
}
} ;
$ ( 'input.js-layout-builder-filter' , context ) . once ( 'block-filter-text' ) . on ( 'keyup' , debounce ( filterBlockList , 200 ) ) ;
}
} ;
behaviors . layoutBuilderBlockDrag = {
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
attach : function attach ( context ) {
2019-02-26 21:13:22 +00:00
$ ( context ) . find ( '.layout-builder__region' ) . sortable ( {
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
items : '> .draggable' ,
2019-02-26 21:13:22 +00:00
connectWith : '.layout-builder__region' ,
2018-04-08 04:27:31 +00:00
placeholder : 'ui-state-drop' ,
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
update : function update ( event , ui ) {
2019-02-26 21:13:22 +00:00
var itemRegion = ui . item . closest ( '.layout-builder__region' ) ;
2018-01-26 20:50:00 +00:00
if ( event . target === itemRegion [ 0 ] ) {
var deltaTo = ui . item . closest ( '[data-layout-delta]' ) . data ( 'layout-delta' ) ;
var deltaFrom = ui . sender ? ui . sender . closest ( '[data-layout-delta]' ) . data ( 'layout-delta' ) : deltaTo ;
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
ajax ( {
2018-01-26 20:50:00 +00:00
url : [ ui . item . closest ( '[data-layout-update-url]' ) . data ( 'layout-update-url' ) , deltaFrom , deltaTo , itemRegion . data ( 'region' ) , ui . item . data ( 'layout-block-uuid' ) , ui . item . prev ( '[data-layout-block-uuid]' ) . data ( 'layout-block-uuid' ) ] . filter ( function ( element ) {
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
return element !== undefined ;
} ) . join ( '/' )
} ) . execute ( ) ;
}
}
} ) ;
}
} ;
2019-02-21 17:22:25 +00:00
behaviors . layoutBuilderDisableInteractiveElements = {
attach : function attach ( ) {
var $blocks = $ ( '#layout-builder [data-layout-block-uuid]' ) ;
$blocks . find ( 'input, textarea, select' ) . prop ( 'disabled' , true ) ;
2019-03-06 18:40:53 +00:00
$blocks . find ( 'a' ) . not ( function ( index , element ) {
return $ ( element ) . closest ( '[data-contextual-id]' ) . length > 0 ;
} ) . on ( 'click mouseup touchstart' , function ( e ) {
2019-02-21 17:22:25 +00:00
e . preventDefault ( ) ;
e . stopPropagation ( ) ;
} ) ;
$blocks . find ( 'button, [href], input, select, textarea, iframe, [tabindex]:not([tabindex="-1"]):not(.tabbable)' ) . not ( function ( index , element ) {
return $ ( element ) . closest ( '[data-contextual-id]' ) . length > 0 ;
} ) . attr ( 'tabindex' , - 1 ) ;
}
} ;
Issue #2905922 by tim.plunkett, tedbow, xjm, EclipseGc, webchick, vijaycs85, larowlan, andrewmacpherson, droplet, Bojhan, mgifford, drpal, phenaproxima, DyanneNova, japerry: Implementation issue for Layout Builder
2017-11-17 19:01:26 +00:00
} ) ( jQuery , Drupal ) ;