API Docs for: 3.13.0
Show:

File: scrollview/js/list-plugin.js

  1. /**
  2. * Provides a plugin, which adds support for a scroll indicator to ScrollView instances
  3. *
  4. * @module scrollview-list
  5. */
  6. var getCN = Y.ClassNameManager.getClassName,
  7. SCROLLVIEW = 'scrollview',
  8. LIST_CLASS = getCN(SCROLLVIEW, 'list'),
  9. ITEM_CLASS = getCN(SCROLLVIEW, 'item'),
  10. CONTENT_BOX = "contentBox",
  11. HOST = "host";
  12.  
  13. /**
  14. * ScrollView plugin that adds class names to immediate descendant "<li>" to
  15. * allow for easier styling through CSS
  16. *
  17. * @class ScrollViewList
  18. * @namespace Plugin
  19. * @extends Plugin.Base
  20. * @constructor
  21. */
  22. function ListPlugin() {
  23. ListPlugin.superclass.constructor.apply(this, arguments);
  24. }
  25.  
  26.  
  27. /**
  28. * The identity of the plugin
  29. *
  30. * @property NAME
  31. * @type String
  32. * @default 'pluginList'
  33. * @static
  34. */
  35. ListPlugin.NAME = 'pluginList';
  36.  
  37. /**
  38. * The namespace on which the plugin will reside.
  39. *
  40. * @property NS
  41. * @type String
  42. * @default 'list'
  43. * @static
  44. */
  45. ListPlugin.NS = 'list';
  46.  
  47.  
  48. /**
  49. * The default attribute configuration for the plugin
  50. *
  51. * @property ATTRS
  52. * @type Object
  53. * @static
  54. */
  55. ListPlugin.ATTRS = {
  56.  
  57. /**
  58. * Specifies whether the list elements (the immediate <ul>'s and the
  59. * immediate <li>'s inside those <ul>'s) have class names attached to
  60. * them or not
  61. *
  62. * @attribute isAttached
  63. * @type boolean
  64. * @deprecated No real use for this attribute on the public API
  65. */
  66. isAttached: {
  67. value:false,
  68. validator: Y.Lang.isBoolean
  69. }
  70. };
  71.  
  72. Y.namespace("Plugin").ScrollViewList = Y.extend(ListPlugin, Y.Plugin.Base, {
  73.  
  74. /**
  75. * Designated initializer
  76. *
  77. * @method initializer
  78. */
  79. initializer: function() {
  80. this._host = this.get(HOST);
  81. this.afterHostEvent("render", this._addClassesToList);
  82. },
  83.  
  84. _addClassesToList: function() {
  85. if (!this.get('isAttached')) {
  86. var cb = this._host.get(CONTENT_BOX),
  87. ulList,
  88. liList;
  89.  
  90. if (cb.hasChildNodes()) {
  91. //get all direct descendants of the UL's that are directly under the content box.
  92. ulList = cb.all('> ul');
  93. liList = cb.all('> ul > li');
  94.  
  95. //go through the UL's and add the class
  96. ulList.each(function(list) {
  97. list.addClass(LIST_CLASS);
  98. });
  99.  
  100. //go through LI's and add the class
  101. liList.each(function(item) {
  102. item.addClass(ITEM_CLASS);
  103. });
  104.  
  105. this.set('isAttached', true);
  106.  
  107. // We need to call this again, since sv-list
  108. // relies on the "-vert" class, to apply padding.
  109. // [ 1st syncUI pass applies -vert, 2nd pass re-calcs dims ]
  110. this._host.syncUI();
  111. }
  112. }
  113. }
  114.  
  115. });
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.