add global hooks for autocomplete functions #3795
This commit is contained in:
@@ -246,6 +246,10 @@ Autocomplete.initialize_wiki_autocomplete = function($fields) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Autocomplete.normal_source = function(term, resp) {
|
Autocomplete.normal_source = function(term, resp) {
|
||||||
|
if (Utility.is_global_hook_defined("Danbooru.Autocomplete.normal_source")) {
|
||||||
|
return window.Danbooru.Autocomplete.normal_source(term, resp);
|
||||||
|
}
|
||||||
|
|
||||||
var key = "ac-" + term.replace(/\./g,'\uFFFF');
|
var key = "ac-" + term.replace(/\./g,'\uFFFF');
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -432,6 +436,10 @@ Autocomplete.static_metatag_source = function(term, resp, metatag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Autocomplete.user_source = function(term, resp, metatag) {
|
Autocomplete.user_source = function(term, resp, metatag) {
|
||||||
|
if (Utility.is_global_hook_defined("Danbooru.Autocomplete.user_source")) {
|
||||||
|
return window.Danbooru.Autocomplete.user_source(term, resp, metatag);
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/users.json",
|
url: "/users.json",
|
||||||
data: {
|
data: {
|
||||||
@@ -466,6 +474,10 @@ Autocomplete.user_source = function(term, resp, metatag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Autocomplete.pool_source = function(term, resp, metatag) {
|
Autocomplete.pool_source = function(term, resp, metatag) {
|
||||||
|
if (Utility.is_global_hook_defined("Danbooru.Autocomplete.pool_source")) {
|
||||||
|
return window.Danbooru.Autocomplete.pool_source(term, resp, metatag);
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/pools.json",
|
url: "/pools.json",
|
||||||
data: {
|
data: {
|
||||||
@@ -489,6 +501,10 @@ Autocomplete.pool_source = function(term, resp, metatag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Autocomplete.favorite_group_source = function(term, resp, metatag) {
|
Autocomplete.favorite_group_source = function(term, resp, metatag) {
|
||||||
|
if (Utility.is_global_hook_defined("Danbooru.Autocomplete.favorite_group_source")) {
|
||||||
|
return window.Danbooru.Autocomplete.favorite_group_source(term, resp, metatag);
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/favorite_groups.json",
|
url: "/favorite_groups.json",
|
||||||
data: {
|
data: {
|
||||||
@@ -509,6 +525,10 @@ Autocomplete.favorite_group_source = function(term, resp, metatag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Autocomplete.saved_search_source = function(term, resp) {
|
Autocomplete.saved_search_source = function(term, resp) {
|
||||||
|
if (Utility.is_global_hook_defined("Danbooru.Autocomplete.saved_search_source")) {
|
||||||
|
return window.Danbooru.Autocomplete.saved_search_source(term, resp);
|
||||||
|
}
|
||||||
|
|
||||||
return SavedSearch.labels(term).then(function(labels) {
|
return SavedSearch.labels(term).then(function(labels) {
|
||||||
resp(labels.map(function(label) {
|
resp(labels.map(function(label) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -138,6 +138,18 @@ Utility.sorttable = function(table) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Utility.is_global_hook_defined = function(path) {
|
||||||
|
let objs = path.split(/\./g);
|
||||||
|
let obj = window;
|
||||||
|
objs.forEach(x => {
|
||||||
|
if (obj) {
|
||||||
|
obj = obj[x]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return typeof obj === 'function';
|
||||||
|
}
|
||||||
|
|
||||||
String.prototype.hash = function() {
|
String.prototype.hash = function() {
|
||||||
var hash = 5381, i = this.length;
|
var hash = 5381, i = this.length;
|
||||||
|
|
||||||
|
|||||||
@@ -72,15 +72,16 @@
|
|||||||
</script>
|
</script>
|
||||||
<script defer src="https://use.fontawesome.com/releases/v5.0.10/js/all.js" integrity="sha384-slN8GvtUJGnv6ca26v8EzVaR9DC58QEwsIk9q1QXdCU8Yu8ck/tL/5szYlBbqmS+" crossorigin="anonymous"></script>
|
<script defer src="https://use.fontawesome.com/releases/v5.0.10/js/all.js" integrity="sha384-slN8GvtUJGnv6ca26v8EzVaR9DC58QEwsIk9q1QXdCU8Yu8ck/tL/5szYlBbqmS+" crossorigin="anonymous"></script>
|
||||||
<script>
|
<script>
|
||||||
window.Danbooru = {
|
if (typeof window.Danbooru !== "object") {
|
||||||
notice: function(msg) {
|
window.Danbooru = {};
|
||||||
console.warn("Danbooru.notice will be deprecated. Use $(window).trigger('danbooru:notice', msg) instead.")
|
}
|
||||||
$(window).trigger("danbooru:notice", msg);
|
window.Danbooru.notice = function(msg) {
|
||||||
},
|
console.warn("Danbooru.notice will be deprecated. Use $(window).trigger('danbooru:notice', msg) instead.")
|
||||||
error: function(msg) {
|
$(window).trigger("danbooru:notice", msg);
|
||||||
console.warn("Danbooru.error will be deprecated. Use $(window).trigger('danbooru:error', msg) instead.")
|
}
|
||||||
$(window).trigger("danbooru:error", msg);
|
window.Danbooru.error = function(msg) {
|
||||||
}
|
console.warn("Danbooru.error will be deprecated. Use $(window).trigger('danbooru:error', msg) instead.")
|
||||||
|
$(window).trigger("danbooru:error", msg);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user