Skip to content

Instantly share code, notes, and snippets.

View timmywil's full-sized avatar

Timmy Willison timmywil

View GitHub Profile
@timmywil
timmywil / what-forces-layout.md
Created June 17, 2016 17:22 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@timmywil
timmywil / index.d.ts
Last active August 14, 2020 22:19
react-native-track-player types
import { Component } from 'react'
import { NativeModules } from 'react-native'
export = RNTrackPlayer
declare namespace RNTrackPlayer {
export type EventType =
| 'playback-state'
| 'playback-error'
| 'playback-queue-ended'
var foo = function foo() {
foo = 5;
console.log(foo);
};
foo();
// outputs: [Function foo]
@timmywil
timmywil / jquery.factory.js
Last active December 19, 2015 15:49
Using jQuery in a CommonJS-like environment and multiple contexts.
// This can be done with what is currently in github (but has not yet been released)
// Using jsdom
var dom = jsdom.jsdom();
var window = dom.createWindow();
var window2 = dom.createWindow();
var factory = require('jquery');
var jquery1 = factory( window );
var jquery2 = factory( window2 );
@timmywil
timmywil / shared.js
Created February 7, 2013 15:20
This is a shared module between server and client. It has one extra dependency in the browser because it should not be used on the server. This pattern was arrived at because it was the only one I found that worked after building with r.js. I'd like to suggest removing the entire if statement even if it has extra content such as defining empty m…
// For node
if (typeof define !== "function") {
var define = require("amdefine")( module );
// Define base64 as empty
define("libs/base64", function() {});
}
define([ "node-uuid", "libs/base64" ],
function( uuid, base64 ) {
function awesome() {
@timmywil
timmywil / backPushState.js
Created November 18, 2011 16:07
A simple pushState plugin that falls back to hashChange (only for going back)
/**
* @license backPushState.js
* A simple pushState library that falls back to hashChange (only for going back)
* Copyright (c) 2011 timmy willison
* Dual licensed under the MIT and GPL licenses.
* http://timmywillison.com/licence/
*/
define([ 'jquery' ],
function( $ ) {
<body>
<div id="foo">...</div>
<script src="jquery.js"></script>
<script>
$( "#foo" ).offset();
</script>
</body>
@timmywil
timmywil / minimal-event.js
Created October 28, 2011 17:01
Fire an event cross-browser
var fire;
if ( document.createEvent ) {
fire = function( node, type ) {
var event = document.createEvent('HTMLEvents');
event.initEvent( type, true, true );
node.dispatchEvent( event );
};
} else {
fire = function( node, type ) {
var event = document.createEventObject();
@timmywil
timmywil / avaya_draggable.js
Created October 28, 2011 13:41
A small draggable implementation for a lightbox
/**
* @license avaya.js
* Load avaya webchat lightbox with iframe
* Copyright (c) 2011 EPB
*/
define([ 'jquery', 'jquery-plugins/minLight' ],
function( $ ) {
"use strict";
@timmywil
timmywil / module_defer.js
Created October 27, 2011 14:11
Modules with deferred dependencies
// This could be compatible with jQuery's Deferred implementation,
// futures.js (slightly different syntax) or any one of a number
// of other implementations
define(['lib/Deferred'], function( Deferred ){
var defer = new Deferred();
require(['lib/templates/?index.html','lib/data/?stats'],
function( template, data ){
defer.resolve({ template: template, data:data });
}
);