API Docs for: 1.8.0
Show:

File: src/visual/faicon.js

  1. /*
  2. * Copyright (c) 2014-2015, Wanadev <http://www.wanadev.fr/>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * * Neither the name of Wanadev nor the names of its contributors may be used
  14. * to endorse or promote products derived from this software without specific
  15. * prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * Authored by: Fabien LOISON <http://flozz.fr/>
  29. */
  30.  
  31. /**
  32. * PhotonUI - Javascript Web User Interface.
  33. *
  34. * @module PhotonUI
  35. * @submodule Visual
  36. * @namespace photonui
  37. */
  38.  
  39. var BaseIcon = require("./baseicon.js");
  40.  
  41. /**
  42. * Font Awesome Icon.
  43. *
  44. * Special contructor params:
  45. *
  46. * new photonui.FAIcon( {optional params...} )
  47. * new photonui.FAIcon( "iconName", {optional params...} )
  48. *
  49. * @class FAIcon
  50. * @constructor
  51. * @extends photonui.BaseIcon
  52. */
  53. var FAIcon = BaseIcon.$extend({
  54.  
  55. // Constructor
  56. __init__: function (params1, params2) {
  57. var params = {};
  58. if (params1 && typeof(params1) == "string") {
  59. params.iconName = params1;
  60. if (params2 && typeof(params2) == "object") {
  61. for (var i in params2) {
  62. params[i] = params2[i];
  63. }
  64. }
  65. } else if (params1) {
  66. params = params1;
  67. }
  68. this.$super(params);
  69. },
  70.  
  71. //////////////////////////////////////////
  72. // Properties and Accessors //
  73. //////////////////////////////////////////
  74.  
  75. // ====== Public properties ======
  76.  
  77. /**
  78. * The Font Awesome icon name (e.g. "fa-cog").
  79. *
  80. * Icon list: http://fontawesome.io/icons/
  81. *
  82. * @property iconName
  83. * @type String
  84. * @default ""
  85. */
  86. _iconName: "",
  87.  
  88. getIconName: function () {
  89. "@photonui-update";
  90. return this._iconName;
  91. },
  92.  
  93. setIconName: function (iconName) {
  94. this._iconName = iconName || "";
  95. this.__html.icon.className = "fa " + this.iconName + " " + this.size;
  96. },
  97.  
  98. /**
  99. * Font Awesome icon size (e.g. "fa-2x").
  100. *
  101. * Icon sizes list: http://fontawesome.io/examples/#larger
  102. *
  103. * @property size
  104. * @type String
  105. * @default ""
  106. */
  107. _size: "",
  108.  
  109. getSize: function () {
  110. "@photonui-update";
  111. return this._size;
  112. },
  113.  
  114. setSize: function (size) {
  115. this._size = size || "";
  116. this.__html.icon.className = "fa " + this.iconName + " " + this.size;
  117. },
  118.  
  119. /**
  120. * The icon color.
  121. *
  122. * @property color
  123. * @type String
  124. * default: "inherit"
  125. */
  126. _color: "inherit",
  127.  
  128. getColor: function () {
  129. "@photonui-update";
  130. return this._color;
  131. },
  132.  
  133. setColor: function (color) {
  134. this._color = color || "inherit";
  135. this.__html.icon.style.color = this.color;
  136. },
  137.  
  138. /**
  139. * Html outer element of the widget (if any).
  140. *
  141. * @property html
  142. * @type HTMLElement
  143. * @default null
  144. * @readOnly
  145. */
  146. getHtml: function () {
  147. return this.__html.outer;
  148. },
  149.  
  150. //////////////////////////////////////////
  151. // Methods //
  152. //////////////////////////////////////////
  153.  
  154. // ====== Private methods ======
  155.  
  156. /**
  157. * Build the widget HTML.
  158. *
  159. * @method _buildHtml
  160. * @private
  161. */
  162. _buildHtml: function () {
  163. this.__html.outer = document.createElement("span");
  164. this.__html.outer.className = "photonui-widget photonui-icon photonui-faicon";
  165.  
  166. this.__html.icon = document.createElement("i");
  167. this.__html.outer.appendChild(this.__html.icon);
  168. }
  169. });
  170.  
  171. module.exports = FAIcon;
  172.