From: Jo-Philipp Wich Date: Fri, 13 Feb 2015 22:37:12 +0000 (+0100) Subject: luci2.ui: add icon() helper function X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=72f719f15fe4723ef7a7d6ecc0bf2b81abfea6ea;p=project%2Fluci2%2Fui.git luci2.ui: add icon() helper function Signed-off-by: Jo-Philipp Wich --- 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 = $('') + .attr('src', src); + + if (typeof(alt) !== 'undefined') + icon.attr('alt', alt); + + if (typeof(title) !== 'undefined') + icon.attr('title', title); + + return icon; } };