Skip to content

Instantly share code, notes, and snippets.

@victorpavlenko
Created March 26, 2015 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorpavlenko/f8965192bd028f064e9b to your computer and use it in GitHub Desktop.
Save victorpavlenko/f8965192bd028f064e9b to your computer and use it in GitHub Desktop.
window.__GLOBALS = {};
function popupScroll() {
var t = $(window).scrollTop();
var h = $(window).height();
var fix = 'elementFixed';
var tail = 'elementTailed';
if (t > 32) $('#popupsContainer .jsPopupRightColumn').addClass(fix); else $('#popupsContainer .jsPopupRightColumn').removeClass(fix);
if ($('#leftScrollableContainer1').length) {
var gH = document.getElementById('leftScrollableContainer1');
gH = gH ? $(gH).height() : 0;
if (t > gH + 31) {
$('.popup-content').css('padding-top', $('#leftFixedSeparator1').outerHeight(true) + gH + 'px');
$('#leftScrollableContainer1').hide();
$('#leftFixedSeparator1').addClass(fix);
} else {
$('#leftFixedSeparator1').removeClass(fix);
$('#leftScrollableContainer1').show();
$('.popup-content').css('padding-top', '0');
}
}
var docH = $(document).height();
var w = $('.opened .jsPopupRightColumn');
var r = $('.opened .jsPopupRightColumn');
var rh = r.height() + 32;
if (t >= docH - rh) w.addClass(tail); else w.removeClass(tail);
}
function hidePopup(top) {
$('#popupsContainer .opened').fadeOut({duration: 250, queue: false});
$('#popupsContainer').fadeOut({duration: 250, queue: false});
$('.popup-shadow').fadeOut({duration: 250, queue: false});
$('#popupsContainer .opened').removeClass('opened');
var t = parseInt($("#scrollBlocker").css("margin-top")) * (-1);
$(".wrapper").unwrap('<div></div>');
$(window).scrollTop(top);
disableAllScrollEffects = false;
}
function closePopupClick(ajaxContent, sourceUrl, top) {
if (ajaxContent) history.pushState({}, null, sourceUrl);
$(this).off('click');
hidePopup(top);
clearInterval(intervalId);
return false;
}
function preparePopup() {
$('#ajaxPopupWrapper').remove();
$('#popupsContainer').append('<div id="ajaxPopupWrapper" data-source-url="" class="opened"><div class="popup-shadow"></div></div>')
}
function setupPopup(sourceUrl, html) {
var $ajaxPopupWrapper = $('#ajaxPopupWrapper');
var ajaxPopupWrapperHtml = $ajaxPopupWrapper.html();
$ajaxPopupWrapper.data('source-url', sourceUrl).html(html + ajaxPopupWrapperHtml);
}
function showPopup(wnd, ajaxContent, sourceUrl) {
disableAllScrollEffects = true;
$('#popupsContainer').removeClass('popup-dimmed');
$('.popup-window').hide();
var t = $(window).scrollTop();
$(window).bind('scroll', popupScroll);
$(".wrapper").wrap($('<div id="scrollBlocker"></div>'));
//.css("margin-top", -t));
if (ajaxContent) setupPopup(sourceUrl, wnd.html())
$(window).scrollTop(0);
$('#popupsContainer').css('margin-left', -wnd.outerWidth(true) / 2 + 'px');
initTabs();
initValidator();
$('#popupsContainer .jsClosePopup').on('click', function () {
return closePopupClick(ajaxContent, sourceUrl, t);
});
$('#popupsContainer .popup-shadow').on('click', function () {
return closePopupClick(ajaxContent, sourceUrl, t);
});
wnd.show().addClass('opened');
$('#popupsContainer').fadeIn({duration: 250, queue: false});
}
function initItemCardEvents() {
}
function loadPopup(id, url, updateHistory, type, force, productId, callback) {
var args = {
id: 'postEditPopup',
url: '#',
updateHistory: true,
type: 'text',
force: false,
productId: false,
callback: callback,
scrollTop: $(this).scrollTop()
};
if (id instanceof Object) {
args = $.extend(args, id);
} else if (id instanceof jQuery) {
// connect args
} else {
args.id = id || args.id;
args.url = url || args.url;
args.updateHistory = updateHistory || args.url;
args.type = type || args.type;
args.force = force || args.force;
args.productId = productId || args.productId;
args.callback = callback || args.callback;
}
preparePopup();
$('.popup-shadow').show();
$('#popupsContainer').fadeIn({duration: 250, queue: false});
if (args.id == 'postViewPopup' || args.id == 'userProfilePopup' || args.id == 'itemCardPopup') {
var sourceUrl = window.location.href;
if (args.updateHistory) history.pushState({id: args.id, url: args.url}, "page2", args.url);
if (args.id == 'itemCardPopup') {
args.url = args.url + '?ajax=1';
}
$.get(
args.url, {}, function (html) {
showPopup($('#' + args.id, html).clone().wrap('<p>').parent(), true, sourceUrl);
if (args.id == 'userProfilePopup' && typeof(initProfileEvents) == 'function') initProfileEvents();
if (args.id == 'postViewPopup' && typeof(initProfileEvents) == 'function') initViewPostEvents();
if (args.id == 'itemCardPopup') {
initRatingEvents('#itemCardPopup');
//initViewCardEvents();
initShopEvents('#itemCardPopup');
}
}
);
if (args.id == 'itemCardPopup') initItemCardEvents();
return false;
}
showPopup($('#' + args.id), false);
if (args.id == 'postEditPopup') {
initPostEditorPopup(args.type, args.force || false, productId);
}
if (typeof args.callback === 'function') {
args.callback();
}
return false;
}
function initPopupEvents(selector) {
$(selector + ' [data-popup-window]').unbind('click').click(function () {
var $this = $(this);
var data = $this.data();
var scrollTop = $this.scrollTop();
loadPopup(data.popupWindow, $this.attr('href'), true, data.popupType, !!data.popupForce, data.productId);
return false;
});
if ($("#popupItemNav").length) {
$("#popupItemNav").scrolltab();
}
}
function initRatingEvents(selector) {
$(selector+' [data-raty]').raty({
starOff: ratуImagesPath + 'star-off.png',
starOn: ratуImagesPath + 'star-on.png',
starHalf: ratуImagesPath + 'star-half.png',
score: function () {
return $(this).attr('data-score') || 0;
},
readOnly:
function () {
return $(this).attr('data-clickable') ? false : true;
}
});
}
$(document).ready(function () {
var $postViewPopup = $('#postViewPopup');
var $popupShadow = null;
var popupRedirectHref = '';
var $btnUytClub = $('#button');
var $main = $('.main');
var $wrapper = $('.wrapper');
var wrapperHeight = $wrapper.height();
var halfWrapperHeight = parseInt(wrapperHeight / 2, 10);
var $headerUserPic = $('.header-aside').find('.userpic[dropdown-source="userpic"]');
var $content = $('.content');
var $sidebar = $('.sidebar');
$('.js-globals input').each(function(index, value){
var $input = $(value);
window.__GLOBALS[$input.data('name')] = $input.data('value');
});
if (!!$content.length && !!$sidebar.length) {
if ($content.height() < $sidebar.height()) {
$content.css('height', $sidebar.height() + 50);
}
}
if (!!$btnUytClub.length && !!$main.length) {
if (!!/blog/.exec(window.location.href)) {
$btnUytClub.css('top', $main.offset().top + 20).css('display', 'block');
} else if (!!/collection/.exec(window.location.href)) {
$btnUytClub.css('top', $main.offset().top - 250).css('display', 'block');
} else {
$btnUytClub.css('top', $main.offset().top + 100).css('display', 'block');
}
}
// $(window).on('resize', function(){
// if (halfWrapperHeight > $(window).scrollTop()) {
// $btnUytClub.css({
// 'top': $main.offset().top + ($firstPost.height() - $btnUytClub.height()) / 2,
// 'bottom': 'auto'
// });
// } else {
// $btnUytClub.css({
// 'top': 'auto',
// 'bottom': '40%'
// });
// }
// });
initPopupEvents('');
initRatingEvents('');
$("[dropdown-source], [data-dropdown-source]").dropdown();
$("[tab-item], [data-tab-item]").click(function () {
var clicked = $(this);
$(".tab-content").each(function () {
$(this).css("display", "none");
});
$("ul.tabset li").each(function () {
var t = $(this);
t.unsetClass("active");
if ($("a", t).attr("href") == ("#" + (clicked.attr("tab-item") || clicked.data("tab-item")))) {
t.setClass("active");
$("#" + (clicked.attr("tab-item") || clicked.data("tab-item"))).css("display", "block");
}
});
});
if ($("#popupGallery").length) {
$('#popupGallery [gallery-holder], #popupGallery [data-gallery-holder]').bxSlider({
pagerCustom: '#popupGallery .thumbs'
});
}
if ($("#scrollUpCategories").length) {
$("#scrollUpCategories").click(function () {
var height = $("#main").offset().top - 84 + ($("#promoBlock").length ? 350 : 0) - ($("#submenu").length ? 62 : 0);
$('html, body').stop().animate({
scrollTop: height
}, 300);
})
}
if (!pseudoPopupWindow) {
$(window).bind('popstate', function (e) {
document.addEventListener('scroll', noScrollOnce);
var state = e.originalEvent.state;
if (state) {
loadPopup(state.id, state.url, false);
} else {
hidePopup();
}
})
}
if (!$postViewPopup.length) {
$postViewPopup = $('#itemCardPopup');
}
if (!!$postViewPopup.length) {
$popupShadow = $('<div />', {
'class': 'popup-shadow'
});
$('.btn-close', $postViewPopup).on('click', function(){
$('.popup-window', $postViewPopup).fadeOut({duration: 250, queue: false});
});
$popupShadow.on('click', function(){
$('.popup-window', $postViewPopup).fadeOut({duration: 250, queue: false});
window.location.href = $('.btn-close', $postViewPopup).attr('href');
});
$postViewPopup.append($popupShadow);
}
// $('.popup-shadow').on('click', function(e){
// var href = $(this).data('href') || '';
// if (href) {
// window.location.href = href;
// } else {
// hidePopup();
// }
// });
});
/*
$(document).click(function (event) {
if ($('#popupsContainer .opened').length==0) return;
if ($(event.target).closest(".jsPopupCloseOutide").length) return;
//$(".item-card, #popupsContainer, #popupShadow ").fadeOut("slow");
hidePopup();
event.stopPropagation();
}
);
*/
$(function () {
setTimeout(function () {
}, 1);
});
function noScrollOnce(event) {
event.preventDefault();
document.removeEventListener('scroll', noScrollOnce);
}
function addAutoresizeFeature(el) {
el.autoResize({
onResize: function () {
$(this).css({opacity: 0.8});
},
animateCallback: function () {
$(this).css({opacity: 1});
},
animateDuration: 300,
extraSpace: 0
});
}
// btn-yut-club
$(function(){
var $btnYutClub = $('.btn-yut-club');
// !!
});
function __extend(Child, Parent) {
var Foo = function() {};
Foo.prototype = Parent.prototype;
Child.prototype = new Foo();
Child.prototype.constructor = Child;
Child.parent = Parent.prototype;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment