shibori 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +27 -0
  5. data/Procfile +1 -0
  6. data/README.md +24 -0
  7. data/Rakefile +2 -0
  8. data/app.json +11 -0
  9. data/builder/lineage_hunter.js +80 -0
  10. data/builder/list_item_hunter.js +106 -0
  11. data/builder/media_hunter.js +51 -0
  12. data/builder/object_factory.js +60 -0
  13. data/builder/parameter_hunter.js +69 -0
  14. data/builder/pattern_assembler.js +258 -0
  15. data/builder/pattern_exporter.js +43 -0
  16. data/builder/patternlab.js +365 -0
  17. data/builder/patternlab_grunt.js +38 -0
  18. data/builder/patternlab_gulp.js +26 -0
  19. data/builder/pseudopattern_hunter.js +78 -0
  20. data/config.json +34 -0
  21. data/docs/Pattern Lab Node.md +225 -0
  22. data/favicon.ico +0 -0
  23. data/gulpfile.js +148 -0
  24. data/index.js +20 -0
  25. data/lib/shibori/version.rb +3 -0
  26. data/lib/shibori.rb +11 -0
  27. data/package.json +44 -0
  28. data/public/data/annotations.js +109 -0
  29. data/public/styleguide/css/static.css +458 -0
  30. data/public/styleguide/css/static.scss +404 -0
  31. data/public/styleguide/css/styleguide-specific.css +170 -0
  32. data/public/styleguide/css/styleguide-specific.scss +204 -0
  33. data/public/styleguide/css/styleguide.css +880 -0
  34. data/public/styleguide/css/styleguide.scss +950 -0
  35. data/public/styleguide/css/vendor/prism.css +112 -0
  36. data/public/styleguide/css/vendor/typeahead.css +66 -0
  37. data/public/styleguide/fonts/icomoon.eot +0 -0
  38. data/public/styleguide/fonts/icomoon.svg +22 -0
  39. data/public/styleguide/fonts/icomoon.ttf +0 -0
  40. data/public/styleguide/fonts/icomoon.woff +0 -0
  41. data/public/styleguide/html/README +1 -0
  42. data/public/styleguide/images/spinner.gif +0 -0
  43. data/public/styleguide/js/annotations-pattern.js +308 -0
  44. data/public/styleguide/js/annotations-viewer.js +289 -0
  45. data/public/styleguide/js/code-pattern.js +120 -0
  46. data/public/styleguide/js/code-viewer.js +443 -0
  47. data/public/styleguide/js/data-saver.js +169 -0
  48. data/public/styleguide/js/pattern-finder.js +114 -0
  49. data/public/styleguide/js/postmessage.js +127 -0
  50. data/public/styleguide/js/styleguide.js +600 -0
  51. data/public/styleguide/js/url-handler.js +182 -0
  52. data/public/styleguide/js/vendor/classlist-polyfill.js +176 -0
  53. data/public/styleguide/js/vendor/jquery.js +4 -0
  54. data/public/styleguide/js/vendor/jwerty.js +523 -0
  55. data/public/styleguide/js/vendor/prism.js +7 -0
  56. data/public/styleguide/js/vendor/typeahead.bundle.min.js +7 -0
  57. data/script/bootstrap +58 -0
  58. data/shibori.gemspec +18 -0
  59. data/shibori.jpg +0 -0
  60. data/source/_data/annotations.js +109 -0
  61. data/source/_data/data.json +93 -0
  62. data/source/_data/listitems.json +782 -0
  63. data/source/_patternlab-files/README +1 -0
  64. data/source/_patternlab-files/index.mustache +94 -0
  65. data/source/_patternlab-files/partials/ishControls.mustache +64 -0
  66. data/source/_patternlab-files/partials/patternNav.mustache +17 -0
  67. data/source/_patternlab-files/partials/patternPaths.mustache +3 -0
  68. data/source/_patternlab-files/partials/viewAllPaths.mustache +3 -0
  69. data/source/_patternlab-files/pattern-header-footer/README +1 -0
  70. data/source/_patternlab-files/pattern-header-footer/footer.html +34 -0
  71. data/source/_patternlab-files/pattern-header-footer/header.html +44 -0
  72. data/source/_patternlab-files/styleguide.mustache +75 -0
  73. data/source/_patternlab-files/viewall.mustache +75 -0
  74. data/source/_patterns/00-atoms/00-typography/00-headings.mustache +6 -0
  75. data/source/_patterns/00-atoms/00-typography/01-headings-options.mustache +7 -0
  76. data/source/_patterns/00-atoms/00-typography/02-body.mustache +2 -0
  77. data/source/_patterns/00-atoms/00-typography/03-text-manipulation.mustache +12 -0
  78. data/source/_patterns/00-atoms/00-typography/04-blockquotes.mustache +3 -0
  79. data/source/_patterns/00-atoms/00-typography/05-lists.mustache +64 -0
  80. data/source/_patterns/00-atoms/01-colors/00-colors-monochromatic.mustache +36 -0
  81. data/source/_patterns/00-atoms/01-colors/01-colors-brand.mustache +26 -0
  82. data/source/_patterns/00-atoms/01-colors/02-colors-gradients.mustache +38 -0
  83. data/source/_patterns/00-atoms/02-buttons/00-btn-lg.mustache +7 -0
  84. data/source/_patterns/00-atoms/02-buttons/01-btn-sm.mustache +7 -0
  85. data/source/_patterns/00-atoms/02-buttons/02-btn-xs.mustache +7 -0
  86. data/source/_patterns/00-atoms/02-buttons/03-btn-block.mustache +7 -0
  87. data/source/_patterns/00-atoms/02-buttons/04-btn-deploy.mustache +4 -0
  88. data/source/_patterns/00-atoms/03-forms/00-text-fields.mustache +24 -0
  89. data/source/_patterns/00-atoms/03-forms/01-select-menu.mustache +6 -0
  90. data/source/_patterns/00-atoms/03-forms/02-checkbox.mustache +10 -0
  91. data/source/_patterns/00-atoms/03-forms/03-radios.mustache +10 -0
  92. data/source/_patterns/00-atoms/03-forms/04-validation.mustache +14 -0
  93. data/source/_patterns/00-atoms/04-quote/00-pullquote.mustache +7 -0
  94. data/source/_patterns/00-atoms/04-quote/01-quote-small.mustache +7 -0
  95. data/source/_patterns/00-atoms/05-code/01-pre.mustache +11 -0
  96. data/source/_patterns/00-atoms/06-tooltips/00-text.mustache +3 -0
  97. data/source/_patterns/00-atoms/06-tooltips/01-diagram-callout.mustache +1 -0
  98. data/source/_patterns/00-atoms/07-loader/00-spinner.mustache +5 -0
  99. data/source/_patterns/00-atoms/08-readmore/00-readmore.mustache +3 -0
  100. data/source/_patterns/00-atoms/09-slider/00-dots.mustache +8 -0
  101. data/source/_patterns/00-atoms/10-tables/00-tables.mustache +26 -0
  102. data/source/_patterns/00-atoms/12-modal/00-modal.mustache +14 -0
  103. data/source/_patterns/00-atoms/13-panel/00-panel.mustache +3 -0
  104. data/source/_patterns/00-atoms/14-users/00-avatar.mustache +3 -0
  105. data/source/_patterns/00-atoms/15-icons/00-icons.mustache +333 -0
  106. data/source/_patterns/00-atoms/15-icons/04-icon-colors.mustache +38 -0
  107. data/source/_patterns/00-atoms/15-icons/05-icon-sizes.mustache +31 -0
  108. data/source/_patterns/00-atoms/15-icons/_02-languages.mustache +0 -0
  109. data/source/_patterns/00-atoms/15-icons/_03-social.mustache +0 -0
  110. data/source/_patterns/00-atoms/15-icons/_05-icon-containers.mustache +0 -0
  111. data/source/_patterns/00-atoms/16-video/01-video.mustache +3 -0
  112. data/source/_patterns/00-atoms/16-video/_00-play-button.mustache +0 -0
  113. data/source/_patterns/00-atoms/17-utilities/00-visibility.mustache +8 -0
  114. data/source/_patterns/00-atoms/17-utilities/01-ui-elements.mustache +3 -0
  115. data/source/_patterns/00-atoms/18-grid/_00-grid.mustache +0 -0
  116. data/source/_patterns/01-molecules/00-text/00-header-groups.mustache +4 -0
  117. data/source/_patterns/01-molecules/00-text/01-intro-text.mustache +5 -0
  118. data/source/_patterns/01-molecules/01-layout/00-one-up.mustache +8 -0
  119. data/source/_patterns/01-molecules/01-layout/01-two-up.mustache +9 -0
  120. data/source/_patterns/01-molecules/01-layout/02-three-up.mustache +10 -0
  121. data/source/_patterns/01-molecules/01-layout/03-four-up.mustache +11 -0
  122. data/source/_patterns/01-molecules/01-layout/04-masonary-2.mustache +24 -0
  123. data/source/_patterns/01-molecules/01-layout/05-masonary-3.mustache +24 -0
  124. data/source/_patterns/01-molecules/02-navigation/01-subnav.mustache +21 -0
  125. data/source/_patterns/01-molecules/02-navigation/02-breadcrumbs.mustache +25 -0
  126. data/source/_patterns/01-molecules/02-navigation/03-side-nav.mustache +11 -0
  127. data/source/_patterns/01-molecules/02-navigation/04-side-nav-small.mustache +32 -0
  128. data/source/_patterns/01-molecules/02-navigation/05-pagination.mustache +0 -0
  129. data/source/_patterns/01-molecules/02-navigation/06-tabs.mustache +46 -0
  130. data/source/_patterns/01-molecules/03-forms/_00-search.mustache +0 -0
  131. data/source/_patterns/01-molecules/04-slider/00-slider.mustache +8 -0
  132. data/source/_patterns/01-molecules/05-messages/00-alert.mustache +15 -0
  133. data/source/_patterns/01-molecules/06-components/_00-social-share.mustache +0 -0
  134. data/source/_patterns/01-molecules/07-Elements/01-Addons-Card.mustache +79 -0
  135. data/source/_patterns/01-molecules/07-Elements/02-Buttons-Card.mustache +131 -0
  136. data/source/_patterns/01-molecules/07-Elements/03-Buildpack-Card.mustache +109 -0
  137. data/source/_patterns/01-molecules/08-vertical-tabs/01-vertical-tabs.mustache +30 -0
  138. data/source/_patterns/02-organisms/03-sections/00-purple.mustache +11 -0
  139. data/source/_patterns/02-organisms/03-sections/01-purple-dark.mustache +12 -0
  140. data/source/_patterns/02-organisms/03-sections/03-gray-light.mustache +12 -0
  141. data/source/css/hk-icon-rails.scss +13 -0
  142. data/source/css/scss/base/_base.scss +62 -0
  143. data/source/css/scss/base/_fonts.scss +12 -0
  144. data/source/css/scss/base/_normalize.scss +431 -0
  145. data/source/css/scss/base/_type.scss +128 -0
  146. data/source/css/scss/base/_utilities.scss +78 -0
  147. data/source/css/scss/components/_alert.scss +38 -0
  148. data/source/css/scss/components/_animate.scss +3340 -0
  149. data/source/css/scss/components/_animation.scss +15 -0
  150. data/source/css/scss/components/_buttons.scss +175 -0
  151. data/source/css/scss/components/_code.scss +26 -0
  152. data/source/css/scss/components/_forms.scss +136 -0
  153. data/source/css/scss/components/_hero.scss +18 -0
  154. data/source/css/scss/components/_hr.scss +11 -0
  155. data/source/css/scss/components/_icons.scss +85 -0
  156. data/source/css/scss/components/_lists.scss +45 -0
  157. data/source/css/scss/components/_logos.scss +15 -0
  158. data/source/css/scss/components/_masonary.scss +46 -0
  159. data/source/css/scss/components/_modal.scss +218 -0
  160. data/source/css/scss/components/_owlCarousel.scss +270 -0
  161. data/source/css/scss/components/_panel.scss +11 -0
  162. data/source/css/scss/components/_pill-box.scss +38 -0
  163. data/source/css/scss/components/_quote.scss +96 -0
  164. data/source/css/scss/components/_readmore.scss +11 -0
  165. data/source/css/scss/components/_slider.scss +96 -0
  166. data/source/css/scss/components/_spinner.scss +64 -0
  167. data/source/css/scss/components/_sprites.scss +3 -0
  168. data/source/css/scss/components/_sr-only.scss +10 -0
  169. data/source/css/scss/components/_tables.scss +62 -0
  170. data/source/css/scss/components/_tooltips.scss +93 -0
  171. data/source/css/scss/components/_users.scss +11 -0
  172. data/source/css/scss/components/_vertical-tabs.scss +129 -0
  173. data/source/css/scss/components/_video.scss +7 -0
  174. data/source/css/scss/ecosystem/_addons-card.scss +3 -0
  175. data/source/css/scss/ecosystem/_cards.scss +369 -0
  176. data/source/css/scss/ecosystem/_elements-brand.scss +32 -0
  177. data/source/css/scss/ecosystem/_elements.scss +4 -0
  178. data/source/css/scss/globals/_colors.scss +189 -0
  179. data/source/css/scss/globals/_mixins.scss +45 -0
  180. data/source/css/scss/globals/_variables.scss +87 -0
  181. data/source/css/scss/layout/_grid-settings.scss +13 -0
  182. data/source/css/scss/layout/_layout.scss +95 -0
  183. data/source/css/scss/page-elements/_headers.scss +3 -0
  184. data/source/css/scss/page-elements/_navigation.scss +254 -0
  185. data/source/css/scss/page-elements/_sections.scss +66 -0
  186. data/source/css/scss/page-elements/_sidebar.scss +34 -0
  187. data/source/css/shibori.scss +63 -0
  188. data/source/fonts/bentonsans/bentonsans-book.eot +0 -0
  189. data/source/fonts/bentonsans/bentonsans-book.svg +400 -0
  190. data/source/fonts/bentonsans/bentonsans-book.ttf +0 -0
  191. data/source/fonts/bentonsans/bentonsans-book.woff +0 -0
  192. data/source/fonts/bentonsans/bentonsans-medium.eot +0 -0
  193. data/source/fonts/bentonsans/bentonsans-medium.svg +416 -0
  194. data/source/fonts/bentonsans/bentonsans-medium.ttf +0 -0
  195. data/source/fonts/bentonsans/bentonsans-medium.woff +0 -0
  196. data/source/fonts/bentonsans/bentonsans-regular.eot +0 -0
  197. data/source/fonts/bentonsans/bentonsans-regular.svg +416 -0
  198. data/source/fonts/bentonsans/bentonsans-regular.ttf +0 -0
  199. data/source/fonts/bentonsans/bentonsans-regular.woff +0 -0
  200. data/source/fonts/hk-icon/hk-icon.eot +0 -0
  201. data/source/fonts/hk-icon/hk-icon.svg +261 -0
  202. data/source/fonts/hk-icon/hk-icon.ttf +0 -0
  203. data/source/fonts/hk-icon/hk-icon.woff +0 -0
  204. data/source/fonts/inconsolata/inconsolata-bold.eot +0 -0
  205. data/source/fonts/inconsolata/inconsolata-bold.svg +239 -0
  206. data/source/fonts/inconsolata/inconsolata-bold.ttf +0 -0
  207. data/source/fonts/inconsolata/inconsolata-bold.woff +0 -0
  208. data/source/fonts/inconsolata/inconsolata-regular.eot +0 -0
  209. data/source/fonts/inconsolata/inconsolata-regular.svg +239 -0
  210. data/source/fonts/inconsolata/inconsolata-regular.ttf +0 -0
  211. data/source/fonts/inconsolata/inconsolata-regular.woff +0 -0
  212. data/source/images/blockquote/close-sm.png +0 -0
  213. data/source/images/blockquote/close.png +0 -0
  214. data/source/images/blockquote/close@2x.png +0 -0
  215. data/source/images/blockquote/open-sm.png +0 -0
  216. data/source/images/blockquote/open.png +0 -0
  217. data/source/images/blockquote/open@2x.png +0 -0
  218. data/source/images/elements/heroku_suported.svg +32 -0
  219. data/source/images/forms/select-input-arrows.svg +8 -0
  220. data/source/js/init.js +26 -0
  221. data/source/js/main.js +22 -0
  222. data/source/js/vendor/bourbon-modal.js +17 -0
  223. data/source/js/vendor/fitvids.js +77 -0
  224. data/source/js/vendor/fixto.js +719 -0
  225. data/source/js/vendor/jquery-2.0.0b2.js +8690 -0
  226. data/source/js/vendor/modernizr.js +4 -0
  227. data/source/js/vendor/owl.carousel.js +3069 -0
  228. data/source/js/vendor/readmore.js +11 -0
  229. data/source/js/vendor/unslider.js +1 -0
  230. data/source/js/vendor/vertical-tabs.js +34 -0
  231. data/test/files/test.css +19 -0
  232. data/test/lineage_hunter_tests.js +262 -0
  233. data/test/list_item_hunter_tests.js +167 -0
  234. data/test/media_hunter_tests.js +74 -0
  235. data/test/object_factory_tests.js +62 -0
  236. data/test/parameter_hunter_tests.js +298 -0
  237. data/test/pattern_assembler_tests.js +43 -0
  238. data/test/patternlab_tests.js +8 -0
  239. metadata +320 -0
