Jetpack_Tiled_Gallery_Layout_Square

The Jetpack by WordPress.com Jetpack Tiled Gallery Layout Square class.

Defined (1)

The class is defined in the following location(s).

/modules/tiled-gallery/tiled-gallery/tiled-gallery-square.php  
  1. class Jetpack_Tiled_Gallery_Layout_Square extends Jetpack_Tiled_Gallery_Layout { 
  2. protected $type = 'square'; 
  3.  
  4. private function compute_items() { 
  5. $content_width = Jetpack_Tiled_Gallery::get_content_width(); 
  6. $images_per_row = $this->columns; 
  7. $margin = 2; 
  8.  
  9. $margin_space = ( $images_per_row * $margin ) * 2; 
  10. $size = floor( ( $content_width - $margin_space ) / $images_per_row ); 
  11. $img_size = $remainder_size = $size; 
  12. $remainder = count( $this->attachments ) % $images_per_row; 
  13. if ( $remainder > 0 ) { 
  14. $remainder_space = ( $remainder * $margin ) * 2; 
  15. $remainder_size = floor( ( $content_width - $remainder_space ) / $remainder ); 
  16.  
  17. $c = 1; 
  18. $items_in_row = 0; 
  19. $rows = array(); 
  20. $row = new stdClass; 
  21. $row->images = array(); 
  22. foreach( $this->attachments as $image ) { 
  23. if ( $remainder > 0 && $c <= $remainder ) { 
  24. $img_size = $remainder_size; 
  25. } else { 
  26. $img_size = $size; 
  27.  
  28. $image->width = $image->height = $img_size; 
  29.  
  30. $item = new Jetpack_Tiled_Gallery_Square_Item( $image, $this->needs_attachment_link, $this->grayscale ); 
  31.  
  32. $row->images[] = $item; 
  33. $c ++; 
  34. $items_in_row++; 
  35.  
  36. if ( $images_per_row === $items_in_row || $remainder + 1 == $c ) { 
  37. $rows[] = $row; 
  38. $items_in_row = 0; 
  39.  
  40. $row->height = $img_size + $margin * 2; 
  41. $row->width = $content_width; 
  42. $row->group_size = $img_size + 2 * $margin; 
  43.  
  44. $row = new stdClass; 
  45. $row->images = array(); 
  46.  
  47. if ( ! empty( $row->images ) ) { 
  48. $row->height = $img_size + $margin * 2; 
  49. $row->width = $content_width; 
  50. $row->group_size = $img_size + 2 * $margin; 
  51.  
  52. $rows[] = $row; 
  53.  
  54. return $rows; 
  55.  
  56. public function HTML( $context = array() ) { 
  57. return parent::HTML( array( 'rows' => $this->compute_items() ) );