2014-07-04 19:28:47 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Refactoring of inline script from index.html.
|
2014-07-09 16:45:44 +00:00
|
|
|
/*global SwaggerUi, log, ApiKeyAuthorization, hljs, window, $ */
|
2014-07-04 19:28:47 +00:00
|
|
|
$(function() {
|
2014-07-09 16:45:44 +00:00
|
|
|
$.getJSON('config.json', function(config) {
|
|
|
|
log(config);
|
|
|
|
loadSwaggerUi(config);
|
|
|
|
});
|
2014-07-04 19:28:47 +00:00
|
|
|
|
2014-07-09 16:45:44 +00:00
|
|
|
var accessToken;
|
|
|
|
function loadSwaggerUi(config) {
|
2014-07-04 19:28:47 +00:00
|
|
|
window.swaggerUi = new SwaggerUi({
|
2014-07-09 16:45:44 +00:00
|
|
|
url: config.url || '/swagger/resources',
|
|
|
|
apiKey: '',
|
|
|
|
dom_id: 'swagger-ui-container',
|
2014-07-04 19:28:47 +00:00
|
|
|
supportHeaderParams: true,
|
|
|
|
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
|
|
|
|
onComplete: function(swaggerApi, swaggerUi) {
|
2014-07-09 16:45:44 +00:00
|
|
|
log('Loaded SwaggerUI');
|
2014-07-04 19:28:47 +00:00
|
|
|
log(swaggerApi);
|
|
|
|
log(swaggerUi);
|
|
|
|
$('pre code').each(function(i, e) {hljs.highlightBlock(e); });
|
|
|
|
},
|
|
|
|
onFailure: function(data) {
|
2014-07-09 16:45:44 +00:00
|
|
|
log('Unable to Load SwaggerUI');
|
2014-07-04 19:28:47 +00:00
|
|
|
log(data);
|
|
|
|
},
|
2014-07-09 16:45:44 +00:00
|
|
|
docExpansion: 'none'
|
2014-07-04 19:28:47 +00:00
|
|
|
});
|
|
|
|
|
2014-07-09 16:45:44 +00:00
|
|
|
$('#explore').click(setAccessToken);
|
|
|
|
$('#api_selector').submit(setAccessToken);
|
|
|
|
$('#input_accessToken').keyup(onInputChange);
|
2014-07-04 19:28:47 +00:00
|
|
|
|
|
|
|
window.swaggerUi.load();
|
2014-07-09 16:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setAccessToken(e) {
|
|
|
|
e.stopPropagation(); // Don't let the default #explore handler fire
|
|
|
|
e.preventDefault();
|
|
|
|
var key = $('#input_accessToken')[0].value;
|
|
|
|
log('key: ' + key);
|
|
|
|
if(key && key.trim() !== '') {
|
|
|
|
log('added accessToken ' + key);
|
|
|
|
window.authorizations.add('key', new ApiKeyAuthorization('accessToken', key, 'query'));
|
|
|
|
accessToken = key;
|
|
|
|
$('.accessTokenDisplay').text('Access Token Set.').addClass('set');
|
|
|
|
$('.accessTokenDisplay').attr('data-tooltip', 'Current Token: ' + key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onInputChange(e) {
|
|
|
|
var el = e.currentTarget;
|
|
|
|
var key = $(e.currentTarget)[0].value;
|
|
|
|
if (!key || key.trim === '') return;
|
|
|
|
if (accessToken !== key) {
|
|
|
|
$('.accessTokenDisplay').text('Access Token changed; submit to confirm.');
|
|
|
|
} else {
|
|
|
|
$('.accessTokenDisplay').text('Access Token Set.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|