docks_theme_api 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. checksums.yaml +15 -0
  2. data/.babelrc +4 -0
  3. data/.editorconfig +8 -0
  4. data/.eslintrc +115 -0
  5. data/.gitignore +24 -0
  6. data/.rubocop.yml +20 -0
  7. data/.travis.yml +16 -0
  8. data/Gemfile +4 -0
  9. data/README.md +5 -0
  10. data/Rakefile +3 -0
  11. data/assets/images/icons.svg +63 -0
  12. data/assets/scripts/coffeescript/pattern_library_helpers.coffee +8 -0
  13. data/assets/scripts/javascript/pattern_library_helpers.js +11 -0
  14. data/assets/scripts/pattern_library.js +10380 -0
  15. data/assets/scripts/pattern_library_demo.js +0 -0
  16. data/assets/styles/less/pattern-library-helpers.less +103 -0
  17. data/assets/styles/pattern-library-demo.css +1882 -0
  18. data/assets/styles/pattern-library.css +1882 -0
  19. data/assets/styles/sass/pattern-library-helpers.sass +90 -0
  20. data/assets/styles/scss/pattern-library-helpers.scss +99 -0
  21. data/assets/styles/stylus/pattern-library-helpers.styl +90 -0
  22. data/assets/templates/erb/demo.erb +26 -0
  23. data/assets/templates/erb/layouts/demo.erb +17 -0
  24. data/assets/templates/erb/layouts/pattern.erb +76 -0
  25. data/assets/templates/erb/partials/sidebar.erb +124 -0
  26. data/assets/templates/erb/partials/symbols/class.erb +1 -0
  27. data/assets/templates/erb/partials/symbols/demo.erb +40 -0
  28. data/assets/templates/erb/partials/symbols/factory.erb +70 -0
  29. data/assets/templates/erb/partials/symbols/function.erb +103 -0
  30. data/assets/templates/erb/partials/symbols/mixin.erb +62 -0
  31. data/assets/templates/erb/partials/symbols/variable.erb +59 -0
  32. data/assets/templates/erb/pattern.erb +102 -0
  33. data/assets/templates/haml/demo.haml +14 -0
  34. data/assets/templates/haml/layouts/demo.haml +6 -0
  35. data/assets/templates/haml/layouts/pattern.haml +38 -0
  36. data/assets/templates/haml/partials/sidebar.haml +68 -0
  37. data/assets/templates/haml/partials/symbols/class.haml +1 -0
  38. data/assets/templates/haml/partials/symbols/demo.haml +23 -0
  39. data/assets/templates/haml/partials/symbols/factory.haml +38 -0
  40. data/assets/templates/haml/partials/symbols/function.haml +54 -0
  41. data/assets/templates/haml/partials/symbols/mixin.haml +31 -0
  42. data/assets/templates/haml/partials/symbols/variable.haml +22 -0
  43. data/assets/templates/haml/pattern.haml +54 -0
  44. data/assets/templates/slim/demo.slim +24 -0
  45. data/assets/templates/slim/layouts/demo.slim +5 -0
  46. data/assets/templates/slim/layouts/pattern.slim +48 -0
  47. data/assets/templates/slim/partials/sidebar.slim +112 -0
  48. data/assets/templates/slim/partials/symbols/class.slim +1 -0
  49. data/assets/templates/slim/partials/symbols/demo.slim +30 -0
  50. data/assets/templates/slim/partials/symbols/factory.slim +57 -0
  51. data/assets/templates/slim/partials/symbols/function.slim +81 -0
  52. data/assets/templates/slim/partials/symbols/mixin.slim +45 -0
  53. data/assets/templates/slim/partials/symbols/variable.slim +35 -0
  54. data/assets/templates/slim/pattern.slim +63 -0
  55. data/docks_config.rb +32 -0
  56. data/docks_theme_api.gemspec +37 -0
  57. data/gulpfile.js +88 -0
  58. data/karma.conf.js +6 -0
  59. data/lib/docks_theme_api/components/base_component.rb +99 -0
  60. data/lib/docks_theme_api/components/code_block_component.rb +10 -0
  61. data/lib/docks_theme_api/components/popover_component.rb +15 -0
  62. data/lib/docks_theme_api/components/table_component.rb +34 -0
  63. data/lib/docks_theme_api/components/tablist_component.rb +11 -0
  64. data/lib/docks_theme_api/components.rb +21 -0
  65. data/lib/docks_theme_api/helpers/ui_helper.rb +69 -0
  66. data/lib/docks_theme_api/theme.rb +21 -0
  67. data/lib/docks_theme_api.rb +1 -0
  68. data/package.json +60 -0
  69. data/source/behaviors/filterable/filterable.coffee +353 -0
  70. data/source/behaviors/filterable/filterable.js +0 -0
  71. data/source/behaviors/filterable/filterable.scss +34 -0
  72. data/source/behaviors/filterable/package.json +3 -0
  73. data/source/behaviors/index.js +0 -0
  74. data/source/components/avatar/avatar.erb +20 -0
  75. data/source/components/avatar/avatar.js +142 -0
  76. data/source/components/avatar/avatar.scss +200 -0
  77. data/source/components/avatar/avatar_container.erb +13 -0
  78. data/source/components/avatar/package.json +3 -0
  79. data/source/components/avatar/spec/avatar_spec.js +81 -0
  80. data/source/components/badge/badge.scss +158 -0
  81. data/source/components/button/button.scss +213 -0
  82. data/source/components/card/card.scss +32 -0
  83. data/source/components/code_block/code-block.scss +353 -0
  84. data/source/components/code_block/code_block.erb +95 -0
  85. data/source/components/code_block/code_block.js +444 -0
  86. data/source/components/code_block/package.json +3 -0
  87. data/source/components/code_block/spec/code_block_spec.js +10 -0
  88. data/source/components/demo/demo.js +244 -0
  89. data/source/components/demo/demo.scss +90 -0
  90. data/source/components/demo/package.json +3 -0
  91. data/source/components/exploded/exploded.erb +25 -0
  92. data/source/components/exploded/exploded.js +694 -0
  93. data/source/components/exploded/exploded.scss +166 -0
  94. data/source/components/exploded/package.json +3 -0
  95. data/source/components/field/field.js +24 -0
  96. data/source/components/field/field.scss +101 -0
  97. data/source/components/field/package.json +3 -0
  98. data/source/components/header/header.scss +33 -0
  99. data/source/components/iframe/iframe.erb +12 -0
  100. data/source/components/iframe/iframe.js +381 -0
  101. data/source/components/iframe/package.json +3 -0
  102. data/source/components/index.js +37 -0
  103. data/source/components/inline_group/inline-group.scss +14 -0
  104. data/source/components/internal_link/internal_link.js +49 -0
  105. data/source/components/internal_link/package.json +3 -0
  106. data/source/components/list/list.scss +230 -0
  107. data/source/components/modal/modal.coffee +84 -0
  108. data/source/components/modal/modal.erb +19 -0
  109. data/source/components/modal/modal.js +0 -0
  110. data/source/components/modal/modal.scss +57 -0
  111. data/source/components/modal/package.json +3 -0
  112. data/source/components/notice/notice.scss +48 -0
  113. data/source/components/popover/package.json +3 -0
  114. data/source/components/popover/popover.coffee +562 -0
  115. data/source/components/popover/popover.erb +21 -0
  116. data/source/components/popover/popover.js +0 -0
  117. data/source/components/popover/popover.scss +139 -0
  118. data/source/components/range/range.scss +78 -0
  119. data/source/components/resizable/package.json +3 -0
  120. data/source/components/resizable/resizable.erb +30 -0
  121. data/source/components/resizable/resizable.js +250 -0
  122. data/source/components/resizable/resizable.scss +245 -0
  123. data/source/components/resizable/size_buttons.js +249 -0
  124. data/source/components/scroll_container/package.json +3 -0
  125. data/source/components/scroll_container/scroll-container.scss +4 -0
  126. data/source/components/scroll_container/scroll_container.js +24 -0
  127. data/source/components/section/section.scss +99 -0
  128. data/source/components/select/package.json +3 -0
  129. data/source/components/select/select.erb +21 -0
  130. data/source/components/select/select.js +35 -0
  131. data/source/components/select/select.scss +163 -0
  132. data/source/components/table/package.json +3 -0
  133. data/source/components/table/table.erb +16 -0
  134. data/source/components/table/table.js +351 -0
  135. data/source/components/table/table.scss +236 -0
  136. data/source/components/tablist/package.json +3 -0
  137. data/source/components/tablist/tablist.erb +13 -0
  138. data/source/components/tablist/tablist.js +246 -0
  139. data/source/components/tablist/tablist.scss +191 -0
  140. data/source/components/tablist/tablist_panel.erb +14 -0
  141. data/source/components/tablist/tablist_tab.erb +20 -0
  142. data/source/components/toggle/package.json +3 -0
  143. data/source/components/toggle/toggle.erb +11 -0
  144. data/source/components/toggle/toggle.js +211 -0
  145. data/source/components/toggle/toggle_container.erb +30 -0
  146. data/source/components/vertical_spacer/vertical-spacer.scss +3 -0
  147. data/source/components/vertical_stack/vertical-stack.scss +19 -0
  148. data/source/components/xray/package.json +3 -0
  149. data/source/components/xray/xray.erb +50 -0
  150. data/source/components/xray/xray.js +123 -0
  151. data/source/components/xray/xray.scss +79 -0
  152. data/source/foundation/app/app.js +15 -0
  153. data/source/foundation/app/package.json +3 -0
  154. data/source/pattern-library-demo.scss +13 -0
  155. data/source/pattern-library.scss +13 -0
  156. data/source/pattern_library.js +8 -0
  157. data/source/pattern_library_demo.js +8 -0
  158. data/source/structures/index.js +11 -0
  159. data/source/structures/sidebar/package.json +3 -0
  160. data/source/structures/sidebar/sidebar.js +69 -0
  161. data/source/structures/sidebar/sidebar.scss +79 -0
  162. data/source/utilities/builder/builder.js +138 -0
  163. data/source/utilities/builder/package.json +3 -0
  164. data/source/utilities/client/client.js +7 -0
  165. data/source/utilities/client/package.json +3 -0
  166. data/source/utilities/colors/colors.scss +112 -0
  167. data/source/utilities/defaults/defaults.scss +38 -0
  168. data/source/utilities/dom_cache/dom_cache.js +24 -0
  169. data/source/utilities/dom_cache/package.json +3 -0
  170. data/source/utilities/events/events.js +25 -0
  171. data/source/utilities/events/package.json +3 -0
  172. data/source/utilities/font_sizes/font-sizes.scss +85 -0
  173. data/source/utilities/foundation/a11y.scss +10 -0
  174. data/source/utilities/foundation/base.scss +29 -0
  175. data/source/utilities/foundation/icon.scss +114 -0
  176. data/source/utilities/foundation/layout.scss +67 -0
  177. data/source/utilities/foundation/page.scss +39 -0
  178. data/source/utilities/foundation/type.scss +208 -0
  179. data/source/utilities/functions/functions.scss +127 -0
  180. data/source/utilities/keycodes/keycodes.js +23 -0
  181. data/source/utilities/keycodes/package.json +3 -0
  182. data/source/utilities/markup/markup.js +90 -0
  183. data/source/utilities/markup/package.json +3 -0
  184. data/source/utilities/media/media.scss +172 -0
  185. data/source/utilities/mixins/mixins.scss +89 -0
  186. data/source/utilities/naming_convention/naming_convention.js +3 -0
  187. data/source/utilities/naming_convention/package.json +3 -0
  188. data/source/utilities/numbers/numbers.js +14 -0
  189. data/source/utilities/numbers/package.json +3 -0
  190. data/source/utilities/painting/package.json +3 -0
  191. data/source/utilities/painting/painting.js +7 -0
  192. data/source/utilities/pattern/package.json +3 -0
  193. data/source/utilities/pattern/pattern.js +50 -0
  194. data/source/utilities/query_string/package.json +3 -0
  195. data/source/utilities/query_string/query_string.js +24 -0
  196. data/source/utilities/template/package.json +3 -0
  197. data/source/utilities/template/template.js +10 -0
  198. data/source/utilities/text_range/package.json +3 -0
  199. data/source/utilities/text_range/text_range.js +30 -0
  200. data/source/utilities/ui_events/package.json +3 -0
  201. data/source/utilities/ui_events/ui_events.js +85 -0
  202. data/source/utilities/variables/variables.scss +18 -0
  203. data/source/utilities/z_indexes/z-indexes.scss +88 -0
  204. data/source/vendor/array_includes.js +28 -0
  205. data/source/vendor/highlight.js +1142 -0
  206. data/source/vendor/index.js +1 -0
  207. data/source/vendor/matrix.js +399 -0
  208. data/source/vendor/query_string.js +66 -0
  209. data/spec/assets/.eslintrc +9 -0
  210. data/spec/assets/spec_fixture.js +33 -0
  211. data/spec/assets/spec_helper.js +19 -0
  212. data/spec/lib/components/base_component_spec.rb +156 -0
  213. data/spec/lib/components_spec.rb +30 -0
  214. data/spec/lib/helpers/ui_helper_spec.rb +62 -0
  215. data/spec/lib/theme_spec.rb +25 -0
  216. data/spec/spec_helper.rb +15 -0
  217. data/tasks/gulp/.eslintrc +6 -0
  218. data/tasks/gulp/browser_sync.js +8 -0
  219. data/tasks/gulp/code_quality/scripts.js +10 -0
  220. data/tasks/gulp/config/index.js +116 -0
  221. data/tasks/gulp/minify/scripts.js +13 -0
  222. data/tasks/gulp/minify/styles.js +13 -0
  223. data/tasks/gulp/pattern_library/index.js +5 -0
  224. data/tasks/gulp/pattern_library/scripts.js +10 -0
  225. data/tasks/gulp/pattern_library/styles.js +10 -0
  226. data/tasks/gulp/scripts.js +8 -0
  227. data/tasks/gulp/spec/scripts.js +11 -0
  228. data/tasks/gulp/styles.js +17 -0
  229. data/tasks/gulp/utilities/babel/relative_require.js +22 -0
  230. data/tasks/gulp/utilities/babel/spec_helper.js +20 -0
  231. data/tasks/gulp/utilities/browserify_bundler.js +22 -0
  232. data/tasks/gulp/utilities/handle_errors.js +13 -0
  233. data/tasks/gulp/watch.js +9 -0
  234. data/tasks/rake/rspec.rake +7 -0
  235. data/tasks/rake/rubocop.rake +8 -0
  236. data/tasks/rake/templates.rake +50 -0
  237. metadata +470 -0
