Skip to content

Instantly share code, notes, and snippets.

@lakenen
lakenen / detectanimation.js
Created June 28, 2012 17:17
JavaScript animated GIF detection!
function isAnimatedGif(src, cb) {
var request = new XMLHttpRequest();
request.open('GET', src, true);
request.responseType = 'arraybuffer';
request.addEventListener('load', function () {
var arr = new Uint8Array(request.response),
i, len, length = arr.length, frames = 0;
// make sure it's a gif (GIF8)
if (arr[0] !== 0x47 || arr[1] !== 0x49 ||
@lakenen
lakenen / script.coffeescript
Created September 28, 2012 00:20
Pulls posts from http://reddit.com/r/nocontext and shows them nicely.
TEXT_DISPLAY_TIME = 10000
delay = (ms, fn) -> setTimeout fn, ms
class NoContexts
constructor: ->
@next()
refreshData: (cb) ->
@noContexts = []
@lakenen
lakenen / getTextBoundingRect.js
Created December 3, 2012 02:26
Get cursor or text position in pixels for input element
// @author Rob W http://stackoverflow.com/users/938089/rob-w
// @name getTextBoundingRect
// @param input Required HTMLElement with `value` attribute
// @param selectionStart Optional number: Start offset. Default 0
// @param selectionEnd Optional number: End offset. Default selectionStart
// @param debug Optional boolean. If true, the created test layer
// will not be removed.
function getTextBoundingRect(input, selectionStart, selectionEnd, debug) {
// Basic parameter validation
if(!input || !('value' in input)) return input;
@lakenen
lakenen / crocodoc-node test results
Created February 1, 2013 18:20
mocha test results showing 460 passing for crocodoc-node (https://github.com/NetDevLtd/crocodoc-node)
$ make test
NODE_PATH="`pwd`:" ./node_modules/.bin/mocha test/specs | tee test/results/tests.log
path.existsSync is now called `fs.existsSync`.
mocha example (using framework)
Array
#indexOf()
✓ should return -1 when the value is not present
@lakenen
lakenen / importNode.js
Created March 14, 2013 21:55
document.importNode shim for IE <= 9. Started with http://stackoverflow.com/questions/1811116/ie-support-for-dom-importnode/9883539#9883539, modified to fix issues (http://stackoverflow.com/questions/14593520/ie9-importing-inline-svg-image-elements-broken) with importing image nodes and other nodes with namespaced:attributes
function importNode(node, allChildren, doc) {
var a, i, il;
doc = doc || document;
try {
return doc.importNode(node, allChildren);
} catch (e) {
switch (node.nodeType) {
case document.ELEMENT_NODE:
var newNode = doc.createElementNS(node.namespaceURI, node.nodeName);
if (node.attributes && node.attributes.length > 0) {
@lakenen
lakenen / demo1.html
Last active December 15, 2015 11:19
Crocodoc 3D Demo #1
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="CSSMatrix.js"></script>
<style>
body {
background-color: #282828;
@lakenen
lakenen / page-transitions.css
Last active December 15, 2015 11:19
Crocodoc 3D Demo #2
/* ... */
.page-transitions .page-layer {
/* cheating a bit and adding a transition to "all" properties */
transition: all 0.3s;
}
.page-layer:first-child,
.page-exploded .page-layer {
background: rgba(255,255,255,0.03);
@lakenen
lakenen / page-affine.js
Created March 27, 2013 05:52
Crocodoc 3D Demo #3
function Page($el) {
// we need a new variable to determine if we should use
// 3d or 2d mode
var affine = !browserSupports3dTransforms();
/* ... */
// small changes to updateLayers and applyTransform
updateLayers = function () {
// detect if the page is flipped backwards
@lakenen
lakenen / jquery.xdr.js
Created March 27, 2013 06:08
jQuery XDR for IE
(function ($) {
"use strict";
if (window.XDomainRequest) {
$.ajaxTransport(function(s) {
if (s.crossDomain && s.async) {
if (s.timeout) {
s.xdrTimeout = s.timeout;
delete s.timeout;
}
var xdr;
@lakenen
lakenen / page-svg.css
Created March 27, 2013 06:22
Crocodoc 3D Demo #4
/* ... */
.crocodoc-page-svg {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}