Skip to content

Instantly share code, notes, and snippets.

@HasStacey
HasStacey / Get the Timezone
Created May 28, 2014 19:29
Get the current timezone
$(document).ready(function(){
function get_time_zone_offset() {
var current_date = new Date();
return -current_date.getTimezoneOffset() / 60;
}
$('body').append('The local time zone is: GMT ' + get_time_zone_offset());
});
@HasStacey
HasStacey / create-classname
Created June 30, 2014 23:52
Create a class name based upon the value passed to the function
// Create a class name based upon the value passed through the function
// For example: if $string = "Lorem Ipsum" this will output "lorem-ipsum" as the class name
function createClass($string) {
// 1. convert to lowercase
// 2. remove special characters
// 3. Strip out multiple spaces & dashes
// 4. Convert single spaces and underscores to dashes
$className = strtolower($string); // 1
$className = preg_replace("/[^a-z0-9_\s-]/", "", $className); // 2
@HasStacey
HasStacey / equal-card-tile-heights
Created July 7, 2014 23:40
Set the heights of all card tiles equal to the tallest
var tileTeamMemberHeight = 0;
$('.tile-teamMember').each(function(){
if($(this).height() > tileTeamMemberHeight ) {
tileTeamMemberHeight = $(this).height();
}
});
$('.tile-teamMember').height(tileTeamMemberHeight);
@HasStacey
HasStacey / JS Countdown timer with PHP variables
Last active August 16, 2020 08:30
Create a JS countdown timer driven by PHP variables
<?php
$year = 2014;
$month = 10;
$day = 21;
$hour = 14;
$min = 00;
$sec = 00;
$target = mktime($hour, $min, $sec, $month, $day, $year);
$current = time();
@HasStacey
HasStacey / SwapPageTitlesOnBlur.js
Last active September 29, 2015 18:40
Swap page titles on blur
// Swapping page titles on blur
var originalPageTitle = document.title;
window.addEventListener('blur', function(){
document.title = 'Don\'t forget to read this...';
});
window.addEventListener('focus', function(){
document.title = originalPageTitle;
});