Commit 75086e7f authored by alexandre's avatar alexandre

move animatedScroll utility to utils namespace

parent 6b584e81
...@@ -6,6 +6,26 @@ window.W.utils = window.W.utils || {}; ...@@ -6,6 +6,26 @@ window.W.utils = window.W.utils || {};
(function (undefined) { (function (undefined) {
'use strict'; 'use strict';
W.utils.animatedScroll = function (el, distance, duration) {
var start = Date.now(),
step = Math.max(distance / (duration / 60), 3),
tick = function () {
if (Date.now() - start > duration) {
// Animation is taking longer than requested
// scroll the remaining distance at onces
el.scrollBy(0, distance);
} else if (distance > 0) {
el.scrollBy(0, step);
distance -= step;
window.requestAnimationFrame(tick)
}
};
window.requestAnimationFrame(tick);
};
W.utils.getUserLanguage = function () { W.utils.getUserLanguage = function () {
var lang = W.utils.getCookie("lang"); var lang = W.utils.getCookie("lang");
......
...@@ -5,24 +5,6 @@ window.W = window.W || {}; ...@@ -5,24 +5,6 @@ window.W = window.W || {};
(function (undefined) { (function (undefined) {
'use strict'; 'use strict';
function animatedScroll (el, distance, duration) {
var start = Date.now(),
step = Math.max(distance / (duration / 60), 3),
tick = function () {
if (Date.now() - start > duration) {
// Animation is taking longer than requested
// scroll the remaining distance at onces
el.scrollBy(0, distance);
} else if (distance > 0) {
el.scrollBy(0, step);
distance -= step;
window.requestAnimationFrame(tick)
}
}
window.requestAnimationFrame(tick);
}
var MyDatetimeFormatter = _.extend({}, Backgrid.CellFormatter.prototype, { var MyDatetimeFormatter = _.extend({}, Backgrid.CellFormatter.prototype, {
fromRaw: function (rawValue, model) { fromRaw: function (rawValue, model) {
moment.locale('fr'); moment.locale('fr');
...@@ -669,7 +651,7 @@ window.W = window.W || {}; ...@@ -669,7 +651,7 @@ window.W = window.W || {};
if (form.height > main.height) { if (form.height > main.height) {
distance -= form.height - main.height; distance -= form.height - main.height;
} }
animatedScroll(document.querySelector('main.main-area'), distance, 500); W.utils.animatedScroll(document.querySelector('main.main-area'), distance, 500);
} }
}); });
} }
...@@ -686,7 +668,7 @@ window.W = window.W || {}; ...@@ -686,7 +668,7 @@ window.W = window.W || {};
if (extraFieldsRect.bottom > mainRect.bottom) { if (extraFieldsRect.bottom > mainRect.bottom) {
var distance = extraFieldsRect.bottom - mainRect.bottom; var distance = extraFieldsRect.bottom - mainRect.bottom;
animatedScroll(main, distance, 500); W.utils.animatedScroll(main, distance, 500);
} }
}); });
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment