Skip to content

Commit

Permalink
Released 0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
oblador committed Jul 16, 2014
1 parent f08ecb1 commit 861796c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
angular-scroll
==============

Only dependent on AngularJS (no jQuery). 6K minified or 1.1K gzipped.
Only dependent on AngularJS (no jQuery). 8K minified or 2K gzipped.

Example
-------
Expand Down
47 changes: 38 additions & 9 deletions angular-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@
* x is a value between 0 and 1, indicating where in the animation you are.
*/
var duScrollDefaultEasing = function (x) {
'use strict';
if (x < 0.5) {
return Math.pow(x * 2, 2) / 2;
}
return 1 - Math.pow((1 - x) * 2, 2) / 2;
};
angular.module('duScroll', [
'duScroll.scrollspy',
'duScroll.requestAnimation',
'duScroll.smoothScroll',
'duScroll.scrollContainer',
'duScroll.spyContext',
'duScroll.scrollHelpers'
]).value('duScrollDuration', 350).value('duScrollGreedy', false).value('duScrollEasing', duScrollDefaultEasing);
angular.module('duScroll.scrollHelpers', []).run([
]).value('duScrollDuration', 350).value('duScrollSpyWait', 100).value('duScrollGreedy', false).value('duScrollEasing', duScrollDefaultEasing);
angular.module('duScroll.scrollHelpers', ['duScroll.requestAnimation']).run([
'$window',
'$q',
'cancelAnimation',
'requestAnimation',
'duScrollEasing',
function ($window, $q, cancelAnimation, requestAnimation, duScrollEasing) {
'use strict';
var proto = angular.element.prototype;
this.$get = function () {
return proto;
};
var isDocument = function (el) {
return typeof HTMLDocument !== 'undefined' && el instanceof HTMLDocument || el.nodeType && el.nodeType === el.DOCUMENT_NODE;
};
Expand Down Expand Up @@ -99,7 +98,7 @@ angular.module('duScroll.scrollHelpers', []).run([
};
proto.scrollToElement = function (target, offset, duration, easing) {
var el = unwrap(this);
var top = this.scrollTop() + unwrap(target).getBoundingClientRect().top - offset;
var top = this.scrollTop() + unwrap(target).getBoundingClientRect().top - (offset || 0);
if (isElement(el)) {
top -= el.getBoundingClientRect().top;
}
Expand Down Expand Up @@ -145,6 +144,7 @@ angular.module('duScroll.scrollHelpers', []).run([
angular.module('duScroll.polyfill', []).factory('polyfill', [
'$window',
function ($window) {
'use strict';
var vendors = [
'webkit',
'moz',
Expand All @@ -170,6 +170,7 @@ angular.module('duScroll.requestAnimation', ['duScroll.polyfill']).factory('requ
'polyfill',
'$timeout',
function (polyfill, $timeout) {
'use strict';
var lastTime = 0;
var fallback = function (callback, element) {
var currTime = new Date().getTime();
Expand All @@ -186,6 +187,7 @@ angular.module('duScroll.requestAnimation', ['duScroll.polyfill']).factory('requ
'polyfill',
'$timeout',
function (polyfill, $timeout) {
'use strict';
var fallback = function (promise) {
$timeout.cancel(promise);
};
Expand All @@ -194,11 +196,16 @@ angular.module('duScroll.requestAnimation', ['duScroll.polyfill']).factory('requ
]);
angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI']).factory('spyAPI', [
'$rootScope',
'$timeout',
'scrollContainerAPI',
'duScrollGreedy',
function ($rootScope, scrollContainerAPI, duScrollGreedy) {
'duScrollSpyWait',
function ($rootScope, $timeout, scrollContainerAPI, duScrollGreedy, duScrollSpyWait) {
'use strict';
var createScrollHandler = function (context) {
return function () {
var timer = false, queued = false;
var handler = function () {
queued = false;
var container = context.container, containerEl = container[0], containerOffset = 0;
if (typeof HTMLElement !== 'undefined' && containerEl instanceof HTMLElement || containerEl.nodeType && containerEl.nodeType === containerEl.ELEMENT_NODE) {
containerOffset = containerEl.getBoundingClientRect().top;
Expand Down Expand Up @@ -236,6 +243,23 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI']).factory('spyA
}
context.currentlyActive = toBeActive;
};
if (!duScrollSpyWait) {
return handler;
}
//Debounce for potential performance savings
return function () {
if (!timer) {
handler();
timer = $timeout(function () {
timer = false;
if (queued) {
handler();
}
}, duScrollSpyWait);
} else {
queued = true;
}
};
};
var contexts = {};
var createContext = function ($scope) {
Expand Down Expand Up @@ -321,6 +345,7 @@ angular.module('duScroll.spyAPI', ['duScroll.scrollContainerAPI']).factory('spyA
angular.module('duScroll.scrollContainerAPI', []).factory('scrollContainerAPI', [
'$document',
function ($document) {
'use strict';
var containers = {};
var setContainer = function (scope, element) {
var id = scope.$id;
Expand Down Expand Up @@ -361,6 +386,7 @@ angular.module('duScroll.smoothScroll', [
'duScrollDuration',
'scrollContainerAPI',
function (duScrollDuration, scrollContainerAPI) {
'use strict';
return {
link: function ($scope, $element, $attr) {
$element.on('click', function (e) {
Expand All @@ -385,6 +411,7 @@ angular.module('duScroll.smoothScroll', [
angular.module('duScroll.spyContext', ['duScroll.spyAPI']).directive('duSpyContext', [
'spyAPI',
function (spyAPI) {
'use strict';
return {
restrict: 'A',
scope: true,
Expand All @@ -401,6 +428,7 @@ angular.module('duScroll.spyContext', ['duScroll.spyAPI']).directive('duSpyConte
angular.module('duScroll.scrollContainer', ['duScroll.scrollContainerAPI']).directive('duScrollContainer', [
'scrollContainerAPI',
function (scrollContainerAPI) {
'use strict';
return {
restrict: 'A',
scope: true,
Expand Down Expand Up @@ -428,6 +456,7 @@ angular.module('duScroll.scrollspy', ['duScroll.spyAPI']).directive('duScrollspy
'$timeout',
'$rootScope',
function (spyAPI, $timeout, $rootScope) {
'use strict';
var Spy = function (targetElementOrId, $element, offset) {
if (angular.isElement(targetElementOrId)) {
this.target = targetElementOrId;
Expand Down
Loading

0 comments on commit 861796c

Please sign in to comment.