Skip to content

Instantly share code, notes, and snippets.

@aderaaij
aderaaij / background-image.haml
Created September 4, 2014 08:43
inline styles in variable image
.foo{:style => "background-image: url('#{current_page.data.imageurl}');"}
(function(DOMParser) {
"use strict";
var
DOMParser_proto = DOMParser.prototype
, real_parseFromString = DOMParser_proto.parseFromString
;
// Firefox/Opera/IE throw errors on unsupported types
try {
@aderaaij
aderaaij / ajaxify.js
Last active November 12, 2017 15:34
ajaxify some stuff
// Ajaxify internal content
(function (window, undefined) {
// Prepare our Variables
var
History = window.History,
$ = window.jQuery,
document = window.document;
// Check to see if History.js is enabled for our Browser
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
clearTimeout(timeout);
timeout = setTimeout(function() {
@aderaaij
aderaaij / offset.js
Created November 29, 2015 18:17
Basic offset function, replacing jQuery's offset.
function offset(elt) {
var rect = elt.getBoundingClientRect(), bodyElt = document.body;
return {
top: rect.top + bodyElt .scrollTop,
left: rect.left + bodyElt .scrollLeft
}
}
//use:
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
{
"env": {
"node": true,
"browser": true,
"es6": true
},
"extends": "airbnb-base",
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
@aderaaij
aderaaij / .eslintrc
Last active October 6, 2017 13:37
React ESLINT config
{
"env": {
"node": true,
"browser": true,
"es6": true
},
"extends": "airbnb-base",
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
@aderaaij
aderaaij / react-links.md
Last active August 4, 2017 17:50
Valueble React / JSX / JS Resources
@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]);