webpack-bootstrap-ui-kit/src/js/_events.router.js

65 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-09-10 01:55:27 +02:00
/**
* Route side-wide events
*/
const EventsUI = (($) => {
const on = $.fn.on;
const off = $.fn.off;
// Constants
const W = window;
const $W = $(W);
const D = document;
const $Body = $('body');
const NAME = 'EventsUI';
class EventsUI {
static process(el, args) {
2020-09-10 01:57:16 +02:00
let modEl = el;
2020-09-10 01:55:27 +02:00
const eventName = args[0];
const tagName = typeof el !== undefined ? $(el).prop('tagName') : null;
switch (tagName) {
case 'HTML':
case 'BODY':
2020-09-10 01:57:16 +02:00
modEl = $W;
2020-09-10 01:55:27 +02:00
break;
}
2020-09-10 01:57:16 +02:00
return [modEl, args];
2020-09-10 01:55:27 +02:00
}
}
// rewrite jQuery functions
$.fn.on = function () {
const result = EventsUI.process(this, arguments);
return on.apply(...result);
};
$.fn.off = function () {
const result = EventsUI.process(this, arguments);
return off.apply(...result);
};
const scrollTop = $.fn.scrollTop;
// rewrite scrollTop
$.fn.scrollTop = function () {
let el = this;
2020-09-10 02:41:31 +02:00
const args = arguments;
2020-09-10 01:55:27 +02:00
const tagName = typeof el !== undefined ? $(el).prop('tagName') : null;
switch (tagName) {
case 'HTML':
case 'BODY':
el = $W;
break;
}
return scrollTop.apply(el, args);
};
})($);
export default EventsUI;