Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
daccc2b8
Commit
daccc2b8
authored
May 16, 2016
by
José Padilla
Committed by
Tom Christie
May 16, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up js style and remove extra getCookie function (#4123)
parent
5392be4d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
35 deletions
+35
-35
rest_framework/static/rest_framework/js/ajax-form.js
+23
-8
rest_framework/static/rest_framework/js/csrf.js
+5
-0
rest_framework/static/rest_framework/js/default.js
+7
-27
No files found.
rest_framework/static/rest_framework/js/ajax-form.js
View file @
daccc2b8
function
replaceDocument
(
docString
)
{
function
replaceDocument
(
docString
)
{
var
doc
=
document
.
open
(
"text/html"
);
var
doc
=
document
.
open
(
"text/html"
);
doc
.
write
(
docString
);
doc
.
write
(
docString
);
doc
.
close
();
doc
.
close
();
}
}
function
doAjaxSubmit
(
e
)
{
function
doAjaxSubmit
(
e
)
{
var
form
=
$
(
this
);
var
form
=
$
(
this
);
var
btn
=
$
(
this
.
clk
);
var
btn
=
$
(
this
.
clk
);
var
method
=
btn
.
data
(
'method'
)
||
form
.
data
(
'method'
)
||
form
.
attr
(
'method'
)
||
'GET'
;
var
method
=
(
method
=
method
.
toUpperCase
()
btn
.
data
(
'method'
)
||
form
.
data
(
'method'
)
||
form
.
attr
(
'method'
)
||
'GET'
).
toUpperCase
();
if
(
method
===
'GET'
)
{
if
(
method
===
'GET'
)
{
// GET requests can always use standard form submits.
// GET requests can always use standard form submits.
return
;
return
;
...
@@ -18,6 +22,7 @@ function doAjaxSubmit(e) {
...
@@ -18,6 +22,7 @@ function doAjaxSubmit(e) {
var
contentType
=
var
contentType
=
form
.
find
(
'input[data-override="content-type"]'
).
val
()
||
form
.
find
(
'input[data-override="content-type"]'
).
val
()
||
form
.
find
(
'select[data-override="content-type"] option:selected'
).
text
();
form
.
find
(
'select[data-override="content-type"] option:selected'
).
text
();
if
(
method
===
'POST'
&&
!
contentType
)
{
if
(
method
===
'POST'
&&
!
contentType
)
{
// POST requests can use standard form submits, unless we have
// POST requests can use standard form submits, unless we have
// overridden the content type.
// overridden the content type.
...
@@ -29,15 +34,18 @@ function doAjaxSubmit(e) {
...
@@ -29,15 +34,18 @@ function doAjaxSubmit(e) {
var
url
=
form
.
attr
(
'action'
);
var
url
=
form
.
attr
(
'action'
);
var
data
;
var
data
;
if
(
contentType
)
{
if
(
contentType
)
{
data
=
form
.
find
(
'[data-override="content"]'
).
val
()
||
''
data
=
form
.
find
(
'[data-override="content"]'
).
val
()
||
''
}
else
{
}
else
{
contentType
=
form
.
attr
(
'enctype'
)
||
form
.
attr
(
'encoding'
)
contentType
=
form
.
attr
(
'enctype'
)
||
form
.
attr
(
'encoding'
)
if
(
contentType
===
'multipart/form-data'
)
{
if
(
contentType
===
'multipart/form-data'
)
{
if
(
!
window
.
FormData
)
{
if
(
!
window
.
FormData
)
{
alert
(
'Your browser does not support AJAX multipart form submissions'
);
alert
(
'Your browser does not support AJAX multipart form submissions'
);
return
;
return
;
}
}
// Use the FormData API and allow the content type to be set automatically,
// Use the FormData API and allow the content type to be set automatically,
// so it includes the boundary string.
// so it includes the boundary string.
// See https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects
// See https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects
...
@@ -55,20 +63,26 @@ function doAjaxSubmit(e) {
...
@@ -55,20 +63,26 @@ function doAjaxSubmit(e) {
data
:
data
,
data
:
data
,
contentType
:
contentType
,
contentType
:
contentType
,
processData
:
false
,
processData
:
false
,
headers
:
{
'Accept'
:
'text/html; q=1.0, */*'
},
headers
:
{
'Accept'
:
'text/html; q=1.0, */*'
},
});
});
ret
.
always
(
function
(
data
,
textStatus
,
jqXHR
)
{
ret
.
always
(
function
(
data
,
textStatus
,
jqXHR
)
{
if
(
textStatus
!=
'success'
)
{
if
(
textStatus
!=
'success'
)
{
jqXHR
=
data
;
jqXHR
=
data
;
}
}
var
responseContentType
=
jqXHR
.
getResponseHeader
(
"content-type"
)
||
""
;
var
responseContentType
=
jqXHR
.
getResponseHeader
(
"content-type"
)
||
""
;
if
(
responseContentType
.
toLowerCase
().
indexOf
(
'text/html'
)
===
0
)
{
if
(
responseContentType
.
toLowerCase
().
indexOf
(
'text/html'
)
===
0
)
{
replaceDocument
(
jqXHR
.
responseText
);
replaceDocument
(
jqXHR
.
responseText
);
try
{
try
{
// Modify the location and scroll to top, as if after page load.
// Modify the location and scroll to top, as if after page load.
history
.
replaceState
({},
''
,
url
);
history
.
replaceState
({},
''
,
url
);
scroll
(
0
,
0
);
scroll
(
0
,
0
);
}
catch
(
err
)
{
}
catch
(
err
)
{
// History API not supported, so redirect.
// History API not supported, so redirect.
window
.
location
=
url
;
window
.
location
=
url
;
}
}
...
@@ -77,19 +91,20 @@ function doAjaxSubmit(e) {
...
@@ -77,19 +91,20 @@ function doAjaxSubmit(e) {
window
.
location
=
url
;
window
.
location
=
url
;
}
}
});
});
return
ret
;
return
ret
;
}
}
function
captureSubmittingElement
(
e
)
{
function
captureSubmittingElement
(
e
)
{
var
target
=
e
.
target
;
var
target
=
e
.
target
;
var
form
=
this
;
var
form
=
this
;
form
.
clk
=
target
;
form
.
clk
=
target
;
}
}
$
.
fn
.
ajaxForm
=
function
()
{
$
.
fn
.
ajaxForm
=
function
()
{
var
options
=
{}
var
options
=
{}
return
this
return
this
.
unbind
(
'submit.form-plugin click.form-plugin'
)
.
unbind
(
'submit.form-plugin click.form-plugin'
)
.
bind
(
'submit.form-plugin'
,
options
,
doAjaxSubmit
)
.
bind
(
'submit.form-plugin'
,
options
,
doAjaxSubmit
)
...
...
rest_framework/static/rest_framework/js/csrf.js
View file @
daccc2b8
function
getCookie
(
name
)
{
function
getCookie
(
name
)
{
var
cookieValue
=
null
;
var
cookieValue
=
null
;
if
(
document
.
cookie
&&
document
.
cookie
!=
''
)
{
if
(
document
.
cookie
&&
document
.
cookie
!=
''
)
{
var
cookies
=
document
.
cookie
.
split
(
';'
);
var
cookies
=
document
.
cookie
.
split
(
';'
);
for
(
var
i
=
0
;
i
<
cookies
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
cookies
.
length
;
i
++
)
{
var
cookie
=
jQuery
.
trim
(
cookies
[
i
]);
var
cookie
=
jQuery
.
trim
(
cookies
[
i
]);
// Does this cookie string begin with the name we want?
// Does this cookie string begin with the name we want?
if
(
cookie
.
substring
(
0
,
name
.
length
+
1
)
==
(
name
+
'='
))
{
if
(
cookie
.
substring
(
0
,
name
.
length
+
1
)
==
(
name
+
'='
))
{
cookieValue
=
decodeURIComponent
(
cookie
.
substring
(
name
.
length
+
1
));
cookieValue
=
decodeURIComponent
(
cookie
.
substring
(
name
.
length
+
1
));
...
@@ -11,6 +14,7 @@ function getCookie(name) {
...
@@ -11,6 +14,7 @@ function getCookie(name) {
}
}
}
}
}
}
return
cookieValue
;
return
cookieValue
;
}
}
...
@@ -26,6 +30,7 @@ function sameOrigin(url) {
...
@@ -26,6 +30,7 @@ function sameOrigin(url) {
var
protocol
=
document
.
location
.
protocol
;
var
protocol
=
document
.
location
.
protocol
;
var
sr_origin
=
'//'
+
host
;
var
sr_origin
=
'//'
+
host
;
var
origin
=
protocol
+
sr_origin
;
var
origin
=
protocol
+
sr_origin
;
// Allow absolute or scheme relative URLs to same origin
// Allow absolute or scheme relative URLs to same origin
return
(
url
==
origin
||
url
.
slice
(
0
,
origin
.
length
+
1
)
==
origin
+
'/'
)
||
return
(
url
==
origin
||
url
.
slice
(
0
,
origin
.
length
+
1
)
==
origin
+
'/'
)
||
(
url
==
sr_origin
||
url
.
slice
(
0
,
sr_origin
.
length
+
1
)
==
sr_origin
+
'/'
)
||
(
url
==
sr_origin
||
url
.
slice
(
0
,
sr_origin
.
length
+
1
)
==
sr_origin
+
'/'
)
||
...
...
rest_framework/static/rest_framework/js/default.js
View file @
daccc2b8
function
getCookie
(
c_name
)
$
(
document
).
ready
(
function
()
{
{
// From http://www.w3schools.com/js/js_cookies.asp
var
c_value
=
document
.
cookie
;
var
c_start
=
c_value
.
indexOf
(
" "
+
c_name
+
"="
);
if
(
c_start
==
-
1
)
{
c_start
=
c_value
.
indexOf
(
c_name
+
"="
);
}
if
(
c_start
==
-
1
)
{
c_value
=
null
;
}
else
{
c_start
=
c_value
.
indexOf
(
"="
,
c_start
)
+
1
;
var
c_end
=
c_value
.
indexOf
(
";"
,
c_start
);
if
(
c_end
==
-
1
)
{
c_end
=
c_value
.
length
;
}
c_value
=
unescape
(
c_value
.
substring
(
c_start
,
c_end
));
}
return
c_value
;
}
$
(
document
).
ready
(
function
()
{
// JSON highlighting.
// JSON highlighting.
prettyPrint
();
prettyPrint
();
...
@@ -30,15 +9,16 @@ $(document).ready(function () {
...
@@ -30,15 +9,16 @@ $(document).ready(function () {
});
});
// Deal with rounded tab styling after tab clicks.
// Deal with rounded tab styling after tab clicks.
$
(
'a[data-toggle="tab"]:first'
).
on
(
'shown'
,
function
(
e
)
{
$
(
'a[data-toggle="tab"]:first'
).
on
(
'shown'
,
function
(
e
)
{
$
(
e
.
target
).
parents
(
'.tabbable'
).
addClass
(
'first-tab-active'
);
$
(
e
.
target
).
parents
(
'.tabbable'
).
addClass
(
'first-tab-active'
);
});
});
$
(
'a[data-toggle="tab"]:not(:first)'
).
on
(
'shown'
,
function
(
e
)
{
$
(
'a[data-toggle="tab"]:not(:first)'
).
on
(
'shown'
,
function
(
e
)
{
$
(
e
.
target
).
parents
(
'.tabbable'
).
removeClass
(
'first-tab-active'
);
$
(
e
.
target
).
parents
(
'.tabbable'
).
removeClass
(
'first-tab-active'
);
});
});
$
(
'a[data-toggle="tab"]'
).
click
(
function
()
{
$
(
'a[data-toggle="tab"]'
).
click
(
function
()
{
document
.
cookie
=
"tabstyle="
+
this
.
name
+
"; path=/"
;
document
.
cookie
=
"tabstyle="
+
this
.
name
+
"; path=/"
;
});
});
// Store tab preference in cookies & display appropriate tab on load.
// Store tab preference in cookies & display appropriate tab on load.
...
@@ -61,7 +41,7 @@ $(document).ready(function () {
...
@@ -61,7 +41,7 @@ $(document).ready(function () {
$
(
'.form-switcher a:first'
).
tab
(
'show'
);
$
(
'.form-switcher a:first'
).
tab
(
'show'
);
}
}
$
(
window
).
load
(
function
()
{
$
(
window
).
load
(
function
()
{
$
(
'#errorModal'
).
modal
(
'show'
);
$
(
'#errorModal'
).
modal
(
'show'
);
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment