Вход Регистрация
Файл: IPBMafia.ru_IPB_3.4.6_Final_Rus _Nulled/board/upload/public/js/ips.gallery_patchwork.js
Строк: 417
<?php
Element
.addMethods({

    
patchwork: function( elementoptions ){

        
options Object.extend({
            
minSize180,
            
optimumSize200,
            
gutterSize10,
            
minRowCount2,
            
maxRowCount5,
            
switchImagestrue,
            
switchInterval8,
            
showRandomImagetrue
        
}, options);

        var 
boxDims = {},
            
curColumns null,
            
curRows null,
            
columnCount,
            
itemWidth,
            
grid = [],
            
maxBigImages,
            
images = [],
            
totalImages,
            
doneInit false,
            
origImageData,
            
rowCount;

        
//------------------------------------
        // Our kinda-constructor
        //------------------------------------
        
var _init = function(){

            
// copy image data to a variable that we won't
            // change
            
origImageData options.imageData.clone();
            
totalImages options.imageData.length;

            
getBoxDims();
            
calculateColumnsAndRows();
            
_createBlocks();
            
resizeWrapper();
            
doneInit true;
        },

        
//------------------------------------
        // Creates the grid our images sit on
        //------------------------------------
        
_createGrid = function(){
            
grid = [];
            for( var 
0rowCounti++ ){
                
grid[i] = new Array( columnCount );
            } 
        },

        
//------------------------------------
        // Randomly positions the larger images
        //------------------------------------
        
_allocateLargeImages = function(){

            
// Position the large images
            
var checkGrid = function(p){
                return 
gridp[0] ][ p[1] ] == null;
            }

            var 
startX Math.floorMath.random() * ( columnCount ) );
            var 
startY Math.floorMath.random() * ( rowCount ) );
            var 
curX startX;
            var 
curY startY;

            
// First loop to build each large image
            // Second loop for each row
            // Third loop for each column
            
ImageLoop:
            for( var 
0maxBigImagesi++ ){
                for( var 
0< ( rowCount ); n++ ){
                    for( var 
0< ( grid].length ); m++ ){

                        
// The coords this image would use if it fits
                        
var possibleCoords = [ 
                                                [ 
curYcurX ],
                                                [ 
curY 1curX ],
                                                [ 
curY 1curX ],
                                                [ 
curYcurX 
                                            ];

                        
// Check the coords are available, insert is possible
                        
if( possibleCoords.allcheckGrid ) ){
                            
gridcurY ][ curX ] = 3;
                            
gridcurY+][ curX+] = 2;
                            
gridcurY ][ curX+] = 2;
                            
gridcurY+][ curX ] = 2;
                            continue 
ImageLoop;
                        }

                        
// subtract 2... 1 so it's zero index
                        // another because our image is 2 wide so we'll not bother
                        // checking the last column - image would never fit anyway.
                        
if( curX++ == ( columnCount ) ){ 
                            
curX 0;
                        }
                    }

                    
// Same as curX loop - subtract 2
                    
if( curY++ == ( rowCount ) ){
                        
curY 0;
                    }
                }
            }

        },

        
//------------------------------------
        // Fills small images and inits all
        //------------------------------------
        
_fillAndInitImages = function(){

            
images = [];

            for( var 
0rowCountn++ ){
                for( var 
0grid].lengthm++ ){
                    
                    if( 
grid][ ] == null ){
                        
images.push
                            new 
patchworkImage( {
                                
pos: [ n],
                                
size'small',
                                
imagegetNextImage(),
                                
fade: !doneInit,
                                
variancegetRandomVariance()
                            } ) 
                        );
                    } else if( 
grid][ ] == ){
                        
images.push
                            new 
patchworkImage( { 
                                
pos: [ n],
                                
size'large',
                                
imagegetNextImage(),
                                
fade: !doneInit,
                                
variancegetRandomVariance()
                            } )
                        );
                    }

                }
            }

        },

        
//------------------------------------
        // Destroys existing images
        //------------------------------------
        
