You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
12 KiB

7 years ago
  1. /*
  2. * Emoji plugin for summernote [https://github.com/summernote/summernote]
  3. * Canonical - https://github.com/nilobarp/summernote-ext-emoji
  4. */
  5. odoo.define('muk_web_utils.summernote_ext_emoji', function (require) {
  6. 'use strict';
  7. var tmpl = $.summernote.renderer.getTemplate();
  8. var emojis = [
  9. 'bowtie', 'smile', 'laughing', 'blush', 'smiley', 'relaxed',
  10. 'smirk', 'heart_eyes', 'kissing_heart', 'kissing_closed_eyes',
  11. 'flushed', 'relieved', 'satisfied', 'grin', 'wink',
  12. 'stuck_out_tongue_winking_eye', 'stuck_out_tongue_closed_eyes',
  13. 'grinning', 'kissing', 'kissing_smiling_eyes', 'stuck_out_tongue',
  14. 'sleeping', 'worried', 'frowning', 'anguished', 'open_mouth',
  15. 'grimacing', 'confused', 'hushed', 'expressionless', 'unamused',
  16. 'sweat_smile', 'sweat', 'disappointed_relieved', 'weary',
  17. 'pensive', 'disappointed', 'confounded', 'fearful', 'cold_sweat',
  18. 'persevere', 'cry', 'sob', 'joy', 'astonished', 'scream',
  19. 'neckbeard', 'tired_face', 'angry', 'rage', 'triumph', 'sleepy',
  20. 'yum', 'mask', 'sunglasses', 'dizzy_face', 'imp', 'smiling_imp',
  21. 'neutral_face', 'no_mouth', 'innocent', 'alien', 'yellow_heart',
  22. 'blue_heart', 'purple_heart', 'heart', 'green_heart',
  23. 'broken_heart', 'heartbeat', 'heartpulse', 'two_hearts',
  24. 'revolving_hearts', 'cupid', 'sparkling_heart', 'sparkles', 'star',
  25. 'star2', 'dizzy', 'boom', 'collision', 'anger', 'exclamation',
  26. 'question', 'grey_exclamation', 'grey_question', 'zzz', 'dash',
  27. 'sweat_drops', 'notes', 'musical_note', 'fire', 'hankey', 'poop',
  28. 'shit', '+1', 'thumbsup', '-1', 'thumbsdown', 'ok_hand', 'punch',
  29. 'facepunch', 'fist', 'v', 'wave', 'hand', 'raised_hand',
  30. 'open_hands', 'point_up', 'point_down', 'point_left',
  31. 'point_right', 'raised_hands', 'pray', 'point_up_2', 'clap',
  32. 'muscle', 'metal', 'fu', 'walking', 'runner', 'running', 'couple',
  33. 'family', 'two_men_holding_hands', 'two_women_holding_hands',
  34. 'dancer', 'dancers', 'ok_woman', 'no_good',
  35. 'information_desk_person', 'raising_hand', 'bride_with_veil',
  36. 'person_with_pouting_face', 'person_frowning', 'bow', 'couplekiss',
  37. 'couple_with_heart', 'massage', 'haircut', 'nail_care', 'boy',
  38. 'girl', 'woman', 'man', 'baby', 'older_woman', 'older_man',
  39. 'person_with_blond_hair', 'man_with_gua_pi_mao', 'man_with_turban',
  40. 'construction_worker', 'cop', 'angel', 'princess', 'smiley_cat',
  41. 'smile_cat', 'heart_eyes_cat', 'kissing_cat', 'smirk_cat',
  42. 'scream_cat', 'crying_cat_face', 'joy_cat', 'pouting_cat',
  43. 'japanese_ogre', 'japanese_goblin', 'see_no_evil', 'hear_no_evil',
  44. 'speak_no_evil', 'guardsman', 'skull', 'feet', 'lips', 'kiss',
  45. 'droplet', 'ear', 'eyes', 'nose', 'tongue', 'love_letter',
  46. 'bust_in_silhouette', 'busts_in_silhouette', 'speech_balloon',
  47. 'thought_balloon', 'feelsgood', 'finnadie', 'goberserk', 'godmode',
  48. 'hurtrealbad', 'rage1', 'rage2', 'rage3', 'rage4', 'suspect',
  49. 'trollface', 'sunny', 'umbrella', 'cloud', 'snowflake', 'snowman',
  50. 'zap', 'cyclone', 'foggy', 'ocean', 'cat', 'dog', 'mouse',
  51. 'hamster', 'rabbit', 'wolf', 'frog', 'tiger', 'koala', 'bear',
  52. 'pig', 'pig_nose', 'cow', 'boar', 'monkey_face', 'monkey', 'horse',
  53. 'racehorse', 'camel', 'sheep', 'elephant', 'panda_face', 'snake',
  54. 'bird', 'baby_chick', 'hatched_chick', 'hatching_chick', 'chicken',
  55. 'penguin', 'turtle', 'bug', 'honeybee', 'ant', 'beetle', 'snail',
  56. 'octopus', 'tropical_fish', 'fish', 'whale', 'whale2', 'dolphin',
  57. 'cow2', 'ram', 'rat', 'water_buffalo', 'tiger2', 'rabbit2',
  58. 'dragon', 'goat', 'rooster', 'dog2', 'pig2', 'mouse2', 'ox',
  59. 'dragon_face', 'blowfish', 'crocodile', 'dromedary_camel',
  60. 'leopard', 'cat2', 'poodle', 'paw_prints', 'bouquet',
  61. 'cherry_blossom', 'tulip', 'four_leaf_clover', 'rose', 'sunflower',
  62. 'hibiscus', 'maple_leaf', 'leaves', 'fallen_leaf', 'herb',
  63. 'mushroom', 'cactus', 'palm_tree', 'evergreen_tree',
  64. 'deciduous_tree', 'chestnut', 'seedling', 'blossom', 'ear_of_rice',
  65. 'shell', 'globe_with_meridians', 'sun_with_face',
  66. 'full_moon_with_face', 'new_moon_with_face', 'new_moon',
  67. 'waxing_crescent_moon', 'first_quarter_moon',
  68. 'waxing_gibbous_moon', 'full_moon', 'waning_gibbous_moon',
  69. 'last_quarter_moon', 'waning_crescent_moon',
  70. 'last_quarter_moon_with_face', 'first_quarter_moon_with_face',
  71. 'moon', 'earth_africa', 'earth_americas', 'earth_asia', 'volcano',
  72. 'milky_way', 'partly_sunny', 'octocat', 'squirrel', 'bamboo',
  73. 'gift_heart', 'dolls', 'school_satchel', 'mortar_board', 'flags',
  74. 'fireworks', 'sparkler', 'wind_chime', 'rice_scene',
  75. 'jack_o_lantern', 'ghost', 'santa', 'christmas_tree', 'gift',
  76. 'bell', 'no_bell', 'tanabata_tree', 'tada', 'confetti_ball',
  77. 'balloon', 'crystal_ball', 'cd', 'dvd', 'floppy_disk', 'camera',
  78. 'video_camera', 'movie_camera', 'computer', 'tv', 'iphone',
  79. 'phone', 'telephone', 'telephone_receiver', 'pager', 'fax',
  80. 'minidisc', 'vhs', 'sound', 'speaker', 'mute', 'loudspeaker',
  81. 'mega', 'hourglass', 'hourglass_flowing_sand', 'alarm_clock',
  82. 'watch', 'radio', 'satellite', 'loop', 'mag', 'mag_right',
  83. 'unlock', 'lock', 'lock_with_ink_pen', 'closed_lock_with_key',
  84. 'key', 'bulb', 'flashlight', 'high_brightness', 'low_brightness',
  85. 'electric_plug', 'battery', 'calling', 'email', 'mailbox',
  86. 'postbox', 'bath', 'bathtub', 'shower', 'toilet', 'wrench',
  87. 'nut_and_bolt', 'hammer', 'seat', 'moneybag', 'yen', 'dollar',
  88. 'pound', 'euro', 'credit_card', 'money_with_wings', 'e-mail',
  89. 'inbox_tray', 'outbox_tray', 'envelope', 'incoming_envelope',
  90. 'postal_horn', 'mailbox_closed', 'mailbox_with_mail',
  91. 'mailbox_with_no_mail', 'door', 'smoking', 'bomb', 'gun', 'hocho',
  92. 'pill', 'syringe', 'page_facing_up', 'page_with_curl',
  93. 'bookmark_tabs', 'bar_chart', 'chart_with_upwards_trend',
  94. 'chart_with_downwards_trend', 'scroll', 'clipboard', 'calendar',
  95. 'date', 'card_index', 'file_folder', 'open_file_folder',
  96. 'scissors', 'pushpin', 'paperclip', 'black_nib', 'pencil2',
  97. 'straight_ruler', 'triangular_ruler', 'closed_book', 'green_book',
  98. 'blue_book', 'orange_book', 'notebook',
  99. 'notebook_with_decorative_cover', 'ledger', 'books', 'bookmark',
  100. 'name_badge', 'microscope', 'telescope', 'newspaper', 'football',
  101. 'basketball', 'soccer', 'baseball', 'tennis', '8ball',
  102. 'rugby_football', 'bowling', 'golf', 'mountain_bicyclist',
  103. 'bicyclist', 'horse_racing', 'snowboarder', 'swimmer', 'surfer',
  104. 'ski', 'spades', 'hearts', 'clubs', 'diamonds', 'gem', 'ring',
  105. 'trophy', 'musical_score', 'musical_keyboard', 'violin',
  106. 'space_invader', 'video_game', 'black_joker',
  107. 'flower_playing_cards', 'game_die', 'dart', 'mahjong', 'clapper',
  108. 'memo', 'pencil', 'book', 'art', 'microphone', 'headphones',
  109. 'trumpet', 'saxophone', 'guitar', 'shoe', 'sandal', 'high_heel',
  110. 'lipstick', 'boot', 'shirt', 'tshirt', 'necktie', 'womans_clothes',
  111. 'dress', 'running_shirt_with_sash', 'jeans', 'kimono', 'bikini',
  112. 'ribbon', 'tophat', 'crown', 'womans_hat', 'mans_shoe',
  113. 'closed_umbrella', 'briefcase', 'handbag', 'pouch', 'purse',
  114. 'eyeglasses', 'fishing_pole_and_fish', 'coffee', 'tea', 'sake',
  115. 'baby_bottle', 'beer', 'beers', 'cocktail', 'tropical_drink',
  116. 'wine_glass', 'fork_and_knife', 'pizza', 'hamburger', 'fries',
  117. 'poultry_leg', 'meat_on_bone', 'spaghetti', 'curry',
  118. 'fried_shrimp', 'bento', 'sushi', 'fish_cake', 'rice_ball',
  119. 'rice_cracker', 'rice', 'ramen', 'stew', 'oden', 'dango', 'egg',
  120. 'bread', 'doughnut', 'custard', 'icecream', 'ice_cream',
  121. 'shaved_ice', 'birthday', 'cake', 'cookie', 'chocolate_bar',
  122. 'candy', 'lollipop', 'honey_pot', 'apple', 'green_apple',
  123. 'tangerine', 'lemon', 'cherries', 'grapes', 'watermelon',
  124. 'strawberry', 'peach', 'melon', 'banana', 'pear', 'pineapple',
  125. 'sweet_potato', 'eggplant', 'tomato', 'corn', 'house',
  126. 'house_with_garden', 'school', 'office', 'post_office', 'hospital',
  127. 'bank', 'convenience_store', 'love_hotel', 'hotel', 'wedding',
  128. 'church', 'department_store', 'european_post_office',
  129. 'city_sunrise', 'city_sunset', 'japanese_castle',
  130. 'european_castle', 'tent', 'factory', 'tokyo_tower', 'japan',
  131. 'mount_fuji', 'sunrise_over_mountains', 'sunrise', 'stars',
  132. 'statue_of_liberty', 'bridge_at_night', 'carousel_horse',
  133. 'rainbow', 'ferris_wheel', 'fountain', 'roller_coaster', 'ship',
  134. 'speedboat', 'boat', 'sailboat', 'rowboat', 'anchor', 'rocket',
  135. 'airplane', 'helicopter', 'steam_locomotive', 'tram',
  136. 'mountain_railway', 'bike', 'aerial_tramway', 'suspension_railway',
  137. 'mountain_cableway', 'tractor', 'blue_car', 'oncoming_automobile',
  138. 'car', 'red_car', 'taxi', 'oncoming_taxi', 'articulated_lorry',
  139. 'bus', 'oncoming_bus', 'rotating_light', 'police_car',
  140. 'oncoming_police_car', 'fire_engine', 'ambulance', 'minibus',
  141. 'truck', 'train', 'station', 'train2', 'bullettrain_front',
  142. 'bullettrain_side', 'light_rail', 'monorail', 'railway_car',
  143. 'trolleybus', 'ticket', 'fuelpump', 'vertical_traffic_light',
  144. 'traffic_light', 'warning', 'construction', 'beginner', 'atm',
  145. 'slot_machine', 'busstop', 'barber', 'hotsprings',
  146. 'checkered_flag', 'crossed_flags', 'izakaya_lantern', 'moyai',
  147. 'circus_tent', 'performing_arts', 'round_pushpin',
  148. 'triangular_flag_on_post'
  149. ];
  150. /* IE polyfill */
  151. if (!Array.prototype.filter) {
  152. Array.prototype.filter = function(fun /* , thisp */) {
  153. var len = this.length >>> 0;
  154. if (typeof fun != "function")
  155. throw new TypeError();
  156. var res = [];
  157. var thisp = arguments[1];
  158. for (var i = 0; i < len; i++) {
  159. if (i in this) {
  160. var val = this[i];
  161. if (fun.call(thisp, val, i, this))
  162. res.push(val);
  163. }
  164. }
  165. return res;
  166. };
  167. }
  168. var addListener = function() {
  169. $('body').on('click', '#emoji-filter', function(e) {
  170. e.stopPropagation();
  171. $('#emoji-filter').focus();
  172. });
  173. $('body').on('keyup', '#emoji-filter', function(e) {
  174. var filteredList = filterEmoji($('#emoji-filter').val());
  175. $("#emoji-dropdown .emoji-list").html(filteredList);
  176. });
  177. };
  178. var dropdown = function() {
  179. return '<div class="dropdown-menu dropdown-keep-open" id="emoji-dropdown" style="width: 200px; padding: 10px;">'
  180. + '<div class="row">'
  181. + '<div class="col-md-12">'
  182. + '<input type="text" class="form-control" id="emoji-filter"/>'
  183. + '<br/>'
  184. + '</div>'
  185. + '</div>'
  186. + '<div class="emoji-list">'
  187. + render(emojis) + '</div>' + '</div>';
  188. };
  189. var render = function(emojis) {
  190. var emoList = '';
  191. /* limit list to 24 images */
  192. var emojis = emojis.slice(0, 24);
  193. var chunks = chunkEmoji(emojis, 4);
  194. for (var j = 0; j < chunks.length; j++) {
  195. emoList += '<div class="row">';
  196. for (var i = 0; i < chunks[j].length; i++) {
  197. var emo = chunks[j][i];
  198. emoList += '<div class="col-xs-3">'
  199. + '<a href="javascript:void(0)" data-event="selectEmoji" data-value="'
  200. + emo
  201. + '"><span style="background: url(\''
  202. + '/muk_web_utils/static/lib/summernote/emoji/pngs/'
  203. + emo
  204. + '.png\'); display: inline-block; width: 24px; height: 24px; background-size: 24px;"></span></a>'
  205. + '</div>';
  206. }
  207. emoList += '</div>';
  208. }
  209. return emoList;
  210. };
  211. var chunkEmoji = function(list, chunkSize) {
  212. var R = [];
  213. for (var i = 0; i < list.length; i += chunkSize)
  214. R.push(list.slice(i, i + chunkSize));
  215. return R;
  216. }
  217. var filterEmoji = function(value) {
  218. var filtered = emojis.filter(function(el) {
  219. return el.indexOf(value) > -1;
  220. });
  221. return render(filtered);
  222. };
  223. $.summernote.addPlugin({
  224. buttons : {
  225. "emoji" : function(lang, options) {
  226. addListener();
  227. return tmpl.iconButton(options.iconPrefix + 'smile-o', {
  228. title : 'Emoji',
  229. value : 'Emoji',
  230. hide : true,
  231. dropdown : dropdown()
  232. });
  233. }
  234. },
  235. events : {
  236. selectEmoji : function(event, editor, layoutInfo, value) {
  237. var $editable = layoutInfo.editable();
  238. var img = new Image();
  239. img.src = '/muk_web_utils/static/lib/summernote/emoji/pngs/' + value + '.png';
  240. img.alt = value;
  241. img.className = 'emoji-icon-inline';
  242. editor.insertNode($editable, img);
  243. }
  244. }
  245. });
  246. });