Вход Регистрация
Файл: plugins/photo/static/js/photo.js
Строк: 2167
<?php
(function( window, $, params ) {'use strict';
    var 
utils window.photoUtils;
    var 
_vars = $.extend({}, (params || {}),
        {
cache: {}, minSize: {width400height400}, spacing30infoBar400cmpListForDeleting: [], curPos0fullScreen: (function()
        {
            if ( !
params.isEnableFullscreen )
            {
                return 
false;
            }
            
            var 
valvalLength;
            var 
fnMap = [
                [
'requestFullscreen','exitFullscreen','fullscreenElement','fullscreenEnabled','fullscreenchange','fullscreenerror'],
                [
'webkitRequestFullscreen','webkitExitFullscreen','webkitFullscreenElement','webkitFullscreenEnabled','webkitfullscreenchange','webkitfullscreenerror'],
                [
'webkitRequestFullScreen','webkitCancelFullScreen','webkitCurrentFullScreenElement','webkitCancelFullScreen','webkitfullscreenchange','webkitfullscreenerror'],
                [
'mozRequestFullScreen','mozCancelFullScreen','mozFullScreenElement','mozFullScreenEnabled','mozfullscreenchange','mozfullscreenerror'],
                [
'msRequestFullscreen','msExitFullscreen','msFullscreenElement','msFullscreenEnabled','MSFullscreenChange','MSFullscreenError']
            ];
            var 
0;
            var 
ret = {};

            for ( ; 
fnMap.lengthi++ )
            {
                
val fnMap[i];

                if ( 
val && val[1in document )
                {
                    for ( 
0valLength val.lengthvalLengthi++ )
                    {
                        
ret[fnMap[0][i]] = val[i];
                    }

                    return 
ret;
                }
            }

            return 
false;
        })()},
        {
globalList: [], lists: [], ID_LIST_LIMIT2DEFAULT_LIST'latest'},
        {
toStringObject.prototype.toString},
        {
            
commentEvents: [
                
'base.comments_list_init',
                
'base.comment_add'
                
'base.comment_delete',
                
'base.attachment_added',
                
'base.attachment_deleted',
                
'base.comment_added',
                
'base.comment_textarea_resize',
                
'base.comment_attachment_added',
                
'base.comment_button_show',
                
'base.add_photo_attachment_submit',
                
'base.comment_attachment_deleted',
                
'base.comment_video_play',
                
'base.comment_attach_media'
            
],
            
commentUnknownEntity: [
                
'base.add_photo_attachment_submit',
                
'base.comment_video_play',
                
'base.comment_attach_media'
            
]
        }
    ),
    
_elements = {
        
preloader: $('<div>').addClass('peep_floatbox_preloader peep_photo_preload')
    },
    
_methods = {
        
isLoading: function()
        {
            return 
_vars.fetchRequest && _vars.fetchRequest.readyState !== 4;
        },
        
setId: function( photoIdlistTypeextenddataphoto )
        {
            if ( 
_methods.isLoading() )
            {
                return 
false;
            }
            
            
_methods.history.replaceState(photoIdlistTypeextenddataphoto);
        },
        
isCached: function( photoId )
        {
            return !
isNaN(+photoId) && _vars.cache.hasOwnProperty(+photoId);
        },
        
cachePhotoComponents: function( photos )
        {
            var 
keysidList = [];
                
            if ( !
photos || utils.getObjectType(photos) !== 'Object' || (keys Object.keys(photos)).length === )
            {
                return 
false;
            }
            
            
keys.forEach(function( item )
            {
                if ( !
_methods.isCached(item) )
                {
                    var 
cmp _vars.cache[item] = photos[item];
                    
idList.push(item);

                    if ( 
cmp.photo.dimension )
                    {
                        try
                        {
                            
cmp.photo.dimension JSON.parse(cmp.photo.dimension);
                        }
                        catch ( 
ignore ) { }
                    }
                    
                    
PEEP.trigger('photo.afterPhotoCached', [cmp.photo.idcmp], _methods);
                }
            });

            
_methods.backgroundLoadPhotos(idList_methods.fullscreen.isFullscreen() ? 'fullscreen' 'main');
        },
        
backgroundLoadPhotos: function( photoIdListtype )
        {
            if ( !Array.
isArray(photoIdList) || photoIdList.length === ) return;

            
photoIdList.forEach(function( item )
            {
                if ( 
_methods.isCached(item) )
                {
                    var 
cmp _methods.getPhotoCmp(item);
                    var 
url = (type === 'fullscreen' && +cmp.photo.hasFullsize) ? cmp.photo.urlFullscreen cmp.photo.url;
                    
                    
setTimeout(function( url )
                    {
                        new 
Image().src url;
                    }, 
1url);
                }
            });
        },
        
setState: function( loading )
        {
            if ( 
utils.getObjectType(loading) !== 'Boolean' )
            {
                
loading true;
            }
            
            switch ( 
loading )
            {
                case 
false:
                    
_methods.utils.hidePreloader();
                    break;
                case 
true:
                default:
                    
_methods.utils.showPreloader();
                    break;
            }
        },
        
getPhotoCmp: function( photoId )
        {
            if ( !
_methods.isCached(photoId) )
            {
                return 
null;
            }
            
            return 
_vars.cache[photoId];
        },
        
deletePhotoCmp: function( photoId )
        {
            
delete _vars.cache[photoId];
        },
        
getIsLoadPrevList: function( index )
        {
            return !
_vars.isPrevCompleted && index _vars.ID_LIST_LIMIT;
        },
        
getIsLoadNextList: function( index, list )
        {
            return !
_vars.isNextCompleted && list.length index _vars.ID_LIST_LIMIT;
        },
        
getPrevId: function( index, list )
        {
            if ( [
'most_discussed''toprated'].indexOf(_vars.listType) !== -)
            {
                return 
index === ? list[list.length 1] : list[index 1];
            }

            return 
index === ?
                (
_vars.lists.length === ?
                    
_vars.globalList[_vars.globalList.length 1] :
                    
_methods.arrayUtils.getMinInList(_vars.lists)) :
                list[
index 1];
        },
        
getNextId: function( index, list )
        {
            if ( [
'most_discussed''toprated'].indexOf(_vars.listType) !== -)
            {
                return 
index === list.length ? list[0] : list[index 1];
            }

            return 
index === list.length ?
                (
_vars.lists.length === ?
                    
_vars.globalList[0] :
                    
_methods.arrayUtils.getMaxInList(_vars.lists)) :
                list[
index 1];
        },
        
clearHistory: function()
        {
            
_vars.globalList.length 0;
            
_vars.lists.length 0;
        },
        
showFloatBox: function()
        {
            if ( 
_elements.hasOwnProperty('photoFB') || _vars.layout === 'page' )
            {
                return;
            }
            
            var 
options = {};
                
            if ( 
_vars.isClassic )
            {
                
options.addClass 'peep_photoview_overlay_pint';
                
options.$title '';
            }
            else
            {
                
options.addClass 'peep_photoview_overlay floatbox_overlayBG';
                
options.layout 'empty';
            }

            
_elements.photoFB = new PEEP_FloatBox(options);
            
_elements.photoFB.bind('show', function()
            {
                
_vars.fbHasContent true;
            });
            
_elements.photoFB.bind('close', function()
            {
                
_methods.history.goInitState();
                
_methods.beforeLoadCmp(_vars.photoId);

                
delete _elements.photoFB;
                
delete _elements.content;
                
delete _vars.direction;
                
delete _vars.photoId;

                
_vars.minSize.width 400;
                
_vars.minSize.height 400;
                
_vars.fbHasContent false;

                
_vars.cmpListForDeleting.forEach(function( item )
                {
                    
_methods.deletePhotoCmp(item);
                });
                
_vars.cmpListForDeleting.length 0;
                
                if ( 
_methods.fullscreen.isFullscreen() )
                {
                    
_methods.fullscreen.exit();
                }
                
                
PEEP.trigger('photo.onFloatboxClose', [], _methods);
            });
        },
        
getDataToSend: function( photoIdlistType )
        {
            var 
dataToSend = {photos: [], photoIdphotoIdlayout_vars.layout}, params = {};
            var 
index _vars.globalList.indexOf(photoId);

            if ( 
index === -)
            {
                var 
listIndex = -1keyInListIndex = -1;
                
                
_vars.lists.some(function( index)
                {
                    
listIndex i;
                    
                    return (
keyInListIndex index.indexOf(photoId)) !== -1;
                });
                
                if ( 
listIndex === -|| keyInListIndex === -)
                {
                    
params.photoId photoId;
                    
                    
dataToSend.photoId photoId;
                    
dataToSend.loadPrevList 1;
                    
dataToSend.loadPrevPhoto 1;
                    
dataToSend.loadNextList 1;
                    
dataToSend.loadNextPhoto 1;
                    
dataToSend.photos.push(photoId);
                }
                else
                {
                    var list = 
_vars.lists.slice(0);
                    list.
push(_vars.globalList);

                    
params.prevId keyInListIndex === ?
                        
_methods.arrayUtils.getMinInList(list) :
                        
_vars.lists[listIndex][keyInListIndex 1];
                    
params.nextId keyInListIndex === _vars.lists[listIndex].length ?
                        
_methods.arrayUtils.getMaxInList(list) :
                        
_vars.lists[listIndex][keyInListIndex 1];
                    
params.listIndex listIndex;
                
                    if ( 
_vars.hasOwnProperty('direction') )
                    {
                        switch ( 
_vars.direction )
                        {
                            case 
'left':
                                
dataToSend.loadPrevList keyInListIndex _vars.ID_LIST_LIMIT 0;
                                break;
                            case 
'right':
                            default:
                                
dataToSend.loadNextList _vars.lists[listIndex].length keyInListIndex _vars.ID_LIST_LIMIT 0;
                                break;
                        }
                    }
                    else
                    {
                        
dataToSend.loadPrevList keyInListIndex _vars.ID_LIST_LIMIT 0;
                        
dataToSend.loadNextList _vars.lists[listIndex].length keyInListIndex _vars.ID_LIST_LIMIT 0;
                    }
                }
            }
            else
            {
                
params.prevId _methods.getPrevId(index_vars.globalList);
                
params.nextId _methods.getNextId(index_vars.globalList);

                if ( 
_vars.hasOwnProperty('direction') )
                {
                    switch ( 
_vars.direction )
                    {
                        case 
'left':
                            
dataToSend.loadPrevList _methods.getIsLoadPrevList(index) ? 0;
                            break;
                        case 
'right':
                        default:
                            
dataToSend.loadNextList _methods.getIsLoadNextList(index_vars.globalList) ? 0;
                            break;
                    }
                }
                else
                {
                    
dataToSend.loadPrevList _methods.getIsLoadPrevList(index) ? 0;
                    
dataToSend.loadNextList _methods.getIsLoadNextList(index_vars.globalList) ? 0;
                }
            }
            
            if ( !
_methods.isCached(photoId) )
            {
                
params.photoId photoId;
                
params.loadCurrent true;

                
dataToSend.photos.push(photoId);
            }

            if ( !
_methods.isCached(params.prevId) )
            {
                
dataToSend.photos.push(params.prevId);
            }

            if ( !
_methods.isCached(params.nextId) )
            {
                
dataToSend.photos.push(params.nextId);
            }
            
            if ( [
'hash''user''desc''all'].indexOf(listType) !== -)
            {
                var 
listData = {};
                
                if ( 
window.hasOwnProperty('browsePhoto') )
                {
                     
listData window.browsePhoto.getListData();
                }
                else
                {
                    var 
searchParse _methods.locationUtils.parseSearch(location.search.substr(1));
                    
                    if ( 
searchParse.hasOwnProperty('searchVal') )
                    {
                        
listData searchParse;
                    }
                }
                    
                $.
extend(dataToSendlistData);
            }
            
            return {
                
dataToSenddataToSend,
                
paramsparams
            
};
        },
        
showPhotoCmp: function( photoIdlistTypedataphoto )
        {
            
PEEP.trigger('photo.onBeforeShow', [photoIdlistType], _methods);
            
            if ( 
photoId !== _vars.photoId )
            {
                
PEEP.trigger('photo.onBeforePhotoChange', [_vars.photoIdphotoId], _methods);
            }
            
            
_methods.showFloatBox();
            
            if ( 
_vars.isDisabled && _vars.layout !== 'page')
            {
                
_elements.photoFB.setContent($(document.getElementById('peep-photo-view-error')));
                
_elements.photoFB.fitWindow({width500height300});
                
                return;
            }
            
            
_methods.beforeLoadCmp(_vars.photoId);
            
_vars.photoId = +photoId;
            
_vars.listType listType || _vars.DEFAULT_LIST;
            
            if ( 
data && data.main && data.main.length === && data.mainUrl )
            {
                
_methods.createFloatboxContent();
                
_elements.photoFB.setContent(_elements.content);
                
                var 
dimension _methods.getScreenDimension(data.main[0], data.main[1]),
                    
imgCss = {}, floatboxCss = {widthdimension.width _vars.infoBarheightdimension.height}, stageCss = {heightdimension.height};
                var 
proportion _methods.utils.getScreenProportion(dimension.widthdimension.heightdata.main[0], data.main[1]);
                
                if ( 
proportion[0] > dimension.imageWeight && proportion[1] > dimension.imageHeight )
                {
                    
imgCss.width dimension.imageWeight;
                    
imgCss.height dimension.imageHeight;
                }
                else
                {
                    
imgCss.width proportion[0];
                    
imgCss.height proportion[1];
                }
                
                if ( 
_vars.isClassic )
                {
                    
stageCss.float 'none';
                    
floatboxCss.height 0;
                }
                else
                {
                    
floatboxCss.top dimension.screenHeight dimension.height 2;
                    
stageCss.width dimension.width;
                    
_elements.content.find('.peep_photoview_info_wrap').height(floatboxCss.height);
                }

                
PEEP.trigger('photo.setStage', [photodatastageCssimgCss], _elements.content);

                
_elements.photoFB.fitWindow(floatboxCss);
                
_elements.content.find('.peep_photoview_stage_wrap').css(stageCss);
                
_elements.content.find('img.peep_photo_view').css(imgCss).attr('src'data.mainUrl);
            }

            
_methods.setState(true);

            var 
send _methods.getDataToSend(_vars.photoId_vars.listType);
            
            if ( 
_methods.isCached(send.dataToSend.photoId) )
            {
                
_methods.loadCachedComponent(send.dataToSend.photoId);
            }
            
            
_methods.backgroundLoadPhotos([send.params.nextIdsend.params.prevId], _methods.fullscreen.isFullscreen() ? 'fullscreen' 'main');
            
            if ( 
_methods.utils.isNotEmptyObject(send.dataToSend) )
            {
                $.
extend(send.dataToSend, {ajaxFunc'getFloatbox'listType_vars.listType});
                
_methods.fetchCmp(send.dataToSendsend.params);
            }
        },
        
fetchCmp: function( dataToSendparams )
        {
            
_vars.fetchRequest = $.ajax(
            {
                
url_vars.ajaxResponder,
                
type'POST',
                
cachefalse,
                
datadataToSend,
                
dataType'json',
                
beforeSend: function( jqXHRsettings )
                {
                    
PEEP.trigger('photo.onBeforeLoadPhoto', [dataToSend.photoId], _methods);
                },
                
success : function( responce )
                {
                    if ( !
responce || !responce.result )
                    {
                        return;
                    }
                    
                    
PEEP.trigger('photo.onRequestComplete', [dataToSendparamsresponce], _methods);
                    
utils.includeScriptAndStyle(responce.scripts);
                    
_methods.cachePhotoComponents(responce.photos);
                        
                    if ( 
params.loadCurrent )
                    {
                        
_methods.loadCachedComponent(params.photoId);
                    }

                    if ( 
responce.prevCompleted && !_vars.isPrevCompleted )
                    {
                        
_vars.isPrevCompleted true;
                        
_methods.arrayUtils.push(_vars.lists_methods.arrayUtils.unionToList(responce.firstList));
                    }

                    if ( 
responce.nextCompleted && !_vars.isNextCompleted )
                    {
                        
_vars.isNextCompleted true;
                        
_methods.arrayUtils.push(_vars.lists_methods.arrayUtils.unionToList(responce.lastList));
                    }

                    var list = 
_methods.arrayUtils.unionToList(responce.prevListparams.photoIdresponce.nextList);

                    if ( 
_vars.globalList.length === )
                    {
                        
_vars.globalList = list;
                    }
                    else
                    {
                        if ( 
_methods.arrayUtils.isMatch(_vars.globalList, list) )
                        {
                            
_vars.globalList _methods.arrayUtils.unionToList(_vars.globalList, list);
                        }
                        else
                        {
                            if ( 
params.listIndex )
                            {
                                
_vars.lists[params.listIndex] = _methods.arrayUtils.unionToList(_vars.lists[params.listIndex], list);
                                
_vars.lists.sort(_methods.arrayUtils.sortBySum);
                            }
                            else
                            {
                                
_methods.arrayUtils.push(_vars.lists, list);
                            }
                            
                            while ( 
true )
                            {
                                var 
listIndex;
                                var 
match _vars.lists.some(function( item)
                                {
                                    
listIndex i;

                                    return 
_methods.arrayUtils.isMatch(_vars.globalListitem);
                                });

                                if ( 
match )
                                {
                                    
_vars.globalList _methods.arrayUtils.unionToList(_vars.globalList_vars.lists[listIndex]);
                                    
_vars.lists.splice(listIndex1);
                                }
                                else
                                {
                                    var 
indexinnerIndex;
                                    var 
some _vars.lists.some(function( item)
                                    {
                                        
index i;
                                        
                                        for ( var 
1_vars.lists.lengthj++ )
                                        {
                                            
innerIndex j;
                                            
                                            if ( 
_vars.lists[j][0] + >= item[item.length -1] )
                                            {
                                                return 
true;
                                            }
                                        }
                                    });
                                    
                                    if ( 
some )
                                    {
                                        
_vars.lists[index] = _methods.arrayUtils.unionToList(_vars.lists[index], _vars.lists[innerIndex]);
                                        
_vars.lists.splice(innerIndex);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                },
                
error: function( jqXHRtextStatuserrorThrown )
                {
                    throw 
textStatus;
                },
                
complete: function( jqXHRtextStatus )
                {

                }
            });
        },
        
loadCachedComponent: function( photoId )
        {
            
_methods.createFloatboxContent();
            
PEEP.trigger('photo.onBeforeLoadFromCache', [photoId], _methods);
            
            if ( 
_vars.layout === 'page' )
            {
                var 
contant = $(document.getElementById('peep-photo-view-page'));

                if ( 
contant.is(':empty') )
                {
                    
contant.html(_elements.content);
                }
            }
            else if ( 
_elements.photoFB.$body[0] && !_elements.photoFB.$body[0].children.length )
            {
                
_elements.photoFB.setContent(_elements.content);

                if ( 
_vars.isClassic )
                {
                    
_elements.photoFB.fitWindow({width_vars.minSize.width});
                }
                else
                {
                    
_elements.photoFB.fitWindow({width_vars.minSize.widthheight_vars.minSize.height});
                }
            }

            
_methods.setContent(photoId);
            
_methods.setComment(photoId);
            
_methods.addCmpMarkup(photoId);

            
PEEP.trigger('photo.markupReady', [_methods.getPhotoCmp(photoId)], _elements.content);
            
            
_methods.fitSize(photoId, function( offset )
            {
                
PEEP.trigger('photo.beforeResize', [photoId], _methods);

                if ( !
_methods.fullscreen.isFullscreen() )
                {
                    if ( 
_vars.layout !== 'page' )
                    {
                        var 
options = {};

                        if ( 
_vars.isClassic )
                        {
                            
_elements.content.find('.peep_photoview_stage_wrap').css({float'none'height_vars.minSize.height});
                            
options.width offset.width;
                        }
                        else
                        {
                            
_elements.content.find('.peep_photoview_stage_wrap').css({width_vars.minSize.widthheight_vars.minSize.height});
                            
_elements.content.css('height'_vars.minSize.height);
                            
options offset;
                        }

                        
_elements.photoFB.fitWindow(options);
                        
_methods.updateComment({entityType'photo_comments'entityId_vars.photoId});
                    }
                    else
                    {
                        
_elements.content.find('.peep_photoview_stage_wrap').css({float'none'height_vars.minSize.height});
                    }
                }

                
PEEP.bindAutoClicks(_elements.content);
                
PEEP.bindTips(_elements.content);

                
PEEP.trigger('photo.afterResize', [photoId], _methods);
                
PEEP.trigger('photo.photo_show', {photoIdphotoId}, _methods);
                
                
_methods.setState(false);
            });
        },
        
fitSize: function( photoIdcallbackresize )
        {
            if ( !
_methods.isCached(photoId) )
            {
                return;
            }

            var 
cmp _methods.getPhotoCmp(photoId);
            var 
complete = function()
            {
                if ( !
_vars.isRunSlideshow  )
                {
                    var 
img _elements.content.find('img.peep_photo_view').css({width'auto'height'auto'})[0];
                    
                    if ( 
_methods.fullscreen.isFullscreen() && +cmp.photo.hasFullsize )
                    {
                        
img.src cmp.photo.urlFullscreen;
                    }
                    else
                    {
                        
img.src cmp.photo.url;
                    }
                }
                
                var 
imageWeight this.naturalWidth;
                var 
imageHeight this.naturalHeight;
                
                var 
screnWeight _vars.layout === 'page' ? $(document.getElementById('peep-photo-view-page')).width() : $(window).width();
                var 
screnHeight = $(window).height();
                
                var 
minWidth screnWeight 400 ? (screnWeight _vars.spacing) : 400;
                var 
minHeight screnHeight 400 ? (screnHeight _vars.spacing) : 400;

                var 
maxWidth _vars.layout === 'page' screnWeight : (screnWeight _vars.spacing 400);
                var 
maxHeight screnHeight _vars.spacing;
                
                if ( 
_vars.layout === 'page' )
                {
                    
callback({widthmaxWidthheightmaxHeight});
                    
                    return;
                }

                var 
width = (imageWeight minWidth && imageWeight maxWidth) ? imageWeight : (imageWeight minWidth) ? minWidth maxWidth;
                var 
height = (imageHeight minHeight && imageHeight maxHeight) ? imageHeight : (imageHeight minHeight) ? minHeight maxHeight;

                if ( 
resize )
                {
                    
_vars.minSize.width = (_vars.minSize.width _vars.infoBar screnWeight) ? maxWidth : (width <= _vars.minSize.width) ? _vars.minSize.width : (width >= maxWidth) ? maxWidthwidth;
                    
_vars.minSize.height = (_vars.minSize.height screnHeight) ? maxHeight : (height <= _vars.minSize.height) ? _vars.minSize.height : (height >= maxHeight) ? maxHeight height;
                }
                else
                {
                    
_vars.minSize.width = (_vars.minSize.width _vars.infoBar screnWeight) ? maxWidth : (width _vars.minSize.width) ? width _vars.minSize.width;
                    
_vars.minSize.height = (_vars.minSize.height screnHeight) ? maxHeight : (height _vars.minSize.height) ? height _vars.minSize.height;
                }

                
PEEP.trigger('photo.fitSize', [_methods.getPhotoCmp(photoId), _vars.minSize], _elements.content);

                
width _vars.minSize.width _vars.infoBar;
                
height _vars.minSize.height;

                
callback({widthwidthheightheighttopscrenHeight - (_vars.minSize.height 2)});
            };
            
            var 
img = new Image();
            
            if ( 
_methods.fullscreen.isFullscreen() && +cmp.photo.hasFullsize )
            {
                
img.src cmp.photo.urlFullscreen;
            }
            else
            {
                
img.src cmp.photo.url;
            }

            
img.complete complete.call(img) : img.onload complete;
        },
        
getScreenDimension: function( imgWidthimgHeightscreenMinWidthscreenMinHeight )
        {
            var 
screenWidth _vars.layout === 'page' ? $(document.getElementById('peep-photo-view-page')).width() : $(window).width(),
                
screenHeight = $(window).height(),

                
minWidth screenMinWidth || 400,
                
minHeight screenMinHeight || 400,

                
maxWidth _vars.layout === 'page' screenWidth : (screenWidth _vars.spacing _vars.infoBar),
                
maxHeight screenHeight _vars.spacing,

                
width imgWidth maxWidth maxWidth imgWidth minWidth minWidth imgWidth,
                
height =  imgHeight maxHeight maxHeight imgHeight minHeight minHeight imgHeight;
            
            return {
                
imageWeightimgWidth,
                
imageHeightimgHeight,
                
maxWidthmaxWidth,
                
maxHeightmaxHeight,
                
widthwidth,
                
heightheight,
                
minWidthminWidth,
                
minHeightminHeight,
                
screenWidthscreenWidth,
                
screenHeightscreenHeight
            
};
        },
        
setContent: function( photoId )
        {
            var 
content _elements.content;
            var 
cmp _methods.getPhotoCmp(photoId);
            
            $(
'.peep_user_list_picture a'content).attr('href'cmp.avatar.url);
            $(
'.peep_user_list_picture img'content).attr({altcmp.avatar.titlesrccmp.avatar.src}).show();
            $(
'.peep_photoview_albumlink'content).attr('href'cmp.albumUrl).html(
                
"'" utils.truncate(cmp.album.name) + "': " cmp.photoIndex ' ' PEEP.getLanguageText('photo''of') + ' ' cmp.photoCount
            
);
            $(
'.peep_user_list_data a.peep_photo_avatar_url'content).attr('href'cmp.avatar.url).html(cmp.avatar.title);
            $(
'.peep_user_list_data .peep_timestamp'content).html(cmp.photo.addDatetime);
            $(
'.peep_user_list_data .peep_photo_album_url'content).attr('href'cmp.albumUrl)
                .
find('.peep_photo_album_name').html(
                    
PEEP.getLanguageText('photo''album') + ': ' utils.truncate(cmp.album.name60)
            );
            
            if ( 
cmp.contextAction.length )
            {
                $(
cmp.contextAction).addClass('peep_photo_context_action').insertAfter($('.peep_photoview_bottom_menu_wrap'content)).show();
            }

            $(
'.peep_photo_share'content).empty().html(function()
            {
                return 
cmp.share || '';
            });
            
            if ( !
_methods.fullscreen.enabled() )
            {
                $(
'.peep_photoview_fullscreen'content).attr({target'_blank'href: (cmp.photo.urlFullscreen cmp.photo.urlFullscreen cmp.photo.url)});
            }
            
            $(
'#btn-photo-edit').off().on('click', function()
            {
                var 
photoId = $(this).attr('rel');
                
                
_elements.editFB PEEP.ajaxFloatBox('PHOTO_CMP_EditPhoto', {photoIdphotoId}, {width580iconClass'peep_ic_edit'titlePEEP.getLanguageText('photo''tb_edit_photo'),
                    
onLoad: function()
                    {
                        
peepForms['photo-edit-form'].bind('success', function( data )
                        {
                            
_elements.editFB.close();

                            if ( 
data && data.result )
                            {
                                if ( 
data.photo.status !== 'approved' )
                                {
                                    
PEEP.info(data.msgApproval);

                                    if ( 
_elements.photoFB )
                                    {
                                        
_elements.photoFB.close();
                                    }

                                    $(
'#photo-description').html(PEEP.getLanguageText('photo''pending_approval'));

                                    if ( 
window.hasOwnProperty('browsePhoto') )
                                    {
                                        
browsePhoto.removePhotoItems(['photo-item-' photoId]);
                                    }
                                }
                                else
                                {
                                    
PEEP.info(data.msg);

                                    
cmp.albumUrl data.albumUrl;
                                    
cmp.album.name data.albumName;
                                    
cmp.photo.description data.description;

                                    $(
'.peep_user_list_data .peep_photo_album_url'content).attr('href'data.albumUrl)
                                        .
find('.peep_photo_album_name').html(
                                            
PEEP.getLanguageText('photo''album') + ': ' utils.truncate(data.albumName60)
                                        );

                                    var 
event = {textutils.descToHashtag(cmp.photo.descriptionutils.getHashtags(cmp.photo.description), params.tagUrl)};
                                    
PEEP.trigger('photo.onSetDescription'event);
                                    $(
'.peep_photoview_description span'content).html(event.text);

                                    if ( 
window.hasOwnProperty('browsePhoto') )
                                    {
                                        
browsePhoto.updateSlot('photo-item-' data.iddata);
                                        
browsePhoto.reorder();
                                    }
                                }
                            }
                            else if ( 
data.msg )
                            {
                                
PEEP.error(data.msg);
                            }
                            
                            
delete _elements.editFB;
                        });
                    }}
                );
            });

            $(
'#photo-mark-featured').off().on('click', function()
            {
                var 
status = $(this).attr('rel');
                var 
photoId = $(this).attr('photo-id');
                var 
$this = $(this);

                $.
ajax(
                {
                    
url_vars.ajaxResponder,
                    
type'POST',
                    
data: {ajaxFunc'ajaxSetFeaturedStatus'entityIdphotoIdstatusstatus},
                    
dataType 'json',
                    
success : function(data)
                    {
                        if ( 
data.result === true )
                        {
                            var 
newStatus status === 'remove_from_featured' 'mark_featured' 'remove_from_featured';
                            var 
newLabel status === 'remove_from_featured' PEEP.getLanguageText('photo''mark_featured') : PEEP.getLanguageText('photo''remove_from_featured');
                            
$this.html(newLabel);
                            
$this.attr('rel'newStatus);
                            
_vars.cmpListForDeleting.push(+photoId);
                            
PEEP.info(data.msg);
                        }
                        else if ( 
data.error != undefined )
                        {
                            
PEEP.warning(data.error);
                        }
                    }
                });
            });

            $(
"#photo-delete").off().on('click', function( event )
            {
                var 
photoId = $(this).attr("rel");

                if ( 
confirm(PEEP.getLanguageText('photo''confirm_delete')) )
                {
                    $.
ajax(
                    {
                        
url_vars.ajaxResponder,
                        
type'POST',
                        
data: {ajaxFunc'ajaxDeletePhoto'entityIdphotoId},
                        
dataType'json',
                        
success: function( data )
                        {
                            if ( 
data.result === true )
                            {
                                
PEEP.info(data.msg);
                                if ( 
data.url )
                                {
                                    
document.location data.url;
                                };
                            }
                            else if ( 
data.error != undefined )
                            {
                                
PEEP.warning(data.error);
                            }
                        }
                    });
                }
            });

            $(
'#btn-photo-flag').off().on('click', function()
            {
                
PEEP.flagContent('photo_comments', $(this).attr("rel"));
            });

            $(
'#photo-approve').off().on('click', function()
            {
                $.
ajax({
                    
url: $(this).attr('url'),
                    
cachefalse,
                    
type'POST',
                    
dataType'json',
                    
success: function( data )
                    {
                        
// TODO show message
                        
PEEP.info(PEEP.getLanguageText('photo''approve_success_message'));
                        $(
'#photo-approve').parent().remove();
                    }
                })
            });

            if ( !
_methods.fullscreen.enabled() )
            {
                
_elements.content.find('.peep_photoview_fullscreen').attr({target'_blank'hrefcmp.photo.url});
            }

            if ( 
cmp.photo.status !== 'approved' )
            {
                $(
'.peep_photoview_description span'content).html(PEEP.getLanguageText('photo''pending_approval'));

                return;
            }

            var 
event = {textutils.descToHashtag(cmp.photo.descriptionutils.getHashtags(cmp.photo.description), params.tagUrl)};
            
PEEP.trigger('photo.onSetDescription'event);
            $(
'.peep_photoview_description span'content).html(event.text);

            var 
userScore cmp.userScore;
            var 
rateInfo cmp.rateInfo;
            var 
rateItems = $('.peep_rates_wrap'content).show().find('.rate_item').off();
            
            if ( +
userScore )
            {
                
content.find('.rate_title').html(
                    
PEEP.getLanguageText('photo''rating_your', {countrateInfo.rates_countscoreuserScore})
                );
            }
            else
            {
                
content.find('.rate_title').html(
                    
PEEP.getLanguageText('photo''rating_total', {countrateInfo.rates_count})
                );
            }

            
content.find('.active_rate_list').css('width', (rateInfo.avg_score 20) + '%');

            var 
eventRate = {
                
canRatetrue,
                
photocmp.photo
            
};
            
PEEP.trigger('photo.canRate'eventRatethis.node);

            if ( !
eventRate.canRate )
            {
                
rateItems.on('click', function( )
                {
                    
e.stopPropagation();

                    var 
event = {
                        
msg''
                    
};
                    
PEEP.trigger('photo.canRateMessage'eventself.node);
                    
PEEP.error(event.msg);
                });
            }
            else
            {
                
rateItems.on('click', function()
                {
                    var 
ownerError;

                    if ( +
_vars.rateUserId === )
                    {
                        
PEEP.error(PEEP.getLanguageText('base''rate_cmp_auth_error_message'));

                        return;
                    }
                    else if ( +
cmp.ownerId === +_vars.rateUserId )
                    {
                        
PEEP.error(PEEP.getLanguageText('base''rate_cmp_owner_cant_rate_error_message'));

                        return;
                    }

                    var 
event = {
                        
canRatetrue,
                        
photocmp.photo
                    
};
                    
PEEP.trigger('photo.canRate'eventthis.node);

                    if ( !
event.canRate ) return;

                    var 
rate = $(this).index() + 1;

                    $.
ajax({
                        
url_vars.ajaxResponder,
                        
dataType'json',
                        
data: {
                            
ajaxFunc'ajaxRate',
                            
entityIdcmp.photo.id,
                            
raterate,
                            
ownerIdcmp.ownerId
                        
},
                        
cachefalse,
                        
type'POST',
                        
success: function( resulttextStatusjqXHR )
                        {
                            if ( 
result )
                            {
                                switch ( 
result.result )
                                {
                                    case 
true:
                                        
PEEP.info(result.msg);

                                        
content.find('.active_rate_list').css('width', (result.rateInfo.avg_score 20) + '%');
                                        
content.find('.rate_title').html(
                                            
PEEP.getLanguageText('photo''rating_your', {countresult.rateInfo.rates_countscorerate})
                                        );

                                        
cmp.userScore rate;
                                        
rateInfo.avg_score result.rateInfo.avg_score;
                                        
rateInfo.rates_count result.rateInfo.rates_count;

                                        
PEEP.trigger('photo.onSetRate', {
                                            
entityIdcmp.photo.id,
                                            
userScorecmp.userScore,
                                            
avgScorerateInfo.avg_score,
                                            
ratesCountrateInfo.rates_count
                                        
}, _methods);
                                        break;
                                    case 
false:
                                    default:
                                        
PEEP.error(result.error);
                                        break;
                                }
                            }
                            else
                            {
                                
PEEP.error('Server error');
                            }
                        },
                        
error: function( jqXHRtextStatuserrorThrown )
                        {
                            throw 
textStatus;
                        }
                    });
                })
                    .
hover(function()
                    {
                        $(
this).prevAll().add(this).addClass('active');
                        
content.find('.active_rate_list').css('width''0px');
                    }, function()
                    {
                        $(
this).prevAll().add(this).removeClass('active');
                        
content.find('.active_rate_list').css('width', (rateInfo.avg_score 20) + '%');
                    });
            }
        },
        
setComment: function( photoId )
        {
            var 
cmp _methods.getPhotoCmp(photoId);

            $(
'.peep_feed_comments'_elements.content).append(cmp.comment);

            
_vars.commentEvents.forEach(function( item )
            {
                
PEEP.bind(item, function( data )
                {
                    
_methods.updateComment(dataitem);
                });
            });
        },
        
updateComment: function( dataeventName )
        {
            if ( !
_elements.hasOwnProperty('photoFB') || (_vars.commentUnknownEntity.indexOf(eventName) === -&& (data.entityType !== 'photo_comments' || data.entityId !== _vars.photoId)) )
            {
                return;
            }

            var 
heightcmp _methods.getPhotoCmp(_vars.photoId),
                
scrollCont _elements.content.find('.peep_photo_scroll_cont'),
                
padding parseInt(_elements.content.find('.peep_photoview_info').css('padding-top')),
                
appendTo _elements.content.find('.peep_feed_comments_input_sticky');

            if ( 
eventName  == 'base.comment_textarea_resize' )
            {
                var 
textarea;

                if ( !
cmp.isMoved )
                {
                    
textarea = $('textarea'scrollCont)[0];
                }
                else
                {
                    
textarea = $('textarea'appendTo)[0];
                }

                if ( 
textarea.selectionStart || textarea.selectionStart == '0' )
                {
                    
_vars.curPos textarea.selectionStart;
                }
                else if ( 
document.selection )
                {
                    
textarea.focus();

                    var 
sel document.selection.createRange();

                    
sel.moveStart('character', -textarea.value.length);
                    
_vars.curPos sel.text.length;
                }
            }

            if ( !
_vars.isClassic && _vars.layout !== 'page' )
            {
                
PEEP.addScroll(scrollCont, {autoReinitialisetrue}).scrollToBottom();

                
scrollCont.css('height''');

                var 
jsp scrollCont.data('jsp'), scrollContHeight jsp.getContentHeight();

                if ( 
_methods.fullscreen.isFullscreen() )
                {
                    
height _elements.content.find('.peep_photoview_info_wrap').height();
                }
                else
                {
                    
height _elements.content.find('.peep_photoview_info_wrap').height() - appendTo.height() - padding;
                }
            
                if ( 
scrollContHeight >= height )
                {
                    if ( !
cmp.isMoved )
                    {
                        
PEEP.trigger('base.move_comments_form'
                        {
                            
entityType'photo_comments',
                            
entityIddata.entityId || _vars.photoId,
                            
customIdcmp.customId,
                            
appendToappendTo
                        
});
                        
cmp.isMoved true;
                        
_elements.content.find('.peep_photoview_info_wrap').addClass('sticked');
                    }

                    
scrollCont.height(_elements.content.find('.peep_photoview_info_wrap').height() - appendTo.height() - padding);
                    
jsp.reinitialise();
                    
jsp.scrollToBottom();
                    
                    if ( 
eventName == 'base.comment_textarea_resize' )
                    {
                        $(
'textarea'appendTo).photoFocus();
                    }
                }
                else
                {
                    if ( 
jsp != null && jsp.getContentHeight() >= height )
                    {
                        
_elements.content.find('.peep_photo_scroll_cont').height(height);
                    }
                    else
                    {
                        if ( 
cmp.isMoved )
                        {
                            
PEEP.trigger('base.move_comments_form'
                            {
                                
entityType'photo_comments',
                                
entityIddata.entityId,
                                
customIdcmp.customId
                            
});
                            
cmp.isMoved false;
                        }
                        
                        
PEEP.removeScroll(scrollCont);
                        
_elements.content.find('.peep_photo_scroll_cont').css('height''auto');
                    }
                    
                    if ( 
eventName == 'base.comment_textarea_resize' )
                    {
                        $(
'textarea'_elements.content.find('.peep_photo_scroll_cont')).photoFocus();
                    }
                }
            }
            
            if ( 
jsp && ['base.comment_added''base.comment_textarea_resize'].indexOf(eventName) !== -)
            {
                
setTimeout(function()
                {   
                    
jsp.scrollToBottom(true);
                }, 
400);
                
                
_elements.content.find('.peep_feed_comments_input_sticky textarea').photoFocus();
            }
            
            if ( [
'base.comment_add''base.comment_delete'].indexOf(eventName) !== -)
            {
                
_vars.cmpListForDeleting.push(+data.entityId);
            }
        },
        
loadPhoto: function( directionlistType )
        {
            if ( 
_methods.isLoading() )
            {
                return;
            }
            
            
_vars.direction = (['left''right'].indexOf(direction) === -1) ? 'right' direction;
            
            var 
data _methods.getDataToSend(_vars.photoId_vars.listType), photoIdextend;
            
            switch ( 
direction )
            {
                case 
'left':
                    
photoId = +data.params.prevId;
                    break;
                case 
'right':
                    
photoId = +data.params.nextId;
                    break;
            }
            
            if ( 
isNaN(photoId) )
            {
                return 
false;
            }
            
            
PEEP.trigger('photo.onPhotoSwitch', [photoId_vars.direction], _methods);
            
            if ( 
window.hasOwnProperty('browsePhoto') )
            {
                
extend browsePhoto.getMoreData();
            }
            
            
_methods.setId(photoIdlistTypeextend);
            
_methods.updateSlideshow();
        },
        
loadPrevPhoto: function()
        {
            
_methods.loadPhoto('left'_vars.listType);
        },
        
loadNextPhoto: function()
        {
            
_methods.loadPhoto('right'_vars.listType);
        },
        
addCmpMarkup: function( photoId )
        {
            if ( !
_methods.isCached(photoId) )
            {
                return;
            }
            
            var 
cmp _methods.getPhotoCmp(photoId);
            
            if ( 
cmp.css )
            {
                
PEEP.addCss(cmp.css);
            }
            
            if ( 
cmp.cssFiles )
            {
                $.
each(cmp.cssFiles, function( keyvalue )
                {
                    
PEEP.addCssFile(value);
                });
            }
            
            if ( 
cmp.scriptFiles )
            {
                
PEEP.addScriptFiles(cmp.scriptFiles, function()
                {
                    if ( 
cmp.onloadScript )
                    {
                        
PEEP.addScript(cmp.onloadScript);
                    }
                });
            }
            else
            {
                if ( 
cmp.onloadScript )
                {
                    
PEEP.addScript(cmp.onloadScript);
                }
            }

            if ( 
cmp.meta )
            {
                
Object.keys(cmp.meta).forEach(function( item )
                {
                    var 
_meta cmp.meta[item];

                    
Object.keys(_meta).forEach(function( attr )
                    {
                        $(
'meta[' item '="' attr '"]').remove();
                        $(
document.head).append('<meta ' item '="' attr '" content="' _meta[attr] + '">');
                    });
                });
            }
        },
        
beforeLoadCmp: function( photoId )
        {
            if ( 
_methods.isCached(photoId) )
            {
                var 
cmp _methods.getPhotoCmp(photoId);

                if ( 
cmp.isMoved )
                {
                    if ( 
_vars.fbHasContent )
                    {
                        
PEEP.removeScroll(_elements.content.find('.peep_photo_scroll_cont'));
                    }
                    
                    if ( 
cmp.isMoved )
                    {
                        
PEEP.trigger('base.move_comments_form'
                        {
                            
entityType'photo_comments',
                            
customIdcmp.customId,
                            
entityIdphotoId
                        
});
                        
cmp.isMoved false;
                        
_elements.content.find('.peep_photoview_info_wrap').removeClass('sticked');
                    }
                }
                
                
PEEP.trigger('base.comments_destroy',
                {
                    
entityType'photo_comments',
                    
customIdcmp.customId,
                    
entityIdphotoId
                
});
                
                $(
'.peep_feed_comments'_elements.content).empty();
                
_elements.content.find('.peep_photoview_info_wrap').height('');
                $(
'.peep_rates_wrap'_elements.content).hide();
                
                var 
index;
                
                if ( (
index _vars.cmpListForDeleting.indexOf(photoId)) !== -)
                {
                    
_methods.deletePhotoCmp(photoId);
                    
_vars.cmpListForDeleting.splice(index1);
                }
                
                $(
'.peep_photo_context_action'_elements.content).remove();
            }
            
            [
'base.move_comments_form''base.comments_destroy'].concat(_vars.commentEvents).forEach(function( item )
            {
                
PEEP.unbind(item);
            });
            
            if ( 
_elements.hasOwnProperty('editFB') )
            {
                
_elements.editFB.close();
            }
        },
        
fullscreen: {
            
request: function( elem )
            {
                var 
keyboardAllowed typeof Element !== 'undefined' && 'ALLOW_KEYBOARD_INPUT' in Element;
                
elem elem || document.documentElement;

                if ( /
5.1[.d]* Safari/.test(navigator.userAgent))
                {
                    
elem[_vars.fullScreen.requestFullscreen]();
                }
                else
                {
                    
elem[_vars.fullScreen.requestFullscreen](keyboardAllowed && Element.ALLOW_KEYBOARD_INPUT);
                }
            },
            exit: function()
            {
                
document[_vars.fullScreen.exitFullscreen]();
            },
            
isFullscreen: function()
            {
                return !!
document[_vars.fullScreen.fullscreenElement];
            },
            
enabled: function()
            {
                return 
_vars.fullScreen && !!document[_vars.fullScreen.fullscreenEnabled];
            },
            
getFullscreenElement: function()
            {
                return 
document[_vars.fullScreen.fullscreenElement];
            },
            
isPhotoInit : function()
            {
                return 
_methods.fullscreen.getFullscreenElement() === document.documentElement || _vars.isPhotoFullscreenInit;
            },
            
onchange: function( event )
            {
                if ( !
_methods.fullscreen.isPhotoInit() ) return;

                var 
content _elements.contentcmp _methods.getPhotoCmp(_vars.photoId);
                
                if ( 
_methods.fullscreen.isFullscreen() )
                {
                    
_vars.isPhotoFullscreenInit true;
                    $(
window).off('resize.photo');
                    
                    
content.height('');
                    
content.find('.peep_photoview_stage_wrap').addClass('peep_photoview_stage_wrap_fullscreen');
                    
content.find('.peep_photoview_info_wrap').css({heightscreen.height});
                    
content.find('.peep_photoview_play_btn').removeClass('stop');
                    
                    if ( 
_vars.layout === 'page' || _vars.isClassic )
                    {
                        $(
document.body).addClass('peep_photo_page_fullscreen');
                        
content.find('.peep_photoview_stage_wrap').css({float'left'widthscreen.widthheightscreen.height});
                        
content.find('.peep_photoview_info').removeClass('peep_photoview_info_onpage');
                    }
                    else
                    {
                        
_elements.photoFB.fitWindow({top'0'widthscreen.widthheightscreen.height});
                        
content.find('.peep_photoview_stage_wrap').css({widthscreen.widthheightscreen.height});
                    }

                    if ( 
cmp.photo.hasFullsize && cmp.photo.dimension )
                    {
                        var 
dimension cmp.photo.dimension;

                        if ( 
dimension.fullscreen && dimension.fullscreen.length === )
                        {
                            var 
css = {};

                            if ( 
dimension.fullscreen[0] > screen.width && dimension.fullscreen[1] > screen.height )
                            {
                                var 
proportion _methods.utils.getScreenProportion(dimension.fullscreen[0], dimension.fullscreen[1]);

                                
css.width proportion[0];
                                
css.height proportion[1];
                            }
                            else
                            {
                                
css.width dimension.fullscreen[0];
                                
css.height dimension.fullscreen[1];
                            }

                            
_elements.content.find('img.peep_photo_view').css(css).attr('src'cmp.photo.url);
                            
_methods.fitSize(_vars.photoId, function(){});
                        }
                    }
                    
                    if ( 
_vars.fbHasContent )
                    {
                        
PEEP.removeScroll(_elements.content.find('.peep_photo_scroll_cont'));
                    }
                }
                else
                {
                    
_vars.isPhotoFullscreenInit false;
                    
_vars.isRunSlideshow false;
                    
_methods.stopSlideshow();
                    
                    
content.find('.peep_photoview_info_btn').removeClass('close').addClass('open');
                    
content.find('.peep_photoview_stage_wrap').removeClass('peep_photoview_stage_wrap_fullscreen');
                    
content.find('.peep_photoview_info_wrap').css({height''});
                    
content.find('.peep_photoview_play_btn').addClass('stop');
                    
                    if ( 
_vars.layout === 'page' || _vars.isClassic )
                    {
                        
_elements.content.find('.peep_photoview_stage_wrap').css({float'none'});
                        
_elements.content.find('.peep_photoview_info').addClass('peep_photoview_info_onpage');
                        $(
document.body).removeClass('peep_photo_page_fullscreen');
                    }
                    
                    if ( 
_vars.isClassic )
                    {
                        
_elements.content.find('.peep_photoview_info').addClass('peep_photoview_pint_mode');
                    }
                    
                    
setTimeout(function()
                    {
                        var 
dimension _methods.getScreenDimension(), css = {};
                        
                        if ( 
_vars.isClassic )
                        {
                            
css.width 'auto';
                            
css.height dimension.maxHeight;
                        }
                        else
                        {
                            
css.width dimension.maxWidth;
                            
css.height dimension.maxHeight;
                            
_vars.minSize.width dimension.maxWidth;
                            
_vars.minSize.height dimension.maxHeight;
                        }
                        
                        
content.find('.peep_photoview_stage_wrap').css(css);
                        
_methods.updateComment({entityType'photo_comments'entityId_vars.photoId});

                        if ( 
_vars.layout != 'page' )
                        {
                            
content.height(css.height);
                            
_elements.photoFB.fitWindow({widthdimension.maxWidth _vars.infoBarheightdimension.maxHeighttopdimension.screenHeight - (dimension.maxHeight 2)});
                        }
                        
                        $(
window).on('resize.photo'_methods.resizeWindow);
                    }, 
100);
                }

                
content.find('.jspPane').css('left'0);
                
content.find('.peep_photoview_info_wrap').height('');
                
                var 
dataToSend _methods.getDataToSend(_vars.photoId_vars.listType);
                    
                
_methods.backgroundLoadPhotos([dataToSend.params.nextIddataToSend.params.prevId], _methods.fullscreen.isFullscreen() ? 'fullscreen' 'main');
                
                
PEEP.trigger('photo.onSizeChange', [_vars.photoId_methods.fullscreen.isFullscreen()], _methods);
            }
        },
        
utils:
        {
            
showPreloader: function()
            {
                if ( 
_vars.layout !== 'page' || _elements.photoFB )
                {
                    if ( !
_elements.photoFB.$canvas.hasClass('peep_floatbox_loading') )
                    
_elements.photoFB.$canvas.prepend(_elements.preloader.css('left', $(window).width() / 160));
                }
            },
            
hidePreloader: function()
            {
                
_elements.preloader.detach();
            },
            
isNotEmptyObject: function( object )
            {
                var 
keys;
                
                if ( !
object || object !== Object(object) || (keys Object.keys(object)).length === )
                {
                    return 
false;
                }
                
                return 
keys.some(function( item )
                {
                    if ( [
'photoId''layout''searchVal''id'].indexOf(item) !== -)
                    {
                        return 
false;
                    }
                    
                    switch ( 
_vars.toString.call(object[item]) )
                    {
                        case 
'[object Array]':
                            return 
object[item].length !== 0;
                        case 
'[object Number]':
                            return !
isNaN(object[item]) && object[item] > 0;
                        default:
                            return 
object[item] != null;
                    }
                });
            },
            
getScreenProportion: function( widthheightscreenWidthscreenHeight )
            {
                
screenWidth screenWidth || window.screen.width;
                
screenHeight screenHeight || window.screen.height;
                
                var 
rw screenWidth widthrh screenHeight heightratio rw rh rw rh;
                
                return [
Math.round(screenWidth ratio), Math.round(screenHeight ratio)];
            }
        },
        
arrayUtils:
        {
            
unionToList: function()
            {
                var 
arr = [].splice.call(arguments0)
                    .
reduce(function( previousValuecurrentItem )
                    {
                        return 
previousValue.concat(currentItem);
                    }, [])
                    .
map(function( item )
                    {
                        return +
item;
                    })
                    .
filter(function( itemiarr )
                    {
                        return !
isNaN(item) && item && arr.indexOf(item) === i;
                    });
                    
                var 
event = {listType: []};
                
PEEP.trigger('photo.collectListType'event_methods);
                
                if ( [
'most_discussed''toprated'].concat(event.listType).indexOf(_vars.listType) !== -)
                {
                    return 
arr;
                }
                
                return 
arr.sort(function( a)
                {
                    return 
a;
                });
            },
            
isMatch: function( array1array2 )
            {
                if ( 
array1.length === || array2.length === )
                {
                    return 
false;
                }

                return (
array1[array1.length 1] <= array2[0] + || array1[0] + <= array2[array2.length 1]);
            },
            
push: function( dstsrc )
            {
                if ( 
src.length )
                {
                    
dst.push(src);
                    
dst.sort(_methods.arrayUtils.sortBySum);
                }
            },
            
getMinInList: function( list )
            {
                var 
min;
                
                list.forEach(function( 
item )
                {
                    var 
_min Math.min.apply(0item);
                    
                    if ( 
min === undefined )
                    {
                        
min _min;
                    }
                    else
                    {
                        if ( 
_min min )
                        {
                            
min _min;
                        }
                    }
                });
                
                return 
min;
            },
            
getMaxInList: function( list)
            {
                var 
max;
                
                list.forEach(function( 
item )
                {
                    var 
_max Math.max.apply(0item);
                    
                    if ( 
max === undefined )
                    {
                        
max _max;
                    }
                    else
                    {
                        if ( 
_max max )
                        {
                            
max _max;
                        }
                    }
                });
                
                return 
max;
            },
            
sortBySum: function( a)
            {
                return 
b.reduce(function( p){return c}) - a.reduce(function( pc){return c});
            }
        },
        
locationUtils: {
            
splitPath: function( pathname )
            {
                
pathname pathname || location.pathname.substr(1);
                
                return 
pathname.split('/');
            },
            
parseSearch: function( search )
            {
                
search search || location.search.substr(1);
                
                var 
chunks search.split('&'), result = {}, chunk;
                
                
chunks.forEach(function( item )
                {
                    
chunk item.split('=');
                    
                    if ( 
chunk.length === )
                    {
                        
result[decodeURIComponent(chunk[0])] = decodeURIComponent(chunk[1]);
                    }
                });

                return 
result;
            },
            
compile: function ( uriComponents )
            {
                var 
keys;
                
                if ( !
uriComponents || uriComponents !== Object(uriComponents) || (keys Object.keys(uriComponents)).length === )
                {
                    return 
'';
                }
                
                var 
result = [];

                
keys.forEach(function( item )
                {
                    
result.push(encodeURIComponent(item) + '=' encodeURIComponent(uriComponents[item]));
                });
                
                return 
result.join('&');
            },
            
parseUrl: function( urlcomponent )
            {
                var 
document.createElement('a'), result = {};
                
a.href url;
                
                
component.forEach(function( item )
                {
                    
result[item] = a[item];
                });
                
                return 
result;
            }
        },
        
history: {
            
replaceState: function( photoIdlistTypeextenddataphoto )
            {
                if ( !
photoId || isNaN(+photoId) )
                {
                    return 
false;
                }
                
                
listType listType || _vars.DEFAULT_LIST;
                
                var 
state;

                if ( (
state window.history.state) == null )
                {
                    
state = {
                        
initPathlocation.pathname,
                        
initSearchlocation.search
                    
};
                }

                var 
url _methods.locationUtils.parseUrl(_vars.urlHome, ['pathname'])['pathname'] + 'photo/view/' photoId '/' listTypesearch;

                if ( 
url.charAt(0) != '/' )
                {
                    
url '/' url;
                }
                
                if ( 
extend && (search _methods.locationUtils.compile(extend)).length )
                {
                    
url += '?' search;
                }
                
                if ( !
_methods.fullscreen.isFullscreen() )
                {
                    
window.history.replaceState(statenullurl);
                }
                
                $(
window).triggerHandler('popstate.photo', {
                    
photoIdphotoId,
                    
listTypelistType,
                    
datadata,
                    
photophoto
                
});
            },
            
popstate: function( eventdata )
            {
                if ( 
data && data.photoId && !isNaN(+data.photoId) )
                {
                    
_methods.showPhotoCmp(+data.photoIddata.listTypedata.datadata.photo);
                }
            },
            
goInitState: function()
            {
                var 
state window.history.state;
                var 
url = (state.initPath state.initPath _methods.locationUtils.parseUrl(_vars.urlHome, ['pathname'])['pathname'] + 'photo/viewlist/' _vars.DEFAULT_LIST) + state.initSearch;
                
                
window.history.replaceState(nullnullurl);
            }
        },
        
createFloatboxContent: function()
        {
            if ( 
_elements.hasOwnProperty('content') )
            {
                return 
_elements.content;
            }
            
            
_elements.content = $(document.getElementById('peep-photo-view')).clone(true).removeAttr('id');
            
_elements.content.find('.peep_photoview_slide_time').slider({min3max:10range'min',
                
slide: function( eventui )
                {
                    var 
tip = $(this).data('peepTip');
                    
                    
tip.find('.peep_tip_title').html(PEEP.getLanguageText('photo''slideshow_interval') + ui.value);
                    
_vars.interval ui.value 1000;
                    
_methods.updateSlideshow();
                }
            });
            
PEEP.trigger('photo.onAfterContentRender', [_elements.content], _methods);
            
            return 
_elements.content;
        },
        
resizeWindow: function(event)
        {
            if ( 
_methods.fullscreen.isFullscreen() || !_methods.fullscreen.isPhotoInit() ) return;

            if ( 
_vars.timerId )
            {
                
clearTimeout(_vars.timerId);
            }
            
            
_vars.timerId setTimeout(function()
            {
                
_methods.fitSize(_vars.photoId, function( offset )
                {
                    
PEEP.trigger('photo.beforeResize', [_vars.photoId], _methods);

                    if ( 
_vars.layout !== 'page' )
                    {
                        var 
options = {};

                        if ( 
_vars.isClassic )
                        {
                            
_elements.content.find('.peep_photoview_stage_wrap').css({float'none'height_vars.minSize.heightwidth''});
                            
options.width offset.width;
                        }
                        else
                        {
                            
_elements.content.find('.peep_photoview_stage_wrap').css({width_vars.minSize.widthheight_vars.minSize.height});
                            
_elements.content.css('height'_vars.minSize.height);
                            
options offset;
                        }

                        
_elements.photoFB.fitWindow(options);
                    }
                    else
                    {
                        
_elements.content.find('.peep_photoview_stage_wrap').css({heightoffset.heightwidthoffset.width});
                    }
                    
                    
_methods.updateComment({entityType :'photo_comments'entityId_vars.photoId});
                    
                    
PEEP.trigger('photo.afterResize', [_vars.photoId], _methods);
                }, 
true);
            }, 
100);
        },
        
runSlideshow: function()
        {
            
_vars.isRunSlideshow true;
            
_vars.slideshowTimeId setInterval(function()
            {
                if ( 
_vars.animate )
                {
                    return;
                }

                
_vars.animate true;
                var 
dataToSend _methods.getDataToSend(_vars.photoId_vars.listType);
                
                if ( !
_methods.isCached(dataToSend.params.nextId) )
                {
                    
_vars.animate false;
                    var 
dataForNext _methods.getDataToSend(dataToSend.params.nextId_vars.listType);
                
                    if ( 
_methods.utils.isNotEmptyObject(dataForNext.dataToSend) )
                    {
                        $.
extend(dataForNext.dataToSend, {ajaxFunc'getFloatbox'listType_vars.listType});
                        
dataForNext.params.loadCurrent false;
                        
_methods.fetchCmp(dataForNext.dataToSenddataForNext.params);
                    }
                }
                else
                {
                    
_methods.setId(dataToSend.params.nextId);
                    
                    var 
nextCmp _methods.getPhotoCmp(dataToSend.params.nextId), image = new Image(), url;
                    
                    if ( +
nextCmp.photo.hasFullsize )
                    {
                        
url nextCmp.photo.urlFullscreen;
                    }
                    else
                    {
                        
url nextCmp.photo.url;
                    }
                    
                    
image.src url;
                    
                    if ( !
image.complete )
                    {
                        
_vars.animate false;
                        
_methods.stopSlideshow();
                        
_methods.runSlideshow();
                        
                        return;
                    }
                    
                    var 
css = {display'inline-block'}, properties = {};

                    if ( 
_vars.effect === 'slide' )
                    {
                        
css.top 0;
                        
css.right screen.width;
                        
properties = {left0};
                    }
                    else
                    {
                        
css.opacity 0;
                        
properties = {opacity1};
                    }

                    var 
img _elements.content.find('img.peep_photo_view');
                    var 
slideImg = $('img.slide'_elements.content).css(css);

                    
slideImg[0].src url;
                    
img.animate({opacity0}, {duration300});
                    
slideImg.animate(properties, {duration300complete: function()
                    {
                        var 
complete = function()
                        {
                            
img.css({opacity1});
                            
slideImg.hide();
                            
_vars.animate false;
                        };

                        
img[0].src url;
                        
img[0].complete complete.call(img) : img[0].onload complete;
                    }});
                }
            }, 
_vars.interval || 3000);
        },
        
stopSlideshow: function()
        {
            if ( 
_vars.slideshowTimeId )
            {
                
clearInterval(_vars.slideshowTimeId);
            }
        },
        
updateSlideshow: function()
        {
            
_methods.stopSlideshow();
            
            if ( 
_vars.isRunSlideshow )
            {
                
_methods.runSlideshow();
            }
        },
        
init: function()
        {
            if ( 
_vars.isInitialized )
            {
                return;
            }
            
            
_vars.isInitialized true;

            $(
window).on({'resize.photo'_methods.resizeWindow'popstate.photo'_methods.history.popstate});
            $(
document).on(_vars.fullScreen.fullscreenchange '.photo'_methods.fullscreen.onchange);

            var 
content = $(document.getElementById('peep-photo-view'));
            
            if ( 
_methods.fullscreen.enabled() )
            {
                $(
'.peep_photoview_fullscreen'content).on('click', function()
                {
                    
_methods.fullscreen.isFullscreen() ? _methods.fullscreen.exit() : _methods.fullscreen.request();
                });
                
                $(
'.peep_photoview_info_btn'content).on('click', function( event )
                {
                    if ( !
_methods.fullscreen.isFullscreen() )
                    {
                        
event.stopImmediatePropagation();
                    }
                    
                    
PEEP.trigger('photo.beforeResize', [_vars.photoId], _methods);
                    
                    if ( $(
this).hasClass('open') )
                    {
                        $(
this).removeClass('open').addClass('close');
                        var 
wrap _elements.content.find('.peep_photoview_stage_wrap');
                        
                        
wrap.width(screen.width 400);
                        
                        if ( 
_vars.isClassic )
                        {
                            
wrap.css('float''left');
                            
_elements.content.find('.peep_photoview_info').removeClass('peep_photoview_pint_mode');
                        }
                        else
                        {
                            
_elements.content.find('.jspPane').css('left'0);
                        }
                        
                        
_methods.updateComment({entityType'photo_comments'entityId_vars.photoId});
                        
                        
PEEP.trigger('photo.afterInfoShow', [_vars.photoId], _methods);
                    }
                    else
                    {
                        $(
this).removeClass('close').addClass('open');
                        
_elements.content.find('.peep_photoview_stage_wrap').width(screen.width);
                        
                        if ( 
_vars.fbHasContent )
                        {
                            
PEEP.removeScroll(_elements.content.find('.peep_photo_scroll_cont'));
                        }
                        
                        
PEEP.trigger('photo.afterInfoHide', [_vars.photoId], _methods);
                    }
                    
                    
PEEP.trigger('photo.afterResize', [_vars.photoId], _methods);
                });
                
                var 
timerId;
                
                $(
'.peep_photoview_slide_settings'content).on({
                    
mouseenter: function()
                    {
                        if ( 
timerId )
                        {
                            
clearTimeout(timerId);
                        }
                        
                        $(
'.peep_photoview_slide_settings_controls'_elements.content).stop(true).css({display'inline-block'opacity1});
                    }
                });
                $(
'.peep_photoview_bottom_menu_wrap'content).on({
                    
mouseleave: function()
                    {
                        if ( 
timerId )
                        {
                            
clearTimeout(timerId);
                        }
                        
                        
timerId setTimeout(function()
                        {
                            $(
'.peep_photoview_slide_settings_controls'_elements.content).fadeOut(1000);
                        }, 
5000);
                    }
                });
                
                $(
'.peep_photoview_slide_settings_effect'content).on('click', function()
                {
                    $(
'.peep_photoview_slide_settings_effect'_elements.content).removeClass('active');
                    
_vars.effect = $(this).addClass('active').attr('effect');
                    
_methods.updateSlideshow();
                });
                
                $(
'.peep_photoview_play_btn'_elements.content).on('click', function( event )
                {
                    if ( !
_methods.fullscreen.isFullscreen() )
                    {
                        
event.stopImmediatePropagation();
                    }
                    
                    if ( $(
this).hasClass('stop') )
                    {
                        
_vars.isRunSlideshow false;
                        
_methods.stopSlideshow();
                        $(
this).removeClass('stop');
                    }
                    else
                    {
                        
_methods.runSlideshow();
                        $(
this).addClass('stop');
                    }
                });
            }

            
PEEP.bind('photo.onAfterEditPhoto', function( photoId )
            {
                
_methods.deletePhotoCmp(photoId);
            });
            
PEEP.bind('photo.onChangeListType', function( listType )
            {
                if ( 
listType != _vars.listType )
                {
                    
_methods.clearHistory();
                }
            });
            
PEEP.bind('photo.deleteCache', function( photos )
            {
                if ( !Array.
isArray(photos) || photos.length === ) return;

                
photos.forEach(function( photoId )
                {
                    
_methods.deletePhotoCmp(photoId);
                });
            });

            var 
event = {
                
selectors: [
                    
'.peep_photoview_stage_wrap',
                    
'img.peep_photo_img'
                
]
            };
            
PEEP.trigger('photo.collectChangePhotoSelectors'event);
            
content.on('click'event.selectors.join(','), function( event )
            {
                if ( !$(
event.target).is(event.currentTarget) )
                {
                    return;
                }

                if ( (
event.pageX - $(this).offset().left) > ($(this).width() / 2) )
                {
                    
_methods.loadNextPhoto();
                }
                else
                {
                    
_methods.loadPrevPhoto();
                }

                
event.stopImmediatePropagation();
            });

            $(
'.peep_photoview_arrow_left'content).on('click'_methods.loadPrevPhoto);
            $(
'.peep_photoview_arrow_right'content).on('click'_methods.loadNextPhoto);


            $.
fn.extend({
                
photoFocus: function () {
                    
this.each(function () {
                        try
                        {
                            if(
this.setSelectionRange)
                            {
                                
this.focus();
                                
this.setSelectionRange(_vars.curPos_vars.curPos);
                            }
                            else if (
this.createTextRange)
                            {
                                var 
range this.createTextRange();

                                
range.collapse(true);
                                
range.moveEnd('character'_vars.curPos);
                                
range.moveStart('character'_vars.curPos);
                                
range.select();
                            }
                        }
                        catch ( 
){ }
                    });

                    return 
this;
                }
            });
        }
    };
    
    
window.photoView Object.defineProperties({}, {
        
init: {value_methods.init},
        
setId: {value_methods.setId}
    });
    
})(
windowwindow.jQuerywindow.photoViewParams);
?>
Онлайн: 2
Реклама