-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcustom.js
More file actions
executable file
·165 lines (152 loc) · 5.52 KB
/
custom.js
File metadata and controls
executable file
·165 lines (152 loc) · 5.52 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
$(document).ready(function() {
$category = $("#id_category");
$tutorial = $("#id_tutorial");
$minute_range = $("#id_minute_range");
$second_range = $("#id_second_range");
$title = $("#id_title");
var tutorial = $tutorial.val();
var category = $category.val();
if (tutorial == "Select a Tutorial" || tutorial =="General"){
$minute_range.attr("disabled", true);
$second_range.attr("disabled", true);
}else{
$minute_range.removeAttr("disabled");
$second_range.removeAttr("disabled");
}
function reset() {
for (var i = 0, l = arguments.length; i < l; i ++) {
switch(arguments[i]) {
case "tutorial":
$tutorial.html("<option value='None'>Select a Tutorial</option>");
$tutorial.attr("disabled", true);
break;
case "minute_range":
$minute_range.html("<option value='None'>min</option>");
$minute_range.attr("disabled", true);
break;
case "second_range":
$second_range.html("<option value='None'>sec</option>");
$second_range.attr("disabled", true);
break;
}
}
}
$category.change(function() {
$("#similar-link").hide();
/* resetting dropdowns */
reset("tutorial", "minute_range", "second_range");
/* see thread-user.js */
$("#question-details-ok").show();
var category = $(this).val();
if(category == "General") {
/* disabling all other fields */
$tutorial.html("<option value='None'>Not required</option>");
$tutorial.removeAttr("disabled");
$minute_range.html("<option value='None'>Not required</option>");
$minute_range.removeAttr("disabled");
$second_range.html("<option value='None'>Not required</option>");
$second_range.removeAttr("disabled");
}else {
$.ajax({
url: "/ajax-tutorials/",
type: "POST",
data: {
category: category
},
success: function(data) {
$("#id_tutorial").html(data);
$("#id_tutorial").removeAttr("disabled");
}
});
}
});
$tutorial.on('input', function() {
/* resetting dropdowns */
reset("minute_range", "second_range");
var category = $category.val();
var tutorial = $(this).val();
if(tutorial == "General") {
/* disabling all other fields */
$minute_range.html("<option value='None'>Not required</option>");
$minute_range.removeAttr("disabled");
$second_range.html("<option value='None'>Not required</option>");
$second_range.removeAttr("disabled");
} else if (tutorial == "Select a Tutorial"){
$minute_range.attr("disabled");
$second_range.attr("disabled");
}else {
$.ajax({
url: "/ajax-duration/",
type: "POST",
data: {
category: category,
tutorial: tutorial
},
success: function(data){
var $response = $(data);
$minute_range.html($response.find("#minutes").html())
$minute_range.removeAttr("disabled");
$second_range.html($response.find("#seconds").html())
$second_range.removeAttr("disabled");
}
});
}
});
// this is in faq page
$tutorial.change(function() {
$.ajax({
url: "/ajax-faq-questions/",
type: "POST",
data: {
category: $category.val(),
tutorial: $tutorial.val(),
},
dataType: "html",
success: function(data) {
$response = $(data);
var similar_count= $response.find("#similar-count").text();
console.log(similar_count);
$("#similar-link").show();
$("#modal-body").html(data);
$.ajax({
url:"/ajax-fetch-questions/",
type: "POST",
data: {
category: $category.val(),
tutorial: $tutorial.val(),
}
});
}
});
});
$title.keyup(function() {
var len = $title.val().split(' ').length;
if(len>=2){
$.ajax({
url: "/ajax-similar-questions/",
type: "POST",
data: {
category: $category.val(),
tutorial: $tutorial.val(),
minute_range: $minute_range.val(),
second_range: $second_range.val(),
title: $title.val()
},
dataType: "html",
success: function(data) {
$response = $(data);
var similar_count= $response.find("#similar-count").text();
console.log(similar_count);
$("#similar-link").show();
$("#modal-body").html(data);
}
});
}
});
$(document).ajaxStart(function() {
$("#ajax-loader").show();
});
$(document).ajaxStop(function() {
$("#ajax-loader").hide();
});
});