Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

Commit

Permalink
fix jshint problems
Browse files Browse the repository at this point in the history
  • Loading branch information
theopak committed Jan 13, 2017
1 parent c625cb1 commit 94636ee
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 82 deletions.
4 changes: 2 additions & 2 deletions gulpfile.js
Expand Up @@ -9,7 +9,7 @@ var gulpif = require('gulp-if');
var handlebars = require('gulp-handlebars');
var wrap = require('gulp-wrap');
var gulpDeclare = require('gulp-declare');
var iife = require("gulp-iife");
var iife = require('gulp-iife');
var watch = require('gulp-watch');
var connect = require('gulp-connect');
var cleanCSS = require('gulp-clean-css');
Expand Down Expand Up @@ -107,7 +107,7 @@ gulp.task('copy', ['clean'], function() {
}))
.pipe(gulp.dest('./dist'))

gulp.src(['./src/main/html/*.html','./src/main/html/*.json', './src/main/html/images/**'], { "base" : "./src/main/html" })
gulp.src(['./src/main/html/*.html','./src/main/html/*.json', './src/main/html/images/**'], { 'base' : './src/main/html' })
.pipe(gulp.dest('./dist'))
});

Expand Down
102 changes: 55 additions & 47 deletions src/main/javascript/view/MainView.js
Expand Up @@ -25,7 +25,7 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
}
},
initialize: function (opts) {
this.listenTo(Backbone, 'mainview:newBaseUrl', this.render)
this.listenTo(Backbone, 'mainview:newBaseUrl', this.render);
var sorterOption, sorterFn, key, value;
opts = opts || {};

Expand Down Expand Up @@ -62,7 +62,9 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
this.model.auths = [];
this.model.swaggerUrl = window.swaggerUrl;
this.model.baseUrl = window.baseUrl;
if (window.clientId) this.model.clientId = window.clientId;
if (window.clientId) {
this.model.clientId = window.clientId;
}
for (key in this.model.securityDefinitions) {
value = this.model.securityDefinitions[key];

Expand All @@ -73,7 +75,7 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
});
}
// It is markdown if it has less than 6 html like tags
this.model.isMarkdown = this.model.info && this.model.info.description && this.model.info.description.split(/<\/?\S+>/).length < 6
this.model.isMarkdown = this.model.info && this.model.info.description && this.model.info.description.split(/<\/?\S+>/).length < 6;
if (this.model.swaggerVersion === '2.0') {
if ('validatorUrl' in opts.swaggerOptions) {

Expand Down Expand Up @@ -135,8 +137,8 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
}


var n = $(this.el).find("#resources_nav [data-resource]").first();
n.trigger("click");
var n = $(this.el).find('#resources_nav [data-resource]').first();
n.trigger('click');
$(window).scrollTop(0);

return this;
Expand All @@ -163,11 +165,11 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
model: resource,
tagName: 'div',
className: function () {
return i == 0 ? 'active' : ''
return i === 0 ? 'active' : '';
},
attributes: {
"data-resource": 'resource_' + resource.name,
"label": resource.name
'data-resource': 'resource_' + resource.name,
'label': resource.name
},
router: this.router,
swaggerOptions: this.options.swaggerOptions
Expand All @@ -182,11 +184,11 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
model: resource,
tagName: 'div',
className: function () {
return i == 0 ? 'active' : ''
return i === 0 ? 'active' : '';
},
attributes: {
"data-resource": 'resource_' + resource.name,
"label": resource.name
'data-resource': 'resource_' + resource.name,
'label': resource.name
},
router: this.router,
swaggerOptions: this.options.swaggerOptions
Expand All @@ -198,44 +200,48 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
$(this.el).html('');
},

