Skip to content

Instantly share code, notes, and snippets.

@brianjlandau
Created March 17, 2010 17:26
Show Gist options
  • Select an option

  • Save brianjlandau/335485 to your computer and use it in GitHub Desktop.

Select an option

Save brianjlandau/335485 to your computer and use it in GitHub Desktop.
(function($) {
$.fn.disable = function(){
return this.attr('disabled', 'disabled');
};
$.fn.enable = function(){
return this.removeAttr('disabled');
};
$.fn.findOrAppend = function(selector, html){
var results = this.find(selector);
if (results.length > 0){
return results;
} else {
html = $(html);
this.append(html);
return html;
}
};
$.fn.margin = function(side){
return this[0] && parseInt( jQuery.curCSS(this[0], ('margin'+side), true), 10 ) || 0;
};
$.overlap = function(e1, e2){
var el1 = $(e1), el2 = $(e2);
var e1x1 = (el1.position().left-el1.margin('Left')), e1x2 = (el1.position().left+el1.outerHeight()+el1.margin('Right')),
e1y1 = (el1.position().top-el1.margin('Top')), e1y2 = (el1.position().top+el1.outerHeight()+el1.margin('Bottom'));
var e2top = (el2.position().top-el2.margin('Top')), e2left = (el2.position().left-el2.margin('Left')),
e2width = el2.outerWidth(true), e2height = el2.outerHeight(true);
return ($.ui.isOver(e1y1, e1x1, e2top, e2left, e2height, e2width) ||
$.ui.isOver(e1y1, e1x2, e2top, e2left, e2height, e2width) ||
$.ui.isOver(e1y2, e1x1, e2top, e2left, e2height, e2width) ||
$.ui.isOver(e1y2, e1x2, e2top, e2left, e2height, e2width));
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment