Skip to content

Instantly share code, notes, and snippets.

@agaase
agaase / propSupprt
Created January 5, 2014 18:41
Tests for native support of a browser property in a specific context
function getPrefix(prop, context) {
var vendorPrefixes = ['moz', 'webkit', 'khtml', 'o', 'ms'],
upper = prop.charAt(0).toUpperCase() + prop.slice(1),
pref, len = vendorPrefixes.length,
q = null;
while (len--) {
q = vendorPrefixes[len];
if (context.toString().indexOf('style')) {
q = q.charAt(0).toUpperCase() + q.slice(1);
}
@agaase
agaase / isonscreen
Created December 8, 2013 09:32
isonscreen
$.fn.isonscreen = function(context){
debugger;
var
//Subtract the offset of the parent container.
//Will be 0 in case cont is undefined
tominus=0,
//Add the scrollTop position incase no cont is undefined.
toadd=0;
if(context){
//Find if the div is itself visible
@agaase
agaase / coverIframes
Last active September 18, 2019 18:57
This jquery extended function covers all the iframes inside an element with a transparent div and dispatches any "click"(only click) to the iframe. This is a workaround for the case when you dont want an iframe to swallow touch events on the page and is normally valid in the case of inline ads.
$.fn.coverIframes = function(){
$.each($("iframe",this),function(i,v){
var ifr = $(v);
var wr = $("<div id='wr"+new Date().getTime()+i+"' style='z-index: 999999; opacity: 0; position:absolute; width:100%;'></div>");
ifr.before(wr);
wr.height(ifr.height());
wr.click(function(event){
var iframe = ifr.get(0);
var iframeDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
// Find click position (coordinates)
@agaase
agaase / Tapper
Created October 12, 2013 11:56
The tap event on an element.
window.onload = function(){
var startPosX=0,startPosY=0;
var elements = $("tapHighlightJS");
for(var i=0;i<elements.length;i++){
var el = $(elements[i]);
el.bind('touchstart', function(ev){
var touchobj = ev.originalEvent.changedTouches[0];
startPosX = touchobj.pageX;
startPosY = touchobj.pageY;
}).bind('touchend', function(ev){
@agaase
agaase / Set fixed style attribute by setting important.
Last active December 24, 2015 05:49
Set fixed style attribute by setting important.
Usage is pretty simple.Just pass an object containing all the attributes you want to set as important.
e.g $("#i1").setFixedStyle({"width":"50px","height":""});
There are two additional options.
1.To just add important parameter to already present style attribute pass empty string.
2.To add important param for all attributes present dont pass anything. It will set all attributes as important.
@agaase
agaase / forcesIframeLinks
Created September 24, 2013 11:42
Forces the links in an iframe to open in new tab.

CSS Loader

@agaase
agaase / gist:6648737
Created September 21, 2013 08:57
isonscreen - A simple jquery function to check if the element is visible on screen.
$.fn.isOnScreen = function(){
var win = $(window);
var viewport = {
top : win.scrollTop(),
left : win.scrollLeft()
};
viewport.right = viewport.left + win.width();
viewport.bottom = viewport.top + win.height();
var bounds = this.offset();