popupemojipicker.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2010 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <title>Popup Emoji Picker</title>
  10. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  11. <script type="text/javascript" src="../base.js"></script>
  12. <script type="text/javascript">
  13. goog.require('goog.dom.classlist');
  14. goog.require('goog.ui.emoji.PopupEmojiPicker');
  15. goog.require('goog.ui.emoji.EmojiPicker');
  16. goog.require('goog.ui.emoji.SpriteInfo');
  17. </script>
  18. <link rel="stylesheet" href="css/demo.css">
  19. <link rel="stylesheet" href="css/emojipicker.css">
  20. <link rel="stylesheet" href="css/emojisprite.css">
  21. <style type="text/css">
  22. /* TabPane styles */
  23. .goog-tabpane {
  24. background: threedface;
  25. padding-left: 1px;
  26. }
  27. .goog-tabpane-tabs {
  28. list-style: none;
  29. margin: 0px;
  30. padding: 0px;
  31. }
  32. .goog-tabpane-cont {
  33. overflow: auto;
  34. clear: both;
  35. background: threedface;
  36. border: 1px solid;
  37. border-color: threedhighlight threedshadow threedshadow threedhighlight;
  38. padding: 2px;
  39. }
  40. .goog-tabpane-tab, .goog-tabpane-tab-selected {
  41. display: block;
  42. float: left;
  43. padding: 0px 3ex;
  44. background: threedface;
  45. border: 1px solid;
  46. border-color: threedhighlight threedshadow threedface threedhighlight;
  47. margin: 0px;
  48. }
  49. .goog-tabpane-tab {
  50. margin-top: 0px;
  51. }
  52. .goog-tabpane-tab-selected {
  53. padding-bottom: 2px;
  54. padding-top: 2px;
  55. position: relative;
  56. top: 1px;
  57. font-weight: bold;
  58. }
  59. /* Emojipicker styles */
  60. .singlePagePicker .goog-palette {
  61. border: 1px solid black;
  62. }
  63. .popupButton {
  64. display: block;
  65. width: 100px;
  66. text-align: center;
  67. padding: 10px;
  68. font: normal 0.8em verdana,sans-serif;
  69. border: 1px solid #000;
  70. }
  71. </style>
  72. </head>
  73. <body>
  74. <h3>Popup Emoji Picker Demo</h3>
  75. This is a demo of popupemojipickers and docked emoji pickers. Selecting an
  76. emoji inserts a pseudo image tag into the text area with the id of that emoji.
  77. <h4>Sprited Emojipicker (contains a mix of sprites and non-sprites):</h4>
  78. <div id="spriteDock1" class="singlePagePicker"></div>
  79. <h4>Sprited Progressively-rendered Emojipicker (contains a mix of sprites and
  80. non-sprites):</h4>
  81. <div id="spriteDock2" class="singlePagePicker"></div>
  82. <h4>Popup Emoji:</h4>
  83. <a href="javascript:void(0)" class="popupButton" id="button1">Gimme some emoji</a>
  84. <hr>
  85. <h4>Fast-load Progressive Sprited Emojipicker</h4>
  86. <div id="fastLoad1" class="singlePagePicker"></div>
  87. <h4>Fast-load Non-progressive Sprited Emojipicker</h4>
  88. <div id="fastLoad2" class="singlePagePicker"></div>
  89. <div id="spriteDock3" class="singlePagePicker"></div>
  90. <h4>Docked emoji:</h4>
  91. <div id="emojiDock"></div>
  92. <h4>Single Page of Emoji</h4>
  93. <div id="singlePageEmojiPicker" class="singlePagePicker"></div>
  94. <h4>Delayed load popup picker:</h4>
  95. <a href="javascript:void(0)" class="popupButton" id="button2">More emoji</a>
  96. <h4>Delayed load docked picker:</h4>
  97. <a href="javascript:void(0)" id="delayedLoadDockDiv" class="popupButton"
  98. onclick="loadPicker()">
  99. Click to load
  100. </a>
  101. <div id="delayedLoadDock" class="singlePagePicker"></div>
  102. <textarea rows="20" cols="200" id="text">
  103. </textarea>
  104. <script type="text/javascript">
  105. var emojiGroup1 = [
  106. 'Emoji 1',
  107. [
  108. ['emoji/200.gif', 'std.200'],
  109. ['emoji/201.gif', 'std.201'],
  110. ['emoji/202.gif', 'std.202'],
  111. ['emoji/203.gif', 'std.203'],
  112. ['emoji/204.gif', 'std.204'],
  113. ['emoji/205.gif', 'std.205'],
  114. ['emoji/206.gif', 'std.206'],
  115. ['emoji/2BC.gif', 'std.2BC'],
  116. ['emoji/2BD.gif', 'std.2BD'],
  117. ['emoji/2BE.gif', 'std.2BE'],
  118. ['emoji/2BF.gif', 'std.2BF'],
  119. ['emoji/2C0.gif', 'std.2C0'],
  120. ['emoji/2C1.gif', 'std.2C1'],
  121. ['emoji/2C2.gif', 'std.2C2'],
  122. ['emoji/2C3.gif', 'std.2C3'],
  123. ['emoji/2C4.gif', 'std.2C4'],
  124. ['emoji/2C5.gif', 'std.2C5'],
  125. ['emoji/2C6.gif', 'std.2C6'],
  126. ['emoji/2C7.gif', 'std.2C7'],
  127. ['emoji/2C8.gif', 'std.2C8'],
  128. ['emoji/2C9.gif', 'std.2C9'],
  129. ['emoji/2CA.gif', 'std.2CA'],
  130. ['emoji/2CB.gif', 'std.2CB'],
  131. ['emoji/2CC.gif', 'std.2CC'],
  132. ['emoji/2CD.gif', 'std.2CD'],
  133. ['emoji/2CE.gif', 'std.2CE']
  134. ]];
  135. var emojiGroup2 = [
  136. 'Emoji 2',
  137. [
  138. ['emoji/2D0.gif', 'std.2D0'],
  139. ['emoji/2D1.gif', 'std.2D1'],
  140. ['emoji/2D2.gif', 'std.2D2'],
  141. ['emoji/2D3.gif', 'std.2D3'],
  142. ['emoji/2D4.gif', 'std.2D4'],
  143. ['emoji/2D5.gif', 'std.2D5'],
  144. ['emoji/2D6.gif', 'std.2D6'],
  145. ['emoji/2D7.gif', 'std.2D7'],
  146. ['emoji/2D8.gif', 'std.2D8'],
  147. ['emoji/2D9.gif', 'std.2D9'],
  148. ['emoji/2DA.gif', 'std.2DA'],
  149. ['emoji/2DB.gif', 'std.2DB'],
  150. ['emoji/2DC.gif', 'std.2DC'],
  151. ['emoji/2DD.gif', 'std.2DD'],
  152. ['emoji/2DE.gif', 'std.2DE'],
  153. ['emoji/2DF.gif', 'std.2DF'],
  154. ['emoji/2E0.gif', 'std.2E0'],
  155. ['emoji/2E1.gif', 'std.2E1'],
  156. ['emoji/2E2.gif', 'std.2E2'],
  157. ['emoji/2E3.gif', 'std.2E3']
  158. ]];
  159. var emojiGroup3 = [
  160. 'Emoji 3',
  161. [
  162. ['emoji/2E4.gif', 'std.2E4'],
  163. ['emoji/2E5.gif', 'std.2E5'],
  164. ['emoji/2E6.gif', 'std.2E6'],
  165. ['emoji/2E7.gif', 'std.2E7'],
  166. ['emoji/2E8.gif', 'std.2E8'],
  167. ['emoji/2E9.gif', 'std.2E9'],
  168. ['emoji/2EA.gif', 'std.2EA'],
  169. ['emoji/2EB.gif', 'std.2EB'],
  170. ['emoji/2EC.gif', 'std.2EC'],
  171. ['emoji/2ED.gif', 'std.2ED'],
  172. ['emoji/2EE.gif', 'std.2EE'],
  173. ['emoji/2EF.gif', 'std.2EF'],
  174. ['emoji/2F0.gif', 'std.2F0'],
  175. ['emoji/2F1.gif', 'std.2F1'],
  176. ['emoji/2F2.gif', 'std.2F2'],
  177. ['emoji/2F3.gif', 'std.2F3'],
  178. ['emoji/2F4.gif', 'std.2F4'],
  179. ['emoji/2F5.gif', 'std.2F5'],
  180. ['emoji/2F6.gif', 'std.2F6'],
  181. ['emoji/2F7.gif', 'std.2F7']
  182. ]
  183. ];
  184. var sprite = 'emoji/sprite.png';
  185. var sprite2 = 'emoji/sprite2.png';
  186. /**
  187. * Creates a SpriteInfo object with the specified properties. If the image is
  188. * sprited via CSS, then only the first parameter needs a value. If the image
  189. * is sprited via metadata, then the first parameter should be left null.
  190. *
  191. * @param {?string} cssClass CSS class to properly display the sprited image.
  192. * @param {string=} opt_url Url of the sprite image.
  193. * @param {number=} opt_width Width of the image being sprited.
  194. * @param {number=} opt_height Height of the image being sprited.
  195. * @param {number=} opt_xOffset Positive x offset of the image being sprited
  196. * within the sprite.
  197. * @param {number=} opt_yOffset Positive y offset of the image being sprited
  198. * within the sprite.
  199. * @param {boolean=} opt_animated Whether the sprite info is for an animated
  200. * emoji.
  201. */
  202. function si(cssClass, opt_url, opt_width, opt_height, opt_xOffset,
  203. opt_yOffset, opt_animated) {
  204. return new goog.ui.emoji.SpriteInfo(cssClass, opt_url, opt_width,
  205. opt_height, opt_xOffset, opt_yOffset, opt_animated);
  206. }
  207. // This group contains a mix of sprited emoji via css, sprited emoji via
  208. // metadata, and non-sprited emoji.
  209. var spritedEmoji1 = [
  210. 'Emoji 1',
  211. [
  212. ['emoji/200.gif', 'std.200', si('SPRITE_200')],
  213. ['emoji/201.gif', 'std.201', si('SPRITE_201')],
  214. ['emoji/202.gif', 'std.202', si('SPRITE_202')],
  215. ['emoji/203.gif', 'std.203', si('SPRITE_203')],
  216. ['emoji/204.gif', 'std.204', si('SPRITE_204')],
  217. ['emoji/205.gif', 'std.205', si('SPRITE_205')],
  218. ['emoji/206.gif', 'std.206', si('SPRITE_206')],
  219. ['emoji/2BC.gif', 'std.2BC', si('SPRITE_2BC')],
  220. ['emoji/2BD.gif', 'std.2BD', si('SPRITE_2BD')],
  221. ['emoji/2BE.gif', 'std.2BE', si(null, sprite, 18, 18, 36, 54)],
  222. ['emoji/2BF.gif', 'std.2BF', si(null, sprite, 18, 18, 0, 126)],
  223. ['emoji/2C0.gif', 'std.2C0', si(null, sprite, 18, 18, 18, 305)],
  224. ['emoji/2C1.gif', 'std.2C1', si(null, sprite, 18, 18, 0, 287)],
  225. ['emoji/2C2.gif', 'std.2C2', si(null, sprite, 18, 18, 18, 126)],
  226. ['emoji/2C3.gif', 'std.2C3', si(null, sprite, 18, 18, 36, 234)],
  227. ['emoji/2C4.gif', 'std.2C4', si(null, sprite, 18, 18, 36, 72)],
  228. ['emoji/2C5.gif', 'std.2C5', si(null, sprite, 18, 18, 54, 54)],
  229. ['emoji/2C6.gif', 'std.2C6'],
  230. ['emoji/2C7.gif', 'std.2C7'],
  231. ['emoji/2C8.gif', 'std.2C8'],
  232. ['emoji/2C9.gif', 'std.2C9'],
  233. ['emoji/2CA.gif', 'std.2CA'],
  234. ['emoji/2CB.gif', 'std.2CB'],
  235. ['emoji/2CC.gif', 'std.2CC'],
  236. ['emoji/2CD.gif', 'std.2CD'],
  237. ['emoji/2CE.gif', 'std.2CE']
  238. ]];
  239. // This group contains a mix of sprited emoji via css, sprited emoji via
  240. // metadata, and non-sprited emoji.
  241. var spritedEmoji2 = [
  242. 'Emoji 1',
  243. [
  244. ['emoji/200.gif', 'std.200', si('SPRITE_200')],
  245. ['emoji/201.gif', 'std.201', si('SPRITE_201')],
  246. ['emoji/202.gif', 'std.202', si('SPRITE_202')],
  247. ['emoji/203.gif', 'std.203', si('SPRITE_203')],
  248. ['emoji/204.gif', 'std.204', si('SPRITE_204')],
  249. ['emoji/205.gif', 'std.205', si('SPRITE_205')],
  250. ['emoji/206.gif', 'std.206', si('SPRITE_206')],
  251. ['emoji/2BC.gif', 'std.2BC', si('SPRITE_2BC')],
  252. ['emoji/2BD.gif', 'std.2BD', si('SPRITE_2BD')],
  253. ['emoji/2BE.gif', 'std.2BE', si(null, sprite, 18, 18, 36, 54)],
  254. ['emoji/2BF.gif', 'std.2BF', si(null, sprite, 18, 18, 0, 126)],
  255. ['emoji/2C0.gif', 'std.2C0', si(null, sprite, 18, 18, 18, 305)],
  256. ['emoji/2C1.gif', 'std.2C1', si(null, sprite, 18, 18, 0, 287)],
  257. ['emoji/2C2.gif', 'std.2C2', si(null, sprite, 18, 18, 18, 126)],
  258. ['emoji/2C3.gif', 'std.2C3', si(null, sprite, 18, 18, 36, 234)],
  259. ['emoji/2C4.gif', 'std.2C4', si(null, sprite, 18, 18, 36, 72)],
  260. ['emoji/2C5.gif', 'std.2C5', si(null, sprite, 18, 18, 54, 54)],
  261. ['emoji/2C6.gif', 'std.2C6'],
  262. ['emoji/2C7.gif', 'std.2C7'],
  263. ['emoji/2C8.gif', 'std.2C8'],
  264. ['emoji/2C9.gif', 'std.2C9'],
  265. ['emoji/2CA.gif', 'std.2CA', si(null, sprite2, 18, 20, 36, 72, 1)],
  266. ['emoji/2E3.gif', 'std.2E3', si(null, sprite2, 18, 18, 0, 0, 1)],
  267. ['emoji/2EF.gif', 'std.2EF', si(null, sprite2, 18, 20, 0, 300, 1)],
  268. ['emoji/2F1.gif', 'std.2F1', si(null, sprite2, 18, 18, 0, 320, 1)]
  269. ]];
  270. var emojiGroups = [emojiGroup1, emojiGroup2, emojiGroup3]
  271. var defaultImgUrl = 'emoji/none.gif';
  272. // Handles clicking on an emoji.
  273. function onEmojiSelected(e) {
  274. var text = goog.dom.getElement('text');
  275. var emoji = this.getSelectedEmoji();
  276. text.value = text.value + '<img src="' + emoji.getUrl() + '" goomoji="' +
  277. emoji.getId() + '">\n';
  278. }
  279. /**
  280. * Creates a new emoji picker according to the desired specifications.
  281. *
  282. * @param {boolean} popup Whether the emojipicker should be a popup.
  283. * @param {Array.<Object>} emojiGroups Emoji groups to add to the picker.
  284. * @param {string} defaultImgUrl URL of the default image for the picker.
  285. * @param {string} elementId Id of the element to attach the popup picker to,
  286. * or to append the docked picker to.
  287. * @param {boolean=} opt_delayedLoad Whether the emojipicker should use
  288. * delayed image loading.
  289. * @param {number=} opt_numRows Optional number of rows to specify for the
  290. * emojipicker's palette.
  291. * @param {number=} opt_numCols Optional number of columns to specify for the
  292. * emojipicker's palette.
  293. * @param {boolean=} opt_progressiveRender Whether to render the sprited
  294. * emojipicker progressively.
  295. * @return {goog.ui.emoji.EmojiPicker|goog.ui.emoji.PopupEmojiPicker} The
  296. * constructed and rendered emojipicker.
  297. */
  298. function createEmojiPicker(popup, emojiGroups, defaultImgUrl, elementId,
  299. opt_delayedLoad, opt_numRows, opt_numCols,
  300. opt_progressiveRender) {
  301. var picker = popup ? new goog.ui.emoji.PopupEmojiPicker(defaultImgUrl) :
  302. new goog.ui.emoji.EmojiPicker(defaultImgUrl);
  303. for (var i = 0; i < emojiGroups.length; i++) {
  304. picker.addEmojiGroup(emojiGroups[i][0], emojiGroups[i][1]);
  305. }
  306. if (!popup) {
  307. picker.setTabLocation(goog.ui.TabPane.TabLocation.BOTTOM);
  308. }
  309. if (opt_delayedLoad) {
  310. picker.setDelayedLoad(opt_delayedLoad);
  311. }
  312. if (opt_numRows) {
  313. picker.setNumRows(opt_numRows);
  314. }
  315. if (opt_numCols) {
  316. picker.setNumColumns(opt_numCols);
  317. }
  318. if (opt_progressiveRender) {
  319. picker.setProgressiveRender(true);
  320. }
  321. picker.render();
  322. var elem = document.getElementById(elementId);
  323. if (popup) {
  324. picker.attach(elem);
  325. } else {
  326. elem.appendChild(picker.getElement());
  327. }
  328. goog.events.listen(
  329. picker, goog.ui.Component.EventType.ACTION, onEmojiSelected);
  330. return picker;
  331. }
  332. // Normal popup non-delayed load emojipicker.
  333. createEmojiPicker(true, emojiGroups, defaultImgUrl, 'button1');
  334. // Docked non-delayed load emojipicker.
  335. createEmojiPicker(false, emojiGroups, defaultImgUrl, 'emojiDock', false,
  336. 3, 20);
  337. // Single page non-delayed load emojipicker.
  338. createEmojiPicker(false, [emojiGroup1], defaultImgUrl,
  339. 'singlePageEmojiPicker');
  340. // Delayed load popup emojipicker.
  341. var delayedPopupPicker = createEmojiPicker(true, emojiGroups, defaultImgUrl,
  342. 'button2', true);
  343. delayedPopupPicker.loadImages();
  344. // Delayed load single page docked picker. Loaded by clicking on a button.
  345. var delayedSinglePagePicker = createEmojiPicker(false, [emojiGroup1],
  346. defaultImgUrl, 'delayedLoadDock', true);
  347. // Non-delayed load sprited docked picker.
  348. var spritedDockedPicker = createEmojiPicker(false, [spritedEmoji1],
  349. defaultImgUrl, 'spriteDock1', false, 3, 6);
  350. // Non-delayed load sprited docked picker.
  351. var spritedDockedPicker2 = createEmojiPicker(false, [spritedEmoji1],
  352. defaultImgUrl, 'spriteDock2', false, 2, 10, true);
  353. // Fast-loading progressive sprited docked picker.
  354. var fastLoadPicker1 = createEmojiPicker(false, [spritedEmoji2],
  355. defaultImgUrl, 'fastLoad1', false, 2, 10, true);
  356. // Fast-loading non-progressive sprited docked picker.
  357. var fastLoadPicker2 = createEmojiPicker(false, [spritedEmoji2],
  358. defaultImgUrl, 'fastLoad2', false, 2, 10, false);
  359. function loadPicker() {
  360. goog.style.setStyle(document.getElementById('delayedLoadDockDiv'),
  361. 'display',
  362. 'none');
  363. delayedSinglePagePicker.loadImages();
  364. goog.dom.classlist.add(delayedSinglePagePicker.getElement(),
  365. 'goog-ui-emojipicker');
  366. }
  367. </script>
  368. </body>
  369. </html>