111 lines
3 KiB
JavaScript
111 lines
3 KiB
JavaScript
#include watcher.js
|
|
|
|
var AmiEmoticonList = function(parent) {
|
|
var container = $e({ attrs: { id: 'emotes' } }),
|
|
watcher = new AmiWatcher;
|
|
parent.appendChild(container);
|
|
|
|
var clear = function() {
|
|
$rc(container);
|
|
};
|
|
|
|
var add = function(emote) {
|
|
container.appendChild($e({
|
|
tag: 'img',
|
|
attrs: {
|
|
src: emote.url,
|
|
alt: emote.strings[0],
|
|
title: emote.strings[0],
|
|
onclick: function() { watcher.call(emote, [emote]); },
|
|
},
|
|
}));
|
|
};
|
|
|
|
var hide = function() { container.classList.add('hidden'); };
|
|
var show = function() { container.classList.remove('hidden'); };
|
|
|
|
return {
|
|
clear: clear,
|
|
hide: hide,
|
|
show: show,
|
|
add: add,
|
|
render: function(emotes, minRank) {
|
|
clear();
|
|
if(emotes.any(minRank)) {
|
|
emotes.forEach(minRank, add);
|
|
show();
|
|
} else hide();
|
|
},
|
|
watch: watcher.watch,
|
|
unwatch: watcher.unwatch,
|
|
};
|
|
};
|
|
|
|
var AmiEmoticons = function() {
|
|
var emotes = [];
|
|
|
|
var clear = function() {
|
|
emotes = [];
|
|
};
|
|
|
|
var add = function(emote) {
|
|
emotes.push(emote);
|
|
};
|
|
|
|
var addLegacy = function(emoteOld) {
|
|
var emote = {
|
|
url: emoteOld.Image.replace('https:', ''),
|
|
minRank: emoteOld.Hierarchy,
|
|
strings: [],
|
|
};
|
|
for(var i = 0; i < emoteOld.Text.length; ++i)
|
|
emote.strings.push(emoteOld.Text[i].slice(1, -1));
|
|
add(emote);
|
|
};
|
|
|
|
return {
|
|
clear: clear,
|
|
add: add,
|
|
addLegacy: addLegacy,
|
|
load: function(batch) {
|
|
for(var i in batch)
|
|
add(batch[i]);
|
|
},
|
|
loadLegacy: function(batch) {
|
|
for(var i in batch)
|
|
addLegacy(batch[i]);
|
|
},
|
|
forEach: function(minRank, callback) {
|
|
if(minRank === undefined) minRank = 0;
|
|
for(var i in emotes) {
|
|
var emote = emotes[i];
|
|
if(emote.minRank <= minRank)
|
|
callback(emote);
|
|
}
|
|
},
|
|
any: function(minRank) {
|
|
if(minRank === undefined) minRank = 0;
|
|
for(var i in emotes)
|
|
if(emotes[i].minRank <= minRank)
|
|
return true;
|
|
return false;
|
|
},
|
|
findByName: function(minRank, name, returnString) {
|
|
var found = [];
|
|
for(var i in emotes) {
|
|
var emote = emotes[i];
|
|
if(emote.minRank <= minRank) {
|
|
for(var j in emote.strings) {
|
|
var string = emote.strings[j];
|
|
if(string.indexOf(name) === 0) {
|
|
found.push(returnString ? string : emote);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return found;
|
|
},
|
|
};
|
|
};
|