//noinspection JSUnusedAssignment var RMIScrolling = RMIScrolling || {}; /** * @param {!HTMLInputElement} inputElemToActivate * @param {!Element} scrollableElem * @constructor */ RMIScrolling.InputActivator = function (inputElemToActivate, scrollableElem) { /** * @type {!HTMLInputElement} * @private */ this.inputElemToActivate_ = inputElemToActivate; /** * @type {!Element} * @private */ this.scrollableElem_ = scrollableElem; scrollableElem.addEventListener('scroll', this.applyWhenScrolledDown_.bind(this)); }; /** * @private */ RMIScrolling.InputActivator.prototype.activateInputElem_ = function () { activateElement(this.inputElemToActivate_); }; /** * @private */ RMIScrolling.InputActivator.prototype.applyWhenScrolledDown_ = function () { /** @type {!Element} */ var scrollableElem = this.scrollableElem_; if (scrollableElem.offsetHeight + scrollableElem.scrollTop >= scrollableElem.scrollHeight) { this.activateInputElem_.apply(this); } }; /** * @param {!HTMLInputElement} inputElemToActivate * @param {!Element} scrollableElem * @returns {RMIScrolling.InputActivator} * @public */ RMIScrolling.InputActivator.initialize = function (inputElemToActivate, scrollableElem) { if(!scrollableElem) { activateElement(inputElemToActivate); throw "scrollableElem was null, inputElemToActivate would never be activated. It therefore has been activated immediately."; } new RMIScrolling.InputActivator(inputElemToActivate, scrollableElem); }; /** * @param {!HTMLInputElement} inputElemToActivate */ function activateElement(inputElemToActivate) { inputElemToActivate.disabled = false; /** @type {string} */ var disabledClassName = 'disabled'; /** @type {string} */ var orgClassName = inputElemToActivate.className; if (orgClassName.indexOf(disabledClassName) > -1) { /** @type {!RegExp} */ var regExp = new RegExp('\\b' + disabledClassName + '\\b'); inputElemToActivate.className = orgClassName.replace(regExp, ''); } }