Skip to content

Instantly share code, notes, and snippets.

View dpmango's full-sized avatar
🌎
Available for project-based work

Sergey Khmelevskoy dpmango

🌎
Available for project-based work
View GitHub Profile
$.fn.digits = function(){
return this.each(function(){
$(this).text( $(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
})
}
$('#animateItem').each(function () {
$(this).prop('Counter',0).animate({
Counter: $(this).text()
}, {
// validation
var emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var emailIsValid = false;
if(emailRegex.test(myEmail.val())){
emailIsValid = true;
} else {
emailIsValid = false;
}
$(".ui-number input").keydown(function (e) {
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
(e.keyCode === 65 && (e.ctrlKey === true || e.metaKey === true)) ||
(e.keyCode >= 35 && e.keyCode <= 40)) {
return;
}
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
e.preventDefault();
}
if ( $(this).val().length > 5 ){
$('.ui-number span').on('click', function(e){
var element = $(this).parent().find('input');
var currentValue = parseInt($(this).parent().find('input').val()) || 0;
if( $(this).data('action') == 'minus' ){
if(currentValue <= 1){
return false;
}else{
element.val( currentValue - 1 );
}
$(document).mouseup(function (e) {
var container = new Array();
container.push($('.mobile-navi'));
$.each(container, function(key, value) {
if (!$(value).is(e.target) && $(value).has(e.target).length === 0) {
$(value).removeClass('is-active');
}
});
});
function calcLocation(){
function containsAll(needles, haystack){
for(var i = 0 , len = needles.length; i < len; i++){
if($.inArray(needles[i], haystack) == -1) return false;
}
return true;
}
function titleCase(str) {
return str.split(' ').map(function(val){
// set dalay on scroll event to prevent huge memory leaks
(function($) {
var uniqueCntr = 0;
$.fn.scrolled = function (waitTime, fn) {
if (typeof waitTime === "function") {
fn = waitTime;
waitTime = 50;
}
var tag = "scrollTimer" + uniqueCntr++;
this.scroll(function () {
var _mastersSlickMobile = $('.masters__wrapper');
var mastersSlickMobileOptions = {
mobileFirst: true,
responsive: [
{
breakpoint: 768,
settings: "unslick"
}
]
}
// hero parallax on mousemove
var movementStrength = 50;
var height = movementStrength / _window.height();
var width = movementStrength / _window.width();
$(".hero").mousemove(function(e){
var pageX = e.pageX - (_window.width() / 2);
var pageY = e.pageY - (_window.height() / 2);
var newvalueX = width * pageX * -1 - 25;
var newvalueY = height * pageY * -1 - 50;
$('.hero-bg').css("background-position", newvalueX+"px "+newvalueY+"px");
@dpmango
dpmango / jquery.StickyFixedBottom.js
Created July 19, 2017 12:26
Stop's fixed element on the bottom of the page (before footer)
_window.scrolled(10, function () {
var stickyEl = $('.results__map');
var windowBottomScroll = _window.scrollTop() + _window.height();
var stopPoint = _document.height() - $('footer').outerHeight();
if (windowBottomScroll >= stopPoint) {
stickyEl.addClass('results__map--stop');
} else if (windowBottomScroll < stopPoint) {
stickyEl.removeClass('results__map--stop');
}