Skip to content

Instantly share code, notes, and snippets.

View benbarnett's full-sized avatar

Ben Barnett benbarnett

View GitHub Profile
@benbarnett
benbarnett / raphael-svg-buildjson
Created June 3, 2010 12:59
loop through the 'paper' variable from Raphael JS and build up the JSON object describing all images and paths within it.
// loop through the 'paper' variable from Raphael JS and build up the JSON object describing all images and paths within it.
buildJSON = function(paper) {
var svgdata = [];
svgdata.push({
width: 390,
height: 400
});
$.each(paper,
We couldn’t find that file to show.
test
contents
<html><head></head></html>
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="2988.895px" height="1885.335px" viewBox="0 0 2988.895 1885.335" enable-background="new 0 0 2988.895 1885.335"
xml:space="preserve">
<text transform="matrix(1 0 0 1 117.5674 193.3823)" fill="#1C3F94" font-family="'ArialMT'" font-size="13.7317">Amersham</text>
<text transform="matrix(1 0 0 1 285.0654 207.4351)" fill="#1C3F94" font-family="'ArialMT'" font-size="13.7317">Chorleywood</text>
<text transform="matrix(1 0 0 1 1316.9741 261.0347)" fill="#1C3F94" font-family="'ArialMT'" font-size="13.7317">Mill Hill East</text>
<text transform="matrix(1 0 0 1 306.2056 236.7271)" fill="#1C3F94" font-family="'ArialMT'" font-size="13.7317">Rickmansworth</t
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@benbarnett
benbarnett / jquery-animate-enhanced-demo.js
Created November 8, 2010 12:16
demo code on jquery anim enhanced plugin home
$('button#start').click(function() {
var results = $('p#results').html("Animating..."),
button = $(this).attr('disabled', 'disabled');
// CSS3 Container
$('.target-css').animate({left: "+=200px", width:320 }, 1500, function() {
results.html('first callback() fired, reversing...');
$(this).animate({left: "-=200px", width:280 }, 1500, function() {
results.html("second callback() fired");
button.removeAttr('disabled');
@benbarnett
benbarnett / youtube-html5-switch.js
Created November 24, 2010 13:35
Detect Flash support and revert to standard YouTube embed code to enable HTML5 player
if (swfobject.hasFlashPlayerVersion("8.0.0")) {
// insert the chromeless player with custom controls and skinning
alert('you have flash, so getting the chromeless/skinned player');
// Lets Flash from another domain call JavaScript
var params = { allowScriptAccess: "always" };
// The element id of the Flash embed
var atts = { id: "ytPlayer" };
// All of the magic handled by SWFObject (http://code.google.com/p/swfobject/)
swfobject.embedSWF("http://www.youtube.com/apiplayer?" +
@benbarnett
benbarnett / jquery.fn.translation.js
Created December 22, 2010 11:55
Calculate translation from transform matrix
function translation(elem) {
var cssPrefixes = ["", "-webkit-", "-moz-", "-o-"],
cStyle = window.getComputedStyle(elem, null),
translation = {
x: 0,
y: 0
};
for (var i = cssPrefixes.length - 1; i >= 0; i--){
var transform = cStyle.getPropertyValue(cssPrefixes[i] + "transform");