The Universal Widget is a simple jQuery plugin used to display collections of objects from a remote API with built-in sorting, filtering, and direction controls.
Requirements:
- jQuery >= 1.6
- Include the
gh-issues-widget.css stylesheet.
To use it, create a div with the class uwidget and initialize it using the .UWidget() method within a jQuery $(document).ready() block.
<html>
<head>
<link href="gh-issues-widget.css" rel="stylesheet">
</head>
<body>
<div class="uwidget" data-width="500px" data-height="300px"></div>
<script type="text/javascript">
$(document).ready(function () {
$('.uwidget').UWidget({
url: 'https://api.url.ext',
handler: function (data) {
// special remote data treatment needed ?
return data;
},
template: 'item_tmpl',
sort: {
enabled: true,
name: 'sort',
values: ['created', 'updated', 'comments'],
labels: ['Creation date', 'Update date', 'Comments']
},
direction: {
enabled: true,
name: 'direction',
values: ['desc', 'asc'],
labels: ['Descending', 'Ascending']
},
filters: {
enabled: true,
name: 'labels',
values: ['bug', 'enhancement'],
labels: ['Bug', 'Enhancement']
}
});
});
</script>
<script type="text/html" id="item_tmpl">
<li>
<span class="gh-issue-comments">
<%= comments %> <%= comments > 1 ? "comments" : "commment" %>
</span>
<span class="gh-issue-title">
<a href="<%= html_url %>"><%= title %></a>
</span>
</li>
</script>
</body>
</html>