diff --git a/public/js/common.js b/public/js/common.js new file mode 100644 index 0000000..0406dbf --- /dev/null +++ b/public/js/common.js @@ -0,0 +1,23 @@ +/** + * Set an alpine.js property + * + * @function setProp + * @param {string} key - Key of the data property + * @param {*} prop - The data property + * @param {string} selector - The jQuery selector to the root element + */ +const setProp = (key, prop, selector = '#root') => { + $(selector).get(0).__x.$data[key] = prop; +}; + +/** + * Get an alpine.js property + * + * @function getProp + * @param {string} key - Key of the data property + * @param {string} selector - The jQuery selector to the root element + * @return {*} The data property + */ +const getProp = (key, selector = '#root') => { + return $(selector).get(0).__x.$data[key]; +}; diff --git a/public/js/download-manager.js b/public/js/download-manager.js index 0dec026..6136232 100644 --- a/public/js/download-manager.js +++ b/public/js/download-manager.js @@ -1,25 +1,3 @@ -/** - * Set an alpine.js property - * - * @function setProp - * @param {string} key - Key of the data property - * @param {*} prop - The data property - */ -const setProp = (key, prop) => { - $('#root').get(0).__x.$data[key] = prop; -}; - -/** - * Get an alpine.js property - * - * @function getProp - * @param {string} key - Key of the data property - * @return {*} The data property - */ -const getProp = (key) => { - return $('#root').get(0).__x.$data[key]; -}; - /** * Get the current queue and update the view * diff --git a/public/js/reader.js b/public/js/reader.js index 6d44a06..f7b26c3 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -61,28 +61,6 @@ const updateMode = (mode, targetPage) => { }); }; -/** - * Set an alpine.js property - * - * @function setProp - * @param {string} key - Key of the data property - * @param {*} prop - The data property - */ -const setProp = (key, prop) => { - $('#root').get(0).__x.$data[key] = prop; -}; - -/** - * Get an alpine.js property - * - * @function getProp - * @param {string} key - Key of the data property - * @return {*} The data property - */ -const getProp = (key) => { - return $('#root').get(0).__x.$data[key]; -}; - /** * Get dimension of the pages in the entry from the API and update the view */ diff --git a/src/views/components/head.html.ecr b/src/views/components/head.html.ecr index d2421d0..e4fdfcf 100644 --- a/src/views/components/head.html.ecr +++ b/src/views/components/head.html.ecr @@ -14,5 +14,6 @@ +