-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjquery.overlap.min.js
11 lines (11 loc) · 1.21 KB
/
jquery.overlap.min.js
1
2
3
4
5
6
7
8
9
10
11
/*
* jQuery Overlap Plugin 0.2
* https://github.com/leandrobrunner/jQuery-Overlap
*
* Copyright (c), Leandro Brunner
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
(function($){$.fn.overlap=function(c){c=$.extend({rect:{x:0,y:0,w:0,h:0},element:false,mark:false,unmark:true,filterMark:function(a){return true},filterUnmark:function(a){return true},callback:function(a){},w:function(a){return a.outerWidth(true)},h:function(a){return a.outerHeight(true)},position:function(a){return a.position()},bring:true},c);Object.prototype.overlap=function(a){return((a.x<=this.x+this.w&&a.x+a.w>=this.x)&&(a.y<=this.y+this.h&&a.y+a.h>=this.y))};if(c.element!=false){if(typeof(c.element)=="string"){c.element=$(c.element)}c.element=c.element.first();var d=c.position(c.element);c.rect={x:d.left,y:d.top,w:c.w(c.element),h:c.h(c.element)}}var e=this.filter(function(a){var b=c.position($(this));if(c.rect.overlap({x:b.left,y:b.top,w:c.w($(this)),h:c.h($(this))})){return true}});if(typeof(c.mark)=="string"){if(c.unmark){this.filter(c.filterUnmark).removeClass(c.mark)}e.filter(c.filterMark).addClass(c.mark);c.callback(e)}if(c.bring){return(e)}else{return(this)}}}(jQuery));