var loading = false,
lastScrollTop = 0,
defaultTexts = {
title: 'Название',
imprText : 'Описание'
};
var handler = null;
function loadFullImpression(imprId) {
if ("pushState" in history){
history.pushState("", document.title, rootLocation + '/' + imprId);
} else {
window.location.href = rootLocation + '/' + imprId;
return;
}
$('#impression_popup').html('
');
$('#impression_popup').load('/contest/clarins/impression', {impressionId : imprId});
}
function revertUrl() {
if("pushState" in history)
history.pushState("", document.title, rootLocation);
else {
window.location.href = rootLocation;
}
}
function hide_popup(){
$('#impression_popup').hide();
$('#impression_popup_img').attr('src','');
$('body').removeClass('noscroll');
revertUrl(); console.log('impression');
}
$(function(){
InputHelper.Create("#title", defaultTexts.title);
InputHelper.Create("#impressionText", defaultTexts.imprText);
var headerH = $("#header_wrap").height();
$("#layout").css('margin-top', headerH + 'px');
$('.add_impression').bind("click", function() {
$('#impression_form').show();
});
if(document.location.hash.indexOf('addImpression') == 1){
$('#add_impression').click();
document.location.hash = '';
}
$('#modal_overlay, #impression_close').bind("click",function(){
$('#impression_form').hide();
})
$('#tabs span.tab').click(function(){
if($(this).hasClass('act')){
$('#' + $(this).attr('id') + '_cnt').slideUp();
$(this).removeClass('act');
}else{
$('#tabs span').removeClass('act');
$('.tab_cnt').hide();
$(this).addClass('act');
$('#' + $(this).attr('id') + '_cnt').slideDown();
}
});
$('#prize_big .modal_wrapper').click(function(){
$('#prize_big').hide();
$('body').removeClass('noscroll');
})
$( "#show_prize" ).click(function() {
$('body').append($( "#prize_big" ));
$( "#prize_big" ).show();
$('body').addClass('noscroll');
});
$("#impression_close_popup").on("click", function(){
hide_popup();
});
$('.redigoPopup').off();
$('#impression_popup').on("click", function(e){
if(e.target && $(e.target).parents('.impression_frame').size() == 0 ) {
hide_popup();
}
});
// SUBMIT FORM
$('#impressionBtn').bind('click', function() {
var tl = '';
var imprText = '';
if($('#title').val() != defaultTexts.title)
tl = $('#title').val();
if($('#impressionText').val() != defaultTexts.imprText)
imprText = $('#impressionText').val();
if(tl.length == 0) {
alert('Не указано название.');
return;
}
if(imprText.length == 0) {
alert('Не указано описание.');
return;
}
$('#impressionBtn').hide();
$('#submit_loading').show();
$('#createImpression').submit();
});
$(window).bind('scroll', function(){
var top = $(window).scrollTop();
if(top > 110)
$("#header_wrap").addClass("fixed");
else
$("#header_wrap").removeClass("fixed");
onScroll();
})
var options = {
autoResize: true, // This will auto-update the layout when the browser window is resized.
container: $("#impressions_list"), // Optional, used for some extra CSS styling
offset: 15, // Optional, the distance between grid items
itemWidth: 283 // Optional, the width of a grid item
};
// Call the layout function.
handler = $('#impressions_list .impression');
handler.wookmark(options);
})
function onScroll(event) {
var options = {
autoResize: true, // This will auto-update the layout when the browser window is resized.
container: $("#impressions_list"), // Optional, used for some extra CSS styling
offset: 15, // Optional, the distance between grid items
itemWidth: 283 // Optional, the width of a grid item
};
// Check if we're within 100 pixels of the bottom edge of the broser window.
var closeToBottom = ($(window).scrollTop() + $(window).height() > $(document).height()-200);
if(closeToBottom) {
var st = $(window).scrollTop();
if (st > lastScrollTop){
if(!loading && skipItems) {
loading = true;
$.ajax({
url : '/contest/clarins/loadmore',
type : 'POST',
data : { skip: skipItems },
success: function(data, textStatus, jqXHR) {
loading = false;
if(data.result.skip == -1)
skipItems = false;
if(data.result && data.result.items && data.result.items.length > 0) {
for(idx in data.result.items) {
var index = Math.floor(idx % 10) + 1;
if(index > 10) index = 1;
data.result.items[idx].index = index;
$("#impressionItemTemplate").template("impressionItem");
$.tmpl("impressionItem", data.result.items[idx]).appendTo("#impressions_list");
}
if(data.result.skip) {
skipItems = data.result.skip;
}
}
// Clear our previous layout handler.
if(handler) handler.wookmarkClear();
// Create a new layout handler.
handler = $('#impressions_list .impression');
handler.wookmark(options);
setMore();
}
});
}
}
lastScrollTop = st;
}
setMore();
}
function setMore(){
$('#impressions_list .impression_txt').each(function(){
var item = $(this);
if(item.html().length > 288 || item.height() > 140){
$(item).parent().find('.more_wrap').show();
}
})
}