Skip to content

Instantly share code, notes, and snippets.

@aderaaij
aderaaij / getPosition.js
Last active November 12, 2017 15:13
Get an elements X and Y position
function getPosition(el) {
let xPos = 0;
let yPos = 0;
while (el) {
if (el.tagName == 'BODY') {
// deal with browser quirks with body/window/document and page scroll
const xScroll = el.scrollLeft || document.documentElement.scrollLeft;
const yScroll = el.scrollTop || document.documentElement.scrollTop;
@aderaaij
aderaaij / setVendor.js
Created October 6, 2017 15:07
Set all vendor prefixes in vanilla js.
export function setVendor(element, property, value) {
element.style["Webkit" + property] = value;
element.style["Moz" + property] = value;
element.style["ms" + property] = value;
element.style["o" + property] = value;
element.style[property] = value;
}
@aderaaij
aderaaij / getSiblings.js
Created October 6, 2017 15:06
Get siblings in vanilla js
export function getSiblings(elem) {
var siblings = [];
var sibling = elem.parentNode.firstChild;
for ( ; sibling; sibling = sibling.nextSibling ) {
if ( sibling.nodeType === 1 && sibling !== elem ) {
siblings.push( sibling );
}
}
return siblings;
}
{
"parser": "babel-eslint",
"env": {
"node": true,
"browser": true,
"es6": true
},
"extends": "airbnb-base",
"parserOptions": {
"sourceType": "module",
mixin svg(id, viewbox, className)
if viewbox
svg(viewbox='#{viewbox}', class!=className)
use(xlink:href='assets/img/sprite.svg#' + id)
else
svg(viewbox='0 0 50 50', class!=className)
use(xlink:href='assets/img/sprite.svg#' + id)
//- Usage: +svg('symbolID', 'viewbox parameters', 'classnames')
@aderaaij
aderaaij / get_excerpt.php
Created October 6, 2017 13:00
Creates a WordPress excerpt based on the amount of characters you want it to have
<?php
/* = Limit Excerpt
/* Usage: echo get_excerpt(250)
-------------------------------------------------------------- */
function get_excerpt($limit, $source = null){
if($source == "content" ? ($excerpt = get_the_content()) : ($excerpt = get_the_excerpt()));
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
@aderaaij
aderaaij / remove_junk_from_head
Created October 6, 2017 12:59
Removing all the WordPress junk from the header.
<?php
// =========================================================================
// REMOVE JUNK FROM HEAD
// =========================================================================
remove_action('wp_head', 'rsd_link'); // remove really simple discovery link
remove_action('wp_head', 'wp_generator'); // remove wordpress version
remove_action('wp_head', 'feed_links', 2); // remove rss feed links (make sure you add them in yourself if youre using feedblitz or an rss service)
remove_action('wp_head', 'feed_links_extra', 3); // removes all extra rss feed links
@aderaaij
aderaaij / modify_admin_bar_position.php
Created October 6, 2017 12:57
Modify the admin bar position on the front-end to the bottom and add the proper styles for the dropdown menu.
<?php
function modify_admin_bar_position() {
if ( is_user_logged_in() ) { ?>
<style type="text/css">
body {
margin-top: -32px;
padding-bottom: 32px;
}
@aderaaij
aderaaij / getComputedTranslateXY.ts
Last active February 12, 2023 15:19
Get the computed Translate X and Y values of a given DOM element. Based on https://stackoverflow.com/questions/21912684/how-to-get-value-of-translatex-and-translatey
function getTranslate(item: HTMLElement): number | number[] | undefined {
const transArr = [];
if (!window.getComputedStyle) {
return;
}
const style = window.getComputedStyle(item);
const transform = style.transform || style.webkitTransform;
let mat = transform.match(/^matrix3d\((.+)\)$/);
if (mat) {
return parseFloat(mat[1].split(', ')[13]);
@aderaaij
aderaaij / react-links.md
Last active August 4, 2017 17:50
Valueble React / JSX / JS Resources