Skip to content

Instantly share code, notes, and snippets.

@jkappers
jkappers / src.js
Created October 15, 2012 15:06
Force line wrapping in SVG text tags
(function() {
var svgns = "http://www.w3.org/2000/svg";
function forceTextWrappingOn(node, width) {
console.log(node);
var chars = node.firstChild.nodeValue.split(' '),
x = parseInt(node.getAttribute('x'), 10),
y = parseInt(node.getAttribute('y'), 10),
index = 0,
tspan, tspanWidth, textNode
@jkappers
jkappers / src.js
Created August 30, 2012 18:44
Attach instances of javascript classes to DOM nodes
(function(exports){
// When the DOM is ready...
$(function(){
// ...Find any elements that have a data-view attribute
$('[data-view]').each(function(){
// Store a reference to the node and the data-view attribute value.
var $node = $(this), attr = $node.data('view');
// Create an instance of a class with a name that matches the value of attr,
// pass the node as a parameter to the constructor, and then store the instance
// in the node's data hash.
@jkappers
jkappers / src.js
Created August 30, 2012 16:13
Quick alpha sorting for content
$.fn.alphabetize = function(options){
var $list = this,
$item = this.children();
options = options || {};
$item.sort(function(a,b){
var x = (options.on && $(a).find(options.on) || $(a)).text(),
y = (options.on && $(b).find(options.on) || $(b)).text();
@jkappers
jkappers / css.css
Last active October 19, 2015 11:07
Micro Optimized CSS for Phark an Gilder/Levin Image Replacement
/* `Utilities
/******************************/
/* Gilder/Levin & Phark image replacement */
a.ir, a.phark { cursor:pointer; text-decoration:none }
a.ir:active, a.phark:active { outline:0 }
.ir, .phark { display:block; position:relative; overflow:hidden }
.ir span { display:block; height:100%; width:100%; position:absolute; top:0; left:0; background:no-repeat 0 0 }
.phark{text-indent:-999em}