luci2.ui: add icon() helper function
[project/luci2/ui.git] / luci2 / htdocs / luci2 / ui.js
index 5ab1ddd..ea08347 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;
                }
        };