diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2015-02-13 23:37:12 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-02-13 23:43:19 +0100 |
commit | 72f719f15fe4723ef7a7d6ecc0bf2b81abfea6ea (patch) | |
tree | ffa0bfec630ad39e351d40436708a11701fc2137 | |
parent | c9f002e803a82692f05b606b60d14795642a43aa (diff) | |
download | luci2-ui-72f719f15fe4723ef7a7d6ecc0bf2b81abfea6ea.tar.gz |
luci2.ui: add icon() helper function
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
-rw-r--r-- | luci2/htdocs/luci2/ui.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/luci2/htdocs/luci2/ui.js b/luci2/htdocs/luci2/ui.js index 5ab1ddd..ea08347 100644 --- a/luci2/htdocs/luci2/ui.js +++ b/luci2/htdocs/luci2/ui.js @@ -733,6 +733,26 @@ .attr('title', title ? title : '') .addClass('btn btn-' + style) .text(label); + }, + + icon: function(src, alt, title) + { + if (!src.match(/\.[a-z]+$/)) + src += '.png'; + + if (!src.match(/^\//)) + src = L.globals.resource + '/icons/' + src; + + var icon = $('<img />') + .attr('src', src); + + if (typeof(alt) !== 'undefined') + icon.attr('alt', alt); + + if (typeof(title) !== 'undefined') + icon.attr('title', title); + + return icon; } }; |