}
if (shouldScroll) {
- // allow some padding to indicate overflow
- if (paddingRight) {
- left -= 15;
- }
- else if (left > 0) {
- left -= 15;
- }
-
- if (left < 0) {
- left = 0;
- }
- else {
- // ensure that our left value is always within the boundaries
- left = Math.min(left, scrollWidth - width);
- }
-
- if (scrollLeft === left) {
- return;
- }
-
- list.classList.add('enableAnimation');
+ this._scrollMenu(list, left, scrollLeft, scrollWidth, width, paddingRight);
+ }
+ },
+
+ _scrollMenu: function (list, left, scrollLeft, scrollWidth, width, paddingRight) {
+ // allow some padding to indicate overflow
+ if (paddingRight) {
+ left -= 15;
+ }
+ else if (left > 0) {
+ left -= 15;
+ }
+
+ if (left < 0) {
+ left = 0;
+ }
+ else {
+ // ensure that our left value is always within the boundaries
+ left = Math.min(left, scrollWidth - width);
+ }
+
+ if (scrollLeft === left) {
+ return;
+ }
+
+ list.classList.add('enableAnimation');
+
+ // new value is larger, we're scrolling towards the end
+ if (scrollLeft < left) {
+ list.firstElementChild.style.setProperty('margin-left', (scrollLeft - left) + 'px', '');
+ }
+ else {
+ // new value is smaller, we're scrolling towards the start
+ list.style.setProperty('padding-left', (scrollLeft - left) + 'px', '');
+ }
+
+ setTimeout(function () {
+ list.classList.remove('enableAnimation');
- // new value is larger, we're scrolling towards the end
- if (scrollLeft < left) {
- list.firstElementChild.style.setProperty('margin-left', (scrollLeft - left) + 'px', '');
- }
- else {
- // new value is smaller, we're scrolling towards the start
- list.style.setProperty('padding-left', (scrollLeft - left) + 'px', '');
- }
+ list.firstElementChild.style.removeProperty('margin-left');
+ list.style.removeProperty('padding-left');
- setTimeout(function () {
- list.classList.remove('enableAnimation');
-
- list.firstElementChild.style.removeProperty('margin-left');
- list.style.removeProperty('padding-left');
-
- list.scrollLeft = left;
- }, 300);
- }
+ list.scrollLeft = left;
+ }, 300);
},
_rebuildMenuOverflow: function (menu) {
if (overlayLeft === null) {
overlayLeft = elCreate('span');
overlayLeft.className = 'tabMenuOverlayLeft icon icon24 fa-angle-left';
+ overlayLeft.addEventListener(WCF_CLICK_EVENT, (function () {
+ var listWidth = list.clientWidth;
+
+ this._scrollMenu(
+ list,
+ list.scrollLeft - ~~(listWidth / 2),
+ list.scrollLeft,
+ list.scrollWidth,
+ listWidth,
+ 0
+ );
+ }).bind(this));
+
menu.insertBefore(overlayLeft, menu.firstChild);
}
if (overlayRight === null) {
overlayRight = elCreate('span');
overlayRight.className = 'tabMenuOverlayRight icon icon24 fa-angle-right';
+ overlayRight.addEventListener(WCF_CLICK_EVENT, (function () {
+ var listWidth = list.clientWidth;
+
+ this._scrollMenu(
+ list,
+ list.scrollLeft + ~~(listWidth / 2),
+ list.scrollLeft,
+ list.scrollWidth,
+ listWidth,
+ 0
+ );
+ }).bind(this));
+
menu.appendChild(overlayRight);
}