Skip to content

Instantly share code, notes, and snippets.

View jlittlejohn's full-sized avatar

Josh Littlejohn jlittlejohn

View GitHub Profile
@jlittlejohn
jlittlejohn / gist:c6cc8fee5b9afa072a33
Created June 17, 2014 18:53
RegEx: Find file where partial is rendered from
render.+['"].*partial-name
@jlittlejohn
jlittlejohn / gist:11483780
Created May 2, 2014 19:19
JS: Randomization Plugin
(function($){
$.fn.rand = function(){
return this.eq(Math.floor(Math.random()*this.length));
};
})(jQuery);
@jlittlejohn
jlittlejohn / gist:9981990
Last active May 1, 2019 16:02
HTACCESS: Force HTTPS using mod_rewrite
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
@jlittlejohn
jlittlejohn / gist:9770529
Created March 25, 2014 20:21
JS: Toggle Required Attribute based on Checkbox
// Toggle Required Attributed based on Checkbox
(function(){
var checkBox = $('input#acceptTextMessages');
var input = $('input#cellPhoneNumber');
function addRequired () {
$(input).attr({required: true}).after('<span class="required">*</span>');
}
function removeRequired () {
@jlittlejohn
jlittlejohn / gist:9769917
Created March 25, 2014 19:52
JS: Self Invoking Anonymous Function Wrapper
(function(){
// code
})();
@jlittlejohn
jlittlejohn / gist:9766232
Created March 25, 2014 16:53
JS: Add Asterisks to Required Form Elements
// Add Asterisks to Required form elements
$('form').find('input:required, select:required, textarea:required').after('<span class="required">*</span>');
@jlittlejohn
jlittlejohn / gist:9765051
Created March 25, 2014 16:04
JS: Toggle Buttons Utility Function
(function( $ ){
$.fn.toggleButtons = function() {
this.on('click', function(e) {
e.preventDefault();
var targetID = $(this).data('id');
if( $(targetID).hasClass('hide') ) {
$(targetID).toggleClass('hide');
} else {
$(targetID).toggle();
@jlittlejohn
jlittlejohn / gist:9764432
Created March 25, 2014 15:37
JS: Equalize Heights of an Array of Elements
/*
Loop over all items in a selection
Set tallest item to maxHeight variable
Set height of all elements to maxHeight variable
*/
(function( $ ){
$.fn.equalizeHeights = function() {
var maxHeight = 0;
var el = $(this);
@jlittlejohn
jlittlejohn / gist:9747755
Created March 24, 2014 19:55
JS: Scroll Effects
// Scroll Effects
$(window).scroll(function(){
var scrollVar = $(window).scrollTop();
var element = $('section#main');
$(homeContent).css({'bottom': scrollVar }); // scrolls element off page
$(homeContent).css({'opacity': (100 - scrollVar) / 100 }); // fades element out on scroll
});
@jlittlejohn
jlittlejohn / gist:9714595
Created March 22, 2014 21:24
JS: Animate ScrollTo Inpage Navigation
// Animate ScrollTo InPage Navigation
$(function(){
$("a.inpage").bind("click", function (event) {
event.preventDefault();
var target = $(this).attr("href");
var headerHeight = $('body > header').height();
$("html, body").stop().animate({
scrollTop: $(target).offset().top - headerHeight
}, 1200);
});