API Docs for: 3.18.1
Show:

File: button/js/plugin.js

  1. /**
  2. * A Button Plugin
  3. *
  4. * @module button-plugin
  5. * @since 3.5.0
  6. */
  7.  
  8. /**
  9. * @class Button
  10. * @param config {Object} Configuration object
  11. * @extends ButtonCore
  12. * @constructor
  13. * @namespace Plugin
  14. */
  15. function ButtonPlugin() {
  16. ButtonPlugin.superclass.constructor.apply(this, arguments);
  17. }
  18.  
  19. Y.extend(ButtonPlugin, Y.ButtonCore, {
  20.  
  21. /**
  22. * @method _afterNodeGet
  23. * @param name {string}
  24. * @private
  25. */
  26. _afterNodeGet: function (name) {
  27. // TODO: point to method (_uiSetLabel, etc) instead of getter/setter
  28. var ATTRS = this.constructor.ATTRS,
  29. fn = ATTRS[name] && ATTRS[name].getter && this[ATTRS[name].getter];
  30.  
  31. if (fn) {
  32. return new Y.Do.AlterReturn('get ' + name, fn.call(this));
  33. }
  34. },
  35.  
  36. /**
  37. * @method _afterNodeSet
  38. * @param name {String}
  39. * @param val {String}
  40. * @private
  41. */
  42. _afterNodeSet: function (name, val) {
  43. var ATTRS = this.constructor.ATTRS,
  44. fn = ATTRS[name] && ATTRS[name].setter && this[ATTRS[name].setter];
  45.  
  46. if (fn) {
  47. fn.call(this, val);
  48. }
  49. },
  50.  
  51. /**
  52. * @method _initNode
  53. * @param config {Object}
  54. * @private
  55. */
  56. _initNode: function(config) {
  57. var node = config.host;
  58. this._host = node;
  59.  
  60. Y.Do.after(this._afterNodeGet, node, 'get', this);
  61. Y.Do.after(this._afterNodeSet, node, 'set', this);
  62. },
  63.  
  64. /**
  65. * @method destroy
  66. * @private
  67. */
  68. destroy: function(){
  69. // Nothing to do, but things are happier with it here
  70. }
  71.  
  72. }, {
  73.  
  74. /**
  75. * Attribute configuration.
  76. *
  77. * @property ATTRS
  78. * @type {Object}
  79. * @private
  80. * @static
  81. */
  82. ATTRS: Y.merge(Y.ButtonCore.ATTRS),
  83.  
  84. /**
  85. * Name of this component.
  86. *
  87. * @property NAME
  88. * @type String
  89. * @static
  90. */
  91. NAME: 'buttonPlugin',
  92.  
  93. /**
  94. * Namespace of this component.
  95. *
  96. * @property NS
  97. * @type String
  98. * @static
  99. */
  100. NS: 'button'
  101.  
  102. });
  103.  
  104. /**
  105. * @method createNode
  106. * @description A factory that plugs a Y.Node instance with Y.Plugin.Button
  107. * @param node {Object}
  108. * @param config {Object}
  109. * @return {Object} A plugged Y.Node instance
  110. * @public
  111. */
  112. ButtonPlugin.createNode = function(node, config) {
  113. var template;
  114.  
  115. if (node && !config) {
  116. if (! (node.nodeType || node.getDOMNode || typeof node === 'string')) {
  117. config = node;
  118. node = config.srcNode;
  119. }
  120. }
  121.  
  122. config = config || {};
  123. template = config.template || Y.Plugin.Button.prototype.TEMPLATE;
  124. node = node || config.srcNode || Y.DOM.create(template);
  125.  
  126. return Y.one(node).plug(Y.Plugin.Button, config);
  127. };
  128.  
  129. Y.namespace('Plugin').Button = ButtonPlugin;
  130.