Skip to content

Instantly share code, notes, and snippets.

/* Flexible iFrame */
.flexible-container {
position: relative;
padding-bottom: 56.25%;
padding-top: 30px;
height: 0;
overflow: hidden;
}
@cferdinandi
cferdinandi / eventThrottler.js
Last active July 31, 2019 11:15
A technique for throttling listener events (like resize or scroll) for better performance. https://developer.mozilla.org/en-US/docs/Web/Reference/Events/resize
var eventTimeout; // Set timeout variable
/**
* The function that runs the event actions
*/
var actualEventHandler = function () {
// handle the event...
};
/**
@cferdinandi
cferdinandi / stop-video.js
Last active February 15, 2024 17:03
A simple method to stop YouTube, Vimeo, and HTML5 videos from playing.
/**
* Stop an iframe or HTML5 <video> from playing
* @param {Element} element The element that contains the video
*/
var stopVideo = function ( element ) {
var iframe = element.querySelector( 'iframe');
var video = element.querySelector( 'video' );
if ( iframe ) {
var iframeSrc = iframe.src;
iframe.src = iframeSrc;
@cferdinandi
cferdinandi / data-options.js
Last active May 2, 2016 19:37
Convert data-options attribute into an object of key/value pairs. ex. data-options="height: 50; width: 50px; title: This is a sample title"
/**
* Remove whitespace from a string
* @private
* @param {String} string
* @returns {String}
*/
var trim = function ( string ) {
return string.replace(/^\s+|\s+$/g, '');
};
@cferdinandi
cferdinandi / spinners.css
Created February 28, 2014 04:26
Simple CSS3 rotation animations.
/* The class that applies the animation. */
.spinner {
display: inline-block;
@include prefixer(animation, spin 2s infinite linear, webkit moz ms o spec);
}
/* The vendor-specific and generic animation keyframes.
* These control the direction and nature of the animation. */
@cferdinandi
cferdinandi / README.md
Last active May 22, 2020 13:24
Two simple functions for getting the ID of next and previous pages (not posts) in Wordpress. Forked from the "Next Page, Not Next Post" plugin by Matt McInvale. http://wordpress.org/plugins/next-page-not-next-post/

Functions

Next Page: next_page_ID($id) Previous Page: previous_page_ID($id)

$id: The ID of the page you're trying to get the next or previous page for.

Examples

<?php
function some_name( array $options = array() ) {
// Set defaults for all passed options
$options = array_merge( array(
'property1' => 'default1',
'property2' => 'default2',
), $options);
}
@cferdinandi
cferdinandi / foreach.js
Last active October 1, 2020 08:01
A simple forEach() implementation for Arrays, Objects and NodeLists. Forked from ForEach.js by Todd Motto. https://github.com/toddmotto/foreach
/**
* A simple forEach() implementation for Arrays, Objects and NodeLists
* @private
* @param {Array|Object|NodeList} collection Collection of items to iterate
* @param {Function} callback Callback function for each iteration
* @param {Array|Object|NodeList} scope Object/NodeList/Array that forEach is iterating over (aka `this`)
*/
var forEach = function (collection, callback, scope) {
if (Object.prototype.toString.call(collection) === '[object Object]') {
for (var prop in collection) {
@cferdinandi
cferdinandi / initEventListeners.js
Last active August 29, 2015 14:01
A simple method to set and remove event listeners for dynamically generated content.
// Event selector defaults
var toggles; // Toggle nodes list
var eventListeners = []; //Listeners array
// Whenever a toggle is clicked, run the function
toggles = document.querySelectorAll('[data-collapse]'); // Get all collapse toggles
forEach(toggles, function (toggle, index) {
eventListeners[index] = exports.FUNCTION.bind( null, VARIABLES );
toggle.addEventListener('click', eventListeners[index], false);
});
@cferdinandi
cferdinandi / jquery-boilerplate.js
Last active January 29, 2016 18:09
A simple jQuery boilerplate.
/*
* jQuery Boilerplate - v3.3.2
* A jump-start for jQuery plugins development.
* http://jqueryboilerplate.com
*
* Made by Zeno Rocha
* Under MIT License
*/
// the semi-colon before function invocation is a safety net against concatenated