Files
danbooru/app/assets/javascripts/utility.js
小太 e975664f48 Use OR instead of AND when excluding tags for blacklist.
This is because there currently is no way to do this, and this commit doesn't remove the AND capability either.
For example, take the original blacklist "a -b -c".
Currently, that means "Don't show a unless both b and c are present", but now it means "Don't show a unless either b or c are present".
For the original meaning, you now have to do this with two blacklists: "a -b" and "a -c"
2013-02-23 14:54:11 +11:00

66 lines
1.3 KiB
JavaScript

(function() {
Danbooru.meta = function(key) {
return $("meta[name=" + key + "]").attr("content");
}
Danbooru.notice = function(msg) {
$('#notice').html(msg).addClass("ui-state-highlight").removeClass("ui-state-error").fadeIn("fast");
}
Danbooru.error = function(msg) {
$('#notice').html(msg).removeClass("ui-state-highlight").addClass("ui-state-error").fadeIn("fast");
}
Danbooru.is_subset = function(array, subarray) {
var all = true;
$.each(subarray, function(i, val) {
if ($.inArray(val, array) === -1) {
all = false;
}
});
return all;
}
Danbooru.intersect = function(a, b) {
a = a.slice(0).sort();
b = b.slice(0).sort();
var result = [];
while (a.length > 0 && b.length > 0)
{
if (a[0] < b[0]) {
a.shift();
}
else if (a[0] > b[0]) {
b.shift();
}
else {
result.push(a.shift());
b.shift();
}
}
return result;
}
Danbooru.without = function(array, element) {
var temp = [];
$.each(array, function(i, v) {
if (v !== element) {
temp.push(v);
}
});
return temp;
}
Danbooru.reject = function(array, f) {
var filtered = [];
$.each(array, function(i, x) {
if (!f(x)) {
filtered.push(x);
}
});
return filtered;
}
})();