Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
rpteam
Revue de Press
Commits
cb0c3f94
Verified
Commit
cb0c3f94
authored
Dec 06, 2017
by
Thibaut Broggi
Browse files
Move inline javascript to compiled webpack resources
parent
c86c970f
Changes
3
Hide whitespace changes
Inline
Side-by-side
apps/rp/templates/rp/article_list.html
View file @
cb0c3f94
...
...
@@ -150,83 +150,4 @@
</div>
</div>
</div>
<script>
function
getCookie
(
name
)
{
var
cookieValue
=
null
;
if
(
document
.
cookie
&&
document
.
cookie
!==
''
)
{
var
cookies
=
document
.
cookie
.
split
(
'
;
'
);
for
(
var
i
=
0
;
i
<
cookies
.
length
;
i
++
)
{
var
cookie
=
jQuery
.
trim
(
cookies
[
i
]);
// Does this cookie string begin with the name we want?
if
(
cookie
.
substring
(
0
,
name
.
length
+
1
)
===
(
name
+
'
=
'
))
{
cookieValue
=
decodeURIComponent
(
cookie
.
substring
(
name
.
length
+
1
));
break
;
}
}
}
return
cookieValue
;
}
var
csrftoken
=
getCookie
(
'
csrftoken
'
);
function
csrfSafeMethod
(
method
)
{
// these HTTP methods do not require CSRF protection
return
(
/^
(
GET|HEAD|OPTIONS|TRACE
)
$/
.
test
(
method
));
}
$
.
ajaxSetup
({
beforeSend
:
function
(
xhr
,
settings
)
{
if
(
!
csrfSafeMethod
(
settings
.
type
)
&&
!
this
.
crossDomain
)
{
xhr
.
setRequestHeader
(
"
X-CSRFToken
"
,
csrftoken
);
}
}
});
function
call_upvote
(
id
)
{
$
.
post
(
"
/api/articles/
"
+
id
+
"
/upvote/
"
,
function
response
(
data
)
{
$
(
"
#count_up_
"
+
id
).
text
(
data
.
und_score_up
);
});
}
function
call_downvote
(
id
)
{
$
.
post
(
"
/api/articles/
"
+
id
+
"
/downvote/
"
,
function
response
(
data
)
{
$
(
"
#count_down_
"
+
id
).
text
(
data
.
und_score_down
);
});
}
function
clean_row
(
id
)
{
$
(
"
#row_
"
+
id
).
hide
();
$
(
"
#row_empty_
"
+
id
).
hide
();
$
(
"
#row_tags_
"
+
id
).
hide
();
}
function
call_recover
(
id
)
{
$
.
post
(
"
/api/articles/
"
+
id
+
"
/recover/
"
,
function
response
(
data
)
{
clean_row
(
id
);
});
}
function
call_reject
(
id
)
{
$
.
post
(
"
/api/articles/
"
+
id
+
"
/reject/
"
,
function
response
(
data
)
{
clean_row
(
id
);
});
}
function
call_publish
(
id
)
{
$
.
post
(
"
/api/articles/
"
+
id
+
"
/publish/
"
,
function
response
(
data
)
{
clean_row
(
id
);
});
}
function
call_priority
(
id
,
flag
)
{
if
(
flag
)
{
var
url
=
"
/api/articles/
"
+
id
+
"
/set_priority/
"
;
}
else
{
var
url
=
"
/api/articles/
"
+
id
+
"
/unset_priority/
"
;
}
$
.
post
(
url
,
function
response
(
data
)
{
$
(
"
#priority_
"
+
id
).
toggleClass
(
"
fa-star
"
).
toggleClass
(
"
fa-star-o
"
);
});
}
</script>
{% endblock %}
static/src/admin.js
View file @
cb0c3f94
...
...
@@ -16,3 +16,6 @@ require('simplemde/dist/simplemde.min.css')
// Local styles
import
styles
from
'
./admin.css
'
;
// RP js
require
(
'
./rp.js
'
)
static/src/rp.js
0 → 100644
View file @
cb0c3f94
$
(
function
()
{
function
getCookie
(
name
)
{
var
cookieValue
=
null
;
if
(
document
.
cookie
&&
document
.
cookie
!==
''
)
{
var
cookies
=
document
.
cookie
.
split
(
'
;
'
);
for
(
var
i
=
0
;
i
<
cookies
.
length
;
i
++
)
{
var
cookie
=
jQuery
.
trim
(
cookies
[
i
]);
// Does this cookie string begin with the name we want?
if
(
cookie
.
substring
(
0
,
name
.
length
+
1
)
===
(
name
+
'
=
'
))
{
cookieValue
=
decodeURIComponent
(
cookie
.
substring
(
name
.
length
+
1
));
break
;
}
}
}
return
cookieValue
;
}
var
csrftoken
=
getCookie
(
'
csrftoken
'
);
function
csrfSafeMethod
(
method
)
{
// these HTTP methods do not require CSRF protection
return
(
/^
(
GET|HEAD|OPTIONS|TRACE
)
$/
.
test
(
method
));
}
$
.
ajaxSetup
({
beforeSend
:
function
(
xhr
,
settings
)
{
if
(
!
csrfSafeMethod
(
settings
.
type
)
&&
!
this
.
crossDomain
)
{
xhr
.
setRequestHeader
(
"
X-CSRFToken
"
,
csrftoken
);
}
}
});
window
.
call_upvote
=
function
(
id
)
{
$
.
post
(
"
/api/articles/
"
+
id
+
"
/upvote/
"
,
function
response
(
data
)
{
$
(
"
#count_up_
"
+
id
).
text
(
data
.
und_score_up
);
});
}
window
.
call_downvote
=
function
(
id
)
{
$
.
post
(
"
/api/articles/
"
+
id
+
"
/downvote/
"
,
function
response
(
data
)
{
$
(
"
#count_down_
"
+
id
).
text
(
data
.
und_score_down
);
});
}
window
.
clean_row
=
function
(
id
)
{
$
(
"
#row_
"
+
id
).
hide
();
$
(
"
#row_empty_
"
+
id
).
hide
();
$
(
"
#row_tags_
"
+
id
).
hide
();
}
window
.
call_recover
=
function
(
id
)
{
$
.
post
(
"
/api/articles/
"
+
id
+
"
/recover/
"
,
function
response
(
data
)
{
clean_row
(
id
);
});
}
window
.
call_reject
=
function
(
id
)
{
$
.
post
(
"
/api/articles/
"
+
id
+
"
/reject/
"
,
function
response
(
data
)
{
clean_row
(
id
);
});
}
window
.
call_publish
=
function
(
id
)
{
$
.
post
(
"
/api/articles/
"
+
id
+
"
/publish/
"
,
function
response
(
data
)
{
clean_row
(
id
);
});
}
window
.
call_priority
=
function
(
id
,
flag
)
{
if
(
flag
)
{
var
url
=
"
/api/articles/
"
+
id
+
"
/set_priority/
"
;
}
else
{
var
url
=
"
/api/articles/
"
+
id
+
"
/unset_priority/
"
;
}
$
.
post
(
url
,
function
response
(
data
)
{
$
(
"
#priority_
"
+
id
).
toggleClass
(
"
fa-star
"
).
toggleClass
(
"
fa-star-o
"
);
});
}
});
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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