Guest User

Untitled

a guest
May 24th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. <template is="dom-repeat" items="[[ data ]]" as="child">
  2. <div class="child-item">
  3. <div class="info" on-click="_toggleClick">
  4. <paper-item>
  5. <iron-icon icon="arrow-drop-up" class="rotate-90"></iron-icon>
  6. <span>[[ child.name ]]</span>
  7. </paper-item>
  8. </div>
  9.  
  10. <iron-collapse opened="false">
  11. <div>Details for child go here</div>
  12. </iron-collapse>
  13. </div>
  14. </template>
  15.  
  16. ...
  17.  
  18. <script>
  19. Polymer({
  20. is: 'child-details',
  21. properties: {
  22. data: {
  23. type: Array,
  24. value: function() {
  25. return [];
  26. }
  27. },
  28. },
  29.  
  30. _toggleClick: function(e, detail) {
  31. try {
  32. var arrowElement = document.querySelector('iron-icon');
  33. arrowElement.classList.toggle('rotate-clockwise-90');
  34. } catch (ex) {
  35. console.log('Unable to rotate arrow.');
  36. console.log(ex);
  37. }
  38.  
  39. try {
  40. var element = Polymer.dom(parent).querySelector('iron-collapse');
  41. element.toggle();
  42. } catch (ex) {
  43. console.log('Unable to toggle iron-collapse.');
  44. console.log(ex);
  45. }
  46. }
  47. });
  48. </script>
  49.  
  50. Unable to toggle iron-collapse.
  51. TypeError: Cannot read property 'toggle' of undefined(...)
  52.  
  53. document.querySelector('iron-icon');
  54.  
  55. var element = Polymer.dom(parent).querySelector('iron-collapse');
  56.  
  57. var div = Polymer.dom(e).rootTarget;
  58. div.querySelector('iron-icon').classList.toggle('rotate-clockwise-90')
  59. div.querySelector('iron-collapse').toggle();
  60.  
  61. <style>
  62. .opened iron-icon {
  63. transform: rotateZ(180deg);
  64. transition: transform 0.3s;
  65. }
  66. </style>
  67.  
  68. <template is="dom-repeat" items="[[ data ]]" as="child">
  69. <div class$="child-item [[isOpenedBasedOn(index, currentOpenedCollapsable)]]">
  70. <div class="info" id="[[index]]" on-click="_toggleClick">
  71. <paper-item>
  72. <iron-icon icon="arrow-drop-up"></iron-icon>
  73. <span>[[ child.name ]]</span>
  74. </paper-item>
  75. </div>
  76.  
  77. <iron-collapse opened="[[isOpenedBasedOn(index, currentOpenedCollapsable)]]">
  78. <div>Details for child go here</div>
  79. </iron-collapse>
  80. </div>
  81. </template>
  82.  
  83. ...
  84.  
  85. <script>
  86. Polymer({
  87. is: 'child-details',
  88. properties: {
  89. data: {
  90. type: Array,
  91. value: function() {
  92. return [];
  93. }
  94. },
  95. currentOpenedCollapsable: {
  96. type: Number,
  97. value: -1
  98. }
  99. },
  100.  
  101. // set index, but close (set to -1) if clicking on the same element.
  102. _toggleClick: function(e) {
  103. var currentIndex = e.currentTarget.id
  104.  
  105. if (this.currentOpenedCollapsable == currentIndex) {
  106. currentIndex = -1;
  107. }
  108.  
  109. this.set('currentOpenedCollapsable', currentIndex);
  110. },
  111.  
  112. // Using the javascript fact that a filled string is always true while an empty string is always false
  113. isOpenedBasedOn: function(elementIndex, currentIndex) {
  114. return (elementIndex == currentIndex) ? 'opened' : '';
  115. },
  116. });
  117. </script>
Add Comment
Please, Sign In to add comment