Skip to content

Instantly share code, notes, and snippets.

View JoeSz's full-sized avatar

Joe JoeSz

View GitHub Profile
@JoeSz
JoeSz / responsive_page_like.html
Last active March 16, 2023 16:58
Responsive Facebook Page Like Box
<!DOCTYPE HTML>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div id="fb-container" style="width:100%;">
<div class="fb-page" data-href="https://www.facebook.com/facebook" data-height="160" data-small-header="true" data-adapt-container-width="true" data-hide-cover="false" data-show-facepile="true"></div>
</div>
<?php
function minify_css( $buffer ) {
if( trim( $buffer ) === "") return $buffer;
// Remove comments
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
// Remove whitespace
$buffer = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $buffer);
@JoeSz
JoeSz / debounce.js
Created September 24, 2016 11:36
JavaScript debounce function
/**
* @link https://davidwalsh.name/javascript-debounce-function
*
* Here's the basic JavaScript debounce function (as taken from Underscore.js):
*/
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
@JoeSz
JoeSz / debounce.min.js
Created September 24, 2016 11:37
JavaScript debounce function minfied and compressed version
function debounce(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}
@JoeSz
JoeSz / onElementHeightChange.js
Created September 24, 2016 14:29
Detect Element Height Change (eg. Window)
// Source: http://stackoverflow.com/questions/14866775/detect-document-height-change
var $j = jQuery.noConflict();
$j( document ).ready(function($) {
function onElementHeightChange(elm, callback){
var lastHeight = elm.clientHeight, newHeight;
(function run(){
newHeight = elm.clientHeight;
if( lastHeight != newHeight )
callback();
@JoeSz
JoeSz / change-url-while-scrolling.html
Created September 24, 2016 15:48
Detect element is in the viewport and then change browser url
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Scrolling URL Hash</title>
<meta name="description" content="Webpage for xxxx">
<style>
body {
height: 2000px;
}
@JoeSz
JoeSz / javascript.hooks-filters.js
Last active November 2, 2016 07:10
JavaScript Hooks and Filters
/*
* Source: http://stackoverflow.com/questions/20131168/jquery-javascript-hooks/20132960#20132960
* Gist: https://gist.github.com/JoeSz/6aa061ff48eaf1af658d3adf9d71ec37
*
* JavaScript Hooks
* Essentially it's a place in code that allows you to tap in to a module to either provide different
* behavior or to react when something happens.
* (http://stackoverflow.com/questions/467557/what-is-meant-by-the-term-hook-in-programming/467568#467568)
*
* or as Wikipedia says:
@JoeSz
JoeSz / throttle.js
Last active September 28, 2016 10:20
JavaScript Throttle
// Returns a function, that, when invoked, will only be triggered at most once
// during a given window of time.
// Source: https://gist.github.com/killersean/6742f98122d1207cf3bd
function throttle(callback, limit, callbackArgs) {
var wait = false;
return function() {
if (wait) {
return;
}
callback.call(callbackArgs);
@JoeSz
JoeSz / timedInterval.js
Last active October 7, 2016 14:43
Timed Interval
/**
* timedInterval
*
* The method calls a function or evaluates an expression at specified intervals (in milliseconds)
* until a specified number of milliseconds.
*
* @param {Function} callback
* @param {int} interval - run every [interval] ms
* @param {int} expiration - run until [expiration] in ms
* @param {mixed} callbackArgs - arguments for callback function
@JoeSz
JoeSz / ie.css
Created September 30, 2016 15:31
Apply style ONLY on IE
/* Source: http://stackoverflow.com/questions/11173106/apply-style-only-on-ie/36448860#36448860 */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
#myElement {
/* Enter your style code */
}
}