Skip to content

Instantly share code, notes, and snippets.

View wholypantalones's full-sized avatar

Jason Dare wholypantalones

View GitHub Profile
@wholypantalones
wholypantalones / table_clone.js
Created July 25, 2012 18:15
clone table row, change values and append
i = 0;
$("#table tbody tr:first").each(function() {
// store the clone in a variable
var myclone = $(this).clone().attr('id', function(_, id) {return id + i++});
myclone.find("#cname").text(cname);
myclone.find("#cStart").text(cfrom);
myclone.find("#cEnd").text(cto);
// add the cloned table rows
myclone.prependTo("#table");
});
@wholypantalones
wholypantalones / hidden.js
Created September 19, 2012 19:55
Change hidden inputs to text
$("input:hidden").each(function() {
var theId = $(this).attr("id");
$(this).prop("type", "text").before(theId + " ");
});
@wholypantalones
wholypantalones / log.Wrapper.js
Created November 27, 2012 16:29 — forked from cointilt/log.Wrapper.js
Log Wrapper
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments) );
}
};
@wholypantalones
wholypantalones / gmt_offset.js
Created November 28, 2012 14:19
get user timezone offset
offset = new Date().getTimezoneOffset() / 60;
var lookup = [];
var i = 0;
for (var name in obj) {
if (obj.hasOwnProperty(name)) {
lookup[i] = obj[name];
i++;
}
}
@wholypantalones
wholypantalones / match.js
Created November 30, 2012 15:24
Exact match text :contains() workaround
$.expr[":"].econtains = function(obj, index, meta, stack){
return (obj.textContent || obj.innerText || $(obj).text() || "").toLowerCase() == meta[3].toLowerCase();
}
$("#select option:econtains(" + thisText + ")").prop("selected", true);
@wholypantalones
wholypantalones / gist:4233688
Created December 7, 2012 14:44
Google Maps V3 API Draggable Rectangle
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(43, -85),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
var geocoder = new google.maps.Geocoder();
$("#search_address").focus().autocomplete({
@wholypantalones
wholypantalones / formSerialize.js
Created January 18, 2013 20:44
jQuery post form data to json.
$("form").submit(function(event) {
event.preventDefault();
console.log(JSON.stringify($("form").serializeObject()));
});
});
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
var numLow = 1;
var numHigh = 9999;
var adjustedHigh = (parseFloat(numHigh) - parseFloat(numLow)) + 1;
var numRand = Math.floor(Math.random()*adjustedHigh) + parseFloat(numLow);
@wholypantalones
wholypantalones / gist:4741161
Created February 8, 2013 19:01
starts with
startsWithP = val.indexOf("P") !== -1