/**
* Emojies picker
*
* @author Pierre HUBERT
*/
ComunicWeb.components.emoji.picker = {
//Source code of the emojies picker
pickerSrc: '
";',
/**
* Initialize Emojie picker
*/
init: function(){
//Check if the picker has to be included in the page
var targetPicker = byId("emojiPicker");
if(!targetPicker){
targetPicker = createElem2({
appendTo: byId("wrapper"),
type: "div",
id: "emojiPicker",
innerHTML: this.pickerSrc
});
wdtEmojiBundle.defaults.emojiSheets.twitter = ComunicWeb.__config.assetsURL + "3rdparty/wdt-emoji/sheets/sheet_twitter_64_indexed_128.png";
wdtEmojiBundle.init('.wdt-emoji-bundle-enabled');
wdtEmojiBundle.changeType("twitter");
}
},
/**
* Add a picker for an element
*
* @param {HTMLElement} elem Target element
* @param {HTMLElement} trigger Alternative element to trigger picker
* @param {function} afterPicker Optionnal function to call once the openPicker
* function has been called on trigger click
*/
addPicker: function(elem, trigger, afterPicker){
//Make sure the system is ready
this.init();
//Check if the default features of the framework can be used
if(!trigger){
wdtEmojiBundle.addPicker(elem);
return;
}
trigger.addEventListener('click', function(e){
wdtEmojiBundle.openPicker.call(this, e);
if(afterPicker)
afterPicker(e);
});
var parent = elem.parentNode;
parent.className += ' wdt-emoji-picker-parent';
elem.className += ' wdt-emoji-bundle-enabled wdt-emoji-picker-ready';
},
/**
* Add a detached picker to a page
*
* @param {HTMLElement} target Target element that will contains the icon
* @param {(emojie : string) => any} callback Callback function called each time a new
* emojie is selected
*/
addDetachedPicker: function(target, callback){
this.init();
//Create input text that will received new emojies
var input = createElem2({
type: "input",
appendTo: target,
class: "wdt-emoji-bundle-enabled hidden",
elemType: "text",
style: "display: none;"
});
ComunicWeb.components.emoji.picker.addPicker(input);
let interval = setInterval(() => {
//Check if input has been detached
if(!input.isConnected){
clearInterval(interval);
return;
}
//Securely send value to callback
if(input.value.length > 0){
let value = input.value;
input.value = "";
callback(value);
}
}, 500);
}
}