docks_theme_api 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.babelrc +4 -0
- data/.editorconfig +8 -0
- data/.eslintrc +115 -0
- data/.gitignore +24 -0
- data/.rubocop.yml +20 -0
- data/.travis.yml +16 -0
- data/Gemfile +4 -0
- data/README.md +5 -0
- data/Rakefile +3 -0
- data/assets/images/icons.svg +63 -0
- data/assets/scripts/coffeescript/pattern_library_helpers.coffee +8 -0
- data/assets/scripts/javascript/pattern_library_helpers.js +11 -0
- data/assets/scripts/pattern_library.js +10380 -0
- data/assets/scripts/pattern_library_demo.js +0 -0
- data/assets/styles/less/pattern-library-helpers.less +103 -0
- data/assets/styles/pattern-library-demo.css +1882 -0
- data/assets/styles/pattern-library.css +1882 -0
- data/assets/styles/sass/pattern-library-helpers.sass +90 -0
- data/assets/styles/scss/pattern-library-helpers.scss +99 -0
- data/assets/styles/stylus/pattern-library-helpers.styl +90 -0
- data/assets/templates/erb/demo.erb +26 -0
- data/assets/templates/erb/layouts/demo.erb +17 -0
- data/assets/templates/erb/layouts/pattern.erb +76 -0
- data/assets/templates/erb/partials/sidebar.erb +124 -0
- data/assets/templates/erb/partials/symbols/class.erb +1 -0
- data/assets/templates/erb/partials/symbols/demo.erb +40 -0
- data/assets/templates/erb/partials/symbols/factory.erb +70 -0
- data/assets/templates/erb/partials/symbols/function.erb +103 -0
- data/assets/templates/erb/partials/symbols/mixin.erb +62 -0
- data/assets/templates/erb/partials/symbols/variable.erb +59 -0
- data/assets/templates/erb/pattern.erb +102 -0
- data/assets/templates/haml/demo.haml +14 -0
- data/assets/templates/haml/layouts/demo.haml +6 -0
- data/assets/templates/haml/layouts/pattern.haml +38 -0
- data/assets/templates/haml/partials/sidebar.haml +68 -0
- data/assets/templates/haml/partials/symbols/class.haml +1 -0
- data/assets/templates/haml/partials/symbols/demo.haml +23 -0
- data/assets/templates/haml/partials/symbols/factory.haml +38 -0
- data/assets/templates/haml/partials/symbols/function.haml +54 -0
- data/assets/templates/haml/partials/symbols/mixin.haml +31 -0
- data/assets/templates/haml/partials/symbols/variable.haml +22 -0
- data/assets/templates/haml/pattern.haml +54 -0
- data/assets/templates/slim/demo.slim +24 -0
- data/assets/templates/slim/layouts/demo.slim +5 -0
- data/assets/templates/slim/layouts/pattern.slim +48 -0
- data/assets/templates/slim/partials/sidebar.slim +112 -0
- data/assets/templates/slim/partials/symbols/class.slim +1 -0
- data/assets/templates/slim/partials/symbols/demo.slim +30 -0
- data/assets/templates/slim/partials/symbols/factory.slim +57 -0
- data/assets/templates/slim/partials/symbols/function.slim +81 -0
- data/assets/templates/slim/partials/symbols/mixin.slim +45 -0
- data/assets/templates/slim/partials/symbols/variable.slim +35 -0
- data/assets/templates/slim/pattern.slim +63 -0
- data/docks_config.rb +32 -0
- data/docks_theme_api.gemspec +37 -0
- data/gulpfile.js +88 -0
- data/karma.conf.js +6 -0
- data/lib/docks_theme_api/components/base_component.rb +99 -0
- data/lib/docks_theme_api/components/code_block_component.rb +10 -0
- data/lib/docks_theme_api/components/popover_component.rb +15 -0
- data/lib/docks_theme_api/components/table_component.rb +34 -0
- data/lib/docks_theme_api/components/tablist_component.rb +11 -0
- data/lib/docks_theme_api/components.rb +21 -0
- data/lib/docks_theme_api/helpers/ui_helper.rb +69 -0
- data/lib/docks_theme_api/theme.rb +21 -0
- data/lib/docks_theme_api.rb +1 -0
- data/package.json +60 -0
- data/source/behaviors/filterable/filterable.coffee +353 -0
- data/source/behaviors/filterable/filterable.js +0 -0
- data/source/behaviors/filterable/filterable.scss +34 -0
- data/source/behaviors/filterable/package.json +3 -0
- data/source/behaviors/index.js +0 -0
- data/source/components/avatar/avatar.erb +20 -0
- data/source/components/avatar/avatar.js +142 -0
- data/source/components/avatar/avatar.scss +200 -0
- data/source/components/avatar/avatar_container.erb +13 -0
- data/source/components/avatar/package.json +3 -0
- data/source/components/avatar/spec/avatar_spec.js +81 -0
- data/source/components/badge/badge.scss +158 -0
- data/source/components/button/button.scss +213 -0
- data/source/components/card/card.scss +32 -0
- data/source/components/code_block/code-block.scss +353 -0
- data/source/components/code_block/code_block.erb +95 -0
- data/source/components/code_block/code_block.js +444 -0
- data/source/components/code_block/package.json +3 -0
- data/source/components/code_block/spec/code_block_spec.js +10 -0
- data/source/components/demo/demo.js +244 -0
- data/source/components/demo/demo.scss +90 -0
- data/source/components/demo/package.json +3 -0
- data/source/components/exploded/exploded.erb +25 -0
- data/source/components/exploded/exploded.js +694 -0
- data/source/components/exploded/exploded.scss +166 -0
- data/source/components/exploded/package.json +3 -0
- data/source/components/field/field.js +24 -0
- data/source/components/field/field.scss +101 -0
- data/source/components/field/package.json +3 -0
- data/source/components/header/header.scss +33 -0
- data/source/components/iframe/iframe.erb +12 -0
- data/source/components/iframe/iframe.js +381 -0
- data/source/components/iframe/package.json +3 -0
- data/source/components/index.js +37 -0
- data/source/components/inline_group/inline-group.scss +14 -0
- data/source/components/internal_link/internal_link.js +49 -0
- data/source/components/internal_link/package.json +3 -0
- data/source/components/list/list.scss +230 -0
- data/source/components/modal/modal.coffee +84 -0
- data/source/components/modal/modal.erb +19 -0
- data/source/components/modal/modal.js +0 -0
- data/source/components/modal/modal.scss +57 -0
- data/source/components/modal/package.json +3 -0
- data/source/components/notice/notice.scss +48 -0
- data/source/components/popover/package.json +3 -0
- data/source/components/popover/popover.coffee +562 -0
- data/source/components/popover/popover.erb +21 -0
- data/source/components/popover/popover.js +0 -0
- data/source/components/popover/popover.scss +139 -0
- data/source/components/range/range.scss +78 -0
- data/source/components/resizable/package.json +3 -0
- data/source/components/resizable/resizable.erb +30 -0
- data/source/components/resizable/resizable.js +250 -0
- data/source/components/resizable/resizable.scss +245 -0
- data/source/components/resizable/size_buttons.js +249 -0
- data/source/components/scroll_container/package.json +3 -0
- data/source/components/scroll_container/scroll-container.scss +4 -0
- data/source/components/scroll_container/scroll_container.js +24 -0
- data/source/components/section/section.scss +99 -0
- data/source/components/select/package.json +3 -0
- data/source/components/select/select.erb +21 -0
- data/source/components/select/select.js +35 -0
- data/source/components/select/select.scss +163 -0
- data/source/components/table/package.json +3 -0
- data/source/components/table/table.erb +16 -0
- data/source/components/table/table.js +351 -0
- data/source/components/table/table.scss +236 -0
- data/source/components/tablist/package.json +3 -0
- data/source/components/tablist/tablist.erb +13 -0
- data/source/components/tablist/tablist.js +246 -0
- data/source/components/tablist/tablist.scss +191 -0
- data/source/components/tablist/tablist_panel.erb +14 -0
- data/source/components/tablist/tablist_tab.erb +20 -0
- data/source/components/toggle/package.json +3 -0
- data/source/components/toggle/toggle.erb +11 -0
- data/source/components/toggle/toggle.js +211 -0
- data/source/components/toggle/toggle_container.erb +30 -0
- data/source/components/vertical_spacer/vertical-spacer.scss +3 -0
- data/source/components/vertical_stack/vertical-stack.scss +19 -0
- data/source/components/xray/package.json +3 -0
- data/source/components/xray/xray.erb +50 -0
- data/source/components/xray/xray.js +123 -0
- data/source/components/xray/xray.scss +79 -0
- data/source/foundation/app/app.js +15 -0
- data/source/foundation/app/package.json +3 -0
- data/source/pattern-library-demo.scss +13 -0
- data/source/pattern-library.scss +13 -0
- data/source/pattern_library.js +8 -0
- data/source/pattern_library_demo.js +8 -0
- data/source/structures/index.js +11 -0
- data/source/structures/sidebar/package.json +3 -0
- data/source/structures/sidebar/sidebar.js +69 -0
- data/source/structures/sidebar/sidebar.scss +79 -0
- data/source/utilities/builder/builder.js +138 -0
- data/source/utilities/builder/package.json +3 -0
- data/source/utilities/client/client.js +7 -0
- data/source/utilities/client/package.json +3 -0
- data/source/utilities/colors/colors.scss +112 -0
- data/source/utilities/defaults/defaults.scss +38 -0
- data/source/utilities/dom_cache/dom_cache.js +24 -0
- data/source/utilities/dom_cache/package.json +3 -0
- data/source/utilities/events/events.js +25 -0
- data/source/utilities/events/package.json +3 -0
- data/source/utilities/font_sizes/font-sizes.scss +85 -0
- data/source/utilities/foundation/a11y.scss +10 -0
- data/source/utilities/foundation/base.scss +29 -0
- data/source/utilities/foundation/icon.scss +114 -0
- data/source/utilities/foundation/layout.scss +67 -0
- data/source/utilities/foundation/page.scss +39 -0
- data/source/utilities/foundation/type.scss +208 -0
- data/source/utilities/functions/functions.scss +127 -0
- data/source/utilities/keycodes/keycodes.js +23 -0
- data/source/utilities/keycodes/package.json +3 -0
- data/source/utilities/markup/markup.js +90 -0
- data/source/utilities/markup/package.json +3 -0
- data/source/utilities/media/media.scss +172 -0
- data/source/utilities/mixins/mixins.scss +89 -0
- data/source/utilities/naming_convention/naming_convention.js +3 -0
- data/source/utilities/naming_convention/package.json +3 -0
- data/source/utilities/numbers/numbers.js +14 -0
- data/source/utilities/numbers/package.json +3 -0
- data/source/utilities/painting/package.json +3 -0
- data/source/utilities/painting/painting.js +7 -0
- data/source/utilities/pattern/package.json +3 -0
- data/source/utilities/pattern/pattern.js +50 -0
- data/source/utilities/query_string/package.json +3 -0
- data/source/utilities/query_string/query_string.js +24 -0
- data/source/utilities/template/package.json +3 -0
- data/source/utilities/template/template.js +10 -0
- data/source/utilities/text_range/package.json +3 -0
- data/source/utilities/text_range/text_range.js +30 -0
- data/source/utilities/ui_events/package.json +3 -0
- data/source/utilities/ui_events/ui_events.js +85 -0
- data/source/utilities/variables/variables.scss +18 -0
- data/source/utilities/z_indexes/z-indexes.scss +88 -0
- data/source/vendor/array_includes.js +28 -0
- data/source/vendor/highlight.js +1142 -0
- data/source/vendor/index.js +1 -0
- data/source/vendor/matrix.js +399 -0
- data/source/vendor/query_string.js +66 -0
- data/spec/assets/.eslintrc +9 -0
- data/spec/assets/spec_fixture.js +33 -0
- data/spec/assets/spec_helper.js +19 -0
- data/spec/lib/components/base_component_spec.rb +156 -0
- data/spec/lib/components_spec.rb +30 -0
- data/spec/lib/helpers/ui_helper_spec.rb +62 -0
- data/spec/lib/theme_spec.rb +25 -0
- data/spec/spec_helper.rb +15 -0
- data/tasks/gulp/.eslintrc +6 -0
- data/tasks/gulp/browser_sync.js +8 -0
- data/tasks/gulp/code_quality/scripts.js +10 -0
- data/tasks/gulp/config/index.js +116 -0
- data/tasks/gulp/minify/scripts.js +13 -0
- data/tasks/gulp/minify/styles.js +13 -0
- data/tasks/gulp/pattern_library/index.js +5 -0
- data/tasks/gulp/pattern_library/scripts.js +10 -0
- data/tasks/gulp/pattern_library/styles.js +10 -0
- data/tasks/gulp/scripts.js +8 -0
- data/tasks/gulp/spec/scripts.js +11 -0
- data/tasks/gulp/styles.js +17 -0
- data/tasks/gulp/utilities/babel/relative_require.js +22 -0
- data/tasks/gulp/utilities/babel/spec_helper.js +20 -0
- data/tasks/gulp/utilities/browserify_bundler.js +22 -0
- data/tasks/gulp/utilities/handle_errors.js +13 -0
- data/tasks/gulp/watch.js +9 -0
- data/tasks/rake/rspec.rake +7 -0
- data/tasks/rake/rubocop.rake +8 -0
- data/tasks/rake/templates.rake +50 -0
- 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,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;
|