Skip to content

Instantly share code, notes, and snippets.

View avhm's full-sized avatar

Anthony Hiley-Mann avhm

View GitHub Profile
@avhm
avhm / jQuery onscreen or offscreen selector
Created November 17, 2010 10:42
jQuery onscreen / offscreen selector
$.expr[':'].onscreen = function(obj){
obj = jQuery(obj)
return obj.position().top < jQuery(window).height() && obj.position().top < jQuery(window).width();
};
$.expr[':'].offscreen = function(obj){
obj = jQuery(obj)
return obj.position().top > jQuery(window).height() && obj.position().top > jQuery(window).width();
};
@avhm
avhm / gist:703244
Created November 17, 2010 10:44
jquery onscreen / offscreen selector
$.expr[':'].onscreen = function(obj){
var $win = $(window), pos = $(obj).position();
return $.contains(document.documentElement, obj) && pos.top < $win.height() && pos.left < $win.width();
};
$.expr[':'].offscreen = function(obj){
return !$(obj).is(':onscreen');
};
@avhm
avhm / overrideScrollAnimation.js
Created March 17, 2011 14:49
Override scroll action
var mouseWheelHandler = function(e){
// Prevent your scroll action here e.g:
$(window).stop(true)
}
/** for Mozilla. */
if (window.addEventListener) window.addEventListener('DOMMouseScroll', mouseWheelHandler, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = mouseWheelHandler;
@avhm
avhm / iosPreventScroll.js
Created March 24, 2011 12:10
Prevent iPhone scrolling on demand
iOsScrollingToggle : function(enabled){
function preventScroll(e){
e.preventDefault();
e.stopPropagation();
}
// This should prevent people from scrolling away from the modal window without closing it
if(enabled){
document.body.removeEventListener('touchmove',preventScroll,false);
} else {
document.body.addEventListener('touchmove',preventScroll,false);
@avhm
avhm / jsImagePreload.js
Created March 25, 2011 11:29
A javascript image preloader
preloader: {
// The element to update on loading progress
$progressBar: $('#loadingbar').find('span'),
// The wrapper for the loading overlay
$loadingBlock: $('#loading'),
init: function(){
this.load();
this.checkForLoad();
},
@avhm
avhm / anim.js
Created July 14, 2011 09:40
Request Animation Frame Fallback
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000 / 60);
};
})();
@avhm
avhm / gist:1232502
Created September 21, 2011 16:14
Simulate Mouse Click
function simulateMouseClick(selector) {
var targets = document.querySelectorAll(selector),
evt = document.createEvent('MouseEvents'),
i, len;
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
for ( i = 0, len = targets.length; i < len; ++i ) {
targets[i].dispatchEvent(evt);
}
}
@avhm
avhm / gist:1255447
Created October 1, 2011 00:57
Proxy setup
# Edit proxy setup
alias proxyConf='mate ~/Git/hoxy/rules/rules.txt'
#Enable redirecting traffic through a local proxy
function proxyEnable() {
# Using configuring system preferences
echo "Enabling proxy...";
networksetup -setwebproxy Ethernet 127.0.0.1 8080;
networksetup -setwebproxy Wi-Fi 127.0.0.1 8080;
@avhm
avhm / gist:1368722
Created November 15, 2011 23:23
Simple textmate 'open preview' code
# Place the below code into a command within a new bundle, and set the output to 'Show as HTML'
#!/bin/bash
echo "<script>window.resizeTo(800,1000); window.location = '$TM_FILEPATH';</script>"
@avhm
avhm / gist:1384216
Created November 21, 2011 22:41
Simulate Mouse Events
jasmineHelpers.simulateMouseEvent = function(selector, events) {
var targets = document.querySelectorAll(selector),
dispatch = [];
// Create our mouse events and push them onto our event array
for (var z in events){
if(events.hasOwnProperty(z)){
var evt = document.createEvent('MouseEvents');
// Init event with sensible defaults
evt.initMouseEvent(events[z], true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);