Skip to content

Instantly share code, notes, and snippets.

@Foodguru
Foodguru / jquery.textchange.js
Created October 7, 2012 20:40 — forked from mkelly12/jquery.textchange.js
Javascript: Textchange with timeout
/*!
* jQuery TextChange Plugin
* http://www.zurb.com/playground/jquery-text-change-custom-event
*
* Copyright 2010, ZURB
* Released under the MIT License
*/
(function ($) {
$.event.special.textchange = {
@Foodguru
Foodguru / gist:3849577
Created October 7, 2012 21:00
JQuery: Select first form input
$('form :input:visible:enabled:not(.no-focus, elect, input[readonly=readonly],input[type=checkbox],input[type=radio],input[type=submit]):first').focus();
@Foodguru
Foodguru / edit.html.mustache
Created October 24, 2012 01:30 — forked from dbi/edit.html.mustache
Rails form helper for mustache spike/proof of concept
<!-- A scaffolded edit view converted to mustache -->
<h1>Editing post</h1>
{{#form}}
{{#errors?}}
<div id="error_explanation">
<h2>{{error_header}}</h2>
</div>
<ul>
@Foodguru
Foodguru / javascript:number_to_currency
Created October 31, 2012 22:50
javascript: number to currency. Rails like
function number_to_currency(number, options) {
try {
var options = options || {};
var precision = options["precision"] || 2;
var unit = options["unit"] || "$";
var separator = precision > 0 ? options["separator"] || "." : "";
var delimiter = options["delimiter"] || ",";
var parts = parseFloat(number).toFixed(precision).split('.');
return unit + number_with_delimiter(parts[0], delimiter) + separator + parts[1].toString();
@Foodguru
Foodguru / javascript: number_to_currency
Created October 31, 2012 22:51
rails like Number to currency implemented in javascript
function number_to_currency(number, options) {
try {
var options = options || {};
var precision = options["precision"] || 2;
var unit = options["unit"] || "$";
var separator = precision > 0 ? options["separator"] || "." : "";
var delimiter = options["delimiter"] || ",";
var parts = parseFloat(number).toFixed(precision).split('.');
return unit + number_with_delimiter(parts[0], delimiter) + separator + parts[1].toString();
@Foodguru
Foodguru / stringFormat.js
Created November 3, 2012 12:43 — forked from tonyto/stringFormat.js
javascript: String Format
String.prototype.format = function() {
var formatted = this;
for (var i = 0; i < arguments.length; i++) {
var regexp = new RegExp('\\{'+i+'\\}', 'gi');
formatted = formatted.replace(regexp, arguments[i]);
}
return formatted;
};