Skip to content

Instantly share code, notes, and snippets.

@soulim
Last active August 29, 2015 14:21
Show Gist options
  • Save soulim/d33e50609e549458f9b5 to your computer and use it in GitHub Desktop.
Save soulim/d33e50609e549458f9b5 to your computer and use it in GitHub Desktop.
var initStatus = function (components) {
var content = '',
allGood = true;
// Iterate over all components from Cachet API response and build
// HTML code for popover window.
//
// One component is represened with its name and state icon.
//
// Example:
//
// <div>
// <span class="glyphicon glyphicon-ok-sign text-success"></span>
// Multiposting API
// </div>
for (var i = 0; i < components.length; i++) {
content += '<div>';
if (components[i].status === 'operational') {
content += '<span class="glyphicon glyphicon-ok-sign text-success"></span>';
} else {
content += '<span class="glyphicon glyphicon-exclamation-sign text-danger"></span>';
}
content += ' ' + components[i].name;
content += '</div>';
if (components[i].status !== 'operational') {
allGood = false;
}
}
var status = $('#popover-example'),
icon = $('#popover-example > span.glyphicon');
// Set status icon state
icon.removeClass('glyphicon-question-sign')
.toggleClass('glyphicon-ok-sign text-success', allGood)
.toggleClass('glyphicon-exclamation-sign text-danger', !allGood);
// Set content of the popover window and activate it
status.data('content', content)
.popover({ trigger: 'hover focus', html: true });
};
new CachetStatus('https://status.gohiring.com', initStatus);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment