Skip to content

Instantly share code, notes, and snippets.

View radist2s's full-sized avatar

Alex Batalov radist2s

  • Georgia, Tbilisi
  • 07:16 (UTC +04:00)
View GitHub Profile
@radist2s
radist2s / bg-image-url.js
Last active June 2, 2017 10:29
Returns background image url or empty string if doesn't exists. (jQuery isn't required) getBgImageUrl()
function getBgImageUrl($el) {
var el = $el instanceof HTMLElement ? $el : (window.jQuery && $el instanceof window.jQuery && $el.get(0))
if (!el) {
return ''
}
var backgroundImage = getComputedStyle(el).backgroundImage
if (!backgroundImage || backgroundImage === 'none') {
@radist2s
radist2s / index.html
Last active January 7, 2018 17:51
Social sharer (Facebook, Twitter, VK)
<html>
<head>
<meta property="og:url" content="http://site.url/" />
<meta property="og:site_name" content="Site Name" />
<meta property="og:title" content="Page title" />
<meta property="og:description" content="Page desc" />
<meta property="og:image" content="/image/share-image.jpg" />
</head>
<body>
<a href="http://www.facebook.com/dialog/feed?app_id=123456789&link=%og:url%&picture=%og:image%&name=%og:title%&description=%og:description%&display=popup&redirect_uri=%origin%/static/html/self-close.html" title="Facebook" target="_blank" class="social-icon social-icon--fb socialIcon"></a>
@radist2s
radist2s / analytics-event-catch.js
Last active September 27, 2019 03:58
Google Analytics event catcher
document.addEventListener('click', function (e) {
if (e.target.hasAttribute('data-ga')) {
catchGaEvent(e)
}
})
function catchGaEvent(e) {
var el = e.target
var event = el.getAttribute('data-ga'),
@radist2s
radist2s / functions.php
Created July 10, 2015 08:18
Worpress Shortcode template include
add_shortcode('template', function ($templates = array()) {
$templates_render_result = '';
foreach ($templates AS $key => $template)
{
if (is_numeric($key) AND $template)
{
$template = sanitize_file_name($template);
if ($template_path = get_template_directory() . "/parts/templates/$template.html" AND is_readable($template_path))
@radist2s
radist2s / functions.php
Created July 10, 2015 08:17
Worpress Open Embed (Video) content wrapper hook/filter
add_filter('embed_oembed_html', function ($oembed) {
return "<div class='video-wrapper'>$oembed</div>";
}, 10);
@radist2s
radist2s / formatMoney.js
Created May 24, 2015 16:32
Format Money
window.formatMoney = function formatMoney(money) {
money = parseInt(money)
money = isFinite(money) ? money : 0
return String(money).replace(/./g, function(c, i, a) {
return i && c !== '.' && ((a.length - i) % 3 === 0) ? ' ' + c : c
})
}
@radist2s
radist2s / animation-end-event.js
Last active October 30, 2016 08:29
CSS3 animation end event
var _animationEndEventName;
function animationEndEventName() {
if (_animationEndEventName !== undefined) {
return _animationEndEventName
}
var detectedAnimation,
el = document.createElement('animationdetector'),
animations = {
@radist2s
radist2s / example.html
Last active August 29, 2015 14:20
tympanus.net PageTransitions
<div class="pt-perspective">
<div class="pt-page"></div>
<div class="pt-page"></div>
<div class="pt-page"></div>
</div>
<script>
var $pages = $('.pt-page')
transition.init($('.pt-page'))
@radist2s
radist2s / gulpfile.js
Last active August 29, 2015 14:19
Gulpfile for using Less compiler with sourcemap support and autoprefixer postcss
var lessSourceFiles = '../../static/less/*.less'
var cssOutPath = '../../static/css'
var gulp = require('gulp')
var watch = require('gulp-watch')
var less = require('gulp-less-sourcemap')
var path = require('path')
var gutil = require('gulp-util')
var notifier = require('node-notifier')
var postcss = require('gulp-postcss')
@radist2s
radist2s / has-scroll-bar.js
Last active June 29, 2017 12:27
Detect if document has vertical or horizontal scroll
window.hasVerticalScroll = function hasVerticalScroll(node) {
return hasScroll(node, 'vertical')
}
window.hasHorizontalScroll = function hasVerticalScroll(node) {
return hasScroll(node, 'horizontal')
}
window.hasScroll = function hasVerticalScroll(node, axis) {
axis = axis ? String(axis).toLowerCase() : ''