luci2.ui: add icon() helper function
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 13 Feb 2015 22:37:12 +0000 (23:37 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Fri, 13 Feb 2015 22:43:19 +0000 (23:43 +0100)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
luci2/htdocs/luci2/ui.js

index 5ab1ddd0bb630243f8204a517af9e69b795474fd..ea083472bcae6eaabefb89da8f11279a2805b8c9 100644 (file)
                                .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;
                }
        };