Skip to content

Instantly share code, notes, and snippets.

@marcusig
Created March 19, 2022 08:19
Show Gist options
  • Save marcusig/8934e1afea6420b8d63ce0eb033a8de3 to your computer and use it in GitHub Desktop.
Save marcusig/8934e1afea6420b8d63ce0eb033a8de3 to your computer and use it in GitHub Desktop.
Wrap layer images with a div. One div per layer
wp.hooks.addAction( 'PC.fe.viewer.item.added', 'MKL/PC/Custom_JS', function( view, viewer ) {
// Set the class name
var layer_class = 'layer-' + view.model.get( 'layerId' );
// Find the existing container.
var layer_container = viewer.$layers.find( '.' + layer_class );
if ( ! layer_container.length ) {
// If the container doesn't exist, add it
view.$el.wrap( '<div class="' + layer_class + '" />' );
} else {
layer_container.append( view.$el );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment