Skip to content

Instantly share code, notes, and snippets.

View jorgepedret's full-sized avatar
😀
Turned on by Open Source

Jorge Pedret jorgepedret

😀
Turned on by Open Source
View GitHub Profile
@jorgepedret
jorgepedret / thug-partial.js
Created September 23, 2012 00:17
Thug global variable bug fix
/* BEFORE */
// locals
for(var local in config.locals)(function(local){
this[local] = config.locals[local]
})(local)
var Int = function(local){
this.local = local
}
@jorgepedret
jorgepedret / install-instructions.html
Created August 2, 2012 17:58
jQuery Textarea Auto-Resize Plugin Installation
<script src="jquery.js"></script>
<script src="autoresize.jquery.js"></script>
<script>
$(function () {
// Apply the autoresize plugin to your textarea
$("textarea").autoresize();
// Pass the debug parameter to see the mirrored element
$("#my-textarea").autoresize({debug:true});
});
@jorgepedret
jorgepedret / File structure
Created July 9, 2012 16:52
Dynamic script paths in Require.js
/*
---------- Development --------------
/assets/
js/
libs/
jquery.bxSlider.js
mustache.js
modules/
utilities.js
partials/
bind_searchbar: function() {
var cooq = this,
input = $("#search"),
results = [],
results_element = '.live-search-results',
current_element = null,
show_search_help = null,
hide_search_help = null;
@jorgepedret
jorgepedret / gist:2583581
Created May 3, 2012 05:45
Modernizr touch detection
Modernizr.load({
test: ('ontouchstart' in window),
yep: 'script/path.js',
complete: function(){
alert('yay, the library is loaded');
}
});
@jorgepedret
jorgepedret / gmaps_load.js
Created April 20, 2012 23:01
Loading Google Maps API on demand
// main.js
function loadGoogleMapsApi(){
if(typeof google === "undefined"){
var script = document.createElement("script");
script.src = "https://maps.google.com/maps/api/js?sensor=false&callback=loadGoogleMapsApiReady";
document.getElementsByTagName("head")[0].appendChild(script);
} else {
loadGoogleMapsApiReady();
}
}
@jorgepedret
jorgepedret / require.packages.js
Created April 20, 2012 22:51
Require.js including multiple files and managing packages
// Sample form package
require_form = function (callback) {
require([
"form",
"validate",
"multiselect",
"form_extend"
], function(){
require(["my_validate"], callback);
}
@jorgepedret
jorgepedret / gist:2365512
Created April 12, 2012 07:55
Expand background image vertically and horizontally to take full screen
(function($){
$(function() {
var bg = $("#site-background").find("img"),
bgh = bg.height(),
bgw = bg.width(),
img_prop = bgw/bgh,
w = $(window),
wh = w.height(),
ww = w.width(),
w_prop = ww/wh;
@jorgepedret
jorgepedret / object.js
Created March 26, 2012 16:23
JavaScript object copy
function object(o){
function F() {};
F.prototype = o;
return new F();
}
@jorgepedret
jorgepedret / iframe.js
Created March 5, 2012 23:44
Dynamic resizing of iframe in a different domain
$(function(){
var parent_url;
// Create the hidden input field that will hold the parent_url variable.
$("form").append('<input name="parent_url" id="parent_url" />');
// We check to see if location hash is empty. It should only go in here if you're using IE and after the form as been submitted.
if(document.location.hash == ""){
var search = document.location.search,
id = "parent_url=",