Skip to content

Instantly share code, notes, and snippets.

View tjFogarty's full-sized avatar
🇮🇪

T.J. Fogarty tjFogarty

🇮🇪
View GitHub Profile
@tjFogarty
tjFogarty / ajax-partial.js
Created February 27, 2014 11:15
Load in sections of a site via AJAX - recommended on non-essential items like a megamenu that might not be used on mobile
/**
* Template
* This allows fetching of non-essential assets via AJAX
* e.g. megamenu
* @param object, configuration parameters
*/
function Template(config) {
this.fetchFile = config.fetchFile;
this.partialsDir = config.partialsDir || '/partials/';
this.fetchURL = this.partialsDir + this.fetchFile;
@tjFogarty
tjFogarty / Gruntfile.js
Last active June 18, 2020 15:35
Gruntfile that I use for projects
// http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically
module.exports = function(grunt) {
/**
* Saves having to declare each dependency
*/
require( "matchdep" ).filterDev( "grunt-*" ).forEach( grunt.loadNpmTasks );
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
@tjFogarty
tjFogarty / class.formhandler.php
Last active February 7, 2018 11:36
Targets form fields with prefixes to their name, e.g. <input type="text" name="prefix_name"> it will collect all data will "prefix_" in the name, or any prefix you specify in the example.
<?php
/**
* FormHandler takes care of automatically collecting form data and sending the data to a specified email address
*
* @example:
* $form = new FormHandler($from = 'guess@what.com', $to = 'what@isit.com', $subject = $_POST['form-name'], $post_data_prefix = 'obf_');
*/
class FormHandler {
public $mail;
@tjFogarty
tjFogarty / environment.php
Created October 6, 2013 12:45
Manage assets based on current environment
/**
* Environment
* Lets us manage assets based on current environment
*/
class Environment {
/**
* @param $localEnvironment (default value is 'localhost' if nothing is passed)
* @return boolean
*/
@tjFogarty
tjFogarty / js-enabled.js
Created August 26, 2013 11:31
Assuming the HTML element has a class of 'no-js', this will swap it for 'js'. Should be placed in the header.
var el = document.getElementsByTagName('html')[0];
el.className = el.className.replace('no-js', 'js');
@tjFogarty
tjFogarty / mobile-nav.js
Created July 9, 2013 15:57
Build mobile navigation from existing list of links
var MobileNav = {
navContainer: $( '.main-nav, .ancillary-nav' ),
navItems: null,
select: null,
navHTML: "<select class=mobile-nav></select>",
optionHTML: null,
init: function() {
// Build navigation then attach event handlers
MobileNav.buildNav();
@tjFogarty
tjFogarty / youtube-event-tracking.js
Created April 30, 2013 14:38
Tracking for any number of YouTube iframes. Uses a data-title attribute for grabbing a title.
// Any iframes with a class of .yt will be collected for event tracking
var Youtube = {
$players: $( '.yt' ),
playerArray: [],
numPlayers: $( '.yt' ).length - 1,
init: function() {
Youtube.assignID();
Youtube.bindEvents();
},
@tjFogarty
tjFogarty / config.php
Created March 19, 2013 15:38
Quick and simple database connection
<?php
include('db.class.php');
$database = new Database();
$database->dbUrl = 'localhost'; //URL of database
$database->dbUser = 'root'; // Username
$database->dbPass = ''; // Password
$database->dbName = 'test_db'; // Name of database you wish to connect to
@tjFogarty
tjFogarty / slider-demo.html
Last active December 14, 2015 18:19
A CodePen by T.J. Fogarty. Touch/keyboard content slider - I wanted to build a simple, reusable content slider just to understand how it works. There's definitely improvements to be made, but it works :) Supports keyboard navigation, and swiping on touch-based devices.
<div class="container">
<div id="slider-container">
<ul class="slider-images clearfix">
<li><img class="scale" src="http://dummyimage.com/500x200/000/fff.gif&text=Slide+1" alt=""></li>
<li><img class="scale" src="http://dummyimage.com/500x200/fff/000.gif&text=Slide+2" alt=""></li>
<li><img class="scale" src="http://dummyimage.com/500x200/000/fff.gif&text=Slide+3" alt=""></li>
<li><img class="scale" src="http://dummyimage.com/500x200/fff/000.gif&text=Slide+4" alt=""></li>
</ul>
</div>
@tjFogarty
tjFogarty / notifications-demo.html
Last active December 14, 2015 10:10
A CodePen by T.J. Fogarty. Notify - A simple little notification system that will let you define a success or an error, so you can hook in with CSS and style accordingly.
<a href="#" class='notify'>Success!</a>
<a href="#" class='notify error'>Error :(</a>