Permalink
Browse files

adding initial capabilities to bound to regions and other elements

  • Loading branch information...
1 parent 65d34c3 commit f57fda92f608522e9e902dec71a8ba7e075a7e30 @addyosmani committed Jul 30, 2011
Showing with 30 additions and 6 deletions.
  1. +1 −1 css/style.css
  2. +8 −1 index.html
  3. +20 −3 js/jquery-noverlap.js
  4. +1 −1 tests/spec/NoverlapSpecs.js
View
@@ -36,7 +36,7 @@ table { border-collapse: collapse; border-spacing: 0; }
hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0; }
input, select { vertical-align: middle; }
-body { font:13px/1.231 sans-serif; *font-size:small; }
+body { font:13px/1.231 sans-serif; *font-size:small; padding:0px;}
select, input, textarea, button { font:99% sans-serif; }
pre, code, kbd, samp { font-family: monospace, sans-serif; }
View
@@ -41,6 +41,12 @@
<a href="#" class="win">elem</a>
<a href="#" class="win">elem</a>
</div>
+
+ <div id="magic1" style="margin-left:200px;height:400px;width:400px;background:black">
+ </div>
+
+ <div id="magic2" style="margin:40px 40px 40px 40px;height:400px;width:400px;background:black">
+ </div>
<footer>
@@ -55,7 +61,8 @@
<script type="text/javascript" src="js/jquery-noverlap.js"></script>
<script type="text/javascript">
$(function(){
- $('.win').noverlap();
+ //$('.win').noverlap({'boundTo':'#magic'});
+ $('.win').noverlap({'boundTo':'#magic2'});
});
</script>
View
@@ -10,12 +10,29 @@
$.fn.noverlap.defaults = {
regionWidth: 600,
regionHeight: 390,
- speed: "slow"
+ regionLeft:0,
+ regionTop:0,
+ speed: "slow",
+ boundTo: null,
+ regionResize: 0.85
};
+
var o = $.extend({}, $.fn.noverlap.defaults, options),
coords = [],
ctx = null;
+
+
+ if(!(o.boundTo==null)){
+ //typeof check needed.
+ //support for all margin types?
+ var elem = $(o.boundTo);
+ o.regionWidth = parseInt(elem.css('width')) * o.regionResize;
+ o.regionHeight = parseInt(elem.css('height')) * o.regionResize;
+ o.regionLeft = parseInt(elem.css('left')) || parseInt(elem.css('margin-left'));
+ o.regionTop = parseInt(elem.css('top')) || parseInt(elem.css('margin-top'));
+ console.log(o);
+ }
return this.each(function() {
cxt = $(this),
@@ -25,8 +42,8 @@
},
complete = false;
while (!complete){
- d.left = parseInt(Math.random() * o.regionWidth);
- d.top = parseInt(Math.random() * o.regionHeight);
+ d.left = parseInt(Math.random() * o.regionWidth + o.regionLeft);
+ d.top = parseInt(Math.random() * o.regionHeight + o.regionTop);
complete = true;
$.each(coords, function(){
if (d.left < this.left + this.width && d.left + d.width > this.left &&
@@ -24,7 +24,7 @@ describe("NoverlapSpec", function(){
expect(isValid).toEqual(true);
});
- it("should pass the overlapping algorithm test", function(){
+ it("should ensure that all elements re-positioned using the plugin pass the overlap test", function(){
var c = null,
complete = false,

0 comments on commit f57fda9

Please sign in to comment.