Add utility regexp split function for non-whitespace words
This commit is contained in:
@@ -15,8 +15,7 @@ Blacklist.parse_entry = function(string) {
|
|||||||
"hits": 0,
|
"hits": 0,
|
||||||
"min_score": null
|
"min_score": null
|
||||||
};
|
};
|
||||||
var matches = string.match(/\S+/g) || [];
|
Utility.regexp_split(string).forEach(function(tag) {
|
||||||
$.each(matches, function(i, tag) {
|
|
||||||
if (tag.charAt(0) === '-') {
|
if (tag.charAt(0) === '-') {
|
||||||
entry.exclude.push(tag.slice(1));
|
entry.exclude.push(tag.slice(1));
|
||||||
} else if (tag.charAt(0) === '~') {
|
} else if (tag.charAt(0) === '~') {
|
||||||
@@ -169,11 +168,11 @@ Blacklist.post_match = function(post, entry) {
|
|||||||
var score = parseInt($post.attr("data-score"));
|
var score = parseInt($post.attr("data-score"));
|
||||||
var score_test = entry.min_score === null || score < entry.min_score;
|
var score_test = entry.min_score === null || score < entry.min_score;
|
||||||
|
|
||||||
var tags = String($post.attr("data-tags")).match(/\S+/g) || [];
|
var tags = Utility.regexp_split($post.attr("data-tags"));
|
||||||
tags = tags.concat(String($post.attr("data-pools")).match(/\S+/g) || []);
|
tags.push(...Utility.regexp_split($post.attr("data-pools")));
|
||||||
tags.push("rating:" + $post.data("rating"));
|
tags.push("rating:" + $post.data("rating"));
|
||||||
tags.push("uploaderid:" + $post.attr("data-uploader-id"));
|
tags.push("uploaderid:" + $post.attr("data-uploader-id"));
|
||||||
$.each(String($post.data("flags")).match(/\S+/g) || [], function(i, v) {
|
Utility.regexp_split($post.data("flags")).forEach(function(v) {
|
||||||
tags.push("status:" + v);
|
tags.push("status:" + v);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -550,8 +550,8 @@ Post.update_tag_count = function(event) {
|
|||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
let tags = [...new Set($(event.target).val().match(/\S+/g))];
|
let tags = Utility.regexp_split($(event.target).val());
|
||||||
if (tags) {
|
if (tags.length) {
|
||||||
count = tags.length;
|
count = tags.length;
|
||||||
string = (count === 1) ? (count + " tag") : (count + " tags")
|
string = (count === 1) ? (count + " tag") : (count + " tags")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,27 +89,25 @@ RelatedTag.current_tag = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RelatedTag.update_selected = function(e) {
|
RelatedTag.update_selected = function(e) {
|
||||||
var current_tags = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
var current_tags = RelatedTag.current_tags();
|
||||||
var $all_tags = $(".related-tags a.search-tag");
|
var $all_tags = $(".related-tags a.search-tag");
|
||||||
$all_tags.removeClass("selected");
|
$all_tags.removeClass("selected");
|
||||||
|
|
||||||
$all_tags.each(function(i, tag) {
|
$all_tags.each(function(i, tag) {
|
||||||
if (current_tags.indexOf(tag.textContent.replace(/ /g, "_")) > -1) {
|
if (current_tags.includes(tag.textContent.replace(/ /g, "_"))) {
|
||||||
$(tag).addClass("selected");
|
$(tag).addClass("selected");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RelatedTag.tags_include = function(name) {
|
RelatedTag.current_tags = function() {
|
||||||
var current = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
return Utility.regexp_split($("#upload_tag_string,#post_tag_string").val().toLowerCase());
|
||||||
return $.inArray(name.toLowerCase(), current) > -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RelatedTag.toggle_tag = function(e) {
|
RelatedTag.toggle_tag = function(e) {
|
||||||
var $field = $("#upload_tag_string,#post_tag_string");
|
var $field = $("#upload_tag_string,#post_tag_string");
|
||||||
var tag = $(e.target).html().replace(/ /g, "_").replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
var tag = $(e.target).html().replace(/ /g, "_").replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
||||||
|
|
||||||
if (RelatedTag.tags_include(tag)) {
|
if (RelatedTag.current_tags().includes(tag)) {
|
||||||
var escaped_tag = Utility.regexp_escape(tag);
|
var escaped_tag = Utility.regexp_escape(tag);
|
||||||
$field.val($field.val().replace(new RegExp("(^|\\s)" + escaped_tag + "($|\\s)", "gi"), "$1$2"));
|
$field.val($field.val().replace(new RegExp("(^|\\s)" + escaped_tag + "($|\\s)", "gi"), "$1$2"));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -108,6 +108,10 @@ Utility.regexp_escape = function(string) {
|
|||||||
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
return string.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utility.regexp_split = function(string) {
|
||||||
|
return [...new Set(String(string === null || string === undefined ? "" : string).match(/\S+/g))];
|
||||||
|
}
|
||||||
|
|
||||||
$.fn.selectEnd = function() {
|
$.fn.selectEnd = function() {
|
||||||
return this.each(function() {
|
return this.each(function() {
|
||||||
this.focus();
|
this.focus();
|
||||||
|
|||||||
Reference in New Issue
Block a user