-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
101 lines (86 loc) · 3.03 KB
/
Copy pathscript.js
File metadata and controls
101 lines (86 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
$(document).ready(function()
{
// prevent submit
$(".qa-form-light-button-flag").attr("type", "button");
$(".qa-form-light-button-flag").click( function()
{
var postId = $(this).data("postid");
var postType = $(this).data("posttype");
var parentId = $(this).data("parentid");
// remove button so no double inserts
// $(this).remove();
$("#flagbox-popup").show();
$(".qa-flag-reasons-wrap .closer").click( function()
{
$("#flagbox-popup").hide();
});
// focus on first element, then Enter and Escape key work
$('.qa-flag-reasons-wrap input').first().focus();
$(".qa-go-flag-send-button").click( function()
{
const flagReason = $("input[name=qa-spam-reason-radio]:checked").val();
const flagNotice = $(".qa-spam-reason-text").val();
let dataArray = {};
dataArray.questionid= flagQuestionid;
dataArray.postid= postId;
dataArray.posttype= postType;
dataArray.parentid= parentId;
dataArray.reasonid= flagReason;
dataArray.notice= flagNotice;
const sendData = JSON.stringify(dataArray);
console.log("sending: "+sendData);
console.log(flagAjaxURL);
// send ajax
$.ajax({
type: "POST",
url: flagAjaxURL,
data: { ajaxdata: sendData },
dataType:"json",
cache: false,
success: function(data)
{
console.log("got server data:");
console.log(data);
if(typeof data.error !== "undefined")
{
alert(data.error);
}
else if(typeof data.success !== "undefined")
{
// if success, reload page
location.reload();
}
else
{
alert(data);
}
},
error: function(data)
{
console.log("Ajax error:");
console.log(data);
}
}); });
}); // END click
// submit by enter key, cancel by escape key
$('.qa-flag-reasons-wrap').on('keyup', function(e)
{
console.log(e.keyCode);
if(e.keyCode == 13)
{
$(this).find('.qa-go-flag-send-button').click();
}
else if(e.keyCode == 27)
{
$(this).find('.closer').click();
}
});
// mouse click on flagbox closes div
$('#flagbox-popup').click(function(e)
{
if(e.target == this)
{
$(this).find('.closer').click();
}
});
});