From 5828f799880786be1efe535e3446c27b0e1092d1 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 7 Oct 2022 20:49:53 +0545 Subject: [PATCH] options: move unique functions in here Nothing else uses these, so move them over to avoid having to export+import. --- javascript/options.js | 28 ++++++++++++++++++++++++++++ javascript/util.js | 28 ---------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/javascript/options.js b/javascript/options.js index c4ffda4..e5d53ec 100644 --- a/javascript/options.js +++ b/javascript/options.js @@ -7,6 +7,34 @@ window.addEventListener('load', init, false); +/** + * Pours the data in template string. + * @param {Object} datObject The data object to be filled in template string. + * @return {string} The new string created from template string and filled + * with the given data. + */ +String.prototype.supplant = function(datObject) { + return this.replace(/{([^{}]*)}/g, + function(match, firstSubMatch) { + var replace = datObject[firstSubMatch]; + return (typeof replace === 'string' || typeof replace === 'number') ? + replace : match; + }); +}; + +/** + * Queries the DOM. + * @param {string} selector Selector to execute. + * @param {HTMLElement=} context HTMLElement to query (optional). + * @return {Array.} Array of matched elements (non-live). + */ +function $(selector, context) { + if (!(context && context instanceof HTMLElement)) { + context = document; + } + return Array.prototype.slice.call(context.querySelectorAll(selector)); +} + /** * Initializes the i18n strings. * Loads values from localStorage and applies them to the elements diff --git a/javascript/util.js b/javascript/util.js index a428b3b..6a233b5 100644 --- a/javascript/util.js +++ b/javascript/util.js @@ -4,34 +4,6 @@ * @fileoverview Some basic, useful utility functions. */ -/** - * Pours the data in template string. - * @param {Object} datObject The data object to be filled in template string. - * @return {string} The new string created from template string and filled - * with the given data. - */ -String.prototype.supplant = function(datObject) { - return this.replace(/{([^{}]*)}/g, - function(match, firstSubMatch) { - var replace = datObject[firstSubMatch]; - return (typeof replace === 'string' || typeof replace === 'number') ? - replace : match; - }); -}; - -/** - * Queries the DOM. - * @param {string} selector Selector to execute. - * @param {HTMLElement=} context HTMLElement to query (optional). - * @return {Array.} Array of matched elements (non-live). - */ -function $(selector, context) { - if (!(context && context instanceof HTMLElement)) { - context = document; - } - return Array.prototype.slice.call(context.querySelectorAll(selector)); -} - /** * Provides units for time, given in hours, as hours or days. * @param {number} time The time, in hours. -- 2.39.5