Skip to content

Instantly share code, notes, and snippets.

View jonathanstark's full-sized avatar

Jonathan Stark jonathanstark

View GitHub Profile
@jonathanstark
jonathanstark / gist:7557818
Last active December 28, 2015 20:29
TechCrunch blog post: carouselify
// Initialize any carousels
$('.carousel-horizontal').carouselify({
outerWrapperSelector: '.carousel-container',
innerWrapperSelector: '.carousel-list',
itemSelector: '.carousel-list > li',
previousSelector: '.carousel-prev',
nextSelector: '.carousel-next'
});
@jonathanstark
jonathanstark / gist:7557809
Last active December 28, 2015 20:29
TechCrunch blog post: collapsify
// Collapse any sub tab nav down to select menus
$('.tab-list, tabs-subnav').collapsify();
@jonathanstark
jonathanstark / gist:7557800
Last active December 28, 2015 20:29
TechCrunch blog post: A typical functional implementation
function toggleSpeakerBio(target) {
closeTransientElementsExcept('speaker');
if (target.hasClass('active')) {
target.removeClass('active');
} else {
$('.speaker-block').removeClass('active');
target.addClass('active');
}
}
@jonathanstark
jonathanstark / gist:7557716
Last active December 28, 2015 20:29
TechCrunch blog post: A typical event handler
$('body').on('click', '.speaker-block > a', function(e){
e.preventDefault();
e.stopPropagation();
toggleSpeakerBio($(this).closest('.speaker-block'));
});
(function (d, w, activeClass) {
if (('ontouchstart' in w) || w.DocumentTouch && d instanceof DocumentTouch) {
var activeElement = null,
clearActive = function() {
if (activeElement) {
activeElement.classList.remove(activeClass);
activeElement = false;
}
},
setActive = function(e) {
@jonathanstark
jonathanstark / adding-js-programmatically-redux.html
Last active December 13, 2015 23:48
Snippet of javascript code that will append external script files programmatically. Intended for responsive web sites where maximum progressive enhancement is desired. Don't want to make needless http requests or load external javascript on devices that can't (or shouldn't) execute javascript. NOT DEPENDENCY SAFE! Scripts will load asynchronousl…
<html>
<head></head>
<body>
<!-- All your kewl content goes here -->
<!-- Append javascript programatically so we don't make needless http requests -->
<script>
(function(){
var goodBrowser = function() {
@jonathanstark
jonathanstark / gzip.htaccess
Created September 26, 2015 18:03
GZIP stuff for Apache .htaccess file
####################
# GZIP COMPRESSION #
####################
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
@jonathanstark
jonathanstark / caching.htaccess
Created September 25, 2015 18:10
Caching stuff for Apache .htaccess file
##### CACHING STUFF #####
# 1 YEAR
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
/* I didn't write this snippet but I can't remeber where I found it. PLMK if you know who the original author is :) */
(function($) {
$.fn.uncomment = function(recurse) {
$(this).contents().each(function() {
if (this.hasChildNodes()) {
$(this).uncomment(recurse);
} else if (this.nodeType == 8) {
// Need to "evaluate" the HTML content,
// otherwise simple text won't replace