Skip to content

Instantly share code, notes, and snippets.

View foleyatwork's full-sized avatar

Kevin Foley foleyatwork

View GitHub Profile
@foleyatwork
foleyatwork / featured.block
Last active December 12, 2015 06:49
The featured posts block dynamically pulls in featured posts from any collection with any category filter or tag filter.
YUI().use('node', 'anim', function (Y) {
Y.on('domready', function () {
(function () {
Y.one('body').delegate('click', function (e) {
e.preventDefault();
var anchor = e.currentTarget.getAttribute('href');
var scrollAnim = new Y.Anim({
node: Y.one(Y.UA.gecko || Y.UA.ie || !!navigator.userAgent.match(/Trident.*rv.11\./) ? 'html' : 'body'),
to: {
scrollTop : Y.one(anchor).getY()
@foleyatwork
foleyatwork / gist:8969411
Last active August 29, 2015 13:56
Disables all pointer events on scroll for 60fps scrolling. Thanks to Paul Irish (source: http://www.thecssninja.com/javascript/pointer-events-60fps).
(function () {
var css = '.disable-hover, .disable-hover * { pointer-events: none !important; }',
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style'),
body = document.body,
timer;
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = css;
@foleyatwork
foleyatwork / ImageLoader-examples.js
Last active August 3, 2022 14:37
How to run Squarespace's ImageLoader manually.
// For all images.
var allImages = document.querySelectorAll('img[data-src]');
for (var i = 0; i < allImages.length; i++) {
ImageLoader.load(allImages[i]);
}
// For a single image.
/**
* Creates a grid with static gutters.
*
* @mixin grid--static-gutter
* @param {Number} columns The number of columns in your grid.
* @param {Number} gutter Gutters, set in pixels regardless of any unit passed.
*/
.grid--static-gutter(@columns: 2, @gutter) {
@width: 100 / @columns;
@marginRight: @gutter * (@columns - 1) / @columns;
@foleyatwork
foleyatwork / SiteWithController.js
Last active September 8, 2015 16:56
An example of a site.js file that works well with sqs-controller.
/**
* This variable gets added to "window" and becomes
* the global namespace for your site.
*
* @namespace Site
* @global
*/
var Site = {};
@foleyatwork
foleyatwork / RefreshImagesOnResize.js
Last active September 8, 2015 17:09
An example of a controller.
/**
* This controller pattern relies on a createController method that
* I typically create in my site.js. To see a boilerplate site.js file
* that works with this style, see the link below.
*
* @see https://gist.github.com/foleyatwork/f2a67d4a28f43a55d1cd
*/
Site.createController('RefreshImagesOnResize', function() {
// When using jQuery inside of a controller, just assume the
@foleyatwork
foleyatwork / ControllersTheOldWay.js
Created September 8, 2015 16:22
An example of the old way of creating controllers.
/*
* This way of creating a controller has a few issue:
* 1. It buries the namespace declaration at the bottom of the document.
* 2. It creates an unnecessary abstraction of the namespace that may not be obvious to developers.
* 3. It requires retyping the namespace in every single file.
*/
(function(exports) {
var HelloWorld = function() {
console.log('Hello, World!');
}
// YUI
if (Y.one('.some-el')) {
// returns undefined if .some-el is not on the page.
}
// jQuery (incorrect)
if ($('.some-el')) {
// returns an array if .some-el is not on the page.
}
/* globals Ok, _, ReactDOM, ENV, Mousetrap */
const OkModalManager = require("~/okmodal/util/OkModalManager");
const App = require("~/okmodal/components/App");
const C = require("~/okmodal/util/Constants");
/**
* Log an error string to the console with a styling OkModal prefix.
* @method logSimpleError
* @param {String} message