Skip to content

Instantly share code, notes, and snippets.

View arturparkhisenko's full-sized avatar
:octocat:
www. www always changes

Artur Parkhisenko arturparkhisenko

:octocat:
www. www always changes
View GitHub Profile
@arturparkhisenko
arturparkhisenko / foo.js
Last active March 18, 2016 17:40
js-module-es2015-aka-es6
function foo() {
return 'Hi from foo!';
}
export default foo;
// or
// export default function foo() {
// return 'Hi from foo!';
// }
var inFullScreen = document.fullscreenEnabled || document.fullscreenElement ||
window.fullScreen || document.webkitIsFullScreen || document.msFullscreenEnabled;
if (inFullScreen) {
//do something..
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
@arturparkhisenko
arturparkhisenko / fitelement.js
Last active September 21, 2015 18:16
fitelement(something with aspect), script for rAF.js
var fitElement = function fitElement(elementSelector, elementAspect) {
var element = (typeof elementSelector === 'string' || elementSelector instanceof String) ? document.querySelector(elementSelector) : elementSelector,
parW = element.parentNode.clientWidth,
parH = element.parentNode.clientHeight,
parAsp = parW / parH,
aspect = elementAspect || 16 / 9,
elW, elH;
if (aspect > parAsp) {
elW = parW;
elH = elW / aspect;
@arturparkhisenko
arturparkhisenko / functions.php
Last active September 10, 2015 14:38
wp excerpt lenght limit
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
@arturparkhisenko
arturparkhisenko / browserInfo.js
Last active January 22, 2016 18:09
Browser-and-OS-detect
function BrowserInfo() {
this.supported = false;
this.isBrowser = true;
this.webBrowser = null;
this.webBrowserVer = null;
this.os = 'unknown os';
var detectedUA = null;
if (typeof window === 'undefined' || !window.navigator) {
@arturparkhisenko
arturparkhisenko / remove.js
Last active August 19, 2017 06:20
function to remove by selector
/**
* remove - removes DOM elements
* working with: usual dom element, selector, jQuery object, Polymer object
* @param {string | object} selectorOrObject - dom object
*/
function remove(selectorOrObject) {
if (!selectorOrObject) {
return;
}
@arturparkhisenko
arturparkhisenko / js-remove-hash.js
Last active September 21, 2015 18:29
remove hash from url
//source: http://stackoverflow.com/questions/4508574/remove-hash-from-url
//Best is Homero Barbosa's answer below:
history.pushState('', document.title, window.location.pathname);
//... or, if you want to maintain the search parameters:
history.pushState('', document.title, window.location.pathname + window.location.search);
//Old, do not use, badwrongfun:
// var loc = window.location.href,
// index = loc.indexOf('#');
// if (index > 0) {
@arturparkhisenko
arturparkhisenko / resize.js
Created September 28, 2015 20:14
resize and throttle with rAF
//https://developer.mozilla.org/en-US/docs/Web/Events/resize
;
(function() {
var throttle = function(type, name, obj_) {
var obj = obj_ || window;
var running = false;
var func = function() {
if (running) {
return;
}
@arturparkhisenko
arturparkhisenko / append-prepend.js
Created October 3, 2015 20:24
append-and-prepend-elements-js
//Setup
let el = document.getElementById('thingy');
let elChild = document.createElement('div');
elChild.innerHTML = 'Content';
//Append
el.appendChild(elChild);
//Prepend
el.insertBefore(elChild, el.firstChild);
@arturparkhisenko
arturparkhisenko / ri-feature-detection.js
Created October 9, 2015 05:56 — forked from gregwhitworth/ri-feature-detection.js
Responsive images feature detection
(function (window) {
document.addEventListener("DOMContentLoaded", function (e) {
var supports = {
srcset: false,
currentSrc: false,
sizes: false,
picture: false
};
var img = new Image();