Guest User

Untitled

a guest
Jul 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. YUI.add('plugin-dt-accordion', function(Y){
  2.  
  3. Y.Node.prototype.wrapInner = function(html) {
  4. var n = Y.Node.create(html);
  5. this.setData('preWrappedContent', this.getContent())
  6. n.prepend(this.getData('preWrappedContent'));
  7. this.setContent(n);
  8. return this;
  9. };
  10.  
  11. var CLASS_OPEN = 'dta-toggle-open',
  12. CLASS_CLOSE = 'dta-toggle-closed';
  13.  
  14.  
  15. Y.namespace('Plugin').DTAccordion = Y.Base.create('dt-accordion', Y.Plugin.Base, [], {
  16.  
  17. _host : null,
  18.  
  19. _delegate : null,
  20.  
  21. _anim : null,
  22.  
  23. initializer : function() {
  24. Y.log('initializer', 'info', 'Y.Plugin.DTAccordion');
  25. this._host = this.get('host');
  26.  
  27.  
  28. this.renderUI();
  29. this.bindUI();
  30.  
  31. },
  32.  
  33.  
  34. destructor : function() {
  35. this.unrenderUI();
  36. this.unbindUI();
  37. },
  38.  
  39. renderUI : function() {
  40. this._host.all('dt').each(function(dt){
  41. dt.wrapInner('<a />').one('a').append('<span />');
  42. dt.addClass(CLASS_CLOSE);
  43. });
  44. this._host.all('dd').addClass(CLASS_CLOSE).plug(Y.Plugin.NodeFX, {from: {}, to:{}, on:{}, duration: .3, easing: Y.Easing.easeOut});
  45. },
  46.  
  47. bindUI : function() {
  48.  
  49. this._delegate = this._host.delegate('click', function(e){
  50. var dt = e.currentTarget,
  51. dd = dt.next('dd');
  52.  
  53. if (dd.fx.get('running')) {
  54. dd.fx.pause();
  55. }
  56.  
  57. dd.fx.set('from.height', dd.get('offsetHeight'));
  58.  
  59. if (dt.hasClass(CLASS_CLOSE)) {
  60. dt.replaceClass(CLASS_CLOSE, CLASS_OPEN);
  61. dd.fx.set('to.height', dd.get('scrollHeight'));
  62. dd.fx.set('on.complete', function(){
  63. dd.replaceClass(CLASS_CLOSE,CLASS_OPEN);
  64. });
  65. } else {
  66. dt.replaceClass(CLASS_OPEN,CLASS_CLOSE);
  67. dd.fx.set('to.height', 0);
  68. dd.fx.set('on.complete', function(){
  69. dd.replaceClass(CLASS_OPEN, CLASS_CLOSE);
  70. });
  71. }
  72.  
  73. dd.fx.run();
  74.  
  75.  
  76. }, 'dt');
  77.  
  78. },
  79.  
  80. unrenderUI : function() {
  81. this._host.all('.' + CLASS_OPEN + ', .' + CLASS_CLOSE).removeClass(CLASS_OPEN).removeClass(CLASS_CLOSE);
  82. this._host.all('dt').each(function(dt){
  83. dt.setContent(dt.getData('preWrappedContent'));
  84. });
  85. },
  86.  
  87. unbindUI : function() {
  88. this._delegate.detach();
  89. }
  90.  
  91.  
  92.  
  93.  
  94. }, {
  95. NS : 'dta',
  96. ATTRS : {
  97. }
  98. });
  99.  
  100. }, '1.0', {requires: ['base-build','plugin','node','event', 'anim']});
Add Comment
Please, Sign In to add comment