Skip to content

Instantly share code, notes, and snippets.

View radist2s's full-sized avatar

Alex Batalov radist2s

  • Georgia, Tbilisi
View GitHub Profile
@radist2s
radist2s / passive-events-detect.js
Created June 19, 2017 13:43
Passive events support
// https://github.com/Modernizr/Modernizr/issues/1894#issuecomment-198035521
window.passiveEventsSupport = function passiveEventsSupport() {
if (passiveEventsSupport.supportsPassive !== undefined) {
return passiveEventsSupport.supportsPassive
}
var supportsPassive = false
var opts = Object.defineProperty && Object.defineProperty({}, 'passive', {
get: function () {
@radist2s
radist2s / wp_cache_delete_group.php
Last active May 25, 2017 12:02
wp_cache_delete_group function
function wp_cache_delete_group($group)
{
/** @type WP_Object_Cache $wp_object_cache */
global $wp_object_cache;
$cache = $wp_object_cache->cache;
if (isset($cache[$group]))
{
unset($cache[$group]);
@radist2s
radist2s / web-support-detector.js
Last active June 20, 2016 13:08
WEBP Support detector. Adding class to html element.
!function () {
function getWebpSupport() {
var canvas = document.createElement('canvas');
return canvas && canvas.getContext && canvas.toDataURL('image/webp').indexOf('data:image/webp') == 0
}
var webpSupport
if (document.cookie.indexOf('webp') == -1) {
webpSupport = getWebpSupport() && 1 || 0
@radist2s
radist2s / raf-queue.js
Last active October 25, 2017 14:14
Request Animation Frame Queue
/**
* Using:
* var queue = new RafAnimationQueue(defaultContext)
* queue.add(firstAnimationFrameCallback) // firstAnimationFrameCallback will executed with defaultContext
* queue.add(secondAnimationFrameCallback, customContext)
* queue.delay() // skip just one frame
* queue.clear() // clear animation queue
**/
window.RafAnimationQueue = (function () {
function RafAnimationQueue(context) {
@radist2s
radist2s / template-code-trim.js
Created January 26, 2016 14:14
HTML template trim. Trim "CDATA" and spaces in html insade <script/> tag
window.templateTrim = function (templateHtml) {
return templateHtml.replace(/\/{2,}<!\[CDATA\[([\s\S]*)\/{2,}]]>/i, '$1').trim()
}
@radist2s
radist2s / svg-functions.php
Created December 30, 2015 10:14
SVG embeding funtions
<?
function embed_svg($svg_path, $image_class = '', Array $attributes = array(), $is_abs_path = FALSE)
{
if (!$is_abs_path)
{
$image_path = get_template_directory() . '/static/img/' . trim($svg_path, ' /');
}
else
{
$image_path = $svg_path;
@radist2s
radist2s / trait.js
Last active January 6, 2016 18:21
JS Class traits
/**
* Usage:
* function MainClass() {}
* MainClass.prototype.delegate() {console.log('Main')}
* var methods = { delegate: function () { console.log('Sub') } }
* var SubClass = trait(MainClass, methods)
* new SubClass().delegate() // >>> Main, Sub
*/
define(function () {
@radist2s
radist2s / images-loaded.js
Created November 29, 2015 10:52
Images loaded simple checker with promises
define(['promise'], function () {
// Use any Promise polyfill
var imgClasses = [HTMLImageElement],
imgElementsList = ['img']
if (window.HTMLPictureElement) {
imgClasses.push(HTMLPictureElement)
imgElementsList.push('picture')
}
@radist2s
radist2s / style-mobile-loader.js
Created November 25, 2015 13:00
CSS loading for mobile
!function () {
function addHtmlClass(klass) {
document.documentElement.setAttribute('class', document.documentElement.getAttribute('class') || '' + ' ' + klass + ' ')
}
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera\s+Mini/i.test(navigator.userAgent)) {
window.fullVersionCookieTest = /nomobile\s*=\s*1(;\s*)?/ig
window.isFullVersion = fullVersionCookieTest.test(document.cookie)
if (!isFullVersion) {
@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') {