Skip to content

Instantly share code, notes, and snippets.

var scrollbarWidth;
function getScrollbarWidth() {
if (scrollbarWidth) {
return scrollbarWidth;
}
var inner = document.createElement('p');
inner.style.width = '100%';
inner.style.height = '200px';
var outer = document.createElement('div');
@tfluehr
tfluehr / blinky
Created September 18, 2009 18:28 — forked from fermion/blinky
Blinky Bookmarklet
javascript:(function(){function anc(e){var p='parentNode';e=$(e);var es=[];while(e=es[property])if(e.nodeType==1)es.push(e);return es;}function visible(el){el=$(el);if(!el){return false;}var a=anc(el);var c=a.length;var v=true;for(var i=0;i<c;i++){if(a[i].style.display=='none'||a[i].style.visibility=='hidden'){v=false;break;}}return v;}(function blinky(){var tmp=document.body.getElementsByTagName('*');tags=[];for(var j=0;j<tmp.length;j++)tags.push(tmp[j]);var fr=[];var ind=[];var l=tags.length;while(l--)var n=tags[l].tagName.toLowerCase();if(n=='iframe'||n=='script'||n=='link'){if(tags[l].tagName.toLowerCase()=='iframe')fr.push(tags[l]);tags[l]=null;ind.push(l);}while(ind.length)Array.splice.call(tags,ind.shift(),1);while(fr.length){try{tmp=fr.shift().contentWindow.document.body.getElementsByTagName('*');var tmp2=[];for(var j=0;j<tmp.length;j++)tmp2.push(tmp[j]);tags=Array.concat.apply(tags,tmp2);}catch(e){}}l=tags.length;if(typeof(lastTag)=='undefined')lastTag=null;if(lastTag)lastTag.style.visibility='';last
function getObject(parts)
{
if (typeof(parts) == 'string')
parts = parts.split('.');
var obj = window;
for (var i = 0, p; obj && (p = parts[i]); i++)
{
obj = (p in obj ? obj[p] : undefined);
}
return obj;
//ported to prototype from http://www.csskarma.com/lab/slidinglabels/
function formatSliderLabels(form)
{
form = $(form);
var labelColor = '#999';
var restingPosition = 5;
var topPosition = 6;
var duration = 0.2;
var labelAdjust = 10;
form.select('.slider label').each(function(el){
@tfluehr
tfluehr / parseInt.js
Created May 12, 2010 14:51
Prototype override of parseInt to default radix to 10
parseInt = parseInt.wrap(function(proceed, val, radix){
if (typeof(radix) == 'undefined'){
radix = 10;
}
return proceed(val, radix);
});
@tfluehr
tfluehr / Override Scripty function.js
Created December 16, 2010 14:08
Example of how to extend/overwrite Scriptaculous Autocompleter.Base
if (typeof(Autocompleter) != 'undefined') { // check if Autocompleter exists
Autocompleter.Base.addMethods({ // adds the listed functions to Autocompleter.Base
onKeyPress: Autocompleter.Base.prototype.onKeyPress.wrap(function(proceed, event){ // "wrap" the existing "onKeyPress" in this new function, exclude the "wrap" and just do onKeyPress: function(event) if you want to always overwrite the existing function
var args = $A(arguments);
args.shift(); // removes "proceed" from the arguments so only the original arguments will get passed to the original function
// place any code here you wish to execute before the original function
var returnVal = proceed.apply(this, args); // runs the original function
// place any code here you wish to execute after the original function
return returnVal;
})
Create an html page with a text area and a button.
The text area will accept a comma separated list of values.
When you click the button:
* Separate the values and add them to a styled list on the page and clear the text area.
+ Each element is displayed with alternating background color.
+ Clicking an item will remove it from the list.
@tfluehr
tfluehr / gist:905635
Created April 6, 2011 13:30
Array method for fast string addition.
Array.prototype.pushReplace = function(pattern){
var args = $A(arguments).slice(1);
this.push(pattern.replace(/\{(\d+)\}/g, function(pattern, index){
return args[index].toString();
}));
return this;
}
@tfluehr
tfluehr / gist:1626664
Created January 17, 2012 13:40
Prototype String Methods in jQuery
$.extend({
string: {
// public interface: $.tmpl
include: function(text, pattern){
return text.indexOf(pattern) > -1;
},
startsWith: function(text, pattern){
return text.lastIndexOf(pattern, 0) === 0;
},
endsWith: function(text, pattern){
@tfluehr
tfluehr / bumpme
Last active March 11, 2021 19:22
Thu Mar 11 19:22:51 UTC 2021