Skip to content

Instantly share code, notes, and snippets.

@eikes
eikes / getElementsByClassName.polyfill.js
Created April 4, 2012 08:04
Polyfill for getElementsByClassName
// Add a getElementsByClassName function if the browser doesn't have one
// Limitation: only works with one class name
// Copyright: Eike Send http://eike.se/nd
// License: MIT License
if (!document.getElementsByClassName) {
document.getElementsByClassName = function(search) {
var d = document, elements, pattern, i, results = [];
if (d.querySelectorAll) { // IE8
return d.querySelectorAll("." + search);
@eikes
eikes / getElementWidth.js
Created April 23, 2012 13:29
Determine html element width without jquery
// Function to determine the width of any element in pixel:
getElementWidth = function (node) {
var ow = node.offsetWidth,
cs = node.currentStyle && node.currentStyle["width"]
|| getComputedStyle && getComputedStyle(node, null).getPropertyValue("width"),
result = parseFloat(ow || cs);
if (cs && cs.match(/%/))
return (parseFloat(cs) / 100) * getElementWidth(node.parentNode);
if (isNaN(result) || result == 0)
return getElementWidth(node.parentNode);
var sidebar = document.getElementById("sidebar");
var sidebarElements = document.getElementsByClassName("sidebarElements");
// here is the function call:
relocate(480, sidebarElements, sidebar);
minwidth(480, moveSomething, moveItBack);
function loadFacebook() {
$script("http//connect.facebook.net/en_US/all.js#xfbml=1");
}
minwidth(600, loadFacebook);
minwidth(480, null, enhanceMobile, true);
@eikes
eikes / imgpreload.js
Created October 20, 2012 23:23
JavaScript image preloader with callback
/*
* Copyright (C) 2012 Eike Send
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@eikes
eikes / settings.js
Created December 10, 2012 11:49
facetedsearch settings with state object
var settings = {
state : {
"orderBy" : "lastname",
"filters" : {
"category" : ["Bird"],
"continent" : ["Africa"]
}
},
items : example_items,
facets : {
{% block collection_widget %}
{% spaceless %}
<div class="collection">
{% if prototype is defined %}
{% set attr = attr|merge({'data-prototype': block('collection_item_widget') }) %}
{% endif %}
<div {{ block('widget_container_attributes') }}>
{{ form_errors(form) }}
<ul>
{% for prototype in form %}
@eikes
eikes / jquery.uncheckable_radio.js
Created March 11, 2014 11:42
jQuery plugin to allow unchecking radio buttons
(function ($) {
$.fn.uncheckableRadio = function () {
return this.each(function () {
var radio = this,
label = $('label[for="' + radio.id + '"]');
if (label.length === 0) {
label = $(radio).closest("label");
}
var label_radio = label.add(radio);
label_radio.mousedown(function () {