Skip to content

Instantly share code, notes, and snippets.

@andfinally
andfinally / sample.js
Last active February 4, 2017 15:49 — forked from gfazioli/old_version_event.js
WordPress actions and filters in Javascript Forked from gfazioli/old_version_event.js.
// Add action
wpdk_add_action( 'test_action', test_action );
// Action function
function test_action()
{
console.log( 'Fires test_action' );
}
wpdk_do_action( 'test_action' );
@andfinally
andfinally / index.html
Last active April 11, 2016 14:46
Breakpoint watcher - when a page has crossed a CSS breakpoint, calls a callback, passing an object representing the breakpoint you've left and an object representing the breakpoint you've entered
<html>
<head>
<title>-- == TEST == --</title>
</head>
<style>
body {
background: #FF1493;
}
@andfinally
andfinally / normalise-url.js
Created October 8, 2013 10:49
Turn a URL into just the path + querystring
// normalizeUrl('http://news.bbc.co.uk/sport/?page=1#test');
// returns "/sport/?page=1"
var normalizeUrl = function (url) {
var a = document.createElement('a');
a.href = url;
a = a.pathname + a.search;
a = a.indexOf('/') === 0 ? a : '/' + a; // because IE doesn't return a leading '/'
return a;
};
@andfinally
andfinally / adjust_page_height.js
Created October 2, 2013 11:05
Periodically check the height of the main content container and reset its height to accommodate any increase in the height of its children that might've happened. Content container has overflow hidden. Content like FB comments can increase in height after page load.
// Make the contentArea height equal to the paneVisible height. (We view the latter through the former.)
var updateHeight = function(){
var height = $(paneVisible).children().height();
if (height) {
$(contentArea).height(height + paneVisibleMargin);
}
};
// Set a periodic height adjustment for the content area. Necessary to account for diverse heights of side-panes as they slide in, and dynamic page elements.
setInterval(function(){
@andfinally
andfinally / ping_google_analytics.js
Created October 1, 2013 10:26
Ping Google Analytics "Log" and the time in hh:mm:ss at intervals - Stephan's code. Seems to log custom event with GA every 1 or 1.5 seconds, with seconds elapsed since the analytics JS started running.
// Converts number of seconds to hh:mm:ss
if( typeof Number.prototype.toHHMMSS !== 'function' ) {
Number.prototype.toHHMMSS = function (){
var hours = Math.floor(this / 3600);
var minutes = Math.floor((this - (hours * 3600)) / 60);
var seconds = this - (hours * 3600) - (minutes * 60);
var str;
str = ( hours === 0 ? '' : (hours < 10 ? '0' + hours : hours ) + ':' );
str += ( minutes < 10 ? '0' + minutes : minutes ) + ':';
str += ( seconds < 10 ? '0' + seconds : seconds );