@@ -0,0 +1,381 @@
1
+ // ___ ___ ___ ___ ___
2
+ // ___ / /\ / /\ / /\ /__/\ / /\
3
+ // / /\ / /:/_ / /::\ / /::\ | |::\ / /:/_
4
+ // / /:/ / /:/ /\ / /:/\:\ / /:/\:\ | |:|:\ / /:/ /\
5
+ // /__/::\ / /:/ /:// /:/~/:/ / /:/~/::\ __|__|:|\:\ / /:/ /:/_
6
+ // \__\/\:\__ /__/:/ /://__/:/ /:/___/__/:/ /:/\:\/__/::::| \:\/__/:/ /:/ /\
7
+ // \ \:\/\\ \:\/:/ \ \:\/:::::/\ \:\/:/__\/\ \:\~~\__\/\ \:\/:/ /:/
8
+ // \__\::/ \ \::/ \ \::/~~~~ \ \::/ \ \:\ \ \::/ /:/
9
+ // /__/:/ \ \:\ \ \:\ \ \:\ \ \:\ \ \:\/:/
10
+ // \__\/ \ \:\ \ \:\ \ \:\ \ \:\ \ \::/
11
+ // \__\/ \__\/ \__\/ \__\/ \__\/
12
+ //
13
+
14
+ import Events from "../../utilities/events";
15
+ import Cache from "../../utilities/dom_cache";
16
+ import { decode_html_entities } from "../../utilities/markup";
17
+
18
+ //*
19
+ // The name of classes relevant to `Iframe` and `Communicator`.
20
+ // @object
21
+
22
+ const classes = {
23
+ root: "iframe",
24
+ content: "iframe__content"
25
+ };
26
+
27
+ //*
28
+ // The name of attributes relevant to `Iframe` and `Communicator`.
29
+ // @object
30
+
31
+ const attrs = {
32
+ id: "data-iframe-id"
33
+ };
34
+
35
+ //*
36
+ // The possible positions of an [`Iframe`](@link) — either the parent (on the
37
+ // main page) or the child (embedded inside an `iframe`).
38
+ //
39
+ // @object
40
+ // @private
41
+
42
+ const positions = {
43
+ parent: "parent",
44
+ child: "child"
45
+ };
46
+
47
+ //*
48
+ // A set of events registered with [`Events`](@link) that relate specifically
49
+ // to features managed by the core `Iframe`.
50
+ //
51
+ // @object
52
+ // @private
53
+
54
+ const iframe_events = [
55
+ "markup_request",
56
+ "markup_request",
57
+ "height_change",
58
+ "markup_change",
59
+ "class_change",
60
+ "height_request",
61
+ "event_handler"
62
+ ];
63
+
64
+ var Iframe, iframes, Communicator,
65
+ create_self, add_event_listeners, move_markup_to_iframe;
66
+
67
+ iframes = [];
68
+
69
+ Events.register(...iframe_events);
70
+
71
+ //*
72
+ // A mechanism for communicating between a given component and one or more
73
+ // [`Iframe`s](@link Iframe).
74
+ //
75
+ // @factoryk
76
+
77
+ Communicator = () => {
78
+ var private_iframes = [], private_iframe,
79
+ actions = {}, communicator;
80
+
81
+ communicator = {
82
+
83
+ //*
84
+ // Trigger an event with the provided data to all attached iframes.
85
+ //
86
+ // @method
87
+ //
88
+ // @param {String} type - The type of event to trigger. Do not pass a string
89
+ // literal — instead, pass an event defined on [`Events.types`](@link).
90
+ //
91
+ // @param {*} data - Any piece of data that can be stringified by
92
+ // `JSON.stringify`.
93
+
94
+ trigger(type, data) {
95
+ for(private_iframe of private_iframes) {
96
+ private_iframe.trigger(type, data);
97
+ }
98
+ },
99
+
100
+ //*
101
+ // Add a listener for when an `Iframe` is triggered with the passed `event`.
102
+ //
103
+ // @method
104
+ //
105
+ // @param {String} type - The type of event to listen for. Do not pass a
106
+ // string literal — instead, pass an event defined on
107
+ // [`Events.types`](@link).
108
+ //
109
+ // @param {Function} action - The callback to run when the event is
110
+ // triggered.
111
+ //
112
+ // @param {Object} action.data - The data that was passed along to the
113
+ // [`Iframe#trigger`](@link) that generated this event.
114
+
115
+ on(event, action) {
116
+ actions[event] = actions[event] || [];
117
+ actions[event].push(action);
118
+ },
119
+
120
+ //*
121
+ // Receives the data for an event and clals all associated event handlers.
122
+ // This is primarily provided so that the `Iframe` can call this method for
123
+ // all listeners that have been registered with it.
124
+ //
125
+ // @method
126
+ //
127
+ // @param {Object} event - All of the data associated with the event.
128
+
129
+ receive(event) {
130
+ var event_actions = actions[event.type],
131
+ action;
132
+
133
+ if(!event_actions) { return; }
134
+ for(action of actions) { action(event); }
135
+ },
136
+
137
+ //*
138
+ // An object that wraps all of the registering functionality.
139
+ //
140
+ // @property
141
+ // @object
142
+
143
+ register: {
144
+
145
+ //*
146
+ // Registers this `Communicator` with the passed ID or `iframe` node.
147
+ //
148
+ // @method
149
+ //
150
+ // @param {String | HTMLElement} id - The `iframe` to register with. If
151
+ // a `String` is passed, it should match some `iframe`'s `data-iframe-id`
152
+ // attribute. Otherwise, you should pass the actual `iframe` node to
153
+ // register with.
154
+ //
155
+ // @returns Boolean - Returns `true` if the registration was successful,
156
+ // and false otherwise.
157
+
158
+ with_iframe(id) {
159
+ var iframe = Iframe.for(id),
160
+ registered = (!!iframe && iframe.register(communicator));
161
+
162
+ if(registered) { private_iframes.push(iframe); }
163
+ return registered;
164
+ },
165
+
166
+ //*
167
+ // Registers this `Communicator` with the `iframe` whose `data-iframe-id`
168
+ // matches that of the passed node.
169
+ //
170
+ // @method
171
+ //
172
+ // @param {HTMLElement} node - The node to match to an `iframe`.
173
+ //
174
+ // @returns Boolean - Returns `true` if the registration was successful,
175
+ // and false otherwise.
176
+
177
+ from_node(node) {
178
+ return this.with_iframe(node.getAttribute(attrs.id));
179
+ },
180
+
181
+ //*
182
+ // Registers this `Communicator` with all `iframe`s on the page.
183
+ //
184
+ // @method
185
+ //
186
+ // @returns Boolean - Returns `true` if there are `iframe`s on the page,
187
+ // and false otherwise.
188
+
189
+ with_all() {
190
+ var iframe;
191
+ for(iframe of iframes) { this.with_iframe(iframe); }
192
+ return iframe.length > 0;
193
+ }
194
+ }
195
+ };
196
+
197
+ return communicator;
198
+ };
199
+
200
+ //*
201
+ // Caches all of the internal details for an [`Iframe`](@link).
202
+ //
203
+ // @private
204
+ // @param {HTMLElement} node - The node backing the `Iframe`. This can be either
205
+ // an actual `iframe` (in the case of the parent) or the wrapping element of
206
+ // a demo that is actually in the `iframe`.
207
+ //
208
+ // @returns Object - The private, internal details of the `Iframe`.
209
+
210
+ create_self = (node) => {
211
+ var self = {
212
+ node,
213
+ id: node.getAttribute(attrs.id),
214
+ ready: false,
215
+ listeners: [],
216
+ message_queue: [],
217
+ message(data) { this.message_target.postMessage(JSON.stringify(data), "*"); },
218
+ queue(data) { this.message_queue.push(data); }
219
+ };
220
+
221
+ if(node.tagName.toLowerCase() === "iframe") {
222
+ Object.assign(self, { position: positions.parent, message_target: node.contentWindow });
223
+ } else {
224
+ Object.assign(self, { position: positions.child, message_target: window.parent });
225
+ }
226
+
227
+ return self;
228
+ };
229
+
230
+ //*
231
+ // Sets up all required event listeners for an [`Iframe`](@link), including the
232
+ // listener for `postMessage` and listeners on the relevant `iframe` for the
233
+ // `load` event (as a hook to run the first set of events).
234
+ //
235
+ // @private
236
+ // @param {Object} self - The internal details of an [`Iframe`](@link).
237
+
238
+ add_event_listeners = (self) => {
239
+ self.node.addEventListener("load", () => {
240
+ var queued_message;
241
+
242
+ self.ready = true;
243
+ for(queued_message of self.message_queue) { self.message(queued_message); }
244
+ self.message_queue = [];
245
+ });
246
+
247
+ window.addEventListener("message", (event) => {
248
+ var data, listener;
249
+
250
+ if(typeof event.data !== "string") { return; }
251
+
252
+ data = JSON.parse(event.data);
253
+ if(data.id !== self.id) { return; }
254
+
255
+ for(listener of self.listeners) { listener.receive(data); }
256
+ });
257
+ };
258
+
259
+ //*
260
+ // Moves the markup for for an iframe into the actual iframe. This looks for the
261
+ // `iframe__content` sibling node of the iframe, takes its inner HTML, decodes
262
+ // the escaped entities, and writes the entirety of the resulting string (which
263
+ // includes the HTML element and all children) to the iframe's window.
264
+ //
265
+ // @private
266
+ // @param {Object} self - The internal details of an [`Iframe`](@link).
267
+
268
+ move_markup_to_iframe = (self) => {
269
+ var iframe = self.node,
270
+ iframe_content = iframe.parentNode.querySelector(`.${classes.content}`),
271
+ iframe_window = iframe.contentWindow;
272
+
273
+ if(!(iframe_content && iframe_window)) { return; }
274
+
275
+ iframe_window.document.open();
276
+ iframe_window.document.write(decode_html_entities(iframe_content.innerHTML));
277
+ iframe_window.document.close();
278
+ };
279
+
280
+ //*
281
+ // The object that manages communication between the parent page and a
282
+ // document embedded in an `iframe`. Essentially, components can register on
283
+ // either side of the coin with the `Iframe` for that side. They can then
284
+ // send messages, which get triggered on the other side, and can listen for
285
+ // events sent from the other side. The registering and sending/ listening is
286
+ // all handled by [`Communicator`](@link); the `Iframe` simply manages the
287
+ // the passing of events between the two sides and the calling of event
288
+ // handlers in listeners that have been registered.
289
+ //
290
+ // @factory
291
+ //
292
+ // @param {HTMLElement} node - The actual `iframe` node (if in the parent) or
293
+ // the wrapper node (if in the child) that will act as the root for the
294
+ // `Iframe`.
295
+
296
+ Iframe = (node) => {
297
+ var self = create_self(node);
298
+ move_markup_to_iframe(self);
299
+ add_event_listeners(self);
300
+
301
+ return {
302
+
303
+ //*
304
+ // Trigger a particular event, such that it gets sent to the other side of
305
+ // the `iframe` bridge. If the `iframe` has not yet loaded, the message
306
+ // will be queued for when the `iframe` communication is available.
307
+ //
308
+ // @method
309
+ //
310
+ // @param {String} type - The type of event to trigger. Do not pass a string
311
+ // literal; instead, pass an event defined on [`Events.types`](@link).
312
+ //
313
+ // @param {*} [data = {}] - The data to pass to the corresponding `Iframe`.
314
+ // This can be anything that can be stringified with `JSON.stringify`.
315
+
316
+ trigger(type, data = {}) {
317
+ data = Object.assign({}, { type, id: self.id }, data);
318
+ data = JSON.parse(JSON.stringify(data));
319
+ return self.ready ? self.message(data) : self.queue(data);
320
+ },
321
+
322
+ //*
323
+ // Registers a listener object with this `Iframe` that will be notified when
324
+ // events are recived from the other side of the `iframe` bridge.
325
+ //
326
+ // @method
327
+ //
328
+ // @param {Communicator} listener - The object that will receive events.
329
+ //
330
+ // @returns Boolean - Returns `true` if the register call was successful
331
+ // (that is, the listener has the required signature and is not already
332
+ // registered), `false` otherwise.
333
+
334
+ register(listener) {
335
+ if(self.listeners.includes(listener)) { return false; }
336
+ self.listeners.push(listener);
337
+ return true;
338
+ }
339
+ };
340
+ };
341
+
342
+ //*
343
+ // Returns the [`Iframe`](@link) object associated with the passed node, or
344
+ // the iframe whose ID matches the passed identifier.
345
+ //
346
+ // @method
347
+ // @static
348
+ //
349
+ // @Param {String | HTMLElement} iframe - If a `String` is passed, the
350
+ // [`Iframe`](@link) for an `iframe` whose `data-iframe-id` matches the string.
351
+ // If an `HTMLElement` is passed, the [`Iframe`](@link) object that was created
352
+ // for that node.
353
+ //
354
+ // @returns {Iframe | Boolean} - If no matching `Iframe` is found, `false` will
355
+ // be returned.
356
+
357
+ Iframe.for = (iframe) => {
358
+ if(typeof iframe === "string") {
359
+ iframe = document.querySelector(`.${classes.base}[${attrs.id}='${iframe}']`);
360
+ }
361
+
362
+ if(!iframe) { return false; }
363
+ return Cache(iframe).get(classes.root);
364
+ };
365
+
366
+ //*
367
+ // Initializes the `Iframe` component.
368
+ //
369
+ // @method
370
+ // @static
371
+ //
372
+ // @param {HTMLElement} [context = document] - The context in which to search
373
+ // for DOM nodes that should be used as the root of an `Iframe` component.
374
+
375
+ Iframe.init = (context = document) => {
376
+ var iframe_nodes = Array.from(context.querySelectorAll(`.${classes.root}`));
377
+ for(let iframe of iframe_nodes) { Iframe(iframe); }
378
+ };
379
+
380
+ export { Communicator, classes, attrs };
381
+ export default Iframe;
@@ -0,0 +1,3 @@
1
+ {
2
+ "main": "iframe.js"
3
+ }
@@ -0,0 +1,37 @@
1
+ import Avatar from "./avatar";
2
+ import CodeBlock from "./code_block";
3
+ import Demo from "./demo";
4
+ import Exploded from "./exploded";
5
+ import Field from "./field";
6
+ import Iframe from "./iframe";
7
+ import InternalLink from "./internal_link";
8
+ import Resizable from "./resizable";
9
+ import ScrollContainer from "./scroll_container";
10
+ import Select from "./select";
11
+ import Table from "./table";
12
+ import Tablist from "./tablist";
13
+ import Toggles from "./toggle";
14
+ import Xray from "./xray";
15
+
16
+ import App from "~foundation/app";
17
+
18
+ /* eslint-disable indent */
19
+
20
+ [
21
+ Avatar,
22
+ CodeBlock,
23
+ Exploded,
24
+ Field,
25
+ Iframe,
26
+ InternalLink,
27
+ Resizable,
28
+ ScrollContainer,
29
+ Demo,
30
+ Select,
31
+ Table,
32
+ Tablist,
33
+ Toggles,
34
+ Xray
35
+ ].forEach(App.register);
36
+
37
+ /* eslint-enable indent */
@@ -0,0 +1,14 @@
1
+ $inline-group--spacing: half(default(spacing));
2
+
3
+ .inline-group {
4
+ display: inline-flex;
5
+ flex-wrap: wrap;
6
+ align-items: center;
7
+ margin-right: negative($inline-group--spacing);
8
+ margin-bottom: negative($inline-group--spacing);
9
+ }
10
+
11
+ .inline-group__item {
12
+ margin-right: $inline-group--spacing;
13
+ margin-bottom: $inline-group--spacing;
14
+ }
@@ -0,0 +1,49 @@
1
+ import Sidebar from "~structures/sidebar";
2
+ import Tablist from "~components/tablist";
3
+ import ScrollContainer from "~components/scroll_container";
4
+
5
+ var InternalLink, move_to_node, on_hash_change, process_initial_hash, current_hash;
6
+
7
+ current_hash = () => {
8
+ return window.location.hash.replace("#", "");
9
+ };
10
+
11
+ move_to_node = (node) => {
12
+ Tablist.activate_panel_containing(node);
13
+ ScrollContainer.for(node).scroll_to(node);
14
+ };
15
+
16
+ on_hash_change = () => {
17
+ var hash = current_hash(),
18
+ node;
19
+
20
+ Sidebar.hide();
21
+ node = document.getElementById(hash);
22
+ if(!node) { return; }
23
+
24
+ node.id = null;
25
+ window.location.hash = hash;
26
+ node.id = hash;
27
+ move_to_node(node);
28
+ };
29
+
30
+ process_initial_hash = () => {
31
+ var hash = current_hash(),
32
+ node;
33
+
34
+ if(!hash.length) { return; }
35
+
36
+ node = document.getElementById(hash);
37
+ if(!node) { return; }
38
+
39
+ move_to_node(node);
40
+ };
41
+
42
+ InternalLink = {
43
+ init() {
44
+ $(window).on("hashchange", on_hash_change);
45
+ setTimeout(process_initial_hash, 0);
46
+ }
47
+ };
48
+
49
+ export default InternalLink;
@@ -0,0 +1,3 @@
1
+ {
2
+ "main": "internal_link.js"
3
+ }