destroyImages = function(){
            
images.each( function(item){
                
item.destroy();
                
delete item;
            });

            
images null;
        },

        
//------------------------------------
        // Calls methods in sequence that will
        // build our grid and blocks
        //------------------------------------
        
_createBlocks = function(){

            
maxBigImages Math.roundMath.sqrtrowCount columnCount )  ) - 2;
            if( 
maxBigImages ){ maxBigImages 1; }
            if( 
maxBigImages ){ maxBigImages 5; }

            
Debug.write("Total images shown: " + ( rowCount columnCount ) );
            
Debug.write("Max big images to show: " maxBigImages );

            
_createGrid();
            
_allocateLargeImages();
            
_fillAndInitImages();
        },

        
//------------------------------------
        // Sets our wrapper dimensions variable
        //------------------------------------
        
getBoxDims = function(){
            
boxDims = $( element ).getDimensions();
        },

        
//------------------------------------
        // Resizes the main wrapper to fit vertically
        //------------------------------------
        
resizeWrapper = function(){
            var 
height calculateHeightitemWidth );

            $(
element).setStyle({
                
'height': ( ( height rowCount ) + ( options.gutterSize * ( rowCount ) ) ) + 'px'
            
});
        },

        
//------------------------------------
        // Calculate number and size of columns
        //------------------------------------
        
calculateColumnsAndRows = function(){
            var 
columns parseIntboxDims.width options.optimumSize );
            var 
leftover boxDims.width options.optimumSize;

            
// If what's left over is bigger than the minimum size,
            // add an extra column. We'll resize the images.
            
if( leftover options.minSize ){
                
columns++;
            }

            
columnCount columns;

            
// So our total item width is the box size divided by columns
            
itemWidth Math.floor( ( boxDims.width - ( options.gutterSize * ( columnCount ) ) ) / columnCount );

            
// How many rows?
            // Check whether rows * cols is more than
            // the total number of images we have,
            // and decrement as necessary.
            
var done false;
            var 
cur options.maxRowCount;

            do {
                var 
= ( cur columnCount );

                if( 
totalImages || cur == options.minRowCount ){
                    
rowCount cur;
                    
done true;
                } else {
                    
cur--;
                }
            } while( !
done );
        },

        
//------------------------------------
        // Returns height value based on width value
        //------------------------------------
        
calculateHeight = function( width ){
            return ( 
width ) * 3;
        },

        
//------------------------------------
        // Returns a random image and then removes it from the array
        // If we're out of elements, we repopulate and start again
        //------------------------------------
        
getNextImage = function(){
            if( 
options.imageData.length === ){
                
_resetImageArray();
            }

            if( 
options.showRandomImage ){
                var 
toreturn options.imageData.spliceMath.floorMath.random() * options.imageData.length ), )[0];

                while( 
typeoftoreturn ) == 'undefined' )
                {
                    
toreturn options.imageData.spliceMath.floorMath.random() * options.imageData.length ), )[0];
                }
            } else {
                var 
toreturn options.imageData.splice0)[0];
            }

            return 
toreturn;
        },

        
getRandomVariance = function(){
            return ( 
Math.random() * options.switchInterval ).toFixed(3);
        },

        
//------------------------------------
        // resets options.imageData to its original value
        //------------------------------------
        
_resetImageArray = function(){
            
options.imageData origImageData.clone();
        },

        
// Debug function
        
outputGrid = function( grid ){
            for( var 
0grid.lengthi++ ){
                var 
rowOutput '';
                for( var 
0grid[i].lengthj++ ){
                    if( 
grid][ ] == || grid][ ] == ){
                        
rowOutput += "[x]";
                    } else if( 
grid][ ] === ) {
                        
rowOutput += "[o]";
                    } else {
                        
rowOutput += "[ ]";
                    }
                }
                
Debug.writerowOutput );
            }
        };

        
//------------------------------------
        // Class for each block
        //------------------------------------
        
