Skip to content

Commit 7b3b706

Browse files
committed
Merge pull request #543 from STRML/fixInlineEvents
Remove inline event handlers from resource template.
2 parents 9b0aa32 + 7a91117 commit 7b3b706

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

dist/swagger-ui.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,11 +1081,11 @@ function program1(depth0,data) {
10811081
if (stack1 = helpers.id) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
10821082
else { stack1 = depth0.id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
10831083
buffer += escapeExpression(stack1)
1084-
+ "' onclick=\"Docs.toggleEndpointListForResource('";
1084+
+ "' class=\"toggleEndpointList\" data-id=\"";
10851085
if (stack1 = helpers.id) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
10861086
else { stack1 = depth0.id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
10871087
buffer += escapeExpression(stack1)
1088-
+ "');\">";
1088+
+ "\">";
10891089
if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
10901090
else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
10911091
buffer += escapeExpression(stack1)
@@ -1106,19 +1106,19 @@ function program1(depth0,data) {
11061106
if (stack1 = helpers.id) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
11071107
else { stack1 = depth0.id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
11081108
buffer += escapeExpression(stack1)
1109-
+ "'\n onclick=\"Docs.toggleEndpointListForResource('";
1109+
+ "' class=\"toggleEndpointList\" data-id=\"";
11101110
if (stack1 = helpers.id) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
11111111
else { stack1 = depth0.id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
11121112
buffer += escapeExpression(stack1)
1113-
+ "');\">Show/Hide</a>\n </li>\n <li>\n <a href='#' onclick=\"Docs.collapseOperationsForResource('";
1113+
+ "\">Show/Hide</a>\n </li>\n <li>\n <a href='#' class=\"collapseResource\" data-id=\"";
11141114
if (stack1 = helpers.id) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
11151115
else { stack1 = depth0.id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
11161116
buffer += escapeExpression(stack1)
1117-
+ "'); return false;\">\n List Operations\n </a>\n </li>\n <li>\n <a href='#' onclick=\"Docs.expandOperationsForResource('";
1117+
+ "\">\n List Operations\n </a>\n </li>\n <li>\n <a href='#' class=\"expandResource\" data-id=";
11181118
if (stack1 = helpers.id) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
11191119
else { stack1 = depth0.id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
11201120
buffer += escapeExpression(stack1)
1121-
+ "'); return false;\">\n Expand Operations\n </a>\n </li>\n <li>\n <a href='";
1121+
+ ">\n Expand Operations\n </a>\n </li>\n <li>\n <a href='";
11221122
if (stack1 = helpers.url) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
11231123
else { stack1 = depth0.url; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
11241124
buffer += escapeExpression(stack1)
@@ -1537,6 +1537,9 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
15371537
operation.parentId = this.model.id;
15381538
this.addOperation(operation);
15391539
}
1540+
$('.toggleEndpointList', this.el).click(this.callDocs.bind(this, 'toggleEndpointListForResource'));
1541+
$('.collapseResource', this.el).click(this.callDocs.bind(this, 'collapseOperationsForResource'));
1542+
$('.expandResource', this.el).click(this.callDocs.bind(this, 'expandOperationsForResoruce'));
15401543
return this;
15411544
};
15421545

@@ -1553,6 +1556,11 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
15531556
return this.number++;
15541557
};
15551558

1559+
ResourceView.prototype.callDocs = function(fnName, e) {
1560+
e.preventDefault();
1561+
return Docs[fnName](e.currentTarget.getAttribute('data-id'));
1562+
};
1563+
15561564
return ResourceView;
15571565

15581566
})(Backbone.View);

dist/swagger-ui.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/coffeescript/view/ResourceView.coffee

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ class ResourceView extends Backbone.View
2020
operation.nickname = id
2121
operation.parentId = @model.id
2222
@addOperation operation
23-
@
23+
24+
$('.toggleEndpointList', @el).click(this.callDocs.bind(this, 'toggleEndpointListForResource'))
25+
$('.collapseResource', @el).click(this.callDocs.bind(this, 'collapseOperationsForResource'))
26+
$('.expandResource', @el).click(this.callDocs.bind(this, 'expandOperationsForResoruce'))
27+
28+
return @
2429

2530
addOperation: (operation) ->
2631

@@ -30,4 +35,12 @@ class ResourceView extends Backbone.View
3035
operationView = new OperationView({model: operation, tagName: 'li', className: 'endpoint', swaggerOptions: @options.swaggerOptions})
3136
$('.endpoints', $(@el)).append operationView.render().el
3237

33-
@number++
38+
@number++
39+
40+
#
41+
# Generic Event handler (`Docs` is global)
42+
#
43+
44+
callDocs: (fnName, e) ->
45+
e.preventDefault()
46+
Docs[fnName](e.currentTarget.getAttribute('data-id'))

src/main/template/resource.handlebars

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
<div class='heading'>
22
<h2>
3-
<a href='#!/{{id}}' onclick="Docs.toggleEndpointListForResource('{{id}}');">{{name}}</a> {{#description}} : {{/description}}{{{description}}}
3+
<a href='#!/{{id}}' class="toggleEndpointList" data-id="{{id}}">{{name}}</a> {{#description}} : {{/description}}{{{description}}}
44
</h2>
55
<ul class='options'>
66
<li>
7-
<a href='#!/{{id}}' id='endpointListTogger_{{id}}'
8-
onclick="Docs.toggleEndpointListForResource('{{id}}');">Show/Hide</a>
7+
<a href='#!/{{id}}' id='endpointListTogger_{{id}}' class="toggleEndpointList" data-id="{{id}}">Show/Hide</a>
98
</li>
109
<li>
11-
<a href='#' onclick="Docs.collapseOperationsForResource('{{id}}'); return false;">
10+
<a href='#' class="collapseResource" data-id="{{id}}">
1211
List Operations
1312
</a>
1413
</li>
1514
<li>
16-
<a href='#' onclick="Docs.expandOperationsForResource('{{id}}'); return false;">
15+
<a href='#' class="expandResource" data-id={{id}}>
1716
Expand Operations
1817
</a>
1918
</li>

0 commit comments

Comments
 (0)