Removing more dependencies

This commit is contained in:
Kasper Rynning-Tønnesen
2018-03-13 20:59:01 +01:00
parent f566a19857
commit 714b885dc5
8 changed files with 178 additions and 72 deletions

View File

@@ -10,6 +10,7 @@ var Admin = {
if(adminpass == undefined || adminpass == "") {
//adminpass = Crypt.get_pass(chan.toLowerCase());
}
$(".delete-context-menu").removeClass("context-menu-disabled");
names = ["vote","addsongs","longsongs","frontpage", "allvideos",
"removeplay", "skip", "shuffle", "userpass"];
//Crypt.set_pass(chan.toLowerCase(), Crypt.tmp_pass);
@@ -144,6 +145,9 @@ var Admin = {
}
$("#admin-lock").removeClass("clickable");
$("#password").attr("placeholder", "Enter admin password");
if(!$(".delete-context-menu").hasClass("context-menu-disabled")) {
$(".delete-context-menu").addClass("context-menu-disabled");
}
},
save: function(userpass) {

View File

@@ -416,65 +416,22 @@ var Channel = {
},
add_context_menu: function() {
$.contextMenu({
selector: '.playlist-element',
reposition: true,
autoHide: true,
items: {
copy: {
name: "Copy link",
callback: function(key, opt){
var this_id = $(this[0]).attr("data-video-id");
var this_url = "https://www.youtube.com/watch?v=" + this_id;
$(".copy_video_id").css("display", "block");
$(".copy_video_id").text(this_url);
var copyTextarea = document.querySelector('.copy_video_id');
copyTextarea.select();
var successful = document.execCommand('copy');
if(successful) {
Materialize.toast("Copied!", 2000, "green lighten");
} else {
Materialize.toast("Error copying..", 2000, "red lighten");
}
$(".copy_video_id").css("display", "none");
}
},
similar: {
name: "Find Similar",
callback: function(key, opt) {
var this_id = $(this[0]).attr("data-video-id");
Search.search(this_id, false, true);
if(Helper.contains($(".search-container").attr("class").split(" "), "hide")) {
Search.showSearch();
}
}
},
"sep1": "---------",
delete: {
name: "Delete",
callback: function(key, opt) {
var this_id = $(this[0]).attr("data-video-id");
var this_type = $(this[0]).attr("data-video-type");
$(document).on("contextmenu", ".vote-container", function(e) {
e.preventDefault();
var that = this;
contextListener(that, e);
});
if(this_type == "suggested") {
number_suggested = number_suggested - 1;
if(number_suggested < 0) number_suggested = 0;
$(document).on("contextmenu", ".add-suggested", function(e) {
e.preventDefault();
var that = this;
contextListener(that, e);
});
var to_display = number_suggested > 9 ? "9+" : number_suggested;
if(!$(".suggested-link span.badge.new.white").hasClass("hide") && to_display == 0){
$(".suggested-link span.badge.new.white").addClass("hide");
}
$(".suggested-link span.badge.new.white").text(to_display);
}
List.vote(this_id, "del");
},
disabled: function(key, opt) {
return w_p;
}
}
}
$(document).on("click", ".list-remove", function(e) {
e.preventDefault();
var that = this;
contextListener(that, e);
});
},
@@ -543,7 +500,7 @@ var Channel = {
var channel_before_move = chan.toLowerCase();
clearTimeout(timed_remove_check);
changing_to_frontpage = true;
$.contextMenu( 'destroy', ".playlist-element" );
//$.contextMenu( 'destroy', ".playlist-element" );
user_change_password = false;
clearTimeout(width_timeout);
if(fireplace_initiated){
@@ -659,7 +616,7 @@ var Channel = {
$(".page-footer").removeClass("padding-bottom-novideo");
$("#favicon").attr("href", "/assets/images/favicon-32x32.png");
$(".context-menu-list").remove();
//$(".context-menu-list").remove();
Helper.log(["Socket", socket]);
if($("#alreadyfp").length == 1){
Frontpage.init();

View File

@@ -181,7 +181,6 @@ function get_list_ajax() {
}
},
error: function(response) {
console.log(response);
if(response.responseJSON.status == 403) {
start_auth();
} else if(response.responseJSON.status == 429) {
@@ -195,6 +194,44 @@ function get_list_ajax() {
});
}
function contextListener(that, e) {
var parent = $(that).parent();
var suggested = false;
if(parent.attr("id").indexOf("suggested-") > -1) suggested = true;
$(".context-menu-root").attr("data-suggested", suggested);
$(".context-menu-root").attr("data-id", parent.attr("id").replace("suggested-", ""));
$("#context-menu-overlay").removeClass("hide");
var left = e.pageX - $(".context-menu-root").width() / 2;
var top = e.pageY;
if(left + $(".context-menu-root").width() > $(window).width()) {
left = $(window).width() - $(".context-menu-root").width() - 15;
} else if (left < 0) {
left = 11;
}
if(top + $(".context-menu-root").width() > $(window).height()) {
top = $(window).height() - $(".context-menu-root").height() - 15;
} else if(top < 0) {
top = 15;
}
$(".context-menu-root").css({left: left,top:top});
$(".context-menu-root").removeClass("hide");
if(!Helper.mobilecheck()) {
mouseContext(left, top);
}
}
function mouseContext(left, top) {
$(document).off("mousemove");
$(document).mousemove(function( event ) {
if(event.pageX < left - 60 || event.pageX > left + $(".context-menu-root").width() + 60 ||
event.pageY < top - 60 || event.pageY > top + $(".context-menu-root").height() + 60) {
$(".context-menu-root").addClass("hide");
$("#context-menu-overlay").addClass("hide");
$(document).off("mousemove");
}
});
}
function get_np_ajax() {
/*var c = Crypt.get_userpass(chan.toLowerCase());
if(c == undefined) c = "";*/

View File

@@ -447,11 +447,6 @@ $(document).on("click", "#chat_submit", function(e){
$("#chatForm").submit();
});
$(document).on("click", ".list-remove", function(e) {
e.preventDefault();
$('#' + $(this).parent().attr("id")).contextMenu();
});
$(document).on("mouseleave", ".card.sticky-action", function(e){
var that = this;
$(that).find(".card-reveal").attr("style", "display: block;transform: translateY(0%);");
@@ -524,6 +519,76 @@ $(document).on("click", ".extra-button-delete", function(e){
}
});
$(document).on("click", "#context-menu-overlay", function(e) {
$(".context-menu-root").addClass("hide");
$("#context-menu-overlay").addClass("hide");
$(".context-menu-root").attr("data-id", "");
});
$(document).on("click", ".copy-context-menu", function(e) {
e.preventDefault();
var that = this;
var parent = $(that).parent();
var id = parent.attr("data-id");
if(id != "") {
$(".copy_video_id").css("display", "block");
$(".copy_video_id").text("https://www.youtube.com/watch?v=" + id);
var copyTextarea = document.querySelector('.copy_video_id');
copyTextarea.select();
var successful = document.execCommand('copy');
if(successful) {
Materialize.toast("Copied!", 2000, "green lighten");
} else {
Materialize.toast("Error copying..", 2000, "red lighten");
}
$(".copy_video_id").css("display", "none");
}
$(".context-menu-root").addClass("hide");
$("#context-menu-overlay").addClass("hide");
$(".context-menu-root").attr("data-id", "");
});
$(document).on("click", ".find-context-menu", function(e) {
e.preventDefault();
var that = this;
var parent = $(that).parent();
var id = parent.attr("data-id");
Search.search(id, false, true);
if(Helper.contains($(".search-container").attr("class").split(" "), "hide")) {
Search.showSearch();
}
$(".context-menu-root").addClass("hide");
$("#context-menu-overlay").addClass("hide");
$(".context-menu-root").attr("data-id", "");
});
$(document).on("click", ".delete-context-menu", function(e) {
var that = this;
if($(that).hasClass("context-menu-disabled")) {
return;
}
var parent = $(that).parent();
var id = parent.attr("data-id");
var suggested = parent.attr("data-suggested");
if(suggested == "true") {
number_suggested = number_suggested - 1;
if(number_suggested < 0) number_suggested = 0;
var to_display = number_suggested > 9 ? "9+" : number_suggested;
if(!$(".suggested-link span.badge.new.white").hasClass("hide") && to_display == 0){
$(".suggested-link span.badge.new.white").addClass("hide");
}
$(".suggested-link span.badge.new.white").text(to_display);
}
List.vote(id, "del");
$(".context-menu-root").addClass("hide");
$("#context-menu-overlay").addClass("hide");
$(".context-menu-root").attr("data-id", "");
})
$(document).on("click", "#closePlayer", function(e){
e.preventDefault();
socket.emit("change_channel");
@@ -589,6 +654,10 @@ $(document).on("click", ".change_user_pass_btn", function(e) {
$("#user-pass-input").focus();
});
$(document).on("contextmenu", "#context-menu-overlay", function(e) {
e.preventDefault();
});
$(document).on("click", ".submit-user-password", function(e) {
e.preventDefault();
if(user_auth_started) {
@@ -1199,7 +1268,7 @@ $(document).on( "click", ".add-suggested", function(e){
var title = $(this).attr("data-video-title");
var length = $(this).attr("data-video-length");
var added_by = $(this).attr("data-added-by");
Search.submit(id, title, length, false, 0, 1, 0, length);
Search.submit(id, title, parseInt(length), false, 0, 1, 0, parseInt(length));
if(added_by == "user") {
number_suggested = number_suggested - 1;
if(number_suggested < 0) number_suggested = 0;