Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. var data = [
  2. {
  3. "node":"h1",
  4. "text":"Why Loving Others is Good Business",
  5. "slug":"why-loving-others-is-good-business"
  6. },
  7. {
  8. "node":"h2",
  9. "text":"Why Loving Others is Good Business",
  10. "slug":"why-loving-others-is-good-business"
  11. },
  12. {
  13. "node":"h2",
  14. "text":"Sales Hole",
  15. "slug":"sales-hole"
  16. },
  17. {
  18. "node":"h3",
  19. "text":"Booking Shows",
  20. "slug":"booking-shows"
  21. },
  22. {
  23. "node":"h4",
  24. "text":"Partner with your Team for a Smart Start",
  25. "slug":"partner-with-your-team-for-a-smart-start"
  26. },
  27. {
  28. "node":"h3",
  29. "text":"Serving Clients",
  30. "slug":"serving-clients"
  31. },
  32. {
  33. "node":"h4",
  34. "text":"Start Qualifying for the Serving Clients Challenge!",
  35. "slug":"start-qualifying-for-the-serving-clients-challenge"
  36. },
  37. {
  38. "node":"h5",
  39. "text":"Start Qualifying for the Serving Clients Challenge!",
  40. "slug":"start-qualifying-for-the-serving-clients-challenge"
  41. },
  42. {
  43. "node":"h6",
  44. "text":"Start Qualifying for the Serving Clients Challenge!",
  45. "slug":"start-qualifying-for-the-serving-clients-challenge"
  46. },
  47. {
  48. "node":"h4",
  49. "text":"Start Qualifying for the Serving Clients Challenge!",
  50. "slug":"start-qualifying-for-the-serving-clients-challenge"
  51. },
  52. {
  53. "node":"h2",
  54. "text":"fdfdfdf",
  55. "slug":"complete-your-elearning-so-you-can-begin-using-clio-go"
  56. },
  57. {
  58. "node":"h3",
  59. "text":"Complete Your eLearning So You Can Begin Using CLIO GO!",
  60. "slug":"complete-your-elearning-so-you-can-begin-using-clio-go"
  61. },
  62. {
  63. "node":"h3",
  64. "text":"Announcing Our Online Hostess Planner 101 Webinar",
  65. "slug":"announcing-our-online-hostess-planner-101-webinar"
  66. },
  67. {
  68. "node":"h3",
  69. "text":"Stylist eCommerce Launches February 1",
  70. "slug":"stylist-ecommerce-launches-february-1"
  71. },
  72. {
  73. "node":"h2",
  74. "text":"Team Building",
  75. "slug":"team-building"
  76. },
  77. {
  78. "node":"h3",
  79. "text":"Intentional Sharing",
  80. "slug":"intentional-sharing"
  81. },
  82. {
  83. "node":"h4",
  84. "text":"Confidently Sharing cabi Builds More Confidence!",
  85. "slug":"confidently-sharing-cabi-builds-more-confidence"
  86. },
  87. {
  88. "node":"h4",
  89. "text":"Applications Open Monday!",
  90. "slug":"applications-open-monday"
  91. },
  92. {
  93. "node":"h3",
  94. "text":"Your Canada Questions\u00e2\u0080\u00a6Answered",
  95. "slug":"your-canada-questionsa-answered"
  96. },
  97. {
  98. "node":"h3",
  99. "text":"Register for our UK Team Building Webinar",
  100. "slug":"register-for-our-uk-team-building-webinar"
  101. },
  102. {
  103. "node":"h2",
  104. "text":"To Know",
  105. "slug":"to-know"
  106. },
  107. {
  108. "node":"h3",
  109. "text":"Month-at-a-Glance",
  110. "slug":"month-at-a-glance"
  111. },
  112. {
  113. "node":"h3",
  114. "text":"Announcing Your Spring 2016 CAM Teams",
  115. "slug":"announcing-your-spring-2016-cam-teams"
  116. },
  117. {
  118. "node":"h3",
  119. "text":"New Arrivals Personal Purchase Pre-Orders",
  120. "slug":"new-arrivals-personal-purchase-pre-orders"
  121. },
  122. {
  123. "node":"h3",
  124. "text":"Upload Your Photo to Your Personal cabionline Website",
  125. "slug":"upload-your-photo-to-your-personal-cabionline-website"
  126. },
  127. {
  128. "node":"h3",
  129. "text":"Just In\u00e2\u0080\u0094Additional Future Scoop Dates & Locations!",
  130. "slug":"just-ina-additional-future-scoop-dates-locations"
  131. },
  132. {
  133. "node":"h1",
  134. "text":"Why Loving Others is Good Business",
  135. "slug":"why-loving-others-is-good-business"
  136. },
  137. {
  138. "node":"h2",
  139. "text":"To Enjoy",
  140. "slug":"to-enjoy"
  141. },
  142. {
  143. "node":"h3",
  144. "text":"Quick Quotables for the Spring 2016 Collection",
  145. "slug":"quick-quotables-for-the-spring-2016-collection"
  146. },
  147. {
  148. "node":"h3",
  149. "text":"Blog Preview: How Becky Styled Spring",
  150. "slug":"blog-preview-how-becky-styled-spring"
  151. }
  152. ];
  153.  
  154.  
  155. function treeChild(data) {
  156.  
  157. var tree ={
  158. children: []
  159. };
  160.  
  161. tree.children.push({
  162. level: nEl(data[0].node),
  163. element: data[0],
  164. children: [],
  165. parent: tree
  166. });
  167.  
  168. var lastElement = tree.children[0];
  169.  
  170.  
  171. for (var i = 1; i<data.length; i++){
  172.  
  173. var actualElement = data[i];
  174.  
  175. if(lastElement.level < nEl(actualElement.node)){
  176. var child = {
  177. level: lastElement.level+1,
  178. element: data[i],
  179. children: [],
  180. parent: lastElement
  181. };
  182.  
  183. lastElement.children.push(child);
  184. lastElement = child;
  185. }else if(lastElement.level > nEl(actualElement.node)){
  186.  
  187. var diference = (lastElement.level - nEl(actualElement.node));
  188.  
  189. var parent = lastElement.parent;
  190. var newlevel= lastElement.level;
  191.  
  192. for(var x=0; x<diference; x++){
  193. newlevel--;
  194. parent = parent.parent;
  195. }
  196.  
  197.  
  198. var child = {
  199. level: newlevel,
  200. element: data[i],
  201. children: [],
  202. parent: parent
  203. };
  204.  
  205. parent.children.push(child);
  206.  
  207. lastElement = child;
  208. }else {
  209. var child = {
  210. level: lastElement.level,
  211. element: data[i],
  212. children: [],
  213. parent: lastElement.parent
  214. };
  215.  
  216. lastElement.parent.children.push(child);
  217. lastElement = child;
  218. }
  219.  
  220. }
  221.  
  222. return tree;
  223.  
  224. }
  225.  
  226.  
  227. function nEl(text) {
  228. return parseInt(text.slice(1,2));
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement