From 94636ee909be65b5336cd9ffa3ad1c0ffbe40e02 Mon Sep 17 00:00:00 2001 From: "Theodore X. Pak" Date: Fri, 13 Jan 2017 16:37:56 -0500 Subject: [PATCH] fix jshint problems --- gulpfile.js | 4 +- src/main/javascript/view/MainView.js | 102 ++++++++++-------- src/main/javascript/view/OperationView.js | 22 ++-- src/main/javascript/view/SidebarHeaderView.js | 48 +++++---- 4 files changed, 94 insertions(+), 82 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 6715907..8b5eeb2 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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'); @@ -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')) }); diff --git a/src/main/javascript/view/MainView.js b/src/main/javascript/view/MainView.js index 7c93105..c242024 100644 --- a/src/main/javascript/view/MainView.js +++ b/src/main/javascript/view/MainView.js @@ -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 || {}; @@ -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]; @@ -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) { @@ -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; @@ -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 @@ -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 @@ -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){ @@ -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); } }); diff --git a/src/main/javascript/view/OperationView.js b/src/main/javascript/view/OperationView.js index dacb766..52df292 100644 --- a/src/main/javascript/view/OperationView.js +++ b/src/main/javascript/view/OperationView.js @@ -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' }; } @@ -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 }; } @@ -188,7 +188,7 @@ 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) { @@ -196,7 +196,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ 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); @@ -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' }; @@ -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 { @@ -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; } }); @@ -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; diff --git a/src/main/javascript/view/SidebarHeaderView.js b/src/main/javascript/view/SidebarHeaderView.js index f22d621..93a63ca 100644 --- a/src/main/javascript/view/SidebarHeaderView.js +++ b/src/main/javascript/view/SidebarHeaderView.js @@ -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 @@ -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); } }