fixes opening url in new tab only in description

This commit is contained in:
bodnia
2016-03-19 10:07:22 +02:00
parent 7a328ba9ad
commit 9c509e5cad
4 changed files with 913 additions and 820 deletions

1689
dist/swagger-ui.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -14,7 +14,6 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
this.router = opts.router; this.router = opts.router;
document.addEventListener('click', this.onLinkClick, true);
// Sort APIs // Sort APIs
if (opts.swaggerOptions.apisSorter) { if (opts.swaggerOptions.apisSorter) {
sorterOption = opts.swaggerOptions.apisSorter; sorterOption = opts.swaggerOptions.apisSorter;
@@ -84,6 +83,12 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
render: function () { render: function () {
$(this.el).html(Handlebars.templates.main(this.model)); $(this.el).html(Handlebars.templates.main(this.model));
this.info = this.$('.info')[0];
if (this.info) {
this.info.addEventListener('click', this.onLinkClick, true);
}
this.model.securityDefinitions = this.model.securityDefinitions || {}; this.model.securityDefinitions = this.model.securityDefinitions || {};
// Render each resource // Render each resource
@@ -136,11 +141,10 @@ SwaggerUi.Views.MainView = Backbone.View.extend({
onLinkClick: function (e) { onLinkClick: function (e) {
var el = e.target; var el = e.target;
if (el.tagName === 'A' && el.href) {
if (location.hostname !== el.hostname || location.port !== el.port) { if (el.tagName === 'A' && el.href && !el.target) {
e.preventDefault(); e.preventDefault();
window.open(el.href, '_blank'); window.open(el.href, '_blank');
} }
} }
}
}); });

View File

@@ -6,11 +6,11 @@
<p>{{externalDocs.description}}</p> <p>{{externalDocs.description}}</p>
<a href="{{externalDocs.url}}" target="_blank">{{externalDocs.url}}</a> <a href="{{externalDocs.url}}" target="_blank">{{externalDocs.url}}</a>
{{/if}} {{/if}}
{{#if info.termsOfServiceUrl}}<div class="info_tos"><a href="{{info.termsOfServiceUrl}}" data-sw-translate>Terms of service</a></div>{{/if}} {{#if info.termsOfServiceUrl}}<div class="info_tos"><a target="_blank" href="{{info.termsOfServiceUrl}}" data-sw-translate>Terms of service</a></div>{{/if}}
{{#if info.contact.name}}<div class='info_name' data-sw-translate>Created by {{info.contact.name}}</div>{{/if}} {{#if info.contact.name}}<div class='info_name' data-sw-translate>Created by {{info.contact.name}}</div>{{/if}}
{{#if info.contact.url}}<div class='info_url' data-sw-translate>See more at <a href="{{info.contact.url}}">{{info.contact.url}}</a></div>{{/if}} {{#if info.contact.url}}<div class='info_url' data-sw-translate>See more at <a href="{{info.contact.url}}">{{info.contact.url}}</a></div>{{/if}}
{{#if info.contact.email}}<div class='info_email'><a target="_parent" href="mailto:{{info.contact.email}}?subject={{info.title}}" data-sw-translate>Contact the developer</a></div>{{/if}} {{#if info.contact.email}}<div class='info_email'><a target="_parent" href="mailto:{{info.contact.email}}?subject={{info.title}}" data-sw-translate>Contact the developer</a></div>{{/if}}
{{#if info.license}}<div class='info_license'><a href='{{info.license.url}}'>{{info.license.name}}</a></div>{{/if}} {{#if info.license}}<div class='info_license'><a target="_blank" href='{{info.license.url}}'>{{info.license.name}}</a></div>{{/if}}
{{/if}} {{/if}}
</div> </div>
<div class='container' id='resources_container'> <div class='container' id='resources_container'>
@@ -24,7 +24,7 @@
, <span style="font-variant: small-caps" data-sw-translate>api version</span>: {{info.version}} , <span style="font-variant: small-caps" data-sw-translate>api version</span>: {{info.version}}
{{/if}}] {{/if}}]
{{#if validatorUrl}} {{#if validatorUrl}}
<span style="float:right"><a href="{{validatorUrl}}/debug?url={{url}}"><img id="validator" src="{{validatorUrl}}?url={{url}}"></a> <span style="float:right"><a target="_blank" href="{{validatorUrl}}/debug?url={{url}}"><img id="validator" src="{{validatorUrl}}?url={{url}}"></a>
</span> </span>
{{/if}} {{/if}}
</h4> </h4>