Dashboard sipadu mbip
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

widget-child-debug.js 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. Copyright (c) 2010, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.com/yui/license.html
  5. version: 3.4.0
  6. build: nightly
  7. */
  8. YUI.add('widget-child', function(Y) {
  9. /**
  10. * Extension enabling a Widget to be a child of another Widget.
  11. *
  12. * @module widget-child
  13. */
  14. var Lang = Y.Lang;
  15. /**
  16. * Widget extension providing functionality enabling a Widget to be a
  17. * child of another Widget.
  18. *
  19. * @class WidgetChild
  20. * @param {Object} config User configuration object.
  21. */
  22. function Child() {
  23. // Widget method overlap
  24. Y.after(this._syncUIChild, this, "syncUI");
  25. Y.after(this._bindUIChild, this, "bindUI");
  26. }
  27. Child.ATTRS = {
  28. /**
  29. * @attribute selected
  30. * @type Number
  31. * @default 0
  32. *
  33. * @description Number indicating if the Widget is selected. Possible
  34. * values are:
  35. * <dl>
  36. * <dt>0</dt> <dd>(Default) Not selected</dd>
  37. * <dt>1</dt> <dd>Fully selected</dd>
  38. * <dt>2</dt> <dd>Partially selected</dd>
  39. * </dl>
  40. */
  41. selected: {
  42. value: 0,
  43. validator: Lang.isNumber
  44. },
  45. /**
  46. * @attribute index
  47. * @type Number
  48. * @readOnly
  49. *
  50. * @description Number representing the Widget's ordinal position in its
  51. * parent Widget.
  52. */
  53. index: {
  54. readOnly: true,
  55. getter: function () {
  56. var parent = this.get("parent"),
  57. index = -1;
  58. if (parent) {
  59. index = parent.indexOf(this);
  60. }
  61. return index;
  62. }
  63. },
  64. /**
  65. * @attribute parent
  66. * @type Widget
  67. * @readOnly
  68. *
  69. * @description Retrieves the parent of the Widget in the object hierarchy.
  70. */
  71. parent: {
  72. readOnly: true
  73. },
  74. /**
  75. * @attribute depth
  76. * @type Number
  77. * @default -1
  78. * @readOnly
  79. *
  80. * @description Number representing the depth of this Widget relative to
  81. * the root Widget in the object heirarchy.
  82. */
  83. depth: {
  84. readOnly: true,
  85. getter: function () {
  86. var parent = this.get("parent"),
  87. root = this.get("root"),
  88. depth = -1;
  89. while (parent) {
  90. depth = (depth + 1);
  91. if (parent == root) {
  92. break;
  93. }
  94. parent = parent.get("parent");
  95. }
  96. return depth;
  97. }
  98. },
  99. /**
  100. * @attribute root
  101. * @type Widget
  102. * @readOnly
  103. *
  104. * @description Returns the root Widget in the object hierarchy. If the
  105. * ROOT_TYPE property is set, the search for the root Widget will be
  106. * constrained to parent Widgets of the specified type.
  107. */
  108. root: {
  109. readOnly: true,
  110. getter: function () {
  111. var getParent = function (child) {
  112. var parent = child.get("parent"),
  113. FnRootType = child.ROOT_TYPE,
  114. criteria = parent;
  115. if (FnRootType) {
  116. criteria = (parent && Y.instanceOf(parent, FnRootType));
  117. }
  118. return (criteria ? getParent(parent) : child);
  119. };
  120. return getParent(this);
  121. }
  122. }
  123. };
  124. Child.prototype = {
  125. /**
  126. * Constructor reference used to determine the root of a Widget-based
  127. * object tree.
  128. * <p>
  129. * Currently used to control the behavior of the <code>root</code>
  130. * attribute so that recursing up the object heirarchy can be constrained
  131. * to a specific type of Widget. Widget authors should set this property
  132. * to the constructor function for a given Widget implementation.
  133. * </p>
  134. *
  135. * @property ROOT_TYPE
  136. * @type Object
  137. */
  138. ROOT_TYPE: null,
  139. /**
  140. * Returns the node on which to bind delegate listeners.
  141. *
  142. * Override of Widget's implementation of _getUIEventNode() to ensure that
  143. * all event listeners are bound to the Widget's topmost DOM element.
  144. * This ensures that the firing of each type of Widget UI event (click,
  145. * mousedown, etc.) is facilitated by a single, top-level, delegated DOM
  146. * event listener.
  147. *
  148. * @method _getUIEventNode
  149. * @for Widget
  150. * @protected
  151. */
  152. _getUIEventNode: function () {
  153. var root = this.get("root"),
  154. returnVal;
  155. if (root) {
  156. returnVal = root.get("boundingBox");
  157. }
  158. return returnVal;
  159. },
  160. /**
  161. * @method next
  162. * @description Returns the Widget's next sibling.
  163. * @param {Boolean} circular Boolean indicating if the parent's first child
  164. * should be returned if the child has no next sibling.
  165. * @return {Widget} Widget instance.
  166. */
  167. next: function (circular) {
  168. var parent = this.get("parent"),
  169. sibling;
  170. if (parent) {
  171. sibling = parent.item((this.get("index")+1));
  172. }
  173. if (!sibling && circular) {
  174. sibling = parent.item(0);
  175. }
  176. return sibling;
  177. },
  178. /**
  179. * @method previous
  180. * @description Returns the Widget's previous sibling.
  181. * @param {Boolean} circular Boolean indicating if the parent's last child
  182. * should be returned if the child has no previous sibling.
  183. * @return {Widget} Widget instance.
  184. */
  185. previous: function (circular) {
  186. var parent = this.get("parent"),
  187. index = this.get("index"),
  188. sibling;
  189. if (parent && index > 0) {
  190. sibling = parent.item([(index-1)]);
  191. }
  192. if (!sibling && circular) {
  193. sibling = parent.item((parent.size() - 1));
  194. }
  195. return sibling;
  196. },
  197. // Override of Y.WidgetParent.remove()
  198. // Sugar implementation allowing a child to remove itself from its parent.
  199. remove: function (index) {
  200. var parent,
  201. removed;
  202. if (Lang.isNumber(index)) {
  203. removed = Y.WidgetParent.prototype.remove.apply(this, arguments);
  204. }
  205. else {
  206. parent = this.get("parent");
  207. if (parent) {
  208. removed = parent.remove(this.get("index"));
  209. }
  210. }
  211. return removed;
  212. },
  213. /**
  214. * @method isRoot
  215. * @description Determines if the Widget is the root Widget in the
  216. * object hierarchy.
  217. * @return {Boolean} Boolean indicating if Widget is the root Widget in the
  218. * object hierarchy.
  219. */
  220. isRoot: function () {
  221. return (this == this.get("root"));
  222. },
  223. /**
  224. * @method ancestor
  225. * @description Returns the Widget instance at the specified depth.
  226. * @param {number} depth Number representing the depth of the ancestor.
  227. * @return {Widget} Widget instance.
  228. */
  229. ancestor: function (depth) {
  230. var root = this.get("root"),
  231. parent;
  232. if (this.get("depth") > depth) {
  233. parent = this.get("parent");
  234. while (parent != root && parent.get("depth") > depth) {
  235. parent = parent.get("parent");
  236. }
  237. }
  238. return parent;
  239. },
  240. /**
  241. * Updates the UI to reflect the <code>selected</code> attribute value.
  242. *
  243. * @method _uiSetChildSelected
  244. * @protected
  245. * @param {number} selected The selected value to be reflected in the UI.
  246. */
  247. _uiSetChildSelected: function (selected) {
  248. var box = this.get("boundingBox"),
  249. sClassName = this.getClassName("selected");
  250. if (selected === 0) {
  251. box.removeClass(sClassName);
  252. }
  253. else {
  254. box.addClass(sClassName);
  255. }
  256. },
  257. /**
  258. * Default attribute change listener for the <code>selected</code>
  259. * attribute, responsible for updating the UI, in response to
  260. * attribute changes.
  261. *
  262. * @method _afterChildSelectedChange
  263. * @protected
  264. * @param {EventFacade} event The event facade for the attribute change.
  265. */
  266. _afterChildSelectedChange: function (event) {
  267. this._uiSetChildSelected(event.newVal);
  268. },
  269. /**
  270. * Synchronizes the UI to match the WidgetChild state.
  271. * <p>
  272. * This method is invoked after bindUI is invoked for the Widget class
  273. * using YUI's aop infrastructure.
  274. * </p>
  275. *
  276. * @method _syncUIChild
  277. * @protected
  278. */
  279. _syncUIChild: function () {
  280. this._uiSetChildSelected(this.get("selected"));
  281. },
  282. /**
  283. * Binds event listeners responsible for updating the UI state in response
  284. * to WidgetChild related state changes.
  285. * <p>
  286. * This method is invoked after bindUI is invoked for the Widget class
  287. * using YUI's aop infrastructure.
  288. * </p>
  289. * @method _bindUIChild
  290. * @protected
  291. */
  292. _bindUIChild: function () {
  293. this.after("selectedChange", this._afterChildSelectedChange);
  294. }
  295. };
  296. Y.WidgetChild = Child;
  297. }, '3.4.0' ,{requires:['base-build', 'widget']});