wp/wp-content/plugins/portfolio/js/front_script.js
changeset 7 cf61fcea0001
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
       
     1 ( function ( $ ) {
       
     2 	$( document ).ready( function() {
       
     3 		var label = $( '.portfolio_images_block > span' );
       
     4 
       
     5 		$( window ).resize( function() {
       
     6 			$( ".portfolio_images_block" ).each( function () {
       
     7 				var $gallery = $( this ),
       
     8 					gallery_wrap_width = $gallery.parent( '.entry' ).width(),
       
     9 					$gallery_rows = $gallery.find( '.portfolio_images_rows' ),
       
    10 					$gallery_first_row = $gallery_rows.filter( ':first' ),
       
    11 					$images = $gallery.find( '.portfolio_images_gallery' ),
       
    12 					images_in_first_row = $gallery_first_row.find( '.portfolio_images_gallery' ),
       
    13 					count_images_in_first_row = images_in_first_row.length,
       
    14 					width_image_block_ = images_in_first_row.outerWidth( true ),
       
    15 					columns = $gallery.data( 'columns' ),
       
    16 					count_images = $images.length,
       
    17 					pre_count_images_in_row = Math.floor( gallery_wrap_width / width_image_block_ ),
       
    18 					count_images_in_row = ( columns < pre_count_images_in_row ) ? columns : pre_count_images_in_row,
       
    19 					count_rows = Math.ceil( count_images / count_images_in_row );
       
    20 				if ( count_images_in_first_row != count_images_in_row && 0 != count_images_in_row ) {
       
    21 
       
    22 					$gallery.empty();
       
    23 					$gallery.append( label );
       
    24 
       
    25 					for( var i = 1; i <= count_rows; i++ ) {
       
    26 						var $new_row = $( '<div/>', {
       
    27 							'class' : 'portfolio_images_rows'
       
    28 						} ),
       
    29 						$new_images_in_row = $images.splice( 0, count_images_in_row );
       
    30 						$new_row.append( $new_images_in_row );
       
    31 						$gallery.append( $new_row );
       
    32 					}
       
    33 				}
       
    34 			} );
       
    35 		} );
       
    36 	} );
       
    37 } )( jQuery );