-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtemplate.js
48 lines (38 loc) · 956 Bytes
/
template.js
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
$(function() {
var $input = $('#title');
var err_style = 'display: none; font-size: 13px; font-weight: normal';
var matchAnywhere = ASK_NOTICE_MATCH;
var notices = ASK_NOTICE_DATA;
function make_error(msg)
{
return $('<div id="qa-error-title" class="qa-error" style="' + err_style + '">' + msg + '</div>');
}
function find_triggers(keywords, input)
{
for (var i in keywords) {
var regex = keywords[i];
if (!matchAnywhere) {
regex = '\\b'+regex+'\\b';
}
if (input.match(regex)) {
return true;
}
}
return false;
}
$input.change(function() {
$('#qa-error-title').remove();
var title = $(this).val().toLowerCase();
$err = null;
for (var n in notices) {
var keywords = notices[n].keys.toLowerCase().split(',');
var message = notices[n].text;
if (find_triggers(keywords, title)) {
$err = make_error(message);
}
}
if ($err) {
$err.insertAfter($input).fadeIn('slow');
}
});
});