From 72f719f15fe4723ef7a7d6ecc0bf2b81abfea6ea Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 13 Feb 2015 23:37:12 +0100 Subject: [PATCH] luci2.ui: add icon() helper function Signed-off-by: Jo-Philipp Wich --- luci2/htdocs/luci2/ui.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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; } }; -- 2.11.0