Skip to content

Instantly share code, notes, and snippets.

View patrickfox's full-sized avatar
🦊

Patrick Fox patrickfox

🦊
  • Razorfish
  • Austin, TX
View GitHub Profile
@patrickfox
patrickfox / $.access()
Last active August 29, 2015 14:02
Accessibility Tools: Focus on anything with access()
/*
$(selector).access(focus_only)
@param(bool): focus_only - true, false(default)
Problem:
Manually managing focus is cumbersome and pollutes the DOM with @tabindex.
Solution:
@patrickfox
patrickfox / Announce.js
Last active February 2, 2024 17:57
Accessibility Tools: Speak text using announce()
/*
$.announce(message, method)
@param(string): message - string of text to be spoken
@param(string): method - polite(default), assertive
Problem:
Using multiple @aria-live throughout your app adds complexity and makes it more difficult to control what is spoken when.
@patrickfox
patrickfox / object_create_polyfill.coffeescript
Last active August 29, 2015 14:05
Object.create() polyfill in CoffeeScript
if typeof Object.create isnt "function"
Object.create = (o, props) ->
F = ->
F:: = o
if typeof (props) is "object"
for prop of props
F[prop] = props[prop] if props.hasOwnProperty((prop))
new F()
@patrickfox
patrickfox / $.get_named_guid()
Created September 9, 2014 14:32
$.get_named_guid() generates a globally unique ID(GUID) based on a unique reference of handle. This GUID can then be called up at a later point by passing in the handle.
$.get_named_guid = function(handle, get_new) {
var _base,
_name = "_" + handle;
get_new = get_new || false;
$.guid = $.guid || 0;
$.named_guids = $.named_guids || [];
_base = $.named_guids["_" + handle];
if (_base[_name] === null) {
@patrickfox
patrickfox / $.get_guid()
Created September 9, 2014 14:35
$.get_guid() generates a globally unique ID(GUID). The get_new flag returns a new id if true, or, by default, returns the previous id.
$.get_guid = function(get_new) {
get_new = get_new || false;
if ($.guid === null) {
$.guid = 0;
}
if (get_new) {
$.guid++;
}
return $.guid;
};
@patrickfox
patrickfox / a7s.js
Created November 18, 2014 05:36
a7s.js - an analytics framework
(function () {
var init, onclick_tracked_item, selector, track_event, track_page, tracked_actions;
selector = '[data-a7s]';
init = function() {
return $(selector).on('click', onclick_tracked_item);
};
@patrickfox
patrickfox / pubshlub.litcoffee
Last active August 29, 2015 14:23
PubShlub - YAPS library

#PubShlub

do ($) ->
	a = {}
	$.publish = (d, c) ->
		a[d] and $.each(a[d], ->
			if @apply
				@apply $, c or []
			)
@patrickfox
patrickfox / throttlr.litcoffee
Last active August 29, 2015 14:23
Throttlr - Keep your resize and scroll events in check, yo

##Throttlr Throttle your window events

Throttlr =
	dom_event: null
	timeout: null
	pubsub_event: null
	publish_event: ->
		#specify your own publish method here, or use PubShlub - https://gist.github.com/patrickfox/c9d29ab6f319364dfe3f
		$.publish @pubsub_event
/*
# announce_view_loaded
Requirements:
- An element with `data-page-title` whose:
- text content is the page title: `<h2 data-page-title="">About Us</h2>` -> "About Us" will be used
- value is the page title: `<h3 data-page-title="Real page title">Displayed Heading</h3>` -> "Real page title" will be used
- An announcer element with an ID of `a11y_announcer` - this element needs to be in the DOM at page load and left alone (e.g. not destroyed or moved)
const site_title = '{Your site's name/title} - ';
import Ember from 'ember';
import {announce_view_loaded} from './../helpers/utils';
export default Ember.Route.extend({
renderTemplate(args) {
this._super(...args);
//this.render('about');
Ember.run.scheduleOnce('afterRender', this, function() {
console.log('afterRender');
announce_view_loaded();