|
1 | 1 | /**
|
2 | 2 | * vivus - JavaScript library to make drawing animation on SVG
|
3 |
| - * @version v0.4.0 |
| 3 | + * @version v0.4.1 |
4 | 4 | * @link https://github.com/maxwellito/vivus
|
5 | 5 | * @license MIT
|
6 | 6 | */
|
7 | 7 |
|
8 | 8 | 'use strict';
|
9 | 9 |
|
10 |
| -(function (window, document) { |
| 10 | +(function () { |
11 | 11 |
|
12 | 12 | 'use strict';
|
13 | 13 |
|
@@ -268,7 +268,7 @@ Pathformer.prototype.parseAttr = function (element) {
|
268 | 268 |
|
269 | 269 | 'use strict';
|
270 | 270 |
|
271 |
| -var requestAnimFrame, cancelAnimFrame, parsePositiveInt; |
| 271 | +var setupEnv, requestAnimFrame, cancelAnimFrame, parsePositiveInt; |
272 | 272 |
|
273 | 273 | /**
|
274 | 274 | * Vivus
|
@@ -320,6 +320,8 @@ var requestAnimFrame, cancelAnimFrame, parsePositiveInt;
|
320 | 320 | */
|
321 | 321 | function Vivus (element, options, callback) {
|
322 | 322 |
|
| 323 | + setupEnv(); |
| 324 | + |
323 | 325 | // Setup
|
324 | 326 | this.isReady = false;
|
325 | 327 | this.setElement(element, options);
|
@@ -953,12 +955,6 @@ Vivus.prototype.isInViewport = function (el, h) {
|
953 | 955 | return (elTop + elHeight * h) <= viewed && (elBottom) >= scrolled;
|
954 | 956 | };
|
955 | 957 |
|
956 |
| -/** |
957 |
| - * Alias for document element |
958 |
| - * |
959 |
| - * @type {DOMelement} |
960 |
| - */ |
961 |
| -Vivus.prototype.docElem = window.document.documentElement; |
962 | 958 |
|
963 | 959 | /**
|
964 | 960 | * Get the viewport height in pixels
|
@@ -986,41 +982,55 @@ Vivus.prototype.scrollY = function () {
|
986 | 982 | return window.pageYOffset || this.docElem.scrollTop;
|
987 | 983 | };
|
988 | 984 |
|
989 |
| -/** |
990 |
| - * Alias for `requestAnimationFrame` or |
991 |
| - * `setTimeout` function for deprecated browsers. |
992 |
| - * |
993 |
| - */ |
994 |
| -requestAnimFrame = (function () { |
995 |
| - return ( |
996 |
| - window.requestAnimationFrame || |
997 |
| - window.webkitRequestAnimationFrame || |
998 |
| - window.mozRequestAnimationFrame || |
999 |
| - window.oRequestAnimationFrame || |
1000 |
| - window.msRequestAnimationFrame || |
1001 |
| - function(/* function */ callback){ |
1002 |
| - return window.setTimeout(callback, 1000 / 60); |
1003 |
| - } |
1004 |
| - ); |
1005 |
| -})(); |
| 985 | +setupEnv = function () { |
1006 | 986 |
|
1007 |
| -/** |
1008 |
| - * Alias for `cancelAnimationFrame` or |
1009 |
| - * `cancelTimeout` function for deprecated browsers. |
1010 |
| - * |
1011 |
| - */ |
1012 |
| -cancelAnimFrame = (function () { |
1013 |
| - return ( |
1014 |
| - window.cancelAnimationFrame || |
1015 |
| - window.webkitCancelAnimationFrame || |
1016 |
| - window.mozCancelAnimationFrame || |
1017 |
| - window.oCancelAnimationFrame || |
1018 |
| - window.msCancelAnimationFrame || |
1019 |
| - function(id){ |
1020 |
| - return window.clearTimeout(id); |
1021 |
| - } |
1022 |
| - ); |
1023 |
| -})(); |
| 987 | + if (Vivus.prototype.docElem) { |
| 988 | + return; |
| 989 | + } |
| 990 | + |
| 991 | + /** |
| 992 | + * Alias for document element |
| 993 | + * |
| 994 | + * @type {DOMelement} |
| 995 | + */ |
| 996 | + Vivus.prototype.docElem = window.document.documentElement; |
| 997 | + |
| 998 | + /** |
| 999 | + * Alias for `requestAnimationFrame` or |
| 1000 | + * `setTimeout` function for deprecated browsers. |
| 1001 | + * |
| 1002 | + */ |
| 1003 | + requestAnimFrame = (function () { |
| 1004 | + return ( |
| 1005 | + window.requestAnimationFrame || |
| 1006 | + window.webkitRequestAnimationFrame || |
| 1007 | + window.mozRequestAnimationFrame || |
| 1008 | + window.oRequestAnimationFrame || |
| 1009 | + window.msRequestAnimationFrame || |
| 1010 | + function(/* function */ callback){ |
| 1011 | + return window.setTimeout(callback, 1000 / 60); |
| 1012 | + } |
| 1013 | + ); |
| 1014 | + })(); |
| 1015 | + |
| 1016 | + /** |
| 1017 | + * Alias for `cancelAnimationFrame` or |
| 1018 | + * `cancelTimeout` function for deprecated browsers. |
| 1019 | + * |
| 1020 | + */ |
| 1021 | + cancelAnimFrame = (function () { |
| 1022 | + return ( |
| 1023 | + window.cancelAnimationFrame || |
| 1024 | + window.webkitCancelAnimationFrame || |
| 1025 | + window.mozCancelAnimationFrame || |
| 1026 | + window.oCancelAnimationFrame || |
| 1027 | + window.msCancelAnimationFrame || |
| 1028 | + function(id){ |
| 1029 | + return window.clearTimeout(id); |
| 1030 | + } |
| 1031 | + ); |
| 1032 | + })(); |
| 1033 | +}; |
1024 | 1034 |
|
1025 | 1035 | /**
|
1026 | 1036 | * Parse string to integer.
|
@@ -1054,4 +1064,4 @@ parsePositiveInt = function (value, defaultValue) {
|
1054 | 1064 | window.Vivus = Vivus;
|
1055 | 1065 | }
|
1056 | 1066 |
|
1057 |
| -}(window, document)); |
| 1067 | +}()); |
0 commit comments