Skip to content

Instantly share code, notes, and snippets.

@markoheijnen
Created January 25, 2013 15:29
Show Gist options
  • Save markoheijnen/4635255 to your computer and use it in GitHub Desktop.
Save markoheijnen/4635255 to your computer and use it in GitHub Desktop.
Add Photobox support to WordPress galleries
<?php
class Gallery_Javascript {
private $link;
function __construct() {
add_filter( 'post_gallery', array( $this, 'enqueue_script' ), 20, 2 );
add_filter( 'gallery_style', array( $this, 'add_class' ) );
}
function enqueue_script( $output, $attr ) {
global $wp_styles;
if( $output )
return $output;
$this->link = isset( $attr['link'] ) && 'file' == $attr['link'] ? true : false;
if( $this->link ) {
wp_enqueue_script(
'jquery-photobox',
plugins_url( '/gallery/photobox/photobox.js', __FILE__ ),
array( 'jquery' ),
'1.4.5'
);
wp_enqueue_style(
'jquery-photobox',
plugins_url( '/gallery/photobox/photobox.css', __FILE__ ),
array(),
'1.4.5',
'all'
);
wp_enqueue_style(
'jquery-photobox-ie8',
plugins_url( '/gallery/photobox/photobox.ie.css', __FILE__ ),
array(),
'1.4.5',
'all'
);
$wp_styles->add_data( 'jquery-photobox-ie8', 'conditional', 'lt IE 9' );
}
return $output;
}
function add_class( $output ) {
if( $this->link ) {
$output = substr_replace( $output, "", -2 );
$output .= " gallery-link-file'>";
}
return $output;
}
}
new Gallery_Javascript;
jQuery( ".gallery-link-file" ).each(function( index ) { jQuery('#'+jQuery(this).attr('id')).photobox('a', { thumbs:true }); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment