This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getScrollbarWidth() { | |
if (this.scrollbarWidth) { | |
return this.scrollbarWidth; | |
} | |
var inner = document.createElement('p'); | |
inner.style.width = '100%'; | |
inner.style.height = '200px'; | |
var outer = document.createElement('div'); | |
outer.style.position = 'absolute'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Many times, when creating a site, I need hidden elements on a page that I must later make visible. Of course it would be great if one could simply hide them via CSS, and later [easily] show them via javascript. However this is not the case, javascript has some difficulties overriding styles set in a stylesheet. So, I've found the best way to accomplish this is to use a combo of CSS and javascript in a two-step process: | |
1. Hide the elements via CSS class – so they are hidden when the user first sees the page | |
2. Hide the elements via javascript and remove the corresponding CSS class, after the DOM has loaded. | |
The second step has the potential to be quite expensive on the DOM, but feel that it's an acceptable trade-off because they elements in question are already hidden. This way they are ready to be manipulated, one doesn't need to worry about fiddling with CSS classes or styles. | |
## Stylesheet | |
.hidden { | |
display: none; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.observeSelect = function(){ | |
$$('select.get').each(function(element){ | |
if(!element.observingChange){ | |
element.observe('change', function(event){ | |
var e = event.element(); | |
if(e.isActive()){ | |
e.indicate(); | |
document.ajaxRequest(e, e.readAttribute('src'), 'get', event, e.serialize()); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
task :pull do | |
run "cd #{current_release} && RAILS_ENV=#{rails_env} rake db:data:dump" | |
download "#{current_release}/db/data.yml", "db/data.yml" | |
`rake db:reset db:data:load` | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Element.addMethods({ | |
viewable: function(el) { | |
// INIT | |
el = $(el); | |
var scroll = document.viewport.getScrollOffsets(); | |
var viewport = document.viewport.getDimensions(); | |
var offsets = el.cumulativeOffset(); | |
var dimensions = el.getDimensions(); | |
// Sanity check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example | |
document.observe("lol:konami", function() { | |
$(document.body).insert(new Element('h1').update("KONAMI!!!").setStyle({fontWeight: "bold", color: "red"})); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Created by Eric Lindvall <[email protected]> | |
# | |
# WHAT: Provides a simple overview of memory allocation occuring during a | |
# require. | |
# | |
# For a longer explanation, see my post at: | |
# | |
# http://bitmonkey.net/post/308322913/tracking-initial-memory-usage-by-file-in-ruby | |
# | |
# NOTE: The numbers provided are of self + children, meaning the same will |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Newbie Programmer | |
def factorial(x) | |
if x == 0 | |
return 1 | |
else | |
return x * factorial(x - 1) | |
end | |
end | |
puts factorial(6) | |
puts factorial(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### | |
## INITIAL CONFIGURATION | |
##### | |
# Fork sstephenson/prototype on GitHub | |
# Go to this url and click the fork button. This will create a prototype | |
# repository under your GitHub account. | |
http://github.com/sstephenson/prototype |
OlderNewer