clickSidebarNav: function (e) {
$('.sticky-nav').toggleClass("nav-open")
clickSidebarNav: function () {
$('.sticky-nav').toggleClass('nav-open');
},

clickResource: function (e) {
if (!$(e.target).is(".item")) {
var n = $(e.target).find(".item").first();
$('.sticky-nav').find("[data-resource].active").removeClass("active");
$(e.target).find("[data-resource]").first().addClass("active");
n.trigger("click")
if (!$(e.target).is('.item')) {
var n = $(e.target).find('.item').first();
$('.sticky-nav').find('[data-resource].active').removeClass('active');
$(e.target).find('[data-resource]').first().addClass('active');
n.trigger('click');
}
},

toggleToken: function (e) {
var t = $(".token-generator"),
tg = $("[data-tg-switch]");
toggleToken: function () {
var t = $('.token-generator'),
tg = $('[data-tg-switch]');

t.toggleClass("hide");
t.hasClass("hide") ? tg.removeClass("active") : tg.addClass("active");
t.parents(".sticky-nav").trigger("mobile_nav:update")
t.toggleClass('hide');
if (t.hasClass('hide')) {
tg.removeClass('active');
} else {
tg.addClass('active');
}
t.parents('.sticky-nav').trigger('mobile_nav:update');
},

closeToken: function (e) {
var t = $(".token-generator"),
tg = $("[data-tg-switch]");
closeToken: function () {
var t = $('.token-generator'),
tg = $('[data-tg-switch]');

t.addClass("hide");
tg.removeClass("active");
t.parents(".sticky-nav").trigger("mobile_nav:update")
t.addClass('hide');
tg.removeClass('active');
t.parents('.sticky-nav').trigger('mobile_nav:update');
},

openToken: function (e) {
var t = $(".token-generator"),
tg = $("[data-tg-switch]");
openToken: function () {
var t = $('.token-generator'),
tg = $('[data-tg-switch]');

t.removeClass("hide");
tg.removeClass("active");
t.parents(".sticky-nav").trigger("mobile_nav:update")
t.removeClass('hide');
tg.removeClass('active');
t.parents('.sticky-nav').trigger('mobile_nav:update');
},

showCustom: function(e){
Expand All @@ -250,24 +256,26 @@ SwaggerUi.Views.MainView = Backbone.View.extend({

toggleSamples: function (e) {
function o(t) {
if ("self" === t) {
if ('self' === t) {
var n = $(window).scrollTop();
return $(window).scrollTop(n)
return $(window).scrollTop(n);
}
return $(window).scrollTop(t)
return $(window).scrollTop(t);
}

var r = $("#resources"),
var r = $('#resources'),
n = $(e.currentTarget);

r.toggleClass("samples-collapsed").addClass("is-collapsing");
n.find('.text').text("Collapse samples");
r.hasClass("samples-collapsed") && n.find('.text').text("Show samples");
r.toggleClass('samples-collapsed').addClass('is-collapsing');
n.find('.text').text('Collapse samples');
if (r.hasClass('samples-collapsed')) {
n.find('.text').text('Show samples');
}

setTimeout(function () {
var t = n.parents(".endpoint").first().offset().top;
r.removeClass("is-collapsing");
o(t)
}, 500)
var t = n.parents('.endpoint').first().offset().top;
r.removeClass('is-collapsing');
o(t);
}, 500);
}
});
22 changes: 12 additions & 10 deletions src/main/javascript/view/OperationView.js
Expand Up @@ -160,7 +160,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
sampleJSON: JSON.stringify(value.createJSONSample(), void 0, 2),
isParam: false,
signature: value.getMockSignature(),
type: "Response",
type: 'Response',
id: this.parentId + '_' + this.nickname + '_succes'
};
}
Expand All @@ -170,7 +170,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
sampleJSON: this.model.responseSampleJSON,
isParam: false,
signature: this.model.responseClassSignature,
type: "Response",
type: 'Response',
id: this.parentId + '_' + this.nickname
};
}
Expand All @@ -188,15 +188,15 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
param = ref4[p];
this.addParameter(param, contentTypeModel.consumes);
if (param.paramType === 'body' || param.in === 'body') {
this.addBodyModel(param)
this.addBodyModel(param);
}
}
if (signatureModel) {
responseSignatureView = new SwaggerUi.Views.SignatureView({
model: signatureModel,
router: this.router,
tagName: 'div',
type: "Response",
type: 'Response',
id: this.parentId + '_' + this.nickname + '_response'
});
$('.model-signature', $(this.el)).append(responseSignatureView.render().el);
Expand Down Expand Up @@ -244,13 +244,15 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
},

