Skip to content

Commit e65b64a

Browse files
author
Emmanouil Konstantinidis
committed
Use button group for methods
1 parent 8dd1794 commit e65b64a

File tree

4 files changed

+24
-37
lines changed

4 files changed

+24
-37
lines changed

rest_framework_docs/static/rest_framework_docs/css/style.css

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

rest_framework_docs/static/rest_framework_docs/js/index.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ $( document ).ready(function() {
5858

5959
var makeRequest = function () {
6060
var url = $('#requestForm #urlInput').val();
61-
var method = 'POST';
61+
var method = $("#methods").find( ".active" ).text();
6262

6363
$.ajax({
6464
url: url,
@@ -77,29 +77,18 @@ $( document ).ready(function() {
7777
$('#urlInput').val(data.path);
7878

7979
// List Methods (Radio Buttons)
80-
// FIXME: Use regex - conver to JSON
80+
// FIXME: Use regex - convert to JSON
8181
var methods = data.methods.replace("[", "").replace("]", "").replace(/'/g, "").replace(/\s/g, "").split(',');
82-
8382
$.each( methods, function( i, method ) {
84-
var methodClass = "radio-inline method " + method.toLowerCase();
85-
$('#methods').append("" +
86-
"<label class='" + methodClass + "'>"+
87-
"<input type='radio' name='methodRadio' value='" + method + "'>" + method +
88-
"</label>" +
89-
"")
83+
var methodClass = "btn btn-sm method " + method.toLowerCase();
84+
$('#methods').append("<button type='button' class='" + methodClass + "'>" + method + "</button>");
9085
});
9186

92-
$(".radio-inline.method").off().on('click', function (evt) {
93-
// Prevent the event firing twice
94-
evt.stopPropagation();
95-
evt.preventDefault();
96-
97-
// Uncheck all checkboxes and
98-
// Check the clicked radio
99-
$('.radio-inline.method').removeClass('active');
100-
$('.radio-inline.method').children('input').attr('checked', false);
101-
$(this).addClass("active");
102-
$(this).children('input').first().attr('checked', true);
87+
$('#methods').children(".btn").first().addClass( 'active' );
88+
89+
$("#methods .method").on('click', function (evt) {
90+
$("#methods .method").removeClass( 'active' );
91+
$(this).addClass( 'active' );
10392
});
10493

10594
$('#requestForm').submit(function (e) {
@@ -111,9 +100,10 @@ $( document ).ready(function() {
111100
});
112101
};
113102

114-
$('.plug').bind('click', function(e) {
103+
$('.plug').bind('click', function(evt) {
115104
// Prevent the accordion from collapsing
116-
e.stopPropagation();
105+
evt.stopPropagation();
106+
evt.preventDefault();
117107

118108
// Open Modal
119109
$('#liveAPIModal').modal('toggle');

rest_framework_docs/static/rest_framework_docs/less/style.less

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,20 @@ body {
176176
.methods {
177177

178178
.method {
179-
padding: 4px 8px;
180179
color: #FFF;
180+
background-color: @gray-light;
181+
border-left: 1px solid @gray;
181182

182-
&.get { background-color: @GetColor; }
183-
&.post { background-color: @PostColor; }
184-
&.patch { background-color: @PutColor; }
185-
&.put { background-color: @PatchColor; }
186-
&.delete { background-color: @DeleteColor; }
187-
&.options { background-color: @OptionsColor; }
188-
189-
&.active {
190-
border: 2px solid red;
183+
&:first-child {
184+
border-left: 0;
191185
}
192186

193-
input[type='radio'] {
194-
display: none;
195-
}
187+
&.get.active { background-color: @GetColor; }
188+
&.post.active { background-color: @PostColor; }
189+
&.patch.active { background-color: @PutColor; }
190+
&.put.active { background-color: @PatchColor; }
191+
&.delete.active { background-color: @DeleteColor; }
192+
&.options.active { background-color: @OptionsColor; }
196193
}
197194
}
198195
}

rest_framework_docs/templates/rest_framework_docs/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h3>Request</h3>
106106
<input type="text" class="form-control" id="urlInput" placeholder="Url">
107107
</div>
108108

109-
<div id="methods" class="methods"></div>
109+
<div class="btn-group methods" id="methods" role="group"></div>
110110

111111
<h5>Headers</h5>
112112
<div class="form-group">

0 commit comments

Comments
 (0)