dynamic-marquee
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -410,4 +410,2 @@ (function (global, factory) { | ||
function Marquee($container) { | ||
var _this = this; | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
@@ -426,3 +424,2 @@ _ref$rate = _ref.rate, | ||
return { | ||
allItemsRemoved: false, | ||
callbacks: [] | ||
@@ -432,12 +429,3 @@ }; | ||
onExit: function onExit(_ref2) { | ||
var _ref2$onEnterResult = _ref2.onEnterResult, | ||
callbacks = _ref2$onEnterResult.callbacks, | ||
allItemsRemoved = _ref2$onEnterResult.allItemsRemoved; | ||
if (allItemsRemoved) { | ||
_this._onAllItemsRemoved.forEach(function (cb) { | ||
return callbacks.push(cb); | ||
}); | ||
} | ||
var callbacks = _ref2.onEnterResult.callbacks; | ||
callbacks.forEach(function (cb) { | ||
@@ -546,17 +534,17 @@ return defer(function () { | ||
value: function clear() { | ||
var _this2 = this; | ||
var _this = this; | ||
this._boundary.enter(function () { | ||
_this2._items.forEach(function (_ref3) { | ||
_this._items.forEach(function (_ref3) { | ||
var item = _ref3.item; | ||
return _this2._removeItem(item); | ||
return _this._removeItem(item); | ||
}); | ||
_this2._items = []; | ||
_this2._waitingForItem = true; | ||
_this2._nextItemWouldBeTouching = false; | ||
_this._items = []; | ||
_this._waitingForItem = true; | ||
_this._nextItemWouldBeTouching = false; | ||
_this2._updateWindowInverseSize(); | ||
_this._updateWindowInverseSize(); | ||
_this2._cleanup(); | ||
_this._cleanup(); | ||
}); | ||
@@ -572,3 +560,3 @@ } | ||
value: function appendItem($el) { | ||
var _this3 = this; | ||
var _this2 = this; | ||
@@ -580,3 +568,3 @@ var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
this._boundary.enter(function () { | ||
if (!_this3._waitingForItem) { | ||
if (!_this2._waitingForItem) { | ||
throw new Error('No room for item.'); | ||
@@ -588,3 +576,3 @@ } // convert to div if $el is a string | ||
var itemAlreadyExists = _this3._items.some(function (_ref5) { | ||
var itemAlreadyExists = _this2._items.some(function (_ref5) { | ||
var item = _ref5.item; | ||
@@ -598,6 +586,6 @@ return item.getOriginalEl() === $el; | ||
_this3._waitingForItem = false; | ||
_this3._pendingItem = new Item($el, _this3._direction, metadata); | ||
_this2._waitingForItem = false; | ||
_this2._pendingItem = new Item($el, _this2._direction, metadata); | ||
_this3._tick(); | ||
_this2._tick(); | ||
}); | ||
@@ -608,3 +596,3 @@ } | ||
value: function _removeItem(item) { | ||
var _this4 = this; | ||
var _this3 = this; | ||
@@ -615,5 +603,5 @@ this._boundary.enter(function (_ref6) { | ||
_this4._items.splice(_this4._items.indexOf(item), 1); | ||
_this3._items.splice(_this3._items.indexOf(item), 1); | ||
_this4._onItemRemoved.forEach(function (cb) { | ||
_this3._onItemRemoved.forEach(function (cb) { | ||
callbacks.push(function () { | ||
@@ -650,3 +638,3 @@ return cb(item.getOriginalEl()); | ||
value: function _scheduleRender() { | ||
var _this5 = this; | ||
var _this4 = this; | ||
@@ -660,3 +648,3 @@ if (!this._renderTimer) { | ||
this._renderTimer = window.setTimeout(function () { | ||
return _this5._tick(); | ||
return _this4._tick(); | ||
}, renderInterval); | ||
@@ -678,11 +666,11 @@ } | ||
value: function _tick() { | ||
var _this6 = this; | ||
var _this5 = this; | ||
this._boundary.enter(function (_ref8) { | ||
var callbacks = _ref8.callbacks; | ||
_this6._renderTimer && clearTimeout(_this6._renderTimer); | ||
_this6._renderTimer = null; | ||
_this5._renderTimer && clearTimeout(_this5._renderTimer); | ||
_this5._renderTimer = null; | ||
if (!_this6._items.length && !_this6._pendingItem) { | ||
_this6._cleanup(); | ||
if (!_this5._items.length && !_this5._pendingItem) { | ||
_this5._cleanup(); | ||
@@ -692,6 +680,6 @@ return; | ||
_this6._scheduleRender(); | ||
_this5._scheduleRender(); | ||
if (!_this6._containerSizeWatcher) { | ||
_this6._containerSizeWatcher = new SizeWatcher(_this6._$window); | ||
if (!_this5._containerSizeWatcher) { | ||
_this5._containerSizeWatcher = new SizeWatcher(_this5._$window); | ||
} | ||
@@ -702,5 +690,5 @@ | ||
if (_this6._correlation) { | ||
var timePassed = now - _this6._correlation.time; | ||
_this6._windowOffset = _this6._correlation.offset + _this6._correlation.rate * -1 * (timePassed / 1000); | ||
if (_this5._correlation) { | ||
var timePassed = now - _this5._correlation.time; | ||
_this5._windowOffset = _this5._correlation.offset + _this5._correlation.rate * -1 * (timePassed / 1000); | ||
} else { | ||
@@ -710,71 +698,71 @@ resynced = true; | ||
if (Math.abs(_this6._windowOffset) > maxTranslateDistance) { | ||
if (Math.abs(_this5._windowOffset) > maxTranslateDistance) { | ||
// resync so that the number of pixels we are translating doesn't get too big | ||
resynced = true; | ||
var shiftAmount = _this6._windowOffset; | ||
var shiftAmount = _this5._windowOffset; | ||
_this6._items.forEach(function (item) { | ||
_this5._items.forEach(function (item) { | ||
return item.offset -= shiftAmount; | ||
}); | ||
_this6._correlation = null; | ||
_this6._windowOffset = 0; | ||
_this5._correlation = null; | ||
_this5._windowOffset = 0; | ||
} | ||
_this6._slider.setOffset(_this6._windowOffset * -1, _this6._rate, resynced); | ||
_this5._slider.setOffset(_this5._windowOffset * -1, _this5._rate, resynced); | ||
if (!_this6._correlation || _this6._correlation.rate !== _this6._rate) { | ||
_this6._correlation = { | ||
if (!_this5._correlation || _this5._correlation.rate !== _this5._rate) { | ||
_this5._correlation = { | ||
time: now, | ||
offset: _this6._windowOffset, | ||
rate: _this6._rate | ||
offset: _this5._windowOffset, | ||
rate: _this5._rate | ||
}; | ||
} | ||
_this6._containerSize = _this6._direction === DIRECTION.RIGHT ? _this6._containerSizeWatcher.getWidth() : _this6._containerSizeWatcher.getHeight(); // if container has size 0 pretend it is 1 to prevent infinite loop | ||
_this5._containerSize = _this5._direction === DIRECTION.RIGHT ? _this5._containerSizeWatcher.getWidth() : _this5._containerSizeWatcher.getHeight(); // if container has size 0 pretend it is 1 to prevent infinite loop | ||
// of adding items that are instantly removed | ||
var containerSize = Math.max(_this6._containerSize, 1); | ||
var justReversedRate = _this6._justReversedRate; | ||
_this6._justReversedRate = false; | ||
var newItemWouldBeTouching = _this6._nextItemWouldBeTouching; | ||
_this6._nextItemWouldBeTouching = null; | ||
var containerSize = Math.max(_this5._containerSize, 1); | ||
var justReversedRate = _this5._justReversedRate; | ||
_this5._justReversedRate = false; | ||
var newItemWouldBeTouching = _this5._nextItemWouldBeTouching; | ||
_this5._nextItemWouldBeTouching = null; | ||
var nextItemTouching = null; | ||
if (_this6._pendingItem) { | ||
_this6._$moving.appendChild(_this6._pendingItem.getContainer()); | ||
if (_this5._pendingItem) { | ||
_this5._$moving.appendChild(_this5._pendingItem.getContainer()); | ||
var touching = _this6._rate <= 0 ? last(_this6._items) : first(_this6._items); | ||
var touching = _this5._rate <= 0 ? last(_this5._items) : first(_this5._items); | ||
if (_this6._rate <= 0) { | ||
_this6._items = [].concat(_toConsumableArray(_this6._items), [{ | ||
item: _this6._pendingItem, | ||
appendRate: _this6._rate, | ||
offset: newItemWouldBeTouching ? touching ? touching.offset + touching.item.getSize() : _this6._windowOffset : _this6._windowOffset + containerSize | ||
if (_this5._rate <= 0) { | ||
_this5._items = [].concat(_toConsumableArray(_this5._items), [{ | ||
item: _this5._pendingItem, | ||
appendRate: _this5._rate, | ||
offset: newItemWouldBeTouching ? touching ? touching.offset + touching.item.getSize() : _this5._windowOffset : _this5._windowOffset + containerSize | ||
}]); | ||
} else { | ||
_this6._items = [{ | ||
item: _this6._pendingItem, | ||
appendRate: _this6._rate, | ||
offset: newItemWouldBeTouching ? touching ? touching.offset - _this6._pendingItem.getSize() : _this6._windowOffset + containerSize - _this6._pendingItem.getSize() : _this6._windowOffset - _this6._pendingItem.getSize() | ||
}].concat(_toConsumableArray(_this6._items)); | ||
_this5._items = [{ | ||
item: _this5._pendingItem, | ||
appendRate: _this5._rate, | ||
offset: newItemWouldBeTouching ? touching ? touching.offset - _this5._pendingItem.getSize() : _this5._windowOffset + containerSize - _this5._pendingItem.getSize() : _this5._windowOffset - _this5._pendingItem.getSize() | ||
}].concat(_toConsumableArray(_this5._items)); | ||
} | ||
_this6._pendingItem = null; | ||
_this5._pendingItem = null; | ||
} // add a buffer on the side to make sure that new elements are added before they would actually be on screen | ||
var buffer = renderInterval / 1000 * Math.abs(_this6._rate); | ||
var buffer = renderInterval / 1000 * Math.abs(_this5._rate); | ||
var requireNewItem = false; | ||
if (!_this6._waitingForItem && _this6._items.length | ||
if (!_this5._waitingForItem && _this5._items.length | ||
/* there should always be items at this point */ | ||
) { | ||
var firstItem = first(_this6._items); | ||
var lastItem = last(_this6._items); | ||
var firstItem = first(_this5._items); | ||
var lastItem = last(_this5._items); | ||
var _touching = _this6._rate <= 0 ? lastItem : firstItem; | ||
var _touching = _this5._rate <= 0 ? lastItem : firstItem; | ||
if (_this6._rate <= 0 && lastItem.offset + _touching.item.getSize() - _this6._windowOffset <= containerSize + buffer || _this6._rate > 0 && _touching.offset - _this6._windowOffset > -1 * buffer) { | ||
_this6._waitingForItem = requireNewItem = true; // if an item is appended immediately below, it would be considered touching | ||
if (_this5._rate <= 0 && lastItem.offset + _touching.item.getSize() - _this5._windowOffset <= containerSize + buffer || _this5._rate > 0 && _touching.offset - _this5._windowOffset > -1 * buffer) { | ||
_this5._waitingForItem = requireNewItem = true; // if an item is appended immediately below, it would be considered touching | ||
// the previous if we haven't just changed direction. | ||
@@ -792,15 +780,15 @@ // This is useful when deciding whether to add a separator on the side that enters the | ||
if (nextItemTouching) { | ||
_this6._nextItemWouldBeTouching = true; | ||
_this5._nextItemWouldBeTouching = true; | ||
} | ||
_this6._items = _toConsumableArray(_this6._items).filter(function (_ref9) { | ||
_this5._items = _toConsumableArray(_this5._items).filter(function (_ref9) { | ||
var item = _ref9.item, | ||
offset = _ref9.offset; | ||
var keep = _this6._rate < 0 ? offset + item.getSize() > _this6._windowOffset : offset < _this6._windowOffset + containerSize; | ||
if (!keep) _this6._removeItem(item); | ||
var keep = _this5._rate < 0 ? offset + item.getSize() > _this5._windowOffset : offset < _this5._windowOffset + containerSize; | ||
if (!keep) _this5._removeItem(item); | ||
return keep; | ||
}); | ||
if (!_this6._items.length) { | ||
_this6._onAllItemsRemoved.forEach(function (cb) { | ||
if (!_this5._items.length) { | ||
_this5._onAllItemsRemoved.forEach(function (cb) { | ||
return callbacks.push(cb); | ||
@@ -810,3 +798,3 @@ }); | ||
_this6._items.reduce(function (newOffset, item) { | ||
_this5._items.reduce(function (newOffset, item) { | ||
if (newOffset !== null && item.offset < newOffset) { | ||
@@ -822,3 +810,3 @@ // the size of the item before has increased and would now be overlapping | ||
_this6._updateWindowInverseSize(); | ||
_this5._updateWindowInverseSize(); | ||
@@ -828,3 +816,3 @@ if (requireNewItem) { | ||
_this6._onItemRequired.some(function (cb) { | ||
_this5._onItemRequired.some(function (cb) { | ||
return deferException(function () { | ||
@@ -842,6 +830,6 @@ nextItem = cb({ | ||
// Note appendItem() will call _tick() synchronously again | ||
_this6.appendItem(nextItem); | ||
_this5.appendItem(nextItem); | ||
} | ||
_this6._nextItemWouldBeTouching = false; | ||
_this5._nextItemWouldBeTouching = false; | ||
} | ||
@@ -848,0 +836,0 @@ }); |
{ | ||
"name": "dynamic-marquee", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "A small library for creating marquees.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/dynamic-marquee.js", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
49998
840