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-11-10 10:11:25 +00:00
|
|
|
var lsKey = 'swagger_accessToken';
|
2014-07-09 16:45:44 +00:00
|
|
|
$.getJSON('config.json', function(config) {
|
2014-11-10 10:11:25 +00:00
|
|
|
log(config);
|
|
|
|
loadSwaggerUi(config);
|
2014-07-09 16:45:44 +00:00
|
|
|
});
|
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-10-07 09:07:41 +00:00
|
|
|
docExpansion: 'none',
|
2014-10-07 09:12:47 +00:00
|
|
|
highlightSizeThreshold: 16384,
|
|
|
|
sorter: 'alpha'
|
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
|
|
|
|
2014-11-10 10:11:25 +00:00
|
|
|
// Recover accessToken from localStorage if present.
|
|
|
|
if (window.localStorage) {
|
|
|
|
var key = window.localStorage.getItem(lsKey);
|
|
|
|
if (key) {
|
|
|
|
$('#input_accessToken').val(key).submit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2014-07-14 20:40:05 +00:00
|
|
|
window.authorizations.add('key', new ApiKeyAuthorization('access_token', key, 'query'));
|
2014-07-09 16:45:44 +00:00
|
|
|
accessToken = key;
|
2014-07-09 17:03:34 +00:00
|
|
|
$('.accessTokenDisplay').text('Token Set.').addClass('set');
|
2014-07-09 16:45:44 +00:00
|
|
|
$('.accessTokenDisplay').attr('data-tooltip', 'Current Token: ' + key);
|
2014-11-10 10:11:25 +00:00
|
|
|
|
|
|
|
// Save this token to localStorage if we can to make it persist on refresh.
|
|
|
|
if (window.localStorage) {
|
|
|
|
window.localStorage.setItem(lsKey, key);
|
|
|
|
}
|
2014-07-09 16:45:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onInputChange(e) {
|
|
|
|
var el = e.currentTarget;
|
|
|
|
var key = $(e.currentTarget)[0].value;
|
|
|
|
if (!key || key.trim === '') return;
|
|
|
|
if (accessToken !== key) {
|
2014-07-09 17:03:34 +00:00
|
|
|
$('.accessTokenDisplay').text('Token changed; submit to confirm.');
|
2014-07-09 16:45:44 +00:00
|
|
|
} else {
|
2014-07-09 17:03:34 +00:00
|
|
|
$('.accessTokenDisplay').text('Token Set.');
|
2014-07-09 16:45:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|