Skip to content

Instantly share code, notes, and snippets.

View jonathanstark's full-sized avatar

Jonathan Stark jonathanstark

View GitHub Profile
@jonathanstark
jonathanstark / adding-js-programmatically.html
Last active September 29, 2021 06:48
Snippet of javascript code that will append external script files programmatically, and in order. 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. Any questions/comments/suggestions gre…
<html>
<head></head>
<body>
<!-- All your kewl content goes here -->
<!-- Append javascript programatically so we don't make needless http requests -->
<script>
(function(doc){
var appendScripts = function(srcs) {
@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() {
(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 / 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'));
});
@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: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: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:7557823
Last active December 28, 2015 20:29
TechCrunchblog post: readmorify
// Initialize any "read more" elements
$('.press-release').readmorify({
buttons: {
more: '<p class="align-center text-btn read-more"><a href="#">Read more</a></p>',
less: '<p class="align-center text-btn read-less"><a href="#">Read less</a></p>'
},
threshold: 280,
duration: 1000 // milliseconds
});
@jonathanstark
jonathanstark / gist:7557837
Last active December 28, 2015 20:29
TechCrunch blog post: toasterize
// Initialize any toasters
$('.toaster').toasterize({
attractor: $('.article-entry p:last'),
minWindowWidth: 960,
viewportSpacing: 44
});
@jonathanstark
jonathanstark / gist:7557840
Last active December 28, 2015 20:29
TechCrunch blog post: lazy load images
// Lazy load "below the fold" images
$(window).on('load', function(){
$('img').each(function(){
if(this.src.match('1x1.png')) {
this.src = $(this).attr('data-src');
}
});
});