summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-10-06 22:20:40 -0500
committerOmar Roth <omarroth@hotmail.com>2018-10-06 22:20:40 -0500
commitf7125c12048d66b11c2dcf12d6f1bcde35ffaf3d (patch)
treeb2d959421344d2b67890802a63d30616cb9cd763
parent6f9056fd8473cf227b1ab572c3d75cbbb79c094e (diff)
downloadinvidious-f7125c12048d66b11c2dcf12d6f1bcde35ffaf3d.tar.gz
invidious-f7125c12048d66b11c2dcf12d6f1bcde35ffaf3d.tar.bz2
invidious-f7125c12048d66b11c2dcf12d6f1bcde35ffaf3d.zip
Move watch page JS into seperate file
-rw-r--r--assets/js/watch.js48
-rw-r--r--src/invidious/comments.cr4
-rw-r--r--src/invidious/views/watch.ecr104
3 files changed, 78 insertions, 78 deletions
diff --git a/assets/js/watch.js b/assets/js/watch.js
new file mode 100644
index 00000000..7301f075
--- /dev/null
+++ b/assets/js/watch.js
@@ -0,0 +1,48 @@
+function toggle_parent(target) {
+ body = target.parentNode.parentNode.children[1];
+ if (body.style.display === null || body.style.display === "") {
+ target.innerHTML = "[ + ]";
+ body.style.display = "none";
+ } else {
+ target.innerHTML = "[ - ]";
+ body.style.display = "";
+ }
+}
+
+function toggle_comments(target) {
+ body = target.parentNode.parentNode.parentNode.children[1];
+ if (body.style.display === null || body.style.display === "") {
+ target.innerHTML = "[ + ]";
+ body.style.display = "none";
+ } else {
+ target.innerHTML = "[ - ]";
+ body.style.display = "";
+ }
+}
+
+function swap_comments(source) {
+ comments = document.getElementById("comments");
+ var fallback = comments.innerHTML;
+ comments.innerHTML =
+ '<h3><center class="loading"><i class="icon ion-ios-refresh"></i></center></h3>';
+
+ if (source == "youtube") {
+ get_youtube_comments();
+ } else if (source == "reddit") {
+ get_reddit_comments();
+ }
+}
+
+function commaSeparateNumber(val) {
+ while (/(\d+)(\d{3})/.test(val.toString())) {
+ val = val.toString().replace(/(\d+)(\d{3})/, "$1" + "," + "$2");
+ }
+ return val;
+}
+
+String.prototype.supplant = function(o) {
+ return this.replace(/{([^{}]*)}/g, function(a, b) {
+ var r = o[b];
+ return typeof r === "string" || typeof r === "number" ? r : a;
+ });
+};
diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr
index ec89c66b..ccd0f8cb 100644
--- a/src/invidious/comments.cr
+++ b/src/invidious/comments.cr
@@ -109,7 +109,7 @@ def template_youtube_comments(comments)
</div>
<div class="pure-u-20-24 pure-u-md-22-24">
<p>
- <a href="javascript:void(0)" onclick="toggle(this)">[ - ]</a>
+ <a href="javascript:void(0)" onclick="toggle_parent(this)">[ - ]</a>
<b>
<a href="#{child["authorUrl"]}">#{child["author"]}</a>
</b>
@@ -158,7 +158,7 @@ def template_reddit_comments(root)
content = <<-END_HTML
<p>
- <a href="javascript:void(0)" onclick="toggle(this)">[ - ]</a>
+ <a href="javascript:void(0)" onclick="toggle_parent(this)">[ - ]</a>
<b><a href="https://www.reddit.com/user/#{author}">#{author}</a></b>
#{score} points
#{recode_date(child.created_utc)} ago
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr
index 4f842c4c..4eaaf9a6 100644
--- a/src/invidious/views/watch.ecr
+++ b/src/invidious/views/watch.ecr
@@ -22,6 +22,7 @@
<meta name="twitter:player" content="<%= host_url %>/embed/<%= video.id %>">
<meta name="twitter:player:width" content="1280">
<meta name="twitter:player:height" content="720">
+<script src="/js/watch.js"></script>
<%= rendered "components/player_sources" %>
<title><%= HTML.escape(video.title) %> - Invidious</title>
<% end %>
@@ -144,61 +145,6 @@
</div>
<script>
-function toggle(target) {
- body = target.parentNode.parentNode.children[1];
- if (body.style.display === null || body.style.display === "") {
- target.innerHTML = "[ + ]";
- body.style.display = "none";
- } else {
- target.innerHTML = "[ - ]";
- body.style.display = "";
- }
-}
-
-function toggle_comments(target) {
- body = target.parentNode.parentNode.parentNode.children[1];
- if (body.style.display === null || body.style.display === "") {
- target.innerHTML = "[ + ]";
- body.style.display = "none";
- } else {
- target.innerHTML = "[ - ]";
- body.style.display = "";
- }
-}
-
-function get_youtube_replies(target) {
- var continuation = target.getAttribute("data-continuation");
-
- var body = target.parentNode.parentNode;
- var fallback = body.innerHTML;
- body.innerHTML =
- '<h3><center class="loading"><i class="icon ion-ios-refresh"></i></center></h3>';
-
- var url =
- "/api/v1/comments/<%= video.id %>?format=html&continuation=" + continuation;
- var xhr = new XMLHttpRequest();
- xhr.responseType = "json";
- xhr.timeout = 20000;
- xhr.open("GET", url, true);
- xhr.send();
-
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4) {
- if (xhr.status == 200) {
- body.innerHTML = xhr.response.contentHtml;
- } else {
- body.innerHTML = fallback;
- }
- }
- };
-
- xhr.ontimeout = function() {
- console.log("Pulling comments timed out.");
-
- body.innerHTML = fallback;
- };
-}
-
function get_reddit_comments() {
var url = "/api/v1/comments/<%= video.id %>?source=reddit&format=html";
var xhr = new XMLHttpRequest();
@@ -304,32 +250,38 @@ function get_youtube_comments() {
};
}
-function swap_comments(source) {
- comments = document.getElementById("comments");
- var fallback = comments.innerHTML;
- comments.innerHTML =
+function get_youtube_replies(target) {
+ var continuation = target.getAttribute('data-continuation');
+
+ var body = target.parentNode.parentNode;
+ var fallback = body.innerHTML;
+ body.innerHTML =
'<h3><center class="loading"><i class="icon ion-ios-refresh"></i></center></h3>';
- if (source == "youtube") {
- get_youtube_comments();
- } else if (source == "reddit") {
- get_reddit_comments();
+ var url = '/api/v1/comments/<%= video.id %>?format=html&continuation=' +
+ continuation;
+ var xhr = new XMLHttpRequest();
+ xhr.responseType = 'json';
+ xhr.timeout = 20000;
+ xhr.open('GET', url, true);
+ xhr.send();
+
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4) {
+ if (xhr.status == 200) {
+ body.innerHTML = xhr.response.contentHtml;
+ } else {
+ body.innerHTML = fallback;
+ }
}
-}
+ };
-function commaSeparateNumber(val){
- while (/(\d+)(\d{3})/.test(val.toString())){
- val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
- }
- return val;
-}
+ xhr.ontimeout = function() {
+ console.log('Pulling comments timed out.');
-String.prototype.supplant = function(o) {
- return this.replace(/{([^{}]*)}/g, function(a, b) {
- var r = o[b];
- return typeof r === "string" || typeof r === "number" ? r : a;
- });
-};
+ body.innerHTML = fallback;
+ };
+}
<% if preferences %>
<% if preferences.comments[0] == "youtube" %>