|
|
@ -8,6 +8,11 @@ |
|
|
|
/** |
|
|
|
* The class provides overreaching options for building the website. |
|
|
|
*/ |
|
|
|
/** |
|
|
|
* The class provides overreaching options for building the website. |
|
|
|
* @property {Array<string>} #functionNames |
|
|
|
* |
|
|
|
*/ |
|
|
|
class PageBuilder { |
|
|
|
#cssClasses; |
|
|
|
#functions; |
|
|
@ -27,6 +32,14 @@ class PageBuilder { |
|
|
|
* Registers a function to be added later in a script tag in the head of the document. |
|
|
|
* @ATTENTION Be careful with intended empty strings (e.g. in variable values), |
|
|
|
* empty strings within the function code will be shrunk. |
|
|
|
/** |
|
|
|
* Registers a function to be added later in a script tag in the head of the document. |
|
|
|
* @ATTENTION Be careful with intended empty strings (e.g. in variable values), |
|
|
|
* empty strings within the function code will be shrunk. |
|
|
|
* @deprecated 'registerFunction' will bew removed. |
|
|
|
* 'registerNamedFunction' will be removed. |
|
|
|
* Use 'registerPageFunction' it fully supports registration/adding of functions. |
|
|
|
* All variations of named, unnamed and reassigned, arrow or brakets notation. |
|
|
|
* @param {string} name |
|
|
|
* @param {function} fun |
|
|
|
*/ |
|
|
@ -36,7 +49,7 @@ class PageBuilder { |
|
|
|
* @param {string} text |
|
|
|
* @returns {string} |
|
|
|
*/ |
|
|
|
function shrinkEmptyStrings(text){ |
|
|
|
function shrinkEmptyStrings(text) { |
|
|
|
for (let i = 1; i < 10; i++) { |
|
|
|
text = text.replaceAll(" ".slice(i), ' '); |
|
|
|
} |
|
|
@ -51,13 +64,13 @@ class PageBuilder { |
|
|
|
); |
|
|
|
let isFuncWritten = clearedFuncText.startsWith('function'); |
|
|
|
let funcHasName = fun.name && fun.name.trim() !== ''; |
|
|
|
if(isFuncWritten){ |
|
|
|
if (isFuncWritten) { |
|
|
|
let isNameInFuncText = clearedFuncText.startsWith(`function ${name}`); |
|
|
|
this.#functions.innerText += (funcHasName && isNameInFuncText |
|
|
|
? clearedFuncText |
|
|
|
: clearedFuncText.replace('function ', 'function '+name) |
|
|
|
)+'; '; |
|
|
|
}else{ |
|
|
|
: clearedFuncText.replace('function ', 'function ' + name) |
|
|
|
) + '; '; |
|
|
|
} else { |
|
|
|
this.#functions.innerText += `const ${name} = ${clearedFuncText}; ` |
|
|
|
} |
|
|
|
this.#functionNames.push(name); |
|
|
@ -65,7 +78,14 @@ class PageBuilder { |
|
|
|
return this; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @deprecated 'registerFunction' will bew removed. |
|
|
|
* 'registerNamedFunction' will be removed. |
|
|
|
* Use 'registerPageFunction' it fully supports registration of functions. |
|
|
|
* All variations of named, unnamed and reassigned, arrow or brakets notation. |
|
|
|
* @param {Function} namedFunction |
|
|
|
* @returns |
|
|
|
*/ |
|
|
|
registerNamedFunction(namedFunction) { |
|
|
|
return this.registerFunction(namedFunction.name, namedFunction) |
|
|
|
} |
|
|
@ -158,6 +178,11 @@ class PageBuilder { |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
|
|
|
|
/** |
|
|
|
* Little helper function. |
|
|
|
* If a single page application is in development. |
|
|
|
* This method sets an autoreload interval for the page. |
|
|
|
* @param {number} relaunchSeconds timeinterval for page to reload (changes) |
|
|
|
*/ |
|
|
|
inDev(relaunchSeconds = 20) { |
|
|
|