angular-bootstrap-affix
Advanced tools
Comparing version 0.2.2 to 0.2.3
'use strict'; | ||
angular.module('mgcrea.bootstrap.affix', ['mgcrea.jquery']).directive('bsAffix', [ | ||
angular.module('mgcrea.bootstrap.affix', []).directive('bsAffix', [ | ||
'$window', | ||
'dimensions', | ||
function ($window, dimensions) { | ||
function ($window) { | ||
var checkPosition = function (instance, el, options) { | ||
var scrollTop = window.pageYOffset; | ||
var scrollHeight = document.body.scrollHeight; | ||
var position = dimensions.offset.call(el[0]); | ||
var height = dimensions.height.call(el[0]); | ||
var position = getOffset(el[0]); | ||
var height = getHeight(el[0]); | ||
var offsetTop = options.offsetTop * 1; | ||
@@ -56,2 +55,22 @@ var offsetBottom = options.offsetBottom * 1; | ||
} | ||
]); | ||
]); | ||
function getOffset(el) { | ||
var box = el.getBoundingClientRect(); | ||
var docElem = el.ownerDocument.documentElement; | ||
return { | ||
top: box.top + window.pageYOffset - docElem.clientTop, | ||
left: box.left + window.pageXOffset - docElem.clientLeft | ||
}; | ||
} | ||
; | ||
function getHeight(el, outer) { | ||
var computedStyle = window.getComputedStyle(el); | ||
var value = el.offsetHeight; | ||
if (outer) { | ||
value += parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom); | ||
} else { | ||
value -= parseFloat(computedStyle.paddingTop) + parseFloat(computedStyle.paddingBottom) + parseFloat(computedStyle.borderTopWidth) + parseFloat(computedStyle.borderBottomWidth); | ||
} | ||
return value; | ||
} | ||
; |
/** | ||
* angular-bootstrap-affix | ||
* @version v0.2.1 - 2014-12-12 | ||
* @link https://github.com/mgcrea/bootstrap-affix | ||
* @author Olivier Louvignes <olivier@mg-crea.com> | ||
* @version v0.2.2 - 2016-01-12 | ||
* @link https://github.com/maxisam/angular-bootstrap-affix | ||
* @author Olivier Louvignes (original), maxisam <maxisam@gmail.com> | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
*/ | ||
"use strict";angular.module("mgcrea.bootstrap.affix",["mgcrea.jquery"]).directive("bsAffix",["$window","dimensions",function($window,dimensions){var checkPosition=function(a,b,c){var d,e=window.pageYOffset,f=document.body.scrollHeight,g=dimensions.offset.call(b[0]),h=dimensions.height.call(b[0]),i=1*c.offsetTop,j=1*c.offsetBottom,k="affix affix-top affix-bottom";d=null!==a.unpin&&e+a.unpin<=g.top?!1:j&&g.top+h>=f-j?"bottom":i&&i>=e?"top":!1,a.affixed!==d&&(a.affixed=d,a.unpin="bottom"===d?g.top-e:null,b.removeClass(k).addClass("affix"+(d?"-"+d:"")))},checkCallbacks=function(scope,instance,iElement,iAttrs){instance.affixed?iAttrs.onUnaffix&&eval("scope."+iAttrs.onUnaffix):iAttrs.onAffix&&eval("scope."+iAttrs.onAffix)};return{restrict:"EAC",link:function(a,b,c){var d={unpin:null};angular.element($window).bind("scroll",function(){checkPosition(d,b,c),checkCallbacks(a,d,b,c)}),angular.element($window).bind("click",function(){setTimeout(function(){checkPosition(d,b,c),checkCallbacks(a,d,b,c)},1)})}}}]); | ||
"use strict";function getOffset(a){var b=a.getBoundingClientRect(),c=a.ownerDocument.documentElement;return{top:b.top+window.pageYOffset-c.clientTop,left:b.left+window.pageXOffset-c.clientLeft}}function getHeight(a,b){var c=window.getComputedStyle(a),d=a.offsetHeight;return b?d+=parseFloat(c.marginTop)+parseFloat(c.marginBottom):d-=parseFloat(c.paddingTop)+parseFloat(c.paddingBottom)+parseFloat(c.borderTopWidth)+parseFloat(c.borderBottomWidth),d}angular.module("mgcrea.bootstrap.affix",[]).directive("bsAffix",["$window",function($window){var checkPosition=function(a,b,c){var d,e=window.pageYOffset,f=document.body.scrollHeight,g=getOffset(b[0]),h=getHeight(b[0]),i=1*c.offsetTop,j=1*c.offsetBottom,k="affix affix-top affix-bottom";d=null!==a.unpin&&e+a.unpin<=g.top?!1:j&&g.top+h>=f-j?"bottom":i&&i>=e?"top":!1,a.affixed!==d&&(a.affixed=d,a.unpin="bottom"===d?g.top-e:null,b.removeClass(k).addClass("affix"+(d?"-"+d:"")))},checkCallbacks=function(scope,instance,iElement,iAttrs){instance.affixed?iAttrs.onUnaffix&&eval("scope."+iAttrs.onUnaffix):iAttrs.onAffix&&eval("scope."+iAttrs.onAffix)};return{restrict:"EAC",link:function(a,b,c){var d={unpin:null};angular.element($window).bind("scroll",function(){checkPosition(d,b,c),checkCallbacks(a,d,b,c)}),angular.element($window).bind("click",function(){setTimeout(function(){checkPosition(d,b,c),checkCallbacks(a,d,b,c)},1)})}}}]); |
{ | ||
"name": "angular-bootstrap-affix", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "bootstrap-affix", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
'use strict'; | ||
angular.module('mgcrea.bootstrap.affix', ['mgcrea.jquery']) | ||
angular.module('mgcrea.bootstrap.affix', []) | ||
.directive('bsAffix', function($window, dimensions) { | ||
.directive('bsAffix', function($window) { | ||
@@ -11,4 +11,4 @@ var checkPosition = function(instance, el, options) { | ||
var scrollHeight = document.body.scrollHeight; | ||
var position = dimensions.offset.call(el[0]); | ||
var height = dimensions.height.call(el[0]); | ||
var position = getOffset(el[0]); | ||
var height = getHeight(el[0]); | ||
var offsetTop = options.offsetTop * 1; | ||
@@ -68,1 +68,21 @@ var offsetBottom = options.offsetBottom * 1; | ||
}); | ||
function getOffset(el) { | ||
var box = el.getBoundingClientRect(); | ||
var docElem = el.ownerDocument.documentElement; | ||
return { | ||
top: box.top + window.pageYOffset - docElem.clientTop, | ||
left: box.left + window.pageXOffset - docElem.clientLeft | ||
}; | ||
}; | ||
function getHeight(el, outer) { | ||
var computedStyle = window.getComputedStyle(el); | ||
var value = el.offsetHeight; | ||
if(outer) { | ||
value += parseFloat(computedStyle.marginTop) + parseFloat(computedStyle.marginBottom); | ||
} else { | ||
value -= parseFloat(computedStyle.paddingTop) + parseFloat(computedStyle.paddingBottom) + parseFloat(computedStyle.borderTopWidth) + parseFloat(computedStyle.borderBottomWidth); | ||
} | ||
return value; | ||
}; |
19751
434