|
26 | 26 | script(src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js") |
27 | 27 | script(src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js") |
28 | 28 | script(src="//cdn.rawgit.com/vctrfrnndz/jquery-accordion/master/js/jquery.accordion.js") |
29 | | - |
30 | | - script. |
31 | | - function navigation() { |
32 | | - |
33 | | - $(window).on('hashchange', setSelected); |
34 | | - |
35 | | - function buildNav() { |
36 | | - var $nav = $('.nav-styleguide ul'); |
37 | | - |
38 | | - $nav.html(''); |
39 | | - |
40 | | - $('[data-group]').each(function(i) { |
41 | | - var $group = $(this); |
42 | | - var name = $group.attr('data-group'); |
43 | | - var id = $group.attr('id'); |
44 | | - var tpl = [ |
45 | | - '<li data-accordion class="'+ ((i === 0) ? 'open' : '') +'"><a class="'+ ((i === 0) ? 'is-current' : '') +'" href="#'+ id +'">', |
46 | | - name, |
47 | | - '</a></li>' |
48 | | - ].join(''); |
49 | | - |
50 | | - var $item = $(tpl); |
51 | | - |
52 | | - if($group.find('h2[id]').length) { |
53 | | - var $list = $('<ul></ul>'); |
54 | | - |
55 | | - $group.find('h2[id]').each(function(i) { |
56 | | - var name = $(this).text(); |
57 | | - var id = $(this).attr('id') || 'foo'; |
58 | | - |
59 | | - $list.append('<li><a href="#'+ id + '">' + name + '</li>'); |
60 | | - |
61 | | - $item.append($list); |
62 | | - }); |
63 | | - } |
64 | | - |
65 | | - return $nav.append($item); |
66 | | - }); |
67 | | - } |
68 | | - |
69 | | - function setSelected(hash) { |
70 | | - var hash = location.hash || hash; |
71 | | - var activeClass = 'is-current'; |
72 | | - var $section = $(hash + '[data-group]'); |
73 | | - var $subSection = $(hash).closest('[data-group]'); |
74 | | - var $navItem = $('.nav-styleguide a[href="' + hash + '"]'); |
75 | | - |
76 | | - $('[data-group], .nav-styleguide a').removeClass(activeClass); |
77 | | - |
78 | | - if(hash.length) { |
79 | | - $('[data-accordion]').removeClass('open'); |
80 | | - } |
81 | | - |
82 | | - if($section.length) { |
83 | | - $section.addClass(activeClass); |
84 | | - } else if ($subSection.length) { |
85 | | - $subSection.addClass(activeClass); |
86 | | - } |
87 | | - |
88 | | - $navItem.addClass(activeClass); |
89 | | - $navItem.closest('[data-accordion]').addClass('open'); |
90 | | - } |
91 | | - |
92 | | - buildNav(); |
93 | | - setSelected(location.hash); |
94 | | - } |
95 | | - |
96 | | - navigation(); |
97 | | - |
98 | | - function accordions() { |
99 | | - $('[data-accordion]').accordion({ |
100 | | - controlElement: 'a', |
101 | | - contentElement: 'ul' |
102 | | - }); |
103 | | - } |
104 | | - |
105 | | - accordions(); |
106 | | - |
107 | | - function playground() { |
108 | | - var $module = $('.js-playground'); |
109 | | - |
110 | | - function setFrame($iframe, content) { |
111 | | - $iframe.get(0).src = "data:text/html;charset=utf-8," + escape(content); |
112 | | - } |
113 | | - |
114 | | - function cleanFrames(html) { |
115 | | - html.find('iframe').remove(); |
116 | | - |
117 | | - return html; |
118 | | - } |
119 | | - |
120 | | - function convertChars(str) { |
121 | | - str = str.replace('©', '©'); |
122 | | - |
123 | | - return str; |
124 | | - } |
125 | | - |
126 | | - $module.each(function() { |
127 | | - var $component = $(this); |
128 | | - var http = location.protocol; |
129 | | - var dom = cleanFrames($('.playground-real-component', $component)); |
130 | | - var scripts = '<script src\="' + http + '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"><\/script><script src\="' + http + '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"><\/script>'; |
131 | | - var html = '<html><head><link href="' + location.origin + '/index.css" rel="stylesheet"></head><body>' + convertChars(dom.html()) + scripts + '</body></html>'; |
132 | | - |
133 | | - setFrame($('iframe', $component), html); |
134 | | - }); |
135 | | - }; |
136 | | - |
137 | | - playground(); |
| 29 | + script(src="landing/index.js") |
0 commit comments