emoji.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Emoji implementation.
  16. *
  17. */
  18. goog.provide('goog.ui.emoji.Emoji');
  19. /**
  20. * Creates an emoji.
  21. *
  22. * A simple wrapper for an emoji.
  23. *
  24. * @param {string} url URL pointing to the source image for the emoji.
  25. * @param {string} id The id of the emoji, e.g., 'std.1'.
  26. * @param {number=} opt_height The height of the emoji, if undefined the
  27. * natural height of the emoji is used.
  28. * @param {number=} opt_width The width of the emoji, if undefined the natural
  29. * width of the emoji is used.
  30. * @param {string=} opt_altText The alt text for the emoji image, eg. the
  31. * unicode character representation of the emoji.
  32. * @constructor
  33. * @final
  34. */
  35. goog.ui.emoji.Emoji = function(url, id, opt_height, opt_width, opt_altText) {
  36. /**
  37. * The URL pointing to the source image for the emoji
  38. *
  39. * @type {string}
  40. * @private
  41. */
  42. this.url_ = url;
  43. /**
  44. * The id of the emoji
  45. *
  46. * @type {string}
  47. * @private
  48. */
  49. this.id_ = id;
  50. /**
  51. * The height of the emoji
  52. *
  53. * @type {?number}
  54. * @private
  55. */
  56. this.height_ = opt_height || null;
  57. /**
  58. * The width of the emoji
  59. *
  60. * @type {?number}
  61. * @private
  62. */
  63. this.width_ = opt_width || null;
  64. /**
  65. * The unicode of the emoji
  66. *
  67. * @type {?string}
  68. * @private
  69. */
  70. this.altText_ = opt_altText || null;
  71. };
  72. /**
  73. * The name of the goomoji attribute, used for emoji image elements.
  74. * @type {string}
  75. * @deprecated Use goog.ui.emoji.Emoji.DATA_ATTRIBUTE instead.
  76. */
  77. goog.ui.emoji.Emoji.ATTRIBUTE = 'goomoji';
  78. /**
  79. * The name of the goomoji data-attribute, used for emoji image elements. Data
  80. * attributes are the preferred way in HTML5 to set custom attributes.
  81. * @type {string}
  82. */
  83. goog.ui.emoji.Emoji.DATA_ATTRIBUTE = 'data-' + goog.ui.emoji.Emoji.ATTRIBUTE;
  84. /**
  85. * @return {string} The URL for this emoji.
  86. */
  87. goog.ui.emoji.Emoji.prototype.getUrl = function() {
  88. return this.url_;
  89. };
  90. /**
  91. * @return {string} The id of this emoji.
  92. */
  93. goog.ui.emoji.Emoji.prototype.getId = function() {
  94. return this.id_;
  95. };
  96. /**
  97. * @return {?number} The height of this emoji.
  98. */
  99. goog.ui.emoji.Emoji.prototype.getHeight = function() {
  100. return this.height_;
  101. };
  102. /**
  103. * @return {?number} The width of this emoji.
  104. */
  105. goog.ui.emoji.Emoji.prototype.getWidth = function() {
  106. return this.width_;
  107. };
  108. /**
  109. * @return {?string} The alt text for the emoji image, eg. the unicode character
  110. * representation of the emoji.
  111. */
  112. goog.ui.emoji.Emoji.prototype.getAltText = function() {
  113. return this.altText_;
  114. };