addBodyModel: function (param) {
if (param.type === 'file') return;
if (param.type === 'file') {
return;
}

var bodySample = {
sampleJSON: param.sampleJSON,
isParam: true,
signature: param.signature,
type: "Body",
type: 'Body',
clickToCopy: true,
id: this.parentId + '_' + this.nickname + '_body'
};
Expand Down Expand Up @@ -352,7 +354,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
}
opts.responseContentType = $('div select[name=responseContentType]', $(this.el)).val();
opts.requestContentType = $('div select[name=parameterContentType]', $(this.el)).val();
$(".submit", $(this.el)).button("loading");
$('.submit', $(this.el)).button('loading');
if (isFileUpload) {
return this.handleFileUpload(map, form);
} else {
Expand Down Expand Up @@ -409,8 +411,8 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({

var clientAuths = window.swaggerUi.api.clientAuthorizations;
if (typeof clientAuths !== 'undefined' && typeof(clientAuths.authz) !== 'undefined') {
_.forEach(clientAuths.authz, function(auth, key) {
if (auth.type == 'header') {
_.forEach(clientAuths.authz, function(auth) {
if (auth.type === 'header') {
headerParams[auth.name] = auth.value;
}
});
Expand Down Expand Up @@ -698,7 +700,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
$('.response_throbber', $(this.el)).hide();
var response_body_el = $('.response_body', $(this.el))[0];

$(".submit", $(this.el)).button("reset");
$('.submit', $(this.el)).button('reset');

// only highlight the response if response is less than threshold, default state is highlight response
var opts = this.options.swaggerOptions;
Expand Down
48 changes: 25 additions & 23 deletions src/main/javascript/view/SidebarHeaderView.js
Expand Up @@ -30,13 +30,13 @@ SwaggerUi.Views.SidebarHeaderView = Backbone.View.extend({
return this;
},

addSidebarItem: function (item, i) {
addSidebarItem: function (item) {
var sidebarItemView = new SwaggerUi.Views.SidebarItemView({
model: item,
tagName: 'div',
className : 'item',
attributes: {
"data-endpoint": item.parentId + '_' + item.nickname
'data-endpoint': item.parentId + '_' + item.nickname
},
router: this.router,
swaggerOptions: this.options.swaggerOptions
Expand All @@ -49,57 +49,59 @@ SwaggerUi.Views.SidebarHeaderView = Backbone.View.extend({
/* @theopak 2016-05-11 NG-4302 */
// console.info(e);
var candidateElement = e.target;
while (candidateElement.parentNode && !candidateElement.hasAttribute("data-endpoint")) {
while (candidateElement.parentNode && !candidateElement.hasAttribute('data-endpoint')) {
candidateElement = candidateElement.parentNode;
// console.info('.');
}
var elem = $(candidateElement);
var eln = $("#" + elem.attr("data-endpoint"));
var eln = $('#' + elem.attr('data-endpoint'));

if (elem.is(".item")) {
scroll(elem.attr("data-endpoint"));
if (elem.is('.item')) {
scroll(elem.attr('data-endpoint'));
setSelected(elem);
updateUrl(eln.find(".path a").first().attr("href"))
updateUrl(eln.find('.path a').first().attr('href'));
}

/* scroll */
function scroll(elem) {
var i = $(".sticky-nav").outerHeight();
var r = $("#" + elem).offset().top - i - 10;
matchMedia() && (r = $("#" + elem).offset().top - 10);
scrollT(r)
var i = $('.sticky-nav').outerHeight();
var r = $('#' + elem).offset().top - i - 10;
if(matchMedia()) {
(r = $('#' + elem).offset().top - 10);
}
scrollT(r);
}

/* set selected value and select operation (class) */
function setSelected(element) {
var nav = $('.sticky-nav [data-navigator]');
{
var nav = $(".sticky-nav [data-navigator]");
$("#" + element.attr("data-endpoint"))
$('#' + element.attr('data-endpoint'));
}
nav.find("[data-resource]").removeClass("active");
nav.find("[data-selected]").removeAttr("data-selected");
element.closest("[data-resource]").addClass("active");
element.attr("data-selected", "");
$(".sticky-nav").find("[data-selected-value]").html(element.text())
nav.find('[data-resource]').removeClass('active');
nav.find('[data-selected]').removeAttr('data-selected');
element.closest('[data-resource]').addClass('active');
element.attr('data-selected', '');
$('.sticky-nav').find('[data-selected-value]').html(element.text());
}

/* update navigation */
function updateUrl(element) {
function updateUrl(/* element */) {
// HACK @theopak 2015-12-30 Commented out bc this is a horrible thing to do
// history.pushState && history.pushState(null, null, element)
}

function matchMedia() {
return window.matchMedia("(min-width: 992px)").matches
return window.matchMedia('(min-width: 992px)').matches;
}

function scrollT(e) {
if ("self" === e) {
if ('self' === e) {
var n = $(window).scrollTop();
return $(window).scrollTop(n)
return $(window).scrollTop(n);
}

return $(window).scrollTop(e)
return $(window).scrollTop(e);
}
}

Expand Down

0 comments on commit 94636ee

Please sign in to comment.