var patchworkImage = Class.create({

            
// Constructor
            
initialize: function( data ){
                var 
self this;
                
this.data data;
                
this.parentElement element;

                
// Build inner element (which holds the image)
                
this.innerElement = new Element('div');

                
// Build outer element (which has a shadow)
                
this.outerElement = new Element('div')
                                        .
setStyle({
                                            
'position''absolute'
                                        
})
                                        .
addClassName('featured_image')
                                        .
addClassName('clickable')
                                        .
hide()
                                        .
insertthis.innerElement );
                
                
// Set the size and position of this block
                
this.sizeAndPosition();

                
// Set the background image on the inner element
                
this.setBackgroundthis.innerElement );

                
// Insert into our grid
                
$( this.parentElement ).insertthis.outerElement );

                
// Decide whether to fade in or not
                
if( this.data.fade ){
                    
this.outerElement.appear({ delayMath.random().toFixed(3), afterFinish: function(){
                        if( 
options.switchImages ){
                            
self.switchImage.bind(self).delayparseInt(options.switchInterval) + parseInt(self.data.variance) );
                        }
                    }});
                } else {
                    
this.outerElement.show();
                }

                
this.outerElement.observe'click', function(e) {
                    
window.location this.data.image.image_url.replace( /&amp;/, '&' );
                }.
bindAsEventListener(this) );

                
// Listen for resize event
                
$( this.parentElement ).on'patchwork:resize'this.resizeEvent.bindAsEventListener(this) );
            },

            
switchImage: function(){
                
                
// Get new image
                
this.data.image getNextImage();
                
                var 
newDiv this.setBackground( new Element('div').hide() );

                
this.outerElement.insertnewDiv );

                new 
Effect.Parallel([
                    new 
Effect.Fadethis.innerElement, { synctrue } ),
                    new 
Effect.AppearnewDiv, { synctrue } )
                ], {
                    
duration1.5,
                    
afterFinish: function(){
                        
this.innerElement.remove();
                        
this.innerElement newDiv;
                    }.
bind(this)
                });

                if( 
options.switchImages ){
                    
this.switchImage.bind(this).delayparseInt(options.switchInterval) + parseInt(this.data.variance) );
                }
            },

            
// Sets the size and position of this block
            
sizeAndPosition: function(){
                var 
itemHeight calculateHeightitemWidth );

                
this.outerElement.setStyle({
                    
'left': ( this.data['pos'][1] * itemWidth ) + ( this.data['pos'][1] * options.gutterSize ) + 'px',
                    
'top': ( this.data['pos'][0] * itemHeight ) + ( this.data['pos'][0] * options.gutterSize ) + 'px',
                    
'width': ( ( this.data.size == 'large' ) ? ( itemWidth ) + options.gutterSize itemWidth ) + 'px',
                    
'height': ( ( this.data.size == 'large' ) ? ( itemHeight options.gutterSize ) : itemHeight ) + 'px'
                
});

                return 
this.outerElement;
            },

            
// Sets the background image on an element
            
setBackground: function( elem ){

                $( 
elem ).setStyle({
                                    
backgroundImage'url(' this.data.image.med_img ')',
                                    
backgroundPosition'center center',
                                    
backgroundRepeat'no-repeat'
                                
});

                if( 
this.data.image.thumb_size.>= itemWidth ){
                    $( 
elem ).setStyle({
                        
'background-size''cover'
                    
});
                }

                return 
elem;
            },

            
// Prepare to destroy ourselves
            
destroy: function(){
                
this.outerElement.remove();
            },

            
// Catches the resize event fired by outer script
            
resizeEvent: function(e){
                
this.sizeAndPosition();
            }
        });

        
//------------------------------------
        // Window resize event
        //------------------------------------
        
Event.observewindow'resize', function(){
            
curColumns columnCount;
            
curRows rowCount;
            
getBoxDims();
            
calculateColumnsAndRows();

            
// Number of columns changed?
            
if( curColumns != columnCount || curRows != rowCount ){
                
destroyImages();
                
_resetImageArray();
                
_createBlocks();
            }

            
resizeWrapper();

            
Event.fireelement'patchwork:resize' );
        });

        
_init();
        return 
element;
    }

});
?>
Онлайн: 2
Реклама