@@ -0,0 +1,443 @@
1
+ /*!
2
+ * Code View Support for the Viewer - v0.1
3
+ *
4
+ * Copyright (c) 2013 Brad Frost, http://bradfrostweb.com & Dave Olsen, http://dmolsen.com
5
+ * Licensed under the MIT license
6
+ *
7
+ */
8
+
9
+ var codeViewer = {
10
+
11
+ // set up some defaults
12
+ codeActive: false,
13
+ tabActive: "e",
14
+ encoded: "",
15
+ mustache: "",
16
+ css: "",
17
+ ids: { "e": "#sg-code-title-html", "m": "#sg-code-title-mustache", "c": "#sg-code-title-css" },
18
+ targetOrigin: (window.location.protocol === "file:") ? "*" : window.location.protocol+"//"+window.location.host,
19
+ copyOnInit: false,
20
+
21
+ /**
22
+ * add the onclick handler to the code link in the main nav
23
+ */
24
+ onReady: function() {
25
+
26
+ // not sure this is needed anymore...
27
+ $('body').addClass('code-ready');
28
+
29
+ $(window).resize(function() {
30
+ if(!codeViewer.codeActive) {
31
+ codeViewer.slideCode($('#sg-code-container').outerHeight());
32
+ }
33
+ });
34
+
35
+ // add the onclick handler
36
+ $('#sg-t-code').click(function(e) {
37
+
38
+ e.preventDefault();
39
+
40
+ // remove the class from the "eye" nav item
41
+ $('#sg-t-toggle').removeClass('active');
42
+
43
+ // if the code link in the main nav is active close the panel. otherwise open
44
+ if ($(this).hasClass('active')) {
45
+ codeViewer.closeCode();
46
+ } else {
47
+ codeViewer.openCode();
48
+ }
49
+
50
+ });
51
+
52
+ // initialize the code viewer
53
+ codeViewer.codeContainerInit();
54
+
55
+ // load the query strings in case code view has to show by default
56
+ var queryStringVars = urlHandler.getRequestVars();
57
+ if ((queryStringVars.view !== undefined) && ((queryStringVars.view === "code") || (queryStringVars.view === "c"))) {
58
+ codeViewer.copyOnInit = ((queryStringVars.copy !== undefined) && (queryStringVars.copy === "true")) ? true : false;
59
+ codeViewer.openCode();
60
+ }
61
+
62
+ },
63
+
64
+ /**
65
+ * decide on if the code panel should be open or closed
66
+ */
67
+ toggleCode: function() {
68
+
69
+ if (!codeViewer.codeActive) {
70
+ codeViewer.openCode();
71
+ } else {
72
+ codeViewer.closeCode();
73
+ }
74
+
75
+ },
76
+
77
+ /**
78
+ * after clicking the code view link open the panel
79
+ */
80
+ openCode: function() {
81
+
82
+ // make sure the annotations overlay is off before showing code view
83
+ $('#sg-t-annotations').removeClass('active');
84
+ annotationsViewer.commentsActive = false;
85
+ var obj = JSON.stringify({ "commentToggle": "off" });
86
+ document.getElementById('sg-viewport').contentWindow.postMessage(obj,codeViewer.targetOrigin);
87
+ annotationsViewer.slideComment(999);
88
+
89
+ // tell the iframe code view has been turned on
90
+ var obj = JSON.stringify({ "codeToggle": "on" });
91
+ document.getElementById('sg-viewport').contentWindow.postMessage(obj,codeViewer.targetOrigin);
92
+
93
+ // note it's turned on in the viewer
94
+ codeViewer.codeActive = true;
95
+ $('#sg-t-code').addClass('active');
96
+
97
+ },
98
+
99
+ /**
100
+ * after clicking the code view link close the panel
101
+ */
102
+ closeCode: function() {
103
+ var obj = JSON.stringify({ "codeToggle": "off" });
104
+ document.getElementById('sg-viewport').contentWindow.postMessage(obj,codeViewer.targetOrigin);
105
+ codeViewer.codeActive = false;
106
+ codeViewer.slideCode($('#sg-code-container').outerHeight());
107
+ $('#sg-t-code').removeClass('active');
108
+ },
109
+
110
+ /**
111
+ * add the basic mark-up and events for the code container
112
+ */
113
+ codeContainerInit: function() {
114
+
115
+ // the bulk of this template is in core/templates/index.mustache
116
+ if (document.getElementById("sg-code-container") === null) {
117
+ $('<div id="sg-code-container" class="sg-view-container"></div>').html($("#code-template").html()).appendTo('body').css('bottom',-$(document).outerHeight());
118
+ setTimeout(function(){ $('#sg-code-container').addClass('anim-ready'); },50); //Add animation class once container is positioned out of frame
119
+ }
120
+
121
+ // make sure the close button handles the click
122
+ $('body').delegate('#sg-code-close-btn','click',function() {
123
+ codeViewer.closeCode();
124
+ return false;
125
+ });
126
+
127
+ // make sure the click events are handled on the HTML tab
128
+ $(codeViewer.ids["e"]).click(function() {
129
+ codeViewer.swapCode("e");
130
+ });
131
+
132
+ // make sure the click events are handled on the Mustache tab
133
+ $(codeViewer.ids["m"]).click(function() {
134
+ codeViewer.swapCode("m");
135
+ });
136
+
137
+ // make sure the click events are handled on the CSS tab
138
+ $(codeViewer.ids["c"]).click(function() {
139
+ codeViewer.swapCode("c");
140
+ });
141
+
142
+ },
143
+
144
+ /**
145
+ * depending on what tab is clicked this swaps out the code container. makes sure prism highlight is added.
146
+ */
147
+ swapCode: function(type) {
148
+
149
+ codeViewer.clearSelection();
150
+ var fill = "";
151
+ var className = (type == "c") ? "css" : "markup";
152
+ $("#sg-code-fill").removeClass().addClass("language-"+className);
153
+ if (type == "m") {
154
+ fill = codeViewer.mustache;
155
+ } else if (type == "e") {
156
+ fill = codeViewer.encoded;
157
+ } else if (type == "c") {
158
+ fill = codeViewer.css;
159
+ }
160
+ $("#sg-code-fill").html(fill).text();
161
+ codeViewer.tabActive = type;
162
+ Prism.highlightElement(document.getElementById("sg-code-fill"));
163
+ $('.sg-code-title-active').removeClass('sg-code-title-active');
164
+ $(codeViewer.ids[type]).toggleClass("sg-code-title-active");
165
+ },
166
+
167
+ /**
168
+ * select the code where using cmd+a/ctrl+a
169
+ */
170
+ selectCode: function() {
171
+ if (codeViewer.codeActive) {
172
+ selection = window.getSelection();
173
+ range = document.createRange();
174
+ range.selectNodeContents(document.getElementById("sg-code-fill"));
175
+ selection.removeAllRanges();
176
+ selection.addRange(range);
177
+ }
178
+ },
179
+
180
+ /**
181
+ * clear any selection of code when swapping tabs or opening a new pattern
182
+ */
183
+ clearSelection: function() {
184
+ if (codeViewer.codeActive) {
185
+ if (window.getSelection().empty) {
186
+ window.getSelection().empty();
187
+ } else if (window.getSelection().removeAllRanges) {
188
+ window.getSelection().removeAllRanges();
189
+ }
190
+ }
191
+ },
192
+
193
+ /**
194
+ * slides the panel
195
+ */
196
+ slideCode: function(pos) {
197
+ $('#sg-code-container').css('bottom',-pos);
198
+ },
199
+
200
+ /**
201
+ * once the AJAX request for the encoded mark-up is finished this runs.
202
+ * if the encoded tab is the current active tab it adds the content to the default code container
203
+ */
204
+ saveEncoded: function() {
205
+ codeViewer.encoded = this.responseText;
206
+ if (codeViewer.tabActive == "e") {
207
+ codeViewer.activateDefaultTab("e",this.responseText);
208
+ }
209
+ },
210
+
211
+ /**
212
+ * once the AJAX request for the mustache mark-up is finished this runs.
213
+ * if the mustache tab is the current active tab it adds the content to the default code container
214
+ */
215
+ saveMustache: function() {
216
+ codeViewer.mustache = this.responseText;
217
+ if (codeViewer.tabActive == "m") {
218
+ codeViewer.activateDefaultTab("m",this.responseText);
219
+ }
220
+ },
221
+
222
+ /**
223
+ * once the AJAX request for the css mark-up is finished this runs. if this function is running then css has been enabled
224
+ * if the css tab is the current active tab it adds the content to the default code container
225
+ */
226
+ saveCSS: function() {
227
+ $('#sg-code-title-css').css("display","block");
228
+ codeViewer.css = this.responseText;
229
+ if (codeViewer.tabActive == "c") {
230
+ codeViewer.activateDefaultTab("c",this.responseText);
231
+ }
232
+ },
233
+
234
+ /**
235
+ * when loading the code view make sure the active tab is highlighted and filled in appropriately
236
+ */
237
+ activateDefaultTab: function(type,code) {
238
+ var typeName = "";
239
+ var className = (type == "c") ? "css" : "markup";
240
+ if (type == "m") {
241
+ typeName = "mustache";
242
+ } else if (type == "e") {
243
+ typeName = "html";
244
+ } else if (type == "c") {
245
+ typeName = "css";
246
+ }
247
+ $('.sg-code-title-active').removeClass('sg-code-title-active');
248
+ $('#sg-code-title-'+typeName).addClass('sg-code-title-active');
249
+ $("#sg-code-fill").removeClass().addClass("language-"+className);
250
+ $("#sg-code-fill").html(code).text();
251
+ Prism.highlightElement(document.getElementById("sg-code-fill"));
252
+ if (codeViewer.copyOnInit) {
253
+ codeViewer.selectCode();
254
+ codeViewer.copyOnInit = false;
255
+ }
256
+ },
257
+
258
+ /**
259
+ * when turning on or switching between patterns with code view on make sure we get
260
+ * the code from from the pattern via post message
261
+ */
262
+ updateCode: function(lineage,lineageR,patternPartial,patternState,cssEnabled) {
263
+
264
+ // clear any selections that might have been made
265
+ codeViewer.clearSelection();
266
+
267
+ // draw lineage
268
+ if (lineage.length !== 0) {
269
+ var lineageList = "";
270
+ $("#sg-code-lineage").css("display","block");
271
+ for (var i = 0; i < lineage.length; i++) {
272
+ lineageList += (i === 0) ? "" : ", ";
273
+ var cssClass = (lineage[i].lineageState != undefined) ? "sg-pattern-state "+lineage[i].lineageState : "";
274
+ lineageList += "<a href='"+lineage[i].lineagePath+"' class='"+cssClass+"' data-patternPartial='"+lineage[i].lineagePattern+"'>"+lineage[i].lineagePattern+"</a>";
275
+ }
276
+ $("#sg-code-lineage-fill").html(lineageList);
277
+ } else {
278
+ $("#sg-code-lineage").css("display","none");
279
+ }
280
+
281
+ // draw reverse lineage
282
+ if (lineageR.length !== 0) {
283
+ var lineageRList = "";
284
+ $("#sg-code-lineager").css("display","block");
285
+ for (var i = 0; i < lineageR.length; i++) {
286
+ lineageRList += (i === 0) ? "" : ", ";
287
+ var cssClass = (lineageR[i].lineageState != undefined) ? "sg-pattern-state "+lineageR[i].lineageState : "";
288
+ lineageRList += "<a href='"+lineageR[i].lineagePath+"' class='"+cssClass+"' data-patternPartial='"+lineageR[i].lineagePattern+"'>"+lineageR[i].lineagePattern+"</a>";
289
+ }
290
+ $("#sg-code-lineager-fill").html(lineageRList);
291
+ } else {
292
+ $("#sg-code-lineager").css("display","none");
293
+ }
294
+
295
+ // when clicking on a lineage item change the iframe source
296
+ $('#sg-code-lineage-fill a, #sg-code-lineager-fill a').on("click", function(e){
297
+ e.preventDefault();
298
+ $("#sg-code-loader").css("display","block");
299
+ var obj = JSON.stringify({ "path": urlHandler.getFileName($(this).attr("data-patternpartial")) });
300
+ document.getElementById("sg-viewport").contentWindow.postMessage(obj,codeViewer.targetOrigin);
301
+ });
302
+
303
+ // show pattern state
304
+ if (patternState != "") {
305
+ $("#sg-code-patternstate").css("display","block");
306
+ var patternStateItem = "<span class=\"sg-pattern-state "+patternState+"\">"+patternState+"</span>";
307
+ $("#sg-code-patternstate-fill").html(patternStateItem);
308
+ } else {
309
+ $("#sg-code-patternstate").css("display","none");
310
+ }
311
+
312
+ // fill in the name of the pattern
313
+ $('#sg-code-lineage-patternname, #sg-code-lineager-patternname, #sg-code-patternstate-patternname').html(patternPartial);
314
+
315
+ // get the file name of the pattern so we can get the various editions of the code that can show in code view
316
+ var fileName = urlHandler.getFileName(patternPartial);
317
+
318
+ // request the encoded markup version of the pattern
319
+ var e = new XMLHttpRequest();
320
+ e.onload = this.saveEncoded;
321
+ e.open("GET", fileName.replace(/\.html/,".escaped.html") + "?" + (new Date()).getTime(), true);
322
+ e.send();
323
+
324
+ // request the mustache markup version of the pattern
325
+ var m = new XMLHttpRequest();
326
+ m.onload = this.saveMustache;
327
+ m.open("GET", fileName.replace(/\.html/,".mustache") + "?" + (new Date()).getTime(), true);
328
+ m.send();
329
+
330
+ // if css is enabled request the css for the pattern
331
+ if (cssEnabled) {
332
+ var c = new XMLHttpRequest();
333
+ c.onload = this.saveCSS;
334
+ c.open("GET", fileName.replace(/\.html/,".css") + "?" + (new Date()).getTime(), true);
335
+ c.send();
336
+ }
337
+
338
+ // move the code into view
339
+ codeViewer.slideCode(0);
340
+
341
+ $("#sg-code-loader").css("display","none");
342
+
343
+ },
344
+
345
+ /**
346
+ * toggle the comment pop-up based on a user clicking on the pattern
347
+ * based on the great MDN docs at https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage
348
+ * @param {Object} event info
349
+ */
350
+ receiveIframeMessage: function(event) {
351
+
352
+ var data = (typeof event.data !== "string") ? event.data : JSON.parse(event.data);
353
+
354
+ // does the origin sending the message match the current host? if not dev/null the request
355
+ if ((window.location.protocol !== "file:") && (event.origin !== window.location.protocol+"//"+window.location.host)) {
356
+ return;
357
+ }
358
+
359
+ // switch based on stuff related to the postmessage
360
+ if (data.codeOverlay !== undefined) {
361
+ if (data.codeOverlay === "on") {
362
+ codeViewer.updateCode(data.lineage,data.lineageR,data.patternPartial,data.patternState,data.cssEnabled);
363
+ } else {
364
+ codeViewer.slideCode($('#sg-code-container').outerHeight());
365
+ }
366
+ } else if (data.keyPress !== undefined) {
367
+ if (data.keyPress == 'ctrl+shift+c') {
368
+ codeViewer.toggleCode();
369
+ return false;
370
+ } else if (data.keyPress == 'cmd+a') {
371
+ codeViewer.selectCode();
372
+ return false;
373
+ } else if (data.keyPress == 'ctrl+shift+u') {
374
+ if (codeViewer.codeActive) {
375
+ codeViewer.swapCode("m");
376
+ return false;
377
+ }
378
+ } else if (data.keyPress == 'ctrl+shift+y') {
379
+ if (codeViewer.codeActive) {
380
+ codeViewer.swapCode("e");
381
+ return false;
382
+ }
383
+ } else if (data.keyPress == 'esc') {
384
+ if (codeViewer.codeActive) {
385
+ codeViewer.closeCode();
386
+ return false;
387
+ }
388
+ }
389
+ }
390
+
391
+ }
392
+
393
+ };
394
+
395
+ // when the document is ready make the codeViewer ready
396
+ $(document).ready(function() { codeViewer.onReady(); });
397
+ window.addEventListener("message", codeViewer.receiveIframeMessage, false);
398
+
399
+ // make sure if a new pattern or view-all is loaded that comments are turned on as appropriate
400
+ $('#sg-viewport').load(function() {
401
+ if (codeViewer.codeActive) {
402
+ var obj = JSON.stringify({ "codeToggle": "on" });
403
+ document.getElementById('sg-viewport').contentWindow.postMessage(obj,codeViewer.targetOrigin);
404
+ }
405
+ });
406
+
407
+ // toggle the code panel
408
+ jwerty.key('ctrl+shift+c', function (e) {
409
+ codeViewer.toggleCode();
410
+ return false;
411
+ });
412
+
413
+ // when the code panel is open hijack cmd+a so that it only selects the code view
414
+ jwerty.key('cmd+a/ctrl+a', function (e) {
415
+ if (codeViewer.codeActive) {
416
+ codeViewer.selectCode();
417
+ return false;
418
+ }
419
+ });
420
+
421
+ // open the mustache panel
422
+ jwerty.key('ctrl+shift+u', function (e) {
423
+ if (codeViewer.codeActive) {
424
+ codeViewer.swapCode("m");
425
+ return false;
426
+ }
427
+ });
428
+
429
+ // open the html panel
430
+ jwerty.key('ctrl+shift+y', function (e) {
431
+ if (codeViewer.codeActive) {
432
+ codeViewer.swapCode("e");
433
+ return false;
434
+ }
435
+ });
436
+
437
+ // close the code panel if using escape
438
+ jwerty.key('esc', function (e) {
439
+ if (codeViewer.codeActive) {
440
+ codeViewer.closeCode();
441
+ return false;
442
+ }
443
+ });
@@ -0,0 +1,169 @@
1
+ /*!
2
+ * jQuery Cookie Plugin v1.3
3
+ * https://github.com/carhartl/jquery-cookie
4
+ *
5
+ * Copyright 2011, Klaus Hartl
6
+ * Dual licensed under the MIT or GPL Version 2 licenses.
7
+ * http://www.opensource.org/licenses/mit-license.php
8
+ * http://www.opensource.org/licenses/GPL-2.0
9
+ */
10
+ (function ($, document, undefined) {
11
+
12
+ var pluses = /\+/g;
13
+
14
+ function raw(s) {
15
+ return s;
16
+ }
17
+
18
+ function decoded(s) {
19
+ return decodeURIComponent(s.replace(pluses, ' '));
20
+ }
21
+
22
+ var config = $.cookie = function (key, value, options) {
23
+
24
+ // write
25
+ if (value !== undefined) {
26
+ options = $.extend({}, config.defaults, options);
27
+
28
+ if (value === null) {
29
+ options.expires = -1;
30
+ }
31
+
32
+ if (typeof options.expires === 'number') {
33
+ var days = options.expires, t = options.expires = new Date();
34
+ t.setDate(t.getDate() + days);
35
+ }
36
+
37
+ value = config.json ? JSON.stringify(value) : String(value);
38
+
39
+ return (document.cookie = [
40
+ encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
41
+ options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
42
+ options.path ? '; path=' + options.path : '',
43
+ options.domain ? '; domain=' + options.domain : '',
44
+ options.secure ? '; secure' : ''
45
+ ].join(''));
46
+ }
47
+
48
+ // read
49
+ var decode = config.raw ? raw : decoded;
50
+ var cookies = document.cookie.split('; ');
51
+ for (var i = 0, l = cookies.length; i < l; i++) {
52
+ var parts = cookies[i].split('=');
53
+ if (decode(parts.shift()) === key) {
54
+ var cookie = decode(parts.join('='));
55
+ return config.json ? JSON.parse(cookie) : cookie;
56
+ }
57
+ }
58
+
59
+ return null;
60
+ };
61
+
62
+ config.defaults = {};
63
+
64
+ $.removeCookie = function (key, options) {
65
+ if ($.cookie(key) !== null) {
66
+ $.cookie(key, null, options);
67
+ return true;
68
+ }
69
+ return false;
70
+ };
71
+
72
+ })(jQuery, document);
73
+
74
+ /*!
75
+ * Data Saver - v0.1
76
+ *
77
+ * Copyright (c) 2013 Dave Olsen, http://dmolsen.com
78
+ * Licensed under the MIT license
79
+ */
80
+
81
+ var DataSaver = {
82
+
83
+ // the name of the cookie to store the data in
84
+ cookieName: "patternlab",
85
+
86
+ /**
87
+ * Add a given value to the cookie
88
+ * @param {String} the name of the key
89
+ * @param {String} the value
90
+ */
91
+ addValue: function (name,val) {
92
+ var cookieVal = $.cookie(this.cookieName);
93
+ if ((cookieVal == null) || (cookieVal == "")) {
94
+ cookieVal = name+"~"+val;
95
+ } else {
96
+ cookieVal = cookieVal+"|"+name+"~"+val;
97
+ }
98
+ $.cookie(this.cookieName,cookieVal);
99
+ },
100
+
101
+ /**
102
+ * Update a value found in the cookie. If the key doesn't exist add the value
103
+ * @param {String} the name of the key
104
+ * @param {String} the value
105
+ */
106
+ updateValue: function (name,val) {
107
+ if (this.findValue(name)) {
108
+ var updateCookieVals = "";
109
+ var cookieVals = $.cookie(this.cookieName).split("|");
110
+ for (var i = 0; i < cookieVals.length; i++) {
111
+ var fieldVals = cookieVals[i].split("~");
112
+ if (fieldVals[0] == name) {
113
+ fieldVals[1] = val;
114
+ }
115
+ if (i > 0) {
116
+ updateCookieVals += "|"+fieldVals[0]+"~"+fieldVals[1];
117
+ } else {
118
+ updateCookieVals += fieldVals[0]+"~"+fieldVals[1];
119
+ }
120
+ }
121
+ $.cookie(this.cookieName,updateCookieVals);
122
+ } else {
123
+ this.addValue(name,val);
124
+ }
125
+ },
126
+
127
+ /**
128
+ * Remove the given key
129
+ * @param {String} the name of the key
130
+ */
131
+ removeValue: function (name) {
132
+ var updateCookieVals = "";
133
+ var cookieVals = $.cookie(this.cookieName).split("|");
134
+ var k = 0;
135
+ for (var i = 0; i < cookieVals.length; i++) {
136
+ var fieldVals = cookieVals[i].split("~");
137
+ if (fieldVals[0] != name) {
138
+ if (k == 0) {
139
+ updateCookieVals += fieldVals[0]+"~"+fieldVals[1];
140
+ } else {
141
+ updateCookieVals += "|"+fieldVals[0]+"~"+fieldVals[1];
142
+ }
143
+ k++;
144
+ }
145
+ }
146
+ $.cookie(this.cookieName,updateCookieVals);
147
+ },
148
+
149
+ /**
150
+ * Find the value using the given key
151
+ * @param {String} the name of the key
152
+ *
153
+ * @return {String} the value of the key or false if the value isn't found
154
+ */
155
+ findValue: function (name) {
156
+ if ($.cookie(this.cookieName)) {
157
+ var cookieVals = $.cookie(this.cookieName).split("|");
158
+ var k = 0;
159
+ for (var i = 0; i < cookieVals.length; i++) {
160
+ var fieldVals = cookieVals[i].split("~");
161
+ if (fieldVals[0] == name) {
162
+ return fieldVals[1];
163
+ }
164
+ }
165
+ }
166
+ return false;
167
+ }
168
+
169
+ };