angular-ui-scrollpoint
Advanced tools
Comparing version 1.1.0 to 1.2.0
/*! | ||
* angular-ui-scrollpoint | ||
* https://github.com/angular-ui/ui-scrollpoint | ||
* Version: 1.1.0 - 2015-10-27T02:34:48.484Z | ||
* Version: 1.2.0 - 2015-11-11T01:47:38.217Z | ||
* License: MIT | ||
@@ -16,3 +16,3 @@ */ | ||
*/ | ||
angular.module('ui.scrollpoint', []).directive('uiScrollpoint', ['$window', function($window) { | ||
angular.module('ui.scrollpoint', []).directive('uiScrollpoint', ['$window', function ($window) { | ||
@@ -29,27 +29,41 @@ function getWindowScrollTop() { | ||
require: '^?uiScrollpointTarget', | ||
link: function(scope, elm, attrs, uiScrollpointTarget) { | ||
scope: { | ||
uiScrollpoint: '@' | ||
}, | ||
link: function (scope, elm, attrs, uiScrollpointTarget) { | ||
var absolute = true, | ||
shift = 0, | ||
fixLimit, | ||
$target = uiScrollpointTarget && uiScrollpointTarget.$element || angular.element($window); | ||
if (!attrs.uiScrollpoint) { | ||
absolute = false; | ||
} else if (typeof (attrs.uiScrollpoint) === 'string') { | ||
// charAt is generally faster than indexOf: http://jsperf.com/indexof-vs-charat | ||
if (attrs.uiScrollpoint.charAt(0) === '-') { | ||
shift = 0, | ||
fixLimit, | ||
$target = uiScrollpointTarget && uiScrollpointTarget.$element || angular.element($window); | ||
function setup(scrollpoint) { | ||
if (!scrollpoint) { | ||
absolute = false; | ||
shift = -parseFloat(attrs.uiScrollpoint.substr(1)); | ||
} else if (attrs.uiScrollpoint.charAt(0) === '+') { | ||
absolute = false; | ||
shift = parseFloat(attrs.uiScrollpoint.substr(1)); | ||
} else if (typeof (scrollpoint) === 'string') { | ||
// charAt is generally faster than indexOf: http://jsperf.com/indexof-vs-charat | ||
if (scrollpoint.charAt(0) === '-') { | ||
absolute = false; | ||
shift = -parseFloat(scrollpoint.substr(1)); | ||
} else if (scrollpoint.charAt(0) === '+') { | ||
absolute = false; | ||
shift = parseFloat(scrollpoint.substr(1)); | ||
} else { | ||
var parsed = parseFloat(scrollpoint); | ||
if (!isNaN(parsed) && isFinite(parsed)) { | ||
absolute = true; | ||
shift = parsed; | ||
} | ||
} | ||
} else if (typeof (scrollpoint) === 'number') { | ||
setup(scrollpoint.toString()); | ||
return; | ||
} | ||
fixLimit = absolute ? scope.uiScrollpoint : elm[0].offsetTop + shift; | ||
} | ||
fixLimit = absolute ? attrs.uiScrollpoint : elm[0].offsetTop + shift; | ||
setup(scope.uiScrollpoint); | ||
function onScroll() { | ||
var limit = absolute ? attrs.uiScrollpoint : elm[0].offsetTop + shift; | ||
var limit = absolute ? scope.uiScrollpoint : elm[0].offsetTop + shift; | ||
// if pageYOffset is defined use it, otherwise use other crap for IE | ||
@@ -64,25 +78,30 @@ var offset = uiScrollpointTarget ? $target[0].scrollTop : getWindowScrollTop(); | ||
} | ||
function reset() { | ||
elm.removeClass('ui-scrollpoint'); | ||
fixLimit = absolute ? attrs.uiScrollpoint : elm[0].offsetTop + shift; | ||
fixLimit = absolute ? scope.uiScrollpoint : elm[0].offsetTop + shift; | ||
onScroll(); | ||
} | ||
scope.$on('scrollpointShouldReset', reset); | ||
$target.on('scroll', onScroll); | ||
onScroll(); // sets the initial state | ||
// Unbind scroll event handler when directive is removed | ||
scope.$on('$destroy', function() { | ||
scope.$on('$destroy', function () { | ||
$target.off('scroll', onScroll); | ||
}); | ||
scope.$watch('uiScrollpoint', function (newScrollpoint) { | ||
setup(newScrollpoint); | ||
onScroll(); | ||
}); | ||
} | ||
}; | ||
}]).directive('uiScrollpointTarget', [function() { | ||
}]).directive('uiScrollpointTarget', [function () { | ||
return { | ||
controller: ['$element', function($element) { | ||
this.$element = $element; | ||
}] | ||
controller: ['$element', function ($element) { | ||
this.$element = $element; | ||
}] | ||
}; | ||
@@ -89,0 +108,0 @@ }]); |
/*! | ||
* angular-ui-scrollpoint | ||
* https://github.com/angular-ui/ui-scrollpoint | ||
* Version: 1.1.0 - 2015-10-27T02:34:48.484Z | ||
* Version: 1.2.0 - 2015-11-11T01:47:38.217Z | ||
* License: MIT | ||
*/ | ||
!function(){"use strict";angular.module("ui.scrollpoint",[]).directive("uiScrollpoint",["$window",function(o){function t(){if(angular.isDefined(o.pageYOffset))return o.pageYOffset;var t=document.compatMode&&"BackCompat"!==document.compatMode?document.documentElement:document.body;return t.scrollTop}return{require:"^?uiScrollpointTarget",link:function(l,n,i,r){function e(){var o=s?i.uiScrollpoint:n[0].offsetTop+p,l=r?a[0].scrollTop:t();!n.hasClass("ui-scrollpoint")&&l>o?(n.addClass("ui-scrollpoint"),u=o):n.hasClass("ui-scrollpoint")&&u>l&&n.removeClass("ui-scrollpoint")}function c(){n.removeClass("ui-scrollpoint"),u=s?i.uiScrollpoint:n[0].offsetTop+p,e()}var u,s=!0,p=0,a=r&&r.$element||angular.element(o);i.uiScrollpoint?"string"==typeof i.uiScrollpoint&&("-"===i.uiScrollpoint.charAt(0)?(s=!1,p=-parseFloat(i.uiScrollpoint.substr(1))):"+"===i.uiScrollpoint.charAt(0)&&(s=!1,p=parseFloat(i.uiScrollpoint.substr(1)))):s=!1,u=s?i.uiScrollpoint:n[0].offsetTop+p,l.$on("scrollpointShouldReset",c),a.on("scroll",e),e(),l.$on("$destroy",function(){a.off("scroll",e)})}}}]).directive("uiScrollpointTarget",[function(){return{controller:["$element",function(o){this.$element=o}]}}])}(); | ||
!function(){"use strict";angular.module("ui.scrollpoint",[]).directive("uiScrollpoint",["$window",function(o){function t(){if(angular.isDefined(o.pageYOffset))return o.pageYOffset;var t=document.compatMode&&"BackCompat"!==document.compatMode?document.documentElement:document.body;return t.scrollTop}return{require:"^?uiScrollpointTarget",scope:{uiScrollpoint:"@"},link:function(e,n,i,l){function r(o){if(o){if("string"==typeof o)if("-"===o.charAt(0))a=!1,f=-parseFloat(o.substr(1));else if("+"===o.charAt(0))a=!1,f=parseFloat(o.substr(1));else{var t=parseFloat(o);!isNaN(t)&&isFinite(t)&&(a=!0,f=t)}else if("number"==typeof o)return void r(o.toString())}else a=!1;u=a?e.uiScrollpoint:n[0].offsetTop+f}function s(){var o=a?e.uiScrollpoint:n[0].offsetTop+f,i=l?p[0].scrollTop:t();!n.hasClass("ui-scrollpoint")&&i>o?(n.addClass("ui-scrollpoint"),u=o):n.hasClass("ui-scrollpoint")&&u>i&&n.removeClass("ui-scrollpoint")}function c(){n.removeClass("ui-scrollpoint"),u=a?e.uiScrollpoint:n[0].offsetTop+f,s()}var u,a=!0,f=0,p=l&&l.$element||angular.element(o);r(e.uiScrollpoint),e.$on("scrollpointShouldReset",c),p.on("scroll",s),s(),e.$on("$destroy",function(){p.off("scroll",s)}),e.$watch("uiScrollpoint",function(o){r(o),s()})}}}]).directive("uiScrollpointTarget",[function(){return{controller:["$element",function(o){this.$element=o}]}}])}(); |
{ | ||
"name": "angular-ui-scrollpoint", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"author": "https://github.com/angular-ui/ui-scrollpoint/graphs/contributors", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
angular.module('ui.scrollpoint', []).directive('uiScrollpoint', ['$window', function($window) { | ||
angular.module('ui.scrollpoint', []).directive('uiScrollpoint', ['$window', function ($window) { | ||
@@ -19,27 +19,41 @@ function getWindowScrollTop() { | ||
require: '^?uiScrollpointTarget', | ||
link: function(scope, elm, attrs, uiScrollpointTarget) { | ||
scope: { | ||
uiScrollpoint: '@' | ||
}, | ||
link: function (scope, elm, attrs, uiScrollpointTarget) { | ||
var absolute = true, | ||
shift = 0, | ||
fixLimit, | ||
$target = uiScrollpointTarget && uiScrollpointTarget.$element || angular.element($window); | ||
if (!attrs.uiScrollpoint) { | ||
absolute = false; | ||
} else if (typeof (attrs.uiScrollpoint) === 'string') { | ||
// charAt is generally faster than indexOf: http://jsperf.com/indexof-vs-charat | ||
if (attrs.uiScrollpoint.charAt(0) === '-') { | ||
shift = 0, | ||
fixLimit, | ||
$target = uiScrollpointTarget && uiScrollpointTarget.$element || angular.element($window); | ||
function setup(scrollpoint) { | ||
if (!scrollpoint) { | ||
absolute = false; | ||
shift = -parseFloat(attrs.uiScrollpoint.substr(1)); | ||
} else if (attrs.uiScrollpoint.charAt(0) === '+') { | ||
absolute = false; | ||
shift = parseFloat(attrs.uiScrollpoint.substr(1)); | ||
} else if (typeof (scrollpoint) === 'string') { | ||
// charAt is generally faster than indexOf: http://jsperf.com/indexof-vs-charat | ||
if (scrollpoint.charAt(0) === '-') { | ||
absolute = false; | ||
shift = -parseFloat(scrollpoint.substr(1)); | ||
} else if (scrollpoint.charAt(0) === '+') { | ||
absolute = false; | ||
shift = parseFloat(scrollpoint.substr(1)); | ||
} else { | ||
var parsed = parseFloat(scrollpoint); | ||
if (!isNaN(parsed) && isFinite(parsed)) { | ||
absolute = true; | ||
shift = parsed; | ||
} | ||
} | ||
} else if (typeof (scrollpoint) === 'number') { | ||
setup(scrollpoint.toString()); | ||
return; | ||
} | ||
fixLimit = absolute ? scope.uiScrollpoint : elm[0].offsetTop + shift; | ||
} | ||
fixLimit = absolute ? attrs.uiScrollpoint : elm[0].offsetTop + shift; | ||
setup(scope.uiScrollpoint); | ||
function onScroll() { | ||
var limit = absolute ? attrs.uiScrollpoint : elm[0].offsetTop + shift; | ||
var limit = absolute ? scope.uiScrollpoint : elm[0].offsetTop + shift; | ||
// if pageYOffset is defined use it, otherwise use other crap for IE | ||
@@ -54,26 +68,31 @@ var offset = uiScrollpointTarget ? $target[0].scrollTop : getWindowScrollTop(); | ||
} | ||
function reset() { | ||
elm.removeClass('ui-scrollpoint'); | ||
fixLimit = absolute ? attrs.uiScrollpoint : elm[0].offsetTop + shift; | ||
fixLimit = absolute ? scope.uiScrollpoint : elm[0].offsetTop + shift; | ||
onScroll(); | ||
} | ||
scope.$on('scrollpointShouldReset', reset); | ||
$target.on('scroll', onScroll); | ||
onScroll(); // sets the initial state | ||
// Unbind scroll event handler when directive is removed | ||
scope.$on('$destroy', function() { | ||
scope.$on('$destroy', function () { | ||
$target.off('scroll', onScroll); | ||
}); | ||
scope.$watch('uiScrollpoint', function (newScrollpoint) { | ||
setup(newScrollpoint); | ||
onScroll(); | ||
}); | ||
} | ||
}; | ||
}]).directive('uiScrollpointTarget', [function() { | ||
}]).directive('uiScrollpointTarget', [function () { | ||
return { | ||
controller: ['$element', function($element) { | ||
this.$element = $element; | ||
}] | ||
controller: ['$element', function ($element) { | ||
this.$element = $element; | ||
}] | ||
}; | ||
}]); |
@@ -1,2 +0,2 @@ | ||
/*global describe, beforeEach, module, inject, it, spyOn, expect, $ */ | ||
/*global describe, beforeEach, afterAll, module, inject, it, spyOn, expect, $, angular */ | ||
describe('uiScrollpoint', function () { | ||
@@ -73,2 +73,42 @@ 'use strict'; | ||
}); | ||
describe('using a scope variable', function() { | ||
var element; | ||
beforeEach(function() { | ||
element = $compile('<div ui-scrollpoint="{{ scrollpoint }}" class="ui-scrollpoint"></div>')(scope); | ||
}); | ||
afterAll(function() { | ||
scope.scrollpoint = undefined; | ||
}); | ||
it('should add/remove the ui-scrollpoint class depending on the value of the scrollpoint variable', function () { | ||
// number (absolute) | ||
scope.scrollpoint = 100; | ||
scope.$digest(); | ||
expect(element.hasClass('ui-scrollpoint')).toBe(false); | ||
expect(element.attr('ui-scrollpoint')).toBe('100'); | ||
// string (absolute) | ||
scope.scrollpoint = "100"; | ||
scope.$digest(); | ||
expect(element.hasClass('ui-scrollpoint')).toBe(false); | ||
expect(element.attr('ui-scrollpoint')).toBe('100'); | ||
// string (plus relative) | ||
scope.scrollpoint = "+100"; | ||
scope.$digest(); | ||
expect(element.hasClass('ui-scrollpoint')).toBe(false); | ||
expect(element.attr('ui-scrollpoint')).toBe('+100'); | ||
// number (minus relative) | ||
scope.scrollpoint = -100; | ||
scope.$digest(); | ||
expect(element.hasClass('ui-scrollpoint')).toBe(true); | ||
expect(element.attr('ui-scrollpoint')).toBe('-100'); | ||
// string (minus relative) | ||
scope.scrollpoint = "-100"; | ||
scope.$digest(); | ||
expect(element.hasClass('ui-scrollpoint')).toBe(true); | ||
expect(element.attr('ui-scrollpoint')).toBe('-100'); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33720
442