Created
March 26, 2015 09:33
-
-
Save victorpavlenko/af7b967b741a797d4784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = (function() { | |
'use strict'; | |
var app = { | |
dom: { | |
ready: $.Deferred() | |
} | |
}; | |
$(function() { | |
app.dom.$window = $(window); | |
app.dom.$document = $(document); | |
app.dom.$html = $(document.documentElement); | |
app.dom.$body = $(document.body); | |
app.dom.$overlay = $('.page-overlay'); | |
app.dom.$window.on('scroll-lock', function(event, scrollbarWidth) { | |
app.dom.$body.css('margin-right', scrollbarWidth); | |
$('header, footer').css('right', scrollbarWidth); | |
}); | |
app.dom.$window.on('scroll-unlock', function() { | |
app.dom.$body.css('margin-right', ''); | |
$('header, footer').css('right', ''); | |
}); | |
app.dom.$document.on('click', '.btn-card-info, .flip-card', function() { | |
$(this).closest('.card-holder').find('.flip-card').toggleClass('flip-card_flipped'); | |
}); | |
if (!Modernizr.cssanimations) { | |
var initializeLoaders = function($context) { | |
var $preloaders; | |
var duration = 800; | |
$context = $context || app.dom.$document; | |
$preloaders = $context.find('.preloader'); | |
$preloaders.each(function() { | |
var startTime = false; | |
var $preloader = $(this).find('.preloader__i'); | |
var width = $preloader.width(); | |
function rotate(time) { | |
var frame; | |
if (startTime !== false) { | |
frame = (Math.floor((time - startTime) / duration * 12)) % 12; | |
$preloader.css('background-position', -frame * width + 'px 0'); | |
} else { | |
startTime = time; | |
} | |
requestAnimationFrame(rotate); | |
} | |
requestAnimationFrame(rotate); | |
}); | |
}; | |
initializeLoaders(); | |
app.dom.$document.on('popup-open', function(event, $popup) { | |
initializeLoaders($popup); | |
}); | |
} | |
initGallery(); | |
app.dom.$document.on('popup-open', function(event, $popup) { | |
initGallery($popup); | |
}); | |
function initGallery($context) { | |
$context = $context || app.dom.$document; | |
$context.find('.post-gallery__slide-list').each(function() { | |
var $slider = $(this); | |
var $gallery = $slider.closest('.post-gallery'); | |
var $prevCount, $nextCount, slideCount; | |
$slider.bxSlider({ | |
pager: false, | |
hideControlOnEnd: true, | |
infiniteLoop: false, | |
touchEnabled: false, | |
prevText: '', | |
nextText: '', | |
onSliderLoad: function() { | |
var currentSlide = $slider.getCurrentSlide(); | |
slideCount = $slider.getSlideCount(); | |
var $prev = $gallery.find('.bx-prev'); | |
var $next = $gallery.find('.bx-next'); | |
$prevCount = $('<span class="count"></span>'); | |
$nextCount = $('<span class="count"></span>'); | |
$prevCount.appendTo($prev); | |
$nextCount.appendTo($next); | |
$prevCount.html(currentSlide); | |
$nextCount.html(slideCount - currentSlide - 1); | |
}, | |
onSlideBefore: function($slideElement, oldIndex, newIndex) { | |
$prevCount.html(newIndex); | |
$nextCount.html(slideCount - newIndex - 1); | |
} | |
}); | |
}); | |
} | |
app.dom.ready.resolve(); | |
}); | |
return app; | |
})(); | |
function postImageUploadFailure() { | |
app.dialog.error('Возникла ошибка при загрузке изображения'); | |
} | |
function postImageUploadStart() { | |
$('#uploadedPostPhotos').append('<div id="tempDelMe">Загрузка...</div>'); | |
} | |
function postImageUploadDone(data) { | |
$('#tempDelMe').remove(); | |
$('#uploadedPostPhoto img').attr('src', data); | |
$('#uploadedPostPhotos').append($('#uploadedPostPhoto').html()); | |
$('#uploadedPostPhotos .jsDeletePostImage').off('click').click(function() { | |
$(this).closest('.post-img').remove(); | |
}); | |
} | |
function scanResult(code, lon, lat) { | |
app.popup.open('/mobile/popup/product.php?productId='+code+'&lat='+lat+'&lon='+lon); | |
} | |
function testProduct() { | |
app.popup.open('/mobile/popup/product.php?productId=032622013052&lat=55.752275&lon=37.5852101'); | |
} | |
function scanError() { | |
app.dialog.error('Возникла ошибка при сканировании штрихкода'); | |
} | |
function dispatchAction(action, onComplete) { | |
var reqType = 'GET'; | |
if ( | |
action['action'] == 'addPost' || | |
action['action'] == 'addReview' || | |
action['action'] == 'addReviewPhoto' || | |
action['action'] == 'addRepost' | |
) reqType = 'POST'; | |
return $.ajax('/sodabox_resources/php/actions.php', { | |
data: action, | |
type: reqType, | |
error: function (xhdr, msg) { | |
app.dialog.error(msg); | |
}, | |
success: function (data) { | |
if (action.action !== 'getPost' && action.action !== 'getChatMessages' && action.action !== 'sendChatMessage') { | |
if (typeof data !== 'object' && (parseInt(data) !== 0)) { | |
app.dialog.error('Ошибка: ' + data); | |
} | |
} | |
if (typeof onComplete === 'function') onComplete(data); | |
} | |
}); | |
} | |
$(document).on('click', ".people-item-bg, .people-item-1", function () { | |
changeState($(this)); | |
}); | |
function changeState(el) { | |
var action = 'Subscribed'; | |
var nameTo; | |
if (el.hasClass('btn-subscr')) { | |
nameTo = 'Отписаться'; | |
el.addClass('btn-unsubscr').removeClass('btn-subscr'); | |
} else if (el.hasClass('btn-unsubscr')) { | |
nameTo = 'Подписаться'; | |
el.addClass('btn-subscr').removeClass('btn-unsubscr'); | |
} else if (el.hasClass('btn-friendship-del')) { | |
action = 'Friendship'; | |
nameTo = 'Добавить в друзья'; | |
el.addClass('btn-friendship').removeClass('btn-friendship-del'); | |
} else if (el.hasClass('btn-friendship')) { | |
action = 'Friendship'; | |
nameTo = 'Ожидание'; | |
el.addClass('people-item-await').removeClass('btn-friendship').removeClass('people-item-bg'); | |
el.unbind('click'); | |
} | |
dispatchAction({action: action, user_id: el.parent().attr('data-id')}); | |
el.html(nameTo); | |
} | |
function people_doLoad(state, people_ajax_get_url, people_pagesize, rand) { | |
if (state.allDone) return; | |
state.loading = true; | |
$.get(people_ajax_get_url, function (data) { | |
state.loading = false; | |
var li=$(data).filter('.people-item'); | |
if (li.length<people_pagesize) { | |
state.allDone=true; | |
$('#loader').css('visibility', 'hidden'); | |
} | |
if (li.length==0) return; | |
id=parseInt($(li[li.length-1]).attr('data-id')); | |
$("#peopleList"+rand).append('<div id="appendedPage' + id + '" style="display:none;">' + data + '</div>'); | |
$('#appendedPage' + id).fadeIn('slow'); | |
}); | |
} | |
function print_r(arr, level) { | |
var print_red_text = ""; | |
if(!level) level = 0; | |
var level_padding = ""; | |
for(var j=0; j<level+1; j++) level_padding += " "; | |
if(typeof(arr) == 'object') { | |
for(var item in arr) { | |
var value = arr[item]; | |
if(typeof(value) == 'object') { | |
print_red_text += level_padding + "'" + item + "' :\n"; | |
print_red_text += print_r(value,level+1); | |
} | |
else | |
print_red_text += level_padding + "'" + item + "' => \"" + value + "\"\n"; | |
} | |
} | |
else print_red_text = "===>"+arr+"<===("+typeof(arr)+")"; | |
return print_red_text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment