Skip to content

Commit

Permalink
Add new badass optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
zackbloom committed Dec 8, 2013
1 parent 0965132 commit 03a97f2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 10 deletions.
1 change: 1 addition & 0 deletions examples/facebook/facebook.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
}

.scroll-container {
position: relative;
overflow: auto;
background: #eee;
padding: 20px;
Expand Down
5 changes: 0 additions & 5 deletions examples/facebook/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,6 @@
openOn: 'click'
});
});
$(function(){
$(document).on('openDrop closeDrop', function(event) {
//log('event', 'type', event.type, 'drop', event.$drop[0]);
});
});
</script>
</body>
</html>
38 changes: 37 additions & 1 deletion tether.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,24 @@ class Tether
right: pageXOffset - left - width + innerWidth
}

$offsetParent = @$target.offsetParent()
offsetPosition = $offsetParent.offset()

offsetPosition.right = document.body.scrollWidth - offsetPosition.left - $offsetParent.width()
offsetPosition.bottom = document.body.scrollHeight - offsetPosition.top - $offsetParent.height()

if next.page.top >= offsetPosition.top and next.page.bottom >= offsetPosition.bottom
if next.page.left >= offsetPosition.left and next.page.right >= offsetPosition.right

scrollTop = $offsetParent.scrollTop()
scrollLeft = $offsetParent.scrollLeft()

next.offset =
top: next.page.top - offsetPosition.top + scrollTop
left: next.page.left - offsetPosition.left + scrollLeft
right: next.page.right - offsetPosition.right - scrollLeft
bottom: next.page.bottom - offsetPosition.bottom - scrollTop

@move next

@history.unshift next
Expand All @@ -255,7 +273,7 @@ class Tether
found = false

for point in @history
unless point[type][key] is position[type][key]
unless point[type]?[key] is position[type][key]
found = true
break

Expand All @@ -275,6 +293,7 @@ class Tether
else
css.right = "#{ pos.right }px"

moved = false
if (same.page.top or same.page.bottom) and (same.page.left or same.page.right)
css.position = 'absolute'
transcribe same.page, position.page
Expand All @@ -283,11 +302,28 @@ class Tether
css.position = 'fixed'
transcribe same.viewport, position.viewport

else if same.offset? and (same.offset.top or same.offset.bottom) and (same.offset.left or same.offset.right)
css.position = 'absolute'

$offsetParent = @$target.offsetParent()

if @$element.offsetParent()[0] isnt $offsetParent[0]
@$element.detach()
$offsetParent.append @$element

transcribe same.offset, position.offset

moved = true

else
css.position = 'absolute'
css.top = "#{ position.page.top }px"
css.left = "#{ position.page.left }px"

if not moved and not @$element.parent().is('body')
@$element.detach()
$(document.body).append @$element

write = false
for key, val of css
if @$element.css(key) isnt val
Expand Down
36 changes: 33 additions & 3 deletions tether.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tether.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 03a97f2

Please sign in to comment.