luci-base: add L.media() URL construction helper
authorJo-Philipp Wich <jo@mein.io>
Tue, 28 Jan 2020 10:14:15 +0000 (11:14 +0100)
committerJo-Philipp Wich <jo@mein.io>
Tue, 28 Jan 2020 10:15:21 +0000 (11:15 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit b60b4790d1b1b8d52657c0c9ba91da86d0b8a28d)

modules/luci-base/htdocs/luci-static/resources/luci.js
modules/luci-base/luasrc/view/header.htm

index 808ab0c5cb2a3e25020539125fde4ba190890547..b281da5e5c0275786bea0b483c6e3ff8f7df5b23 100644 (file)
                        return this.path(this.env.resource, arguments);
                },
 
+               /**
+                * Construct an URL path relative to the media resource path of the
+                * LuCI ui (usually `/luci-static/$theme_name`).
+                *
+                * The resulting URL is guaranteed to only contain the characters
+                * `a-z`, `A-Z`, `0-9`, `_`, `.`, `%`, `,`, `;`, and `-` as well
+                * as `/` for the path separator.
+                *
+                * @instance
+                * @memberof LuCI
+                *
+                * @param {string[]} [parts]
+                * An array of parts to join into an URL path. Parts may contain
+                * slashes and any of the other characters mentioned above.
+                *
+                * @return {string}
+                * Returns the resulting URL path.
+                */
+               media: function() {
+                       return this.path(this.env.media, arguments);
+               },
+
                /**
                 * Return the complete URL path to the current view.
                 *
index 1ef0e5b01300359593a4daaa46b55ada974f6ce7..08911c7f5ba5b9c1af52bbc232d665f30fc826e2 100644 (file)
@@ -18,6 +18,7 @@
 <script type="text/javascript">
        L = new LuCI(<%= luci.http.write_json({
                token          = token,
+               media          = media,
                resource       = resource,
                scriptname     = luci.http.getenv("SCRIPT_NAME"),
                pathinfo       = luci.http.getenv("PATH_INFO"),