Skip to content

Instantly share code, notes, and snippets.

View yellowberri-snippets's full-sized avatar

Dalton Yellowberri yellowberri-snippets

View GitHub Profile
@yellowberri-snippets
yellowberri-snippets / JS: Resize Polling Function
Created October 28, 2013 21:42
JS: Resize Polling Function
var poll = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
$(window).resize(function(){
// Poll the window.resize event every 25ms for changes and fire specific code.
@yellowberri-snippets
yellowberri-snippets / JS: Poll If Element is On Screen
Created October 29, 2013 15:54
JS: Poll If Element is On Screen
// Poll element's distance from bottom of browser window. When element is visible, perform action.
// I couldn't think of a better name, and YouBet rhymes with offset. Find + Replace if it bugs you.
var poll = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
@yellowberri-snippets
yellowberri-snippets / JS: Mobile UA Check
Created October 31, 2013 16:20
JS: Mobile UA Check
function isMobile() {
return (/Android|iPhone|iPad|iPod|BlackBerry|Windows Phone/i).test(navigator.userAgent || navigator.vendor || window.opera);
}
@yellowberri-snippets
yellowberri-snippets / JS: JQUERY: skrollr Breakpoint Workaround
Last active December 27, 2015 04:59
JS: JQUERY: skrollr Breakpoint Workaround
function skrollrInit() {
if ( $(window).width() < 528 ) {
footer.attr('data-end', 'height:750px;');
}
else {
footer.attr('data-end', 'height:560px;');
}
$('html').removeClass('no-skrollr');
skrollr.init();
@yellowberri-snippets
yellowberri-snippets / JS: JQUERY: Get Distance to Bottom of Browser
Last active December 27, 2015 04:59
JS: JQUERY: Get Distance to Bottom of Browser
function distanceToBottom() {
var distanceToTop = $(window).scrollTop();
var windowHeight = $(window).height();
var documentHeight = $('html').height();
var distanceFromEnd = (documentHeight - (distanceToTop + windowHeight));
return distanceFromEnd;
}
@yellowberri-snippets
yellowberri-snippets / PHP: Youtube ID from URL
Created November 5, 2013 22:23
PHP: Youtube ID from URL
function youtubeGetID($url) {
$url = explode('?v=', $url);
return $url[1];
}
@yellowberri-snippets
yellowberri-snippets / JS: Quirks or Standards Mode Debug Alert
Created November 7, 2013 21:04
JS: Quirks or Standards Mode Debug Alert
javascript:window.alert('You are in ' + (document.compatMode==='CSS1Compat'?'Standards':'Quirks') + ' mode.')
function vimeoEmbed($url) {
$url = explode('vimeo.com/', $url);
$firstPart = '//player.vimeo.com/video/';
$secondPart = '?title=1&amp;byline=0&amp;portrait=0&amp;color=ebbe1e';
return $firstPart . $url[1] . $secondPart;
}
function youtubeGetID($url) {
$url = explode('?v=', $url);
$embedURL = '//www.youtube.com/embed/' . $url[1];
return $embedURL;
}
@yellowberri-snippets
yellowberri-snippets / JS: Youtube iFrame Embed API
Created November 20, 2013 16:51
JS: Youtube iFrame Embed API
// More information at:
// http://stackoverflow.com/questions/7988476/listening-for-youtube-event-in-javascript-or-jquery/7988536#7988536
function getFrameID(id){
var elem = document.getElementById(id);
if (elem) {
if(/^iframe$/i.test(elem.tagName)) return id; //Frame, OK
// else: Look for frame
var elems = elem.getElementsByTagName("iframe");
if (!elems.length) return null; //No iframe found, FAILURE