UNPKG

@ccos/webos

Version:

A Base JavaScript Framework for Skyworth/Coocaa TV

57 lines (56 loc) 3.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), (exports.focusable = void 0); var focusable_core_1 = require("./focusable-core/focusable-core.js"), listener = ((exports.focusable = focusable_core_1.default), document.removeEventListener("keydown", focusable_core_1.default.focusKeyDownEvent, !1), document.addEventListener("keydown", focusable_core_1.default.focusKeyDownEvent), document.removeEventListener("keyup", focusable_core_1.default.focusKeyUpEvent, !1), document.addEventListener("keyup", focusable_core_1.default.focusKeyUpEvent), (focusable_core_1.default.itemAttrname = "focusable".concat(Math.ceil(1e4 * Math.random()))), ["left", "up", "right", "down", "on-focus", "on-blur", "long-press"]); function titleCase(e) { return (e = e.slice(0, 1).toUpperCase() + e.slice(1).toLowerCase()).replace(/-(\w)/g, function (e, t) { return t.toUpperCase(); }); } var install = function (e) { var t = "2" == e.version.split(".")[0], o = e.prototype, a = "bind"; t || ((o = e.config.globalProperties), (a = "beforeMount")), e.directive( "focusable", (((e = {})[a] = function (o, e, a) { o && (e.value || void 0 === e.value ? (o.setAttribute("".concat(focusable_core_1.default.itemAttrname), ""), o.$on || (o.$on = {}), t ? (o.$on = a.data.on) : listener.forEach(function (e) { var t = titleCase(e); a.props && a.props["on".concat(t)] && (o.$on[e] = a.props["on".concat(t)]); }), -1 !== (o.getAttribute("class") || "").split(" ").indexOf(focusable_core_1.default.focusClassName) && o.setAttribute("".concat(focusable_core_1.default.focusedAttrname), "")) : o.removeAttribute(focusable_core_1.default.itemAttrname)); }), (e.update = function (o, e, a) { o && (e.value || void 0 === e.value ? (o.setAttribute("".concat(focusable_core_1.default.itemAttrname), ""), o.$on || (o.$on = {}), t ? (o.$on = a.data.on) : listener.forEach(function (e) { var t = titleCase(e); a.props && a.props["on".concat(t)] && (o.$on[e] = a.props["on".concat(t)]); }), -1 !== (o.getAttribute("class") || "").split(" ").indexOf(focusable_core_1.default.focusClassName) && o.setAttribute("".concat(focusable_core_1.default.focusedAttrname), "")) : o.removeAttribute(focusable_core_1.default.itemAttrname)); }), e) ), (o.$tv = focusable_core_1.default); }; exports.default = { install: install };