Skip to content

Instantly share code, notes, and snippets.

var MyApp = {
addPlaceholders: function(props) {
// default configuration
var config = {
'class': 'placeholder' // apply CSS classes to an input displaying a placeholder
};
// if any properties were supplied, apply them to the config object
@johnkpaul
johnkpaul / gist:1044075
Created June 24, 2011 02:04
Add to JavaScript function prototype ability to find source in file
if(typeof _scriptsRecorded == "undefined"){
var scriptBodies = {}
var scripts = document.querySelectorAll("script");
for(var i = 0, len = scripts.length;i<len;i++){
var script = scripts[i];
(function(src){
$.get(src, function(data){
scriptBodies[src] = data;
})
})(script.src)
@johnkpaul
johnkpaul / gist:1087002
Created July 17, 2011 01:21
Implicit conversions in scala
class Mixin(value: Int){
def myCrazyNameOperator(f: Int => Int) : Int = f(value)
}
implicit def toWTF(value: Int) = new Mixin(value);
def double(int: Int) = {2 * int}
def triple(int:Int) = {3 * int}
@johnkpaul
johnkpaul / gist:1556717
Created January 3, 2012 20:19
log all jQuery event triggers to the console
var __temp_trigger = $.fn.trigger;
$.fn.trigger = function(){console.log(arguments, " triggered on element ", this); return __temp_trigger.apply(this,arguments);}
@johnkpaul
johnkpaul / gist:1589927
Created January 10, 2012 16:38
Add elements to bizodo select boxes programatically
var options_to_add = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,"20+"];
var event = document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
for(var i=0,len=options_to_add.length;i<len;i++){
$$(".option_add")[0].dispatchEvent(event)
var empty_element = $$(".option_editor_row").filter(function(el){return el.firstChild.value == ""})[0];
div{
background:url(http://img850.imageshack.us/img850/2400/rowofstars.gif) repeat;
}
.original-background{
background:url(http://img850.imageshack.us/img850/2400/rowofstars.gif) repeat;
}
.diagonal-background:before{
content:"";
background:url(http://img850.imageshack.us/img850/2400/rowofstars.gif) repeat;
width:200%;
height:200%;
position:absolute;
@johnkpaul
johnkpaul / getComputedStyleCssText.js
Created February 6, 2012 20:58
Approximate cssText on a CSSStyleDeclaration object in Firefox
function getComputedStyleCssText(element){
var cssObject = window.getComputedStyle(element),
prop,
cssText,
cssAccumulator = [];
if(cssObject.cssText != ""){
return cssObject.cssText;
}
@johnkpaul
johnkpaul / getComputedStylePropertyValue.js
Created February 10, 2012 16:42
Shim for getComputedStyle in old IEs
(function(window, undefined){
window.getComputedStylePropertyValue = function(el,cssProperty){
if(!window.getComputedStyle){
if(document.defaultView && document.defaultView.getComputedStyle){
return document.defaultView.getComputedStyle.getPropertyValue(cssProperty);
}
else{
var camelCasedCssProperty = getCamelCasedCssProperty(cssProperty);
if(el.currentStyle){
return el.currentStyle(camelCasedCssProperty);