(function() {
try {
// PRECONFIG
window.qworkshop_ebay = {
config: {
slide_count: null,
slide_active: 1,
slide_change: 6000,
interval: null
},
elements: {
slider_box: null,
slider_list: null,
slider_items: null,
slider_right: null,
slider_left: null
},
functions: {
slider_left: function() {
if (window.qworkshop_ebay.config.slide_active === 1) {
window.qworkshop_ebay.config.slide_active = window.qworkshop_ebay.config.slide_count;
} else {
window.qworkshop_ebay.config.slide_active = window.qworkshop_ebay.config.slide_active – 1;
};
window.qworkshop_ebay.elements.slider_list.style.left = window.qworkshop_ebay.functions.evaluate_left_position();
},
slider_right: function() {
if (window.qworkshop_ebay.config.slide_active === window.qworkshop_ebay.config.slide_count) {
window.qworkshop_ebay.config.slide_active = 1
} else {
window.qworkshop_ebay.config.slide_active = window.qworkshop_ebay.config.slide_active + 1;
};
window.qworkshop_ebay.elements.slider_list.style.left = window.qworkshop_ebay.functions.evaluate_left_position();
},
slider_list_mouseover: function() {
clearInterval(window.qworkshop_ebay.config.interval);
},
slider_list_mouseout: function() {
window.qworkshop_ebay.config.interval = setInterval(window.qworkshop_ebay.functions.slider_right, window.qworkshop_ebay.config.slide_change);
},
evaluate_left_position: function() {
var slide_active_for_left = window.qworkshop_ebay.config.slide_active – 1;
return “-” + (slide_active_for_left * 100) + “%”;
}
},
init: function() {
window.qworkshop_ebay.functions.slider_list_mouseout();
}
};
// CHECK IF window.qworkshop_ebay exist and check it against interface
// CONFIG
window.qworkshop_ebay.elements.slider_box = document.querySelector(“[data-hook=’js__sec–slider’]”);
if (window.qworkshop_ebay.elements.slider_box === null) throw new Error(“SLIDER_BOX not found!”);
window.qworkshop_ebay.elements.slider_list = window.qworkshop_ebay.elements.slider_box.querySelector(“[data-hook=’js__sec–slider__list’]”);
window.qworkshop_ebay.elements.slider_items = window.qworkshop_ebay.elements.slider_box.querySelectorAll(“.sec–slider__item”);
window.qworkshop_ebay.elements.slider_right = window.qworkshop_ebay.elements.slider_box.querySelector(“[data-hook=’js__sec–slider__right’]”);
window.qworkshop_ebay.elements.slider_left = window.qworkshop_ebay.elements.slider_box.querySelector(“[data-hook=’js__sec–slider__left’]”);
window.qworkshop_ebay.config.slide_count = window.qworkshop_ebay.elements.slider_items.length;
// TESTS
if (window.qworkshop_ebay.elements.slider_list === null) throw new Error(“SLIDER_LIST not found!”);
if (window.qworkshop_ebay.elements.slider_items.length === 0) throw new Error(“SLIDER_ITEMS not found!”);
if (window.qworkshop_ebay.config.slide_count !== window.qworkshop_ebay.elements.slider_items.length) throw new Error(“Setting SLIDE_COUNT error!”);
if (window.qworkshop_ebay.config.slide_count > 1) {
if (window.qworkshop_ebay.elements.slider_right === null) throw new Error(“SLIDER_RIGHT_BTN not found!”);
if (window.qworkshop_ebay.elements.slider_left === null) throw new Error(“SLIDER_LEFT_BTN not found!”);
};
if (window.qworkshop_ebay.config.slide_count === 1) {
// HIDE BUTTONS
if (window.qworkshop_ebay.elements.slider_left !== null) {
window.qworkshop_ebay.elements.slider_left.classList.add(“sec–slider__btn–hide”);
};
if (window.qworkshop_ebay.elements.slider_right !== null) {
window.qworkshop_ebay.elements.slider_right.classList.add(“sec–slider__btn–hide”);
};
} else {
// ADD EVENTS
window.qworkshop_ebay.elements.slider_left.addEventListener(“click”, window.qworkshop_ebay.functions.slider_left);
window.qworkshop_ebay.elements.slider_right.addEventListener(“click”, window.qworkshop_ebay.functions.slider_right);
window.qworkshop_ebay.elements.slider_list.addEventListener(“mouseover”, window.qworkshop_ebay.functions.slider_list_mouseover);
window.qworkshop_ebay.elements.slider_list.addEventListener(“mouseout”, window.qworkshop_ebay.functions.slider_list_mouseout);
// INIT
window.qworkshop_ebay.init();
};
} catch (error) {
if (typeof error === “string”) {
error = {
“message”: error,
“name”: “UserException”
};
};
console.error(“SLIDER_EBAY_PLUGIN ::: ” + error.name + ” ::: ” + error.message);
return;
};
})();