;(function() {
function emoji(){}
// settings
emoji.img_path = 'emoji/';
emoji.sheet_path = 'sheet_64.png';
emoji.use_css_imgs = false;
emoji.colons_mode = false;
emoji.text_mode = false;
emoji.include_title = false;
emoji.allow_native = true;
emoji.use_sheet = false;
emoji.inits = {};
emoji.map = {};
emoji.replace_emoticons = function(str){
emoji.init_emoticons();
return str.replace(emoji.rx_emoticons, function(m, $1, $2){
var val = emoji.map.emoticons[$2];
return val ? $1+emoji.replacement(val, $2) : m;
});
};
emoji.replace_emoticons_with_colons = function(str){
emoji.init_emoticons();
return str.replace(emoji.rx_emoticons, function(m, $1, $2){
var val = emoji.data[emoji.map.emoticons[$2]][3][0];
return val ? $1+':'+val+':' : m;
});
};
emoji.replace_colons = function(str){
emoji.init_colons();
return str.replace(emoji.rx_colons, function(m){
var idx = m.substr(1, m.length-2);
var val = emoji.map.colons[idx];
return val ? emoji.replacement(val, idx, ':') : m;
});
};
emoji.replace_unified = function(str){
emoji.init_unified();
return str.replace(emoji.rx_unified, function(m){
var val = emoji.map.unified[m];
return val ? emoji.replacement(val) : m;
});
};
emoji.replacement = function(idx, actual, wrapper){
wrapper = wrapper || '';
if (emoji.colons_mode) return ':'+emoji.data[idx][3][0]+':';
var text_name = (actual) ? wrapper+actual+wrapper : emoji.data[idx][6] || wrapper+emoji.data[idx][3][0]+wrapper;
if (emoji.text_mode) return text_name;
emoji.init_env();
if (emoji.replace_mode == 'unified' && emoji.allow_native && emoji.data[idx][0][0]) return emoji.data[idx][0][0];
if (emoji.replace_mode == 'softbank' && emoji.allow_native && emoji.data[idx][1]) return emoji.data[idx][1];
if (emoji.replace_mode == 'google' && emoji.allow_native && emoji.data[idx][2]) return emoji.data[idx][2];
var img = emoji.data[idx][7] || emoji.img_path+idx+'.png';
var title = emoji.include_title ? ' title="'+(actual || emoji.data[idx][3][0])+'"' : '';
var text = emoji.include_text ? wrapper+(actual || emoji.data[idx][3][0])+wrapper : '';
if (emoji.supports_css) {
var px = emoji.data[idx][4];
var py = emoji.data[idx][5];
if (emoji.use_sheet && px != null && py != null){
var mul = 100 / (emoji.sheet_size - 1);
var style = 'background: url('+emoji.sheet_path+');background-position:'+(mul*px)+'% '+(mul*py)+'%;background-size:'+emoji.sheet_size+'00%';
return ''+text+'';
}else if (emoji.use_css_imgs){
return ''+text+'';
}else{
return ''+text+'';
}
}
return '';
};
emoji.init_emoticons = function(){
if (emoji.inits.emoticons) return;
emoji.init_colons(); // we require this for the emoticons map
emoji.inits.emoticons = 1;
var a = [];
emoji.map.emoticons = {};
for (var i in emoji.emoticons_data){
// because we never see some characters in our text except as entities, we must do some replacing
var emoticon = i.replace(/\&/g, '&').replace(/\/g, '>');
if (!emoji.map.colons[emoji.emoticons_data[i]]) continue;
emoji.map.emoticons[emoticon] = emoji.map.colons[emoji.emoticons_data[i]];
a.push(emoji.escape_rx(emoticon));
}
emoji.rx_emoticons = new RegExp(('(^|\\s)('+a.join('|')+')(?=$|[\\s|\\?\\.,!])'), 'g');
};
emoji.init_colons = function(){
if (emoji.inits.colons) return;
emoji.inits.colons = 1;
emoji.rx_colons = new RegExp('\:[^\\s:]+\:', 'g');
emoji.map.colons = {};
for (var i in emoji.data){
for (var j=0; j":"laughing",
":->":"laughing",
"8)":"sunglasses",
":\\\\":"confused",
":-\\\\":"confused",
":\/":"confused",
":-\/":"confused",
":|":"neutral_face",
":-|":"neutral_face",
":o":"open_mouth",
":-o":"open_mouth",
">:(":"angry",
">:-(":"angry",
":p":"stuck_out_tongue",
":-p":"stuck_out_tongue",
":P":"stuck_out_tongue",
":-P":"stuck_out_tongue",
":b":"stuck_out_tongue",
":-b":"stuck_out_tongue",
";p":"stuck_out_tongue_winking_eye",
";-p":"stuck_out_tongue_winking_eye",
";b":"stuck_out_tongue_winking_eye",
";-b":"stuck_out_tongue_winking_eye",
";P":"stuck_out_tongue_winking_eye",
";-P":"stuck_out_tongue_winking_eye",
":o)":"monkey_face",
"D:":"anguished"
};
if (typeof exports === 'object') {
module.exports = emoji;
} else if (typeof define === 'function' && define.amd) {
define(function() { return emoji; });
} else {
this.emoji = emoji;
}
}).call(function() {
return this || (typeof window !== 'undefined' ? window : global);
}());