Skip to content

Instantly share code, notes, and snippets.

View fermion's full-sized avatar
👋

Rob Sterner fermion

👋
View GitHub Profile
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';
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;
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());
}
});
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
// Example
document.observe("lol:konami", function() {
$(document.body).insert(new Element('h1').update("KONAMI!!!").setStyle({fontWeight: "bold", color: "red"}));
});
# Created by Eric Lindvall <eric@sevenscale.com>
#
# 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
//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){
# Newbie Programmer
def factorial(x)
if x == 0
return 1
else
return x * factorial(x - 1)
end
end
puts factorial(6)
puts factorial(0)
#####
## 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
<div id="manageable_id_102" class="ep_manageable">
<div class="ep_manageable_data">
<input type="checkbox" name="bulkaction_eprintids" value="102" id="select-102" class="ep_resource_manager_select_check">
<a href="http://resourcemanager.quango-vm.local/102/"><span class="ep_manageable_data_title">My New EdShare Resource</span></a>
<span class="ep_manageable_data_viewperms">Just me</span>
</div>
<div class="ep_manageable_controls">
<ul>
<li><a href="http://resourcemanager.quango-vm.local/102/">View</a></li>
<li><a href="http://resourcemanager.quango-vm.local/cgi/users/home?screen=EPrint::Edit&amp;eprintid=102">Edit</a></li>