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:14:42 +0000 (11:14 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/luci.js
modules/luci-base/luasrc/view/header.htm

index 3a8c6b4b17b0dec6aa4584dec03ef552e84d14af..3b861bfc186f63803c284c3ee0dbabe873777095 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 6f7f0e48e7e421d4f6605f9cdd725400b2a677f0..fbede8ff57407f487ca7147551f1a2e3e86b685e 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"),