Skip to content

Instantly share code, notes, and snippets.

@sstephenson
sstephenson / gist:134653
Created June 23, 2009 16:26
preserving_scroll_position.js
Element.addMethods({
preservingScrollPosition: function(element, callback) {
element = $(element);
var offset = element.cumulativeOffset().top - document.viewport.getScrollOffsets().top;
callback();
window.scrollTo(0, element.cumulativeOffset().top - offset);
return element;
}
});
(function() {
var focusInHandler = function(e) { e.findElement().fire("focus:in") };
var focusOutHandler = function(e) { e.findElement().fire("focus:out") };
if (document.addEventListener) {
document.observe("focus", focusInHandler, true);
document.observe("blur", focusOutHandler, true);
} else {
document.observe("focusin", focusInHandler);
document.observe("focusout", focusOutHandler);
// In most browsers, a <label> tag around a form field, e.g.:
//
// <label>
// <input type="checkbox" id="private" name="private">
// This message is private
// </label>
//
// works just as if you'd specified a for= attribute on the label
// for the first visible field inside the label. In Safari 4, this
// seems not to be the case (i.e. the for= attribute is required).
[RAILS_ROOT]/app/models/projects/comment.rb:146:in `ping_commentable'
[RAILS_ROOT]/app/models/projects/history.rb:13:in `ignore'
[RAILS_ROOT]/app/models/projects/comment.rb:146:in `ping_commentable'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `send'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:178:in `evaluate_method'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:166:in `call'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:93:in `run'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `each'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `send'
[RAILS_ROOT]/vendor/rails/activesupport/lib/active_support/callbacks.rb:92:in `run'
(function() {
var queue = [];
function checkQueue() {
if (queue.any())
queue.pop().fire("dom:modified");
}
var notify;
function deferFire(element) {
if (!queue.include(element))
#!/usr/bin/env zsh
function resolve_symlink() {
local result=`readlink $1`
[ -z $result ] && echo $1 || $0 $result
}
function expand_path() {
cd -qP $1
pwd
# Using Sprockets in Rails 3
MyApp::Application.routes.draw do
match 'application.js', :to => Sprockets::Server.new(YAML.load_file(Rails.root.join("config/sprockets/application.yml")))
end
// Mobile Safari doesn't fire touchstart or touchend events for
// input[type=text], input[type=password], input[type=search],
// and textarea elements.
(function() {
if (!("createTouch" in document)) return;
var selector = "input[type=text], input[type=password], input[type=search], textarea";
function fire(element, type, identifier) {
var touch = document.createTouch(window, element, identifier, 0, 0, 0, 0);
#!/usr/bin/env ruby
# js1k packer
if ARGV[0] == "-n"
ARGV.shift
wrap = false
else
wrap = true
end
# A reference counter that invokes a callback when it reaches zero.
# Use it to implement after-finished callbacks in asynchronous code.
(exports ? this).Finalizer = class Finalizer
@from: (finalizerOrCallback) ->
if finalizerOrCallback instanceof Finalizer
finalizerOrCallback
else
new Finalizer(finalizerOrCallback ? ->)