Skip to content

Instantly share code, notes, and snippets.

View walterdavis's full-sized avatar

Walter Lee Davis walterdavis

View GitHub Profile
<%= form_for @foo do |f| %>
<%= f.text_field :name %>
<%= f.text_field :color %>
<%= f.submit 'Save' %>
<%= f.email_field :friend %>
<%= f.submit 'Semd to a friend', formaction: params.merge(action: 'send_to_friend') %>
<%- end -%>
<script type="text/javascript">
if(! ('formAction' in document.createElement('input') ){
document.addEventListener('click', function(evt){
Number.prototype.formatMoney = function(c, d, t){
var n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "," : d,
t = t == undefined ? "." : t,
s = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};
// get a reference to the color examples, and hide them all
var color_samples = $$('#color-sample img').invoke('hide');
// get a reference to all of the color radio group elements
var colors = $$('input[name="color"]');
// handler function to show only the selected color swatch
var choose_color = function(){
// re-hide all of the swatches
color_samples.invoke('hide');
// loop through the color buttons
colors.each(function(elm, idx){
@walterdavis
walterdavis / rails.js
Last active March 4, 2018 16:42
Slight change to the disable-with handling to allow for timing errors in Safari
(function($, undefined) {
/**
* Unobtrusive scripting adapter for jQuery
* https://github.com/rails/jquery-ujs
*
* Requires jQuery 1.8.0 or later.
*
* Released under the MIT license
*
@walterdavis
walterdavis / function.html
Last active August 29, 2015 14:26
Paste this into the head of a Freeway page to call out from that page to an iframe enclosing it, to adjust that iframe to fit the height of the current page.
<script type="text/javascript">
window.addEventListener('load', function(evt){
var box = document.getElementById('PageDiv'), h;
if (box.hasOwnProperty(outerHeight)){ // old IE
h = box.outerHeight;
}else{
var style = document.defaultView.getComputedStyle(box, '');
h = style.getPropertyValue("height");
}
if(top.resize_iframe) top.resize_iframe( parseInt(h, 10) );
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Inner 1</title>
<style type="text/css" media="screen">
body {
height: 100%;
margin: 0;
}
@walterdavis
walterdavis / inner.html
Last active August 29, 2015 14:26
Set an iframe to the height of its contents.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Inner (menu) page</title>
<script type="text/javascript">
window.addEventListener('load', function(evt){
var menu = document.getElementById('item1');
if (menu.hasOwnProperty(outerHeight)){ // old IE
top.resize_iframe( parseInt(menu.outerHeight, 10) );
@walterdavis
walterdavis / example.html
Last active August 29, 2015 14:23
Scroll to position after page load
<!-- add these lines to the HEAD of the page — before </head> -->
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.7/prototype.js" type="text/javascript" charset="utf-8"></script>
<script src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1.9/scriptaculous.js?load=effects" type="text/javascript"></script>
<!-- add these lines to the very end of the BODY of the page — before </body> -->
<script type="text/javascript">
if(window.location.search){
@walterdavis
walterdavis / index.html
Last active August 29, 2015 14:21
JSONP and Mustache
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Language" content="en">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" type="text/css" media="screen">
<title>API Test</title>
</head>
<body>
@walterdavis
walterdavis / application.rb
Created May 3, 2015 18:06
When you have an Asset model...
Rails.application.config.assets.prefix = '/the-other-assets'