Skip to content

Instantly share code, notes, and snippets.

View SashaKolbasov's full-sized avatar

Alex SashaKolbasov

View GitHub Profile
@SashaKolbasov
SashaKolbasov / script.js
Last active May 16, 2018 14:49
Easy Accordion.
// js-acc
var accItems = $('.js-acc > .item');
var accTitles = $('.js-acc > .item > .title');
accItems.removeClass('open').find('.desc').slideUp();
accItems.eq(0).addClass('open').find('.desc').slideDown();
accTitles.on('click', function() {
var parent = $(this).parent('.item');
if (parent.hasClass('open')) {
parent.removeClass('open').find('.desc').slideUp();
} else {
@SashaKolbasov
SashaKolbasov / script.js
Last active March 31, 2019 16:03
Thousands Separator
var price = Math.floor(price) + '';
price = price.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, '$1 ');
function sep(n){return n.replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g,'$1 ');}
function rmm(min,max){return Math.floor(Math.random()*(max-min+1))+min;}
@SashaKolbasov
SashaKolbasov / script.js
Last active January 8, 2017 12:38
Change SVG Color
$('img[src$=".svg"]').each(function () {
var $img = $(this),
imgID = $img.attr('id'),
imgClass = $img.attr('class'),
imgURL = $img.attr('src');
$.get(imgURL, function (data) {
var $svg = $(data).find('svg');
if (typeof imgID !== 'undefined') {
$svg = $svg.attr('id', imgID);
}
@SashaKolbasov
SashaKolbasov / script.js
Created January 4, 2017 19:01
Body Click to Hide block
$('body').click(function (e) {
if ($(e.target).closest('selector').length == 0) {
$('selector').removeClass('_active');
}
});
@SashaKolbasov
SashaKolbasov / style.less
Created January 4, 2017 09:46
Placeholder Focus
.plchfcs {
opacity: 1;
transition: opacity .15s ease-out;
}
input {
&::-webkit-input-placeholder {
.plchfcs;
}
&::-moz-placeholder {
.plchfcs;
@SashaKolbasov
SashaKolbasov / html.html
Last active January 13, 2017 19:09
Easy Preloader
<div id="preloader" class="preloader"><span class="spinner"></span></div>
@SashaKolbasov
SashaKolbasov / style.less
Created January 4, 2017 09:44
Footer Clamp Down
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
}
.wrapper {
display: flex;
@SashaKolbasov
SashaKolbasov / script.js
Last active January 4, 2017 08:59
Scrollbar Width
function scrollWidth() {
var div = document.createElement('div');
div.style.overflowY = 'scroll';
div.style.width = '50px';
div.style.height = '50px';
div.style.visibility = 'hidden';
document.body.appendChild(div);
var s = div.offsetWidth - div.clientWidth;
document.body.removeChild(div);
return s;
@SashaKolbasov
SashaKolbasov / base.sql
Last active August 28, 2018 03:52
WordPress transfer
UPDATE wp_options SET option_value = REPLACE(option_value, 'http://olddomain.ru', 'http://newdomain.ru') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = REPLACE(guid, 'http://olddomain.ru','http://newdomain.ru');
UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://olddomain.ru', 'http://newdomain.ru');
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://test.truemisha.ru','https://misha.blog');
@SashaKolbasov
SashaKolbasov / events.js
Last active April 11, 2016 18:24
Cross-browser events on JavaScript.
var eventsObj = {
addEvent: function (el, type, fn) {
if (typeof addEventListener !== 'undefined') {
el.addEventListener(type, fn, false);
} else if (typeof attachEvent !== 'undefined') {
el.attachEvent('on' + type, fn);
} else {
el['on' + type] = fn;
}
},