Skip to content

Commit f4d7251

Browse files
📝 Add docstrings to inline
Docstrings generation was requested by @dotpipe. * #3 (comment) The following files were modified: * `API/dotpipe.js` * `activeMenu/dotpipe.js` * `addons/dotpipe.js` * `bridge/dotpipe.js` * `carousel/dotpipe.js` * `cart/dotpipe.js` * `columns/dotpipe.js` * `csv-test/dotpipe.js` * `doted/dotpipe.js` * `dotpipe.js` * `guitar/dotpipe.js` * `inline/dotpipe.js` * `landing/dotpipe.js` * `login/dotpipe.js` * `tree-view/dotpipe.js`
1 parent 8986a1b commit f4d7251

15 files changed

Lines changed: 1605 additions & 105 deletions

File tree

API/dotpipe.js

Lines changed: 128 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5356,12 +5356,38 @@ function escapeHtml(html) {
53565356
}
53575357

53585358
/**
5359-
*
5360-
* @param {JSON Object} value
5361-
* @param {string} tempTag
5362-
* @param {} root
5363-
* @param {*} id
5364-
* @returns HTML Object
5359+
* Render a JSON-defined UI fragment into a DOM container.
5360+
*
5361+
* Given a JSON "template" object, creates DOM nodes described by the object's keys
5362+
* and appends them into the provided container (tempTag). Supports nested objects,
5363+
* common presentation keys and helper directives used by the framework:
5364+
* - tagname / tagName: element tag to create (defaults to "div")
5365+
* - header: object rendered via modalaHead (also injects a CSP meta tag)
5366+
* - buttons: array of button definitions (text/value/attributes)
5367+
* - sources: semicolon-separated sources for cards/carousels (img/audio/video/html/php)
5368+
* - css / js: external asset URLs to inject as <link> / <script>
5369+
* - html / php: URL to fetch and insert as HTML (fetched asynchronously)
5370+
* - select / options: create <select> and populate <option> elements
5371+
* - br: numeric count of <br> elements to insert
5372+
* - style: CSS text for the element
5373+
* - textcontent / innerhtml / innertext: content setters (newlines converted to <br>)
5374+
* - boxes / id / index and arbitrary attributes are applied where appropriate
5375+
*
5376+
* This function mutates the DOM: it appends created elements to tempTag (or the
5377+
* element referenced by tempTag if an id string is passed), may append a CSP meta
5378+
* tag when header is present, and triggers domContentLoad() after insertion.
5379+
*
5380+
* @param {Object} value - JSON template describing the element and its children.
5381+
* Keys and supported directives are documented above.
5382+
* @param {HTMLElement|string} tempTag - Container element or the id of a container
5383+
* to append generated content into.
5384+
* @param {HTMLElement} [root] - Optional root element used for header processing;
5385+
* defaults to tempTag when omitted.
5386+
* @param {*} [id] - Optional identifier passed through to nested processing (unused
5387+
* by most templates).
5388+
* @returns {HTMLElement|undefined} The container element (tempTag as an HTMLElement)
5389+
* after appending the generated content, or
5390+
* undefined if required inputs are missing.
53655391
*/
53665392
function modala(value, tempTag, root, id) {
53675393
if (typeof (tempTag) == "string") {
@@ -5798,6 +5824,21 @@ function fileOrder(elem) {
57985824
}
57995825

58005826

5827+
/**
5828+
* Parse an HTML string and convert the first top-level element into a JSON-like tree.
5829+
*
5830+
* The returned object represents the element structure with these fields:
5831+
* - tagName: lower-cased tag name (e.g., "div")
5832+
* - attributes: an object mapping attribute names to values
5833+
* - children: an array of child nodes where element children are nested objects (same shape)
5834+
* and text nodes are represented as { type: 'text', content: '...' }.
5835+
*
5836+
* Only the first child of the parsed document body is converted (i.e., the top-level element
5837+
* produced by parsing `htmlString`). Empty text nodes are skipped.
5838+
*
5839+
* @param {string} htmlString - HTML markup to parse (must contain at least one top-level element).
5840+
* @returns {{tagName: string, attributes: Object<string,string>, children: Array<Object>|Array>} A JSON-like representation of the first top-level element.
5841+
*/
58015842
function htmlToJson(htmlString) {
58025843
const parser = new DOMParser();
58035844
const doc = parser.parseFromString(htmlString, 'text/html');
@@ -5833,9 +5874,31 @@ function htmlToJson(htmlString) {
58335874
}
58345875
// Helpers to track which elements have pipe listeners
58355876
const pipeListenersSet = new WeakSet();
5877+
/**
5878+
* Check whether an element is already registered in the internal set of pipe listeners.
5879+
* @param {Element} elem - DOM element to test.
5880+
* @returns {boolean} True if the element is present in the pipe listeners set.
5881+
*/
58365882
function hasPipeListener(elem) { return pipeListenersSet.has(elem); }
5883+
/**
5884+
* Mark a DOM element as having a pipe listener attached so it won't be re-registered.
5885+
* @param {Element} elem - The element to mark (typically a pipe-related element).
5886+
*/
58375887
function markPipeListener(elem) { pipeListenersSet.add(elem); }
58385888

5889+
/**
5890+
* Attaches global pipe listeners and processes CSV-for-each elements under a root node.
5891+
*
5892+
* Adds capturing listeners for 'click' and custom 'inline' events on the provided root element. When an event
5893+
* targets an element that is eligible (has the 'mouse' class or an id) and hasn't already been wired, the element
5894+
* is marked as having a pipe listener, passed through the `pipes` processor, and—if it has an `inline` attribute—
5895+
* registered in `dotPipe.matrix` and executed via `dotPipe.runInline`.
5896+
*
5897+
* Additionally, scans for `<csv-foreach>` elements within the root and invokes `processCsvForeach` for any
5898+
* unprocessed instances, marking them with the `processed` class to avoid duplicate work.
5899+
*
5900+
* @param {Document|Element} [rootElem=document] - Root node to attach listeners to and to scan for `<csv-foreach>` elements.
5901+
*/
58395902
function addPipe(rootElem = document) {
58405903
// Global listeners for clicks or custom 'inline' events
58415904
['click', 'inline'].forEach(eventType => {
@@ -5898,7 +5961,15 @@ function addPipe(rootElem = document) {
58985961
// }
58995962
// });
59005963

5901-
// }
5964+
/**
5965+
* Ensure an element has a click handler that invokes the pipe dispatcher and then triggers a DOM re-scan.
5966+
*
5967+
* Attaches a click listener to the provided element that calls pipes(elem). Attempts to remove a previous click listener first
5968+
* (note: removal relies on identical function reference). After wiring the listener, calls domContentLoad(true) to reprocess
5969+
* dynamic/custom tags within the document.
5970+
*
5971+
* @param {Element} elem - The DOM element to bind the click handler to; nothing is done if the element has no id.
5972+
*/
59025973

59035974
function flashClickListener(elem) {
59045975
if (elem.id) {
@@ -5952,6 +6023,22 @@ function sortNodesByName(selector) {
59526023
}
59536024

59546025

6026+
/**
6027+
* Execute a set of declarative UI actions described by an element's attributes and classes.
6028+
*
6029+
* Inspects the provided DOM element for dotPipe-specific attributes and class markers (e.g., `ajax`, `modal`, `inline`, `insert`, `query`, `headers`, `download`, `clear-node`, `turn`, `x-toggle`, `set`, `get`, `remove`, carousel controls, redirect, etc.) and performs the corresponding side-effectful operations:
6030+
* - Triggers registered callbacks and inline macros.
6031+
* - Performs navigation/AJAX loads via `navigate` for `ajax` attributes (supports multiple `file:target:limit` parts).
6032+
* - Opens links or modals, starts/stops carousels, rotates lists, toggles classes, sets/removes attributes, clears or removes nodes, and initiates downloads.
6033+
* - Parses `query` and `headers` attributes into request data used by AJAX navigation.
6034+
* - Honors `disabled`, `clear-node`, and `redirect` semantics and returns early when appropriate.
6035+
*
6036+
* Most actions mutate the DOM, initiate network requests, or trigger other global behaviors; this function does not return a value.
6037+
*
6038+
* @param {Element} elem - The element whose attributes/classes define the actions to perform.
6039+
* @param {boolean} [stop=false] - Reserved/unused in current implementation; callers may pass true to indicate higher-level flow control (no effect here).
6040+
* @returns {void}
6041+
*/
59556042
function pipes(elem, stop = false) {
59566043

59576044
var query = "";
@@ -6237,6 +6324,40 @@ function displayColoredJson(elementId, jsonObj) {
62376324
document.getElementById(elementId).innerHTML = `<pre>${prettyHtml}</pre>`;
62386325
}
62396326

6327+
/**
6328+
* Send an AJAX request using an element's `ajax` attribute and insert or render the response
6329+
* according to the element's CSS classes (JSON, HTML, plain text, tree view, modala, etc.).
6330+
*
6331+
* The function builds a query string by combining `query` with any form-encoded data returned
6332+
* by `formAJAX(elem, classname)` when `classname` matches elements on the page, encodes it,
6333+
* applies request options via `setAJAXOpts`, then performs an XMLHttpRequest to
6334+
* `elem.getAttribute("ajax") + "?" + encodedQuery`. Response handling branches by the
6335+
* element's classes:
6336+
* - `strict-json` — validates response is JSON and replaces document.body with it.
6337+
* - `json` — parses JSON, calls `displayColoredJson(insertId, parsed)`, and writes pretty JSON
6338+
* to the element referenced by `insert` (if present).
6339+
* - `text-html` — writes response as innerHTML into the element referenced by `insert`.
6340+
* - `plain-text` — writes response as textContent into the element referenced by `insert`.
6341+
* - `tree-view` — parses JSON and calls `renderTree(parsed, targetElement)`.
6342+
* - `modala` — parses JSON and renders via `modala()` into the `insert` target; supports
6343+
* multi-box behavior controlled by `boxes` and `modala-multi-first` / `modala-multi-last`.
6344+
* - default — writes response HTML into the element referenced by `insert` if present.
6345+
*
6346+
* After inserting or rendering content the function invokes `domContentLoad()` and
6347+
* `flashClickListener(elem)` to initialize processed content and UI behavior.
6348+
*
6349+
* Note: this function mutates the DOM and logs warnings when required `insert` targets are missing.
6350+
*
6351+
* @param {Element} elem - The source element; must have an `ajax` attribute with the request URL,
6352+
* and may include classes (e.g., `json`, `text-html`, `modala`) and an
6353+
* `insert` attribute naming the target element id for inserted content.
6354+
* @param {Map|Object|null} [opts=null] - Optional request option container; will be normalized via
6355+
* `setAJAXOpts`. (Internal option handling; callers rarely need to set this.)
6356+
* @param {string} [query=""] - Query string fragment to append to the request URL; additional form
6357+
* data may be appended from elements matching `classname`.
6358+
* @param {string} [classname=""] - If non-empty and matching elements exist, `formAJAX(elem, classname)`
6359+
* is used to collect and append form-encoded data to `query`.
6360+
*/
62406361
function navigate(elem, opts = null, query = "", classname = "") {
62416362
//formAJAX at the end of this line
62426363
// console.log(elem);

activeMenu/dotpipe.js

Lines changed: 111 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5356,12 +5356,31 @@ function escapeHtml(html) {
53565356
}
53575357

53585358
/**
5359-
*
5360-
* @param {JSON Object} value
5361-
* @param {string} tempTag
5362-
* @param {} root
5363-
* @param {*} id
5364-
* @returns HTML Object
5359+
* Render a JSON-described UI node into a target DOM container.
5360+
*
5361+
* Processes a JSON "modal" descriptor (hierarchical object with keys like
5362+
* tagname, header, css, js, html, php, buttons, sources, select/options,
5363+
* textcontent/innerhtml/innertext, style, and arbitrary attributes), creates
5364+
* corresponding DOM nodes, appends them to the provided target, and triggers
5365+
* post-processing for any newly inserted dotPipe elements.
5366+
*
5367+
* This function has side effects: it appends created elements (and any fetched
5368+
* HTML/CSS/JS resources) into the DOM, may inject a CSP <meta> when a
5369+
* header object is present, performs fetches for external html/php sources,
5370+
* and calls domContentLoad() after insertion.
5371+
*
5372+
* @param {Object} value - JSON descriptor for the element to create. Expected
5373+
* properties include `tagname` (or `tagName`), `header`, `buttons`, `sources`,
5374+
* `css`, `js`, `html`, `php`, `select`/`options`, `textcontent`/`innerhtml`/`innertext`,
5375+
* `style`, and arbitrary attributes. Nested objects are rendered recursively.
5376+
* @param {string|HTMLElement} tempTag - Target container element or the id of
5377+
* the target element to which the rendered node will be appended.
5378+
* @param {HTMLElement} [root] - Optional root element used for header processing;
5379+
* if omitted it defaults to the resolved tempTag.
5380+
* @param {*} [id] - Optional identifier passed through to nested processing (not
5381+
* required for typical use).
5382+
* @returns {HTMLElement|undefined} The target container (tempTag) after appending
5383+
* the rendered content, or undefined if required inputs are missing or invalid.
53655384
*/
53665385
function modala(value, tempTag, root, id) {
53675386
if (typeof (tempTag) == "string") {
@@ -5798,6 +5817,19 @@ function fileOrder(elem) {
57985817
}
57995818

58005819

5820+
/**
5821+
* Parse an HTML string and return a JSON representation of its first top-level element.
5822+
*
5823+
* The returned object describes the element tree with these keys:
5824+
* - tagName: lowercase tag name
5825+
* - attributes: map of attribute names to values
5826+
* - children: array of child nodes; element children are similar objects, text nodes are
5827+
* represented as { type: 'text', content: '...' } (whitespace-only text nodes are omitted)
5828+
*
5829+
* @param {string} htmlString - HTML fragment or document to parse.
5830+
* @return {object|null} JSON representation of the first element found in the parsed HTML body,
5831+
* or null if no element is present.
5832+
*/
58015833
function htmlToJson(htmlString) {
58025834
const parser = new DOMParser();
58035835
const doc = parser.parseFromString(htmlString, 'text/html');
@@ -5833,9 +5865,34 @@ function htmlToJson(htmlString) {
58335865
}
58345866
// Helpers to track which elements have pipe listeners
58355867
const pipeListenersSet = new WeakSet();
5868+
/**
5869+
* Check whether a DOM element is registered as a pipe listener.
5870+
*
5871+
* @param {Element} elem - The DOM element to check.
5872+
* @return {boolean} True if the element is registered in the internal pipeListenersSet, otherwise false.
5873+
*/
58365874
function hasPipeListener(elem) { return pipeListenersSet.has(elem); }
5875+
/**
5876+
* Mark an element as processed for pipe listeners so it won't be registered again.
5877+
* @param {Element} elem - The DOM element to mark as having pipe listeners attached.
5878+
*/
58375879
function markPipeListener(elem) { pipeListenersSet.add(elem); }
58385880

5881+
/**
5882+
* Install event listeners and initialize per-root dynamic handlers for dotPipe elements.
5883+
*
5884+
* Attaches capture-phase listeners for "click" and custom "inline" events on the provided root (default: document).
5885+
* When an event originates from an unprocessed element that either has class "mouse" or an id, this will:
5886+
* - mark the element as having a pipe listener,
5887+
* - invoke pipes(target) to perform standard pipe processing,
5888+
* - if the element has an `inline` attribute, ensure a dotPipe.matrix entry for it and run dotPipe.runInline for that entry.
5889+
*
5890+
* Additionally scans the root for <csv-foreach> elements and runs processCsvForeach on any not already processed, marking them with the "processed" class.
5891+
*
5892+
* Note: This function mutates global state (adds listeners, updates dotPipe.matrix, and may fetch/insert content via pipes/runInline).
5893+
*
5894+
* @param {Element|Document} [rootElem=document] - Root element under which listeners are attached and child custom tags are initialized.
5895+
*/
58395896
function addPipe(rootElem = document) {
58405897
// Global listeners for clicks or custom 'inline' events
58415898
['click', 'inline'].forEach(eventType => {
@@ -5898,7 +5955,14 @@ function addPipe(rootElem = document) {
58985955
// }
58995956
// });
59005957

5901-
// }
5958+
/**
5959+
* Ensure an element runs the pipe processing on click and refreshes dotPipe processing.
5960+
*
5961+
* If the provided element has an `id`, a click listener is attached that calls `pipes(elem)` when clicked.
5962+
* After (re)binding, `domContentLoad(true)` is invoked to (re)process dotPipe-supported elements.
5963+
*
5964+
* @param {HTMLElement} elem - The target element; must be a DOM element (typically with an `id`) to receive the click binding.
5965+
*/
59025966

59035967
function flashClickListener(elem) {
59045968
if (elem.id) {
@@ -5952,6 +6016,24 @@ function sortNodesByName(selector) {
59526016
}
59536017

59546018

6019+
/**
6020+
* Process a custom dotPipe element and perform its configured actions (AJAX loads, navigation, modal rendering, DOM mutations, downloads, carousel controls, toggles, attribute ops, etc.).
6021+
*
6022+
* This inspects attributes and classes on the provided element and executes the corresponding behavior:
6023+
* - Triggers callback functions named by the `callback` attribute.
6024+
* - Performs navigation/AJAX loads when `ajax` is present (may call `navigate` or create cloned loaders).
6025+
* - Opens links for `<lnk>` elements, triggers downloads for elements with class `download`.
6026+
* - Handles modal lists via `modal` and carousel controls / stepping via carousel-related classes.
6027+
* - Applies simple DOM operations driven by attributes: `display`, `turn`, `x-toggle`, `set`, `get`, `delete`, `remove`, `headers`, `query`, `form-class`, `file-order`, and `clear-node`.
6028+
* - Invokes dotPipe inline macro registration/run when encountering inline content during `turn` processing.
6029+
* - Early-returns for disabled elements or after actions that replace responsibility (e.g., carousel start, download, redirect).
6030+
*
6031+
* Note: The function mutates the DOM, may call global helpers (dotPipe, navigate, modalList, shiftFilesLeft/Right, carousel, fileOrder, etc.), and may change window.location. It does not return a value.
6032+
*
6033+
* @param {HTMLElement} elem - The element to process; expected to be a custom dotPipe tag or decorated element.
6034+
* @param {boolean} [stop=false] - Optional flag (currently unused) reserved for future control of processing flow.
6035+
* @returns {void}
6036+
*/
59556037
function pipes(elem, stop = false) {
59566038

59576039
var query = "";
@@ -6237,6 +6319,28 @@ function displayColoredJson(elementId, jsonObj) {
62376319
document.getElementById(elementId).innerHTML = `<pre>${prettyHtml}</pre>`;
62386320
}
62396321

6322+
/**
6323+
* Send an AJAX request built from an element's `ajax` attribute and injects the response into the DOM.
6324+
*
6325+
* Builds a query string (optionally augmented by formAJAX when `classname` matches), encodes it,
6326+
* applies AJAX options via setAJAXOpts, issues an XMLHttpRequest to the URL from the element's
6327+
* `ajax` attribute, and handles the response according to classes on the element:
6328+
* - `strict-json`: replaces document.body with the raw JSON response if it's valid JSON.
6329+
* - `json`: pretty-prints JSON into the target `insert` element and calls domContentLoad.
6330+
* - `text-html`: inserts response as HTML into the `insert` element.
6331+
* - `plain-text`: inserts response as text into the `insert` element.
6332+
* - `tree-view`: parses JSON and renders it via renderTree into the element with elem.id.
6333+
* - `modala`: parses JSON and renders modala content into the element named by `insert`, supporting multi-box behavior.
6334+
* - default: injects raw response into the `insert` element when no special class or callback is present.
6335+
*
6336+
* Side effects: performs network request, mutates DOM (inserts/replaces content), calls domContentLoad()
6337+
* and flashClickListener(), and may log warnings for missing `insert` targets.
6338+
*
6339+
* @param {Element} elem - The source element containing attributes that control navigation (must have an `ajax` attribute; optional `insert`, and behavior-driving CSS classes).
6340+
* @param {Map|Object|null} [opts=null] - AJAX option container passed to setAJAXOpts (method, headers, mode, etc.). If null, defaults are applied.
6341+
* @param {string} [query=""] - Additional query string to append to the request URL (will be URI-encoded).
6342+
* @param {string} [classname=""] - If non-empty, formAJAX(elem, classname) will be called and its output appended to the query string.
6343+
*/
62406344
function navigate(elem, opts = null, query = "", classname = "") {
62416345
//formAJAX at the end of this line
62426346
// console.log(elem);

0 commit comments

Comments
 (0)