lookbook 1.5.1 → 2.0.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -21
  3. data/app/assets/lookbook/css/lookbook.css +9 -0
  4. data/app/assets/lookbook/css/themes/blue.css +7 -0
  5. data/app/assets/lookbook/css/themes/green.css +7 -0
  6. data/app/assets/lookbook/css/themes/indigo.css +7 -0
  7. data/app/assets/lookbook/css/themes/rose.css +7 -0
  8. data/app/assets/lookbook/css/themes/zinc.css +7 -0
  9. data/app/assets/lookbook/css/tooltip.css +9 -6
  10. data/app/assets/lookbook/img/lucide-sprite.svg +4960 -0
  11. data/app/assets/lookbook/js/app.js +22 -4
  12. data/app/assets/lookbook/js/helpers/dom.js +4 -7
  13. data/app/assets/lookbook/js/helpers/string.js +4 -11
  14. data/app/assets/lookbook/js/{embed.js → iframe.js} +0 -0
  15. data/app/assets/lookbook/js/index.js +61 -0
  16. data/app/assets/lookbook/js/lib/lookbook.js +113 -0
  17. data/app/assets/lookbook/js/lib/tippy.js +1 -0
  18. data/app/assets/lookbook/js/lookbook-core.js +1 -0
  19. data/app/assets/lookbook/js/lookbook.js +2 -61
  20. data/app/components/lookbook/base_component.rb +3 -1
  21. data/app/components/lookbook/button/component.html.erb +13 -24
  22. data/app/components/lookbook/button/component.js +13 -3
  23. data/app/components/lookbook/button/component.rb +16 -25
  24. data/app/components/lookbook/code/component.rb +0 -2
  25. data/app/components/lookbook/copy_button/component.html.erb +4 -4
  26. data/app/components/lookbook/copy_button/component.rb +6 -3
  27. data/app/components/lookbook/debug_menu/component.html.erb +1 -0
  28. data/app/components/lookbook/debug_menu/component.rb +12 -1
  29. data/app/components/lookbook/display_options/editor/component.html.erb +1 -1
  30. data/app/components/lookbook/display_options/field/component.css +0 -26
  31. data/app/components/lookbook/display_options/field/component.html.erb +1 -1
  32. data/app/components/lookbook/embed/component.html.erb +6 -51
  33. data/app/components/lookbook/embed/component.rb +17 -16
  34. data/app/components/lookbook/embed/inspector/component.html.erb +102 -0
  35. data/app/components/lookbook/embed/inspector/component.js +46 -0
  36. data/app/components/lookbook/embed/inspector/component.rb +64 -0
  37. data/app/components/lookbook/embed_code_dropdown/component.css +12 -0
  38. data/app/components/lookbook/embed_code_dropdown/component.html.erb +19 -0
  39. data/app/components/lookbook/embed_code_dropdown/component.js +26 -0
  40. data/app/components/lookbook/embed_code_dropdown/component.rb +41 -0
  41. data/app/components/lookbook/header/component.html.erb +7 -6
  42. data/app/components/lookbook/header/component.rb +5 -1
  43. data/app/components/lookbook/icon/component.html.erb +1 -1
  44. data/app/components/lookbook/icon_button/component.html.erb +20 -0
  45. data/app/components/lookbook/icon_button/component.rb +46 -0
  46. data/app/components/lookbook/nav/component.html.erb +0 -1
  47. data/app/components/lookbook/nav/entity/component.rb +2 -2
  48. data/app/components/lookbook/nav/item/component.rb +1 -1
  49. data/app/components/lookbook/params/editor/component.rb +1 -0
  50. data/app/components/lookbook/prose/component.rb +1 -3
  51. data/app/components/lookbook/tabs/component.html.erb +2 -2
  52. data/app/components/lookbook/tabs/component.js +1 -1
  53. data/app/components/lookbook/tag_component.rb +2 -1
  54. data/app/components/lookbook/text_button/component.html.erb +26 -0
  55. data/app/components/lookbook/text_button/component.rb +42 -0
  56. data/app/components/lookbook/toolbar/component.html.erb +1 -1
  57. data/app/components/lookbook/viewport/component.rb +0 -4
  58. data/app/controllers/concerns/lookbook/targetable_concern.rb +24 -19
  59. data/app/controllers/concerns/lookbook/with_panels_concern.rb +30 -0
  60. data/app/controllers/concerns/lookbook/with_preview_controller_concern.rb +4 -3
  61. data/app/controllers/lookbook/application_controller.rb +9 -12
  62. data/app/controllers/lookbook/embeds_controller.rb +148 -0
  63. data/app/controllers/lookbook/inspector_controller.rb +3 -22
  64. data/app/controllers/lookbook/page_controller.rb +7 -6
  65. data/app/controllers/lookbook/pages_controller.rb +3 -4
  66. data/app/controllers/lookbook/preview_controller.rb +17 -0
  67. data/app/controllers/lookbook/previews_controller.rb +8 -10
  68. data/app/helpers/lookbook/application_helper.rb +3 -19
  69. data/app/views/layouts/lookbook/application.html.erb +85 -60
  70. data/app/views/layouts/lookbook/embed.html.erb +16 -0
  71. data/app/views/layouts/lookbook/shell.html.erb +1 -1
  72. data/app/views/layouts/lookbook/skeleton.html.erb +13 -8
  73. data/app/views/lookbook/embeds/show.html.erb +12 -0
  74. data/app/views/lookbook/inspector/panels/_notes.html.erb +1 -1
  75. data/app/views/lookbook/inspector/panels/_output.html.erb +3 -3
  76. data/app/views/lookbook/inspector/panels/_source.html.erb +6 -6
  77. data/app/views/lookbook/inspector/show.html.erb +130 -123
  78. data/app/views/lookbook/pages/show.html.erb +81 -34
  79. data/app/views/lookbook/partials/_iframe_content_scripts.html.erb +1 -0
  80. data/app/views/lookbook/partials/_user_styles.html.erb +5 -0
  81. data/app/views/lookbook/{preview.html.erb → previews/group.html.erb} +7 -7
  82. data/app/views/lookbook/previews/preview.html.erb +5 -0
  83. data/app/views/lookbook/previews/show.html.erb +1 -0
  84. data/config/app.yml +31 -16
  85. data/config/panels.yml +23 -25
  86. data/config/routes.rb +3 -1
  87. data/config/tags.yml +6 -2
  88. data/lib/lookbook/cable/cable.rb +53 -0
  89. data/{app/channels/lookbook → lib/lookbook/cable}/connection.rb +0 -0
  90. data/{app/channels/lookbook → lib/lookbook/cable}/reload_channel.rb +0 -0
  91. data/lib/lookbook/engine.rb +109 -87
  92. data/lib/lookbook/entities/collections/entity_collection.rb +11 -6
  93. data/lib/lookbook/entities/collections/page_collection.rb +33 -8
  94. data/lib/lookbook/entities/collections/preview_collection.rb +42 -17
  95. data/lib/lookbook/entities/collections/render_target_collection.rb +4 -0
  96. data/lib/lookbook/entities/collections/scenario_collection.rb +4 -0
  97. data/lib/lookbook/entities/concerns/{annotatable.rb → annotatable_entity.rb} +7 -6
  98. data/lib/lookbook/entities/concerns/{inspectable.rb → inspectable_entity.rb} +2 -1
  99. data/lib/lookbook/entities/concerns/{locatable.rb → locatable_entity.rb} +8 -14
  100. data/lib/lookbook/entities/concerns/navigable_entity.rb +44 -0
  101. data/lib/lookbook/entities/entity.rb +7 -2
  102. data/lib/lookbook/entities/{page.rb → page_entity.rb} +10 -6
  103. data/lib/lookbook/entities/{page_section.rb → page_section_entity.rb} +1 -1
  104. data/lib/lookbook/entities/preview_entity.rb +99 -0
  105. data/lib/lookbook/entities/renderable_entity.rb +50 -0
  106. data/lib/lookbook/entities/rendered_scenario_entity.rb +53 -0
  107. data/lib/lookbook/entities/scenario_entity.rb +112 -0
  108. data/lib/lookbook/entities/scenario_group_entity.rb +53 -0
  109. data/lib/lookbook/error.rb +5 -5
  110. data/lib/lookbook/file_watcher.rb +19 -35
  111. data/lib/lookbook/helpers/class_names_helper.rb +28 -0
  112. data/lib/lookbook/helpers/page_helper.rb +18 -0
  113. data/{app/helpers/lookbook → lib/lookbook/helpers}/preview_helper.rb +3 -0
  114. data/lib/lookbook/helpers/ui_elements_helper.rb +115 -0
  115. data/lib/lookbook/preview.rb +79 -0
  116. data/lib/lookbook/preview_controller_actions.rb +50 -0
  117. data/lib/lookbook/preview_parser.rb +4 -2
  118. data/lib/lookbook/reloaders.rb +71 -0
  119. data/lib/lookbook/runtime_context.rb +49 -0
  120. data/lib/lookbook/services/data/resolvers/data_resolver.rb +4 -6
  121. data/lib/lookbook/services/entities/entity_tree_builder.rb +6 -6
  122. data/lib/lookbook/services/list_resolver.rb +35 -0
  123. data/lib/lookbook/services/markdown_renderer.rb +12 -2
  124. data/lib/lookbook/services/priority_prefix_parser.rb +16 -0
  125. data/lib/lookbook/services/urls/search_param_encoder.rb +16 -0
  126. data/lib/lookbook/services/urls/search_param_parser.rb +7 -6
  127. data/lib/lookbook/stores/config_store.rb +16 -16
  128. data/lib/lookbook/stores/input_store.rb +1 -3
  129. data/lib/lookbook/stores/panel_store.rb +28 -50
  130. data/lib/lookbook/support/deprecation.rb +5 -0
  131. data/lib/lookbook/support/errors/preview_template_error.rb +7 -0
  132. data/lib/lookbook/support/evented_file_update_checker.rb +69 -0
  133. data/lib/lookbook/support/null_websocket.rb +9 -0
  134. data/lib/lookbook/support/store.rb +9 -0
  135. data/lib/lookbook/support/tree_node.rb +7 -7
  136. data/lib/lookbook/support/utils/path_utils.rb +7 -1
  137. data/lib/lookbook/support/utils/utils.rb +8 -0
  138. data/lib/lookbook/tags/{position_tag.rb → priority_tag.rb} +4 -4
  139. data/lib/lookbook/tags/renders_tag.rb +4 -0
  140. data/lib/lookbook/tags/tag_provider.rb +3 -0
  141. data/lib/lookbook/tags/type_tag.rb +7 -0
  142. data/lib/lookbook/tags/yard_tag.rb +1 -2
  143. data/lib/lookbook/version.rb +1 -1
  144. data/lib/lookbook/websocket.rb +6 -53
  145. data/lib/lookbook.rb +179 -53
  146. data/public/lookbook-assets/css/lookbook.css +141 -83
  147. data/public/lookbook-assets/css/lookbook.css.map +1 -1
  148. data/public/lookbook-assets/css/themes/blue.css +7 -0
  149. data/public/lookbook-assets/css/themes/blue.css.map +1 -1
  150. data/public/lookbook-assets/css/themes/green.css +7 -0
  151. data/public/lookbook-assets/css/themes/green.css.map +1 -1
  152. data/public/lookbook-assets/css/themes/indigo.css +7 -0
  153. data/public/lookbook-assets/css/themes/indigo.css.map +1 -1
  154. data/public/lookbook-assets/css/themes/rose.css +7 -0
  155. data/public/lookbook-assets/css/themes/rose.css.map +1 -1
  156. data/public/lookbook-assets/css/themes/zinc.css +7 -0
  157. data/public/lookbook-assets/css/themes/zinc.css.map +1 -1
  158. data/public/lookbook-assets/img/lucide-sprite.svg +4960 -0
  159. data/public/lookbook-assets/js/embed.js +1363 -841
  160. data/public/lookbook-assets/js/embed.js.map +1 -1
  161. data/public/lookbook-assets/js/iframe.js +906 -0
  162. data/public/lookbook-assets/js/iframe.js.map +1 -0
  163. data/public/lookbook-assets/js/index.js +13567 -0
  164. data/public/lookbook-assets/js/index.js.map +1 -0
  165. data/public/lookbook-assets/js/lookbook-core.js +85 -0
  166. data/public/lookbook-assets/js/lookbook-core.js.map +1 -0
  167. data/public/lookbook-assets/js/lookbook.js +165 -12754
  168. data/public/lookbook-assets/js/lookbook.js.map +1 -1
  169. data/public/lookbook-assets/lookbook-esm.js +1427 -0
  170. data/public/lookbook-assets/lookbook-esm.js.map +1 -0
  171. data/public/lookbook-assets/lookbook-global.js +1427 -0
  172. data/public/lookbook-assets/lookbook-global.js.map +1 -0
  173. data/public/lookbook-assets/lookbook.js +1427 -0
  174. data/public/lookbook-assets/lookbook.js.map +1 -0
  175. metadata +80 -72
  176. data/app/components/lookbook/embed/component.js +0 -39
  177. data/app/helpers/lookbook/component_helper.rb +0 -84
  178. data/app/helpers/lookbook/output_helper.rb +0 -19
  179. data/app/helpers/lookbook/page_helper.rb +0 -34
  180. data/app/views/layouts/lookbook/inspector.html.erb +0 -7
  181. data/app/views/layouts/lookbook/page.html.erb +0 -53
  182. data/app/views/layouts/lookbook/standalone.html.erb +0 -5
  183. data/lib/lookbook/entities/collections/component_collection.rb +0 -4
  184. data/lib/lookbook/entities/collections/preview_example_collection.rb +0 -4
  185. data/lib/lookbook/entities/component.rb +0 -31
  186. data/lib/lookbook/entities/concerns/navigable.rb +0 -43
  187. data/lib/lookbook/entities/preview.rb +0 -87
  188. data/lib/lookbook/entities/preview_example.rb +0 -100
  189. data/lib/lookbook/entities/preview_group.rb +0 -48
  190. data/lib/lookbook/preview_actions.rb +0 -43
  191. data/lib/lookbook/process.rb +0 -21
  192. data/lib/lookbook/rendered_example.rb +0 -37
  193. data/lib/lookbook/services/position_prefix_parser.rb +0 -16
  194. data/lib/lookbook/services/urls/search_param_builder.rb +0 -13
  195. data/lib/lookbook/tags/component_tag.rb +0 -13
@@ -0,0 +1,906 @@
1
+ (() => {
2
+ var $b2e1fd3e30ab1f5c$exports = {};
3
+ /*
4
+ * File: iframeResizer.contentWindow.js
5
+ * Desc: Include this file in any page being loaded into an iframe
6
+ * to force the iframe to resize to the content size.
7
+ * Requires: iframeResizer.js on host page.
8
+ * Doc: https://github.com/davidjbradshaw/iframe-resizer
9
+ * Author: David J. Bradshaw - dave@bradshaw.net
10
+ *
11
+ */ // eslint-disable-next-line sonarjs/cognitive-complexity, no-shadow-restricted-names
12
+ (function(undefined) {
13
+ if (typeof window === "undefined") return; // don't run for server side render
14
+ var autoResize = true, base = 10, bodyBackground = "", bodyMargin = 0, bodyMarginStr = "", bodyObserver = null, bodyPadding = "", calculateWidth = false, doubleEventList = {
15
+ resize: 1,
16
+ click: 1
17
+ }, eventCancelTimer = 128, firstRun = true, height = 1, heightCalcModeDefault = "bodyOffset", heightCalcMode = heightCalcModeDefault, initLock = true, initMsg = "", inPageLinks = {}, interval = 32, intervalTimer = null, logging = false, mouseEvents = false, msgID = "[iFrameSizer]", msgIdLen = msgID.length, myID = "", resetRequiredMethods = {
18
+ max: 1,
19
+ min: 1,
20
+ bodyScroll: 1,
21
+ documentElementScroll: 1
22
+ }, resizeFrom = "child", sendPermit = true, target = window.parent, targetOriginDefault = "*", tolerance = 0, triggerLocked = false, triggerLockedTimer = null, throttledTimer = 16, width = 1, widthCalcModeDefault = "scroll", widthCalcMode = widthCalcModeDefault, win = window, onMessage = function() {
23
+ warn("onMessage function not defined");
24
+ }, onReady = function() {}, onPageInfo = function() {}, customCalcMethods = {
25
+ height: function() {
26
+ warn("Custom height calculation function not defined");
27
+ return document.documentElement.offsetHeight;
28
+ },
29
+ width: function() {
30
+ warn("Custom width calculation function not defined");
31
+ return document.body.scrollWidth;
32
+ }
33
+ }, eventHandlersByName = {}, passiveSupported = false;
34
+ function noop() {}
35
+ try {
36
+ var options = Object.create({}, {
37
+ passive: {
38
+ get: function() {
39
+ passiveSupported = true;
40
+ }
41
+ }
42
+ });
43
+ window.addEventListener("test", noop, options);
44
+ window.removeEventListener("test", noop, options);
45
+ } catch (error) {
46
+ /* */ }
47
+ function addEventListener(el, evt, func, options) {
48
+ el.addEventListener(evt, func, passiveSupported ? options || {} : false);
49
+ }
50
+ function removeEventListener(el, evt, func) {
51
+ el.removeEventListener(evt, func, false);
52
+ }
53
+ function capitalizeFirstLetter(string) {
54
+ return string.charAt(0).toUpperCase() + string.slice(1);
55
+ }
56
+ // Based on underscore.js
57
+ function throttle(func) {
58
+ var context, args, result, timeout = null, previous = 0, later = function() {
59
+ previous = Date.now();
60
+ timeout = null;
61
+ result = func.apply(context, args);
62
+ if (!timeout) // eslint-disable-next-line no-multi-assign
63
+ context = args = null;
64
+ };
65
+ return function() {
66
+ var now = Date.now();
67
+ if (!previous) previous = now;
68
+ var remaining = throttledTimer - (now - previous);
69
+ context = this;
70
+ args = arguments;
71
+ if (remaining <= 0 || remaining > throttledTimer) {
72
+ if (timeout) {
73
+ clearTimeout(timeout);
74
+ timeout = null;
75
+ }
76
+ previous = now;
77
+ result = func.apply(context, args);
78
+ if (!timeout) // eslint-disable-next-line no-multi-assign
79
+ context = args = null;
80
+ } else if (!timeout) timeout = setTimeout(later, remaining);
81
+ return result;
82
+ };
83
+ }
84
+ function formatLogMsg(msg) {
85
+ return msgID + "[" + myID + "] " + msg;
86
+ }
87
+ function log(msg) {
88
+ if (logging && "object" === typeof window.console) // eslint-disable-next-line no-console
89
+ console.log(formatLogMsg(msg));
90
+ }
91
+ function warn(msg) {
92
+ if ("object" === typeof window.console) // eslint-disable-next-line no-console
93
+ console.warn(formatLogMsg(msg));
94
+ }
95
+ function init() {
96
+ readDataFromParent();
97
+ log("Initialising iFrame (" + window.location.href + ")");
98
+ readDataFromPage();
99
+ setMargin();
100
+ setBodyStyle("background", bodyBackground);
101
+ setBodyStyle("padding", bodyPadding);
102
+ injectClearFixIntoBodyElement();
103
+ checkHeightMode();
104
+ checkWidthMode();
105
+ stopInfiniteResizingOfIFrame();
106
+ setupPublicMethods();
107
+ setupMouseEvents();
108
+ startEventListeners();
109
+ inPageLinks = setupInPageLinks();
110
+ sendSize("init", "Init message from host page");
111
+ onReady();
112
+ }
113
+ function readDataFromParent() {
114
+ function strBool(str) {
115
+ return "true" === str;
116
+ }
117
+ var data = initMsg.slice(msgIdLen).split(":");
118
+ myID = data[0];
119
+ bodyMargin = undefined === data[1] ? bodyMargin : Number(data[1]) // For V1 compatibility
120
+ ;
121
+ calculateWidth = undefined === data[2] ? calculateWidth : strBool(data[2]);
122
+ logging = undefined === data[3] ? logging : strBool(data[3]);
123
+ interval = undefined === data[4] ? interval : Number(data[4]);
124
+ autoResize = undefined === data[6] ? autoResize : strBool(data[6]);
125
+ bodyMarginStr = data[7];
126
+ heightCalcMode = undefined === data[8] ? heightCalcMode : data[8];
127
+ bodyBackground = data[9];
128
+ bodyPadding = data[10];
129
+ tolerance = undefined === data[11] ? tolerance : Number(data[11]);
130
+ inPageLinks.enable = undefined === data[12] ? false : strBool(data[12]);
131
+ resizeFrom = undefined === data[13] ? resizeFrom : data[13];
132
+ widthCalcMode = undefined === data[14] ? widthCalcMode : data[14];
133
+ mouseEvents = undefined === data[15] ? mouseEvents : Boolean(data[15]);
134
+ }
135
+ function depricate(key) {
136
+ var splitName = key.split("Callback");
137
+ if (splitName.length === 2) {
138
+ var name = "on" + splitName[0].charAt(0).toUpperCase() + splitName[0].slice(1);
139
+ this[name] = this[key];
140
+ delete this[key];
141
+ warn("Deprecated: '" + key + "' has been renamed '" + name + "'. The old method will be removed in the next major version.");
142
+ }
143
+ }
144
+ function readDataFromPage() {
145
+ function readData() {
146
+ var data = window.iFrameResizer;
147
+ log("Reading data from page: " + JSON.stringify(data));
148
+ Object.keys(data).forEach(depricate, data);
149
+ onMessage = "onMessage" in data ? data.onMessage : onMessage;
150
+ onReady = "onReady" in data ? data.onReady : onReady;
151
+ targetOriginDefault = "targetOrigin" in data ? data.targetOrigin : targetOriginDefault;
152
+ heightCalcMode = "heightCalculationMethod" in data ? data.heightCalculationMethod : heightCalcMode;
153
+ widthCalcMode = "widthCalculationMethod" in data ? data.widthCalculationMethod : widthCalcMode;
154
+ }
155
+ function setupCustomCalcMethods(calcMode, calcFunc) {
156
+ if ("function" === typeof calcMode) {
157
+ log("Setup custom " + calcFunc + "CalcMethod");
158
+ customCalcMethods[calcFunc] = calcMode;
159
+ calcMode = "custom";
160
+ }
161
+ return calcMode;
162
+ }
163
+ if ("iFrameResizer" in window && Object === window.iFrameResizer.constructor) {
164
+ readData();
165
+ heightCalcMode = setupCustomCalcMethods(heightCalcMode, "height");
166
+ widthCalcMode = setupCustomCalcMethods(widthCalcMode, "width");
167
+ }
168
+ log("TargetOrigin for parent set to: " + targetOriginDefault);
169
+ }
170
+ function chkCSS(attr, value) {
171
+ if (-1 !== value.indexOf("-")) {
172
+ warn("Negative CSS value ignored for " + attr);
173
+ value = "";
174
+ }
175
+ return value;
176
+ }
177
+ function setBodyStyle(attr, value) {
178
+ if (undefined !== value && "" !== value && "null" !== value) {
179
+ document.body.style[attr] = value;
180
+ log("Body " + attr + ' set to "' + value + '"');
181
+ }
182
+ }
183
+ function setMargin() {
184
+ // If called via V1 script, convert bodyMargin from int to str
185
+ if (undefined === bodyMarginStr) bodyMarginStr = bodyMargin + "px";
186
+ setBodyStyle("margin", chkCSS("margin", bodyMarginStr));
187
+ }
188
+ function stopInfiniteResizingOfIFrame() {
189
+ document.documentElement.style.height = "";
190
+ document.body.style.height = "";
191
+ log('HTML & body height set to "auto"');
192
+ }
193
+ function manageTriggerEvent(options) {
194
+ var listener = {
195
+ add: function(eventName) {
196
+ function handleEvent() {
197
+ sendSize(options.eventName, options.eventType);
198
+ }
199
+ eventHandlersByName[eventName] = handleEvent;
200
+ addEventListener(window, eventName, handleEvent, {
201
+ passive: true
202
+ });
203
+ },
204
+ remove: function(eventName) {
205
+ var handleEvent = eventHandlersByName[eventName];
206
+ delete eventHandlersByName[eventName];
207
+ removeEventListener(window, eventName, handleEvent);
208
+ }
209
+ };
210
+ if (options.eventNames && Array.prototype.map) {
211
+ options.eventName = options.eventNames[0];
212
+ options.eventNames.map(listener[options.method]);
213
+ } else listener[options.method](options.eventName);
214
+ log(capitalizeFirstLetter(options.method) + " event listener: " + options.eventType);
215
+ }
216
+ function manageEventListeners(method) {
217
+ manageTriggerEvent({
218
+ method: method,
219
+ eventType: "Animation Start",
220
+ eventNames: [
221
+ "animationstart",
222
+ "webkitAnimationStart"
223
+ ]
224
+ });
225
+ manageTriggerEvent({
226
+ method: method,
227
+ eventType: "Animation Iteration",
228
+ eventNames: [
229
+ "animationiteration",
230
+ "webkitAnimationIteration"
231
+ ]
232
+ });
233
+ manageTriggerEvent({
234
+ method: method,
235
+ eventType: "Animation End",
236
+ eventNames: [
237
+ "animationend",
238
+ "webkitAnimationEnd"
239
+ ]
240
+ });
241
+ manageTriggerEvent({
242
+ method: method,
243
+ eventType: "Input",
244
+ eventName: "input"
245
+ });
246
+ manageTriggerEvent({
247
+ method: method,
248
+ eventType: "Mouse Up",
249
+ eventName: "mouseup"
250
+ });
251
+ manageTriggerEvent({
252
+ method: method,
253
+ eventType: "Mouse Down",
254
+ eventName: "mousedown"
255
+ });
256
+ manageTriggerEvent({
257
+ method: method,
258
+ eventType: "Orientation Change",
259
+ eventName: "orientationchange"
260
+ });
261
+ manageTriggerEvent({
262
+ method: method,
263
+ eventType: "Print",
264
+ eventNames: [
265
+ "afterprint",
266
+ "beforeprint"
267
+ ]
268
+ });
269
+ manageTriggerEvent({
270
+ method: method,
271
+ eventType: "Ready State Change",
272
+ eventName: "readystatechange"
273
+ });
274
+ manageTriggerEvent({
275
+ method: method,
276
+ eventType: "Touch Start",
277
+ eventName: "touchstart"
278
+ });
279
+ manageTriggerEvent({
280
+ method: method,
281
+ eventType: "Touch End",
282
+ eventName: "touchend"
283
+ });
284
+ manageTriggerEvent({
285
+ method: method,
286
+ eventType: "Touch Cancel",
287
+ eventName: "touchcancel"
288
+ });
289
+ manageTriggerEvent({
290
+ method: method,
291
+ eventType: "Transition Start",
292
+ eventNames: [
293
+ "transitionstart",
294
+ "webkitTransitionStart",
295
+ "MSTransitionStart",
296
+ "oTransitionStart",
297
+ "otransitionstart"
298
+ ]
299
+ });
300
+ manageTriggerEvent({
301
+ method: method,
302
+ eventType: "Transition Iteration",
303
+ eventNames: [
304
+ "transitioniteration",
305
+ "webkitTransitionIteration",
306
+ "MSTransitionIteration",
307
+ "oTransitionIteration",
308
+ "otransitioniteration"
309
+ ]
310
+ });
311
+ manageTriggerEvent({
312
+ method: method,
313
+ eventType: "Transition End",
314
+ eventNames: [
315
+ "transitionend",
316
+ "webkitTransitionEnd",
317
+ "MSTransitionEnd",
318
+ "oTransitionEnd",
319
+ "otransitionend"
320
+ ]
321
+ });
322
+ if ("child" === resizeFrom) manageTriggerEvent({
323
+ method: method,
324
+ eventType: "IFrame Resized",
325
+ eventName: "resize"
326
+ });
327
+ }
328
+ function checkCalcMode(calcMode, calcModeDefault, modes, type) {
329
+ if (calcModeDefault !== calcMode) {
330
+ if (!(calcMode in modes)) {
331
+ warn(calcMode + " is not a valid option for " + type + "CalculationMethod.");
332
+ calcMode = calcModeDefault;
333
+ }
334
+ log(type + ' calculation method set to "' + calcMode + '"');
335
+ }
336
+ return calcMode;
337
+ }
338
+ function checkHeightMode() {
339
+ heightCalcMode = checkCalcMode(heightCalcMode, heightCalcModeDefault, getHeight, "height");
340
+ }
341
+ function checkWidthMode() {
342
+ widthCalcMode = checkCalcMode(widthCalcMode, widthCalcModeDefault, getWidth, "width");
343
+ }
344
+ function startEventListeners() {
345
+ if (true === autoResize) {
346
+ manageEventListeners("add");
347
+ setupMutationObserver();
348
+ } else log("Auto Resize disabled");
349
+ }
350
+ // function stopMsgsToParent() {
351
+ // log('Disable outgoing messages')
352
+ // sendPermit = false
353
+ // }
354
+ // function removeMsgListener() {
355
+ // log('Remove event listener: Message')
356
+ // removeEventListener(window, 'message', receiver)
357
+ // }
358
+ function disconnectMutationObserver() {
359
+ if (null !== bodyObserver) /* istanbul ignore next */ // Not testable in PhantonJS
360
+ bodyObserver.disconnect();
361
+ }
362
+ function stopEventListeners() {
363
+ manageEventListeners("remove");
364
+ disconnectMutationObserver();
365
+ clearInterval(intervalTimer);
366
+ }
367
+ // function teardown() {
368
+ // stopMsgsToParent()
369
+ // removeMsgListener()
370
+ // if (true === autoResize) stopEventListeners()
371
+ // }
372
+ function injectClearFixIntoBodyElement() {
373
+ var clearFix = document.createElement("div");
374
+ clearFix.style.clear = "both";
375
+ // Guard against the following having been globally redefined in CSS.
376
+ clearFix.style.display = "block";
377
+ clearFix.style.height = "0";
378
+ document.body.appendChild(clearFix);
379
+ }
380
+ function setupInPageLinks() {
381
+ function getPagePosition() {
382
+ return {
383
+ x: window.pageXOffset === undefined ? document.documentElement.scrollLeft : window.pageXOffset,
384
+ y: window.pageYOffset === undefined ? document.documentElement.scrollTop : window.pageYOffset
385
+ };
386
+ }
387
+ function getElementPosition(el) {
388
+ var elPosition = el.getBoundingClientRect(), pagePosition = getPagePosition();
389
+ return {
390
+ x: parseInt(elPosition.left, 10) + parseInt(pagePosition.x, 10),
391
+ y: parseInt(elPosition.top, 10) + parseInt(pagePosition.y, 10)
392
+ };
393
+ }
394
+ function findTarget(location) {
395
+ function jumpToTarget(target) {
396
+ var jumpPosition = getElementPosition(target);
397
+ log("Moving to in page link (#" + hash + ") at x: " + jumpPosition.x + " y: " + jumpPosition.y);
398
+ sendMsg(jumpPosition.y, jumpPosition.x, "scrollToOffset") // X&Y reversed at sendMsg uses height/width
399
+ ;
400
+ }
401
+ var hash = location.split("#")[1] || location, hashData = decodeURIComponent(hash), target = document.getElementById(hashData) || document.getElementsByName(hashData)[0];
402
+ if (undefined === target) {
403
+ log("In page link (#" + hash + ") not found in iFrame, so sending to parent");
404
+ sendMsg(0, 0, "inPageLink", "#" + hash);
405
+ } else jumpToTarget(target);
406
+ }
407
+ function checkLocationHash() {
408
+ var hash = window.location.hash;
409
+ var href = window.location.href;
410
+ if ("" !== hash && "#" !== hash) findTarget(href);
411
+ }
412
+ function bindAnchors() {
413
+ function setupLink(el) {
414
+ function linkClicked(e) {
415
+ e.preventDefault();
416
+ /* jshint validthis:true */ findTarget(this.getAttribute("href"));
417
+ }
418
+ if ("#" !== el.getAttribute("href")) addEventListener(el, "click", linkClicked);
419
+ }
420
+ Array.prototype.forEach.call(document.querySelectorAll('a[href^="#"]'), setupLink);
421
+ }
422
+ function bindLocationHash() {
423
+ addEventListener(window, "hashchange", checkLocationHash);
424
+ }
425
+ function initCheck() {
426
+ // Check if page loaded with location hash after init resize
427
+ setTimeout(checkLocationHash, eventCancelTimer);
428
+ }
429
+ function enableInPageLinks() {
430
+ /* istanbul ignore else */ // Not testable in phantonJS
431
+ if (Array.prototype.forEach && document.querySelectorAll) {
432
+ log("Setting up location.hash handlers");
433
+ bindAnchors();
434
+ bindLocationHash();
435
+ initCheck();
436
+ } else warn("In page linking not fully supported in this browser! (See README.md for IE8 workaround)");
437
+ }
438
+ if (inPageLinks.enable) enableInPageLinks();
439
+ else log("In page linking not enabled");
440
+ return {
441
+ findTarget: findTarget
442
+ };
443
+ }
444
+ function setupMouseEvents() {
445
+ if (mouseEvents !== true) return;
446
+ function sendMouse(e) {
447
+ sendMsg(0, 0, e.type, e.screenY + ":" + e.screenX);
448
+ }
449
+ function addMouseListener(evt, name) {
450
+ log("Add event listener: " + name);
451
+ addEventListener(window.document, evt, sendMouse);
452
+ }
453
+ addMouseListener("mouseenter", "Mouse Enter");
454
+ addMouseListener("mouseleave", "Mouse Leave");
455
+ }
456
+ function setupPublicMethods() {
457
+ log("Enable public methods");
458
+ win.parentIFrame = {
459
+ autoResize: function autoResizeF(resize) {
460
+ if (true === resize && false === autoResize) {
461
+ autoResize = true;
462
+ startEventListeners();
463
+ } else if (false === resize && true === autoResize) {
464
+ autoResize = false;
465
+ stopEventListeners();
466
+ }
467
+ sendMsg(0, 0, "autoResize", JSON.stringify(autoResize));
468
+ return autoResize;
469
+ },
470
+ close: function closeF() {
471
+ sendMsg(0, 0, "close");
472
+ // teardown()
473
+ },
474
+ getId: function getIdF() {
475
+ return myID;
476
+ },
477
+ getPageInfo: function getPageInfoF(callback) {
478
+ if ("function" === typeof callback) {
479
+ onPageInfo = callback;
480
+ sendMsg(0, 0, "pageInfo");
481
+ } else {
482
+ onPageInfo = function() {};
483
+ sendMsg(0, 0, "pageInfoStop");
484
+ }
485
+ },
486
+ moveToAnchor: function moveToAnchorF(hash) {
487
+ inPageLinks.findTarget(hash);
488
+ },
489
+ reset: function resetF() {
490
+ resetIFrame("parentIFrame.reset");
491
+ },
492
+ scrollTo: function scrollToF(x, y) {
493
+ sendMsg(y, x, "scrollTo") // X&Y reversed at sendMsg uses height/width
494
+ ;
495
+ },
496
+ scrollToOffset: function scrollToF(x, y) {
497
+ sendMsg(y, x, "scrollToOffset") // X&Y reversed at sendMsg uses height/width
498
+ ;
499
+ },
500
+ sendMessage: function sendMessageF(msg, targetOrigin) {
501
+ sendMsg(0, 0, "message", JSON.stringify(msg), targetOrigin);
502
+ },
503
+ setHeightCalculationMethod: function setHeightCalculationMethodF(heightCalculationMethod) {
504
+ heightCalcMode = heightCalculationMethod;
505
+ checkHeightMode();
506
+ },
507
+ setWidthCalculationMethod: function setWidthCalculationMethodF(widthCalculationMethod) {
508
+ widthCalcMode = widthCalculationMethod;
509
+ checkWidthMode();
510
+ },
511
+ setTargetOrigin: function setTargetOriginF(targetOrigin) {
512
+ log("Set targetOrigin: " + targetOrigin);
513
+ targetOriginDefault = targetOrigin;
514
+ },
515
+ size: function sizeF(customHeight, customWidth) {
516
+ var valString = "" + (customHeight || "") + (customWidth ? "," + customWidth : "");
517
+ sendSize("size", "parentIFrame.size(" + valString + ")", customHeight, customWidth);
518
+ }
519
+ };
520
+ }
521
+ function initInterval() {
522
+ if (0 !== interval) {
523
+ log("setInterval: " + interval + "ms");
524
+ intervalTimer = setInterval(function() {
525
+ sendSize("interval", "setInterval: " + interval);
526
+ }, Math.abs(interval));
527
+ }
528
+ }
529
+ // Not testable in PhantomJS
530
+ /* istanbul ignore next */ function setupBodyMutationObserver() {
531
+ function addImageLoadListners(mutation) {
532
+ function addImageLoadListener(element) {
533
+ if (false === element.complete) {
534
+ log("Attach listeners to " + element.src);
535
+ element.addEventListener("load", imageLoaded, false);
536
+ element.addEventListener("error", imageError, false);
537
+ elements.push(element);
538
+ }
539
+ }
540
+ if (mutation.type === "attributes" && mutation.attributeName === "src") addImageLoadListener(mutation.target);
541
+ else if (mutation.type === "childList") Array.prototype.forEach.call(mutation.target.querySelectorAll("img"), addImageLoadListener);
542
+ }
543
+ function removeFromArray(element) {
544
+ elements.splice(elements.indexOf(element), 1);
545
+ }
546
+ function removeImageLoadListener(element) {
547
+ log("Remove listeners from " + element.src);
548
+ element.removeEventListener("load", imageLoaded, false);
549
+ element.removeEventListener("error", imageError, false);
550
+ removeFromArray(element);
551
+ }
552
+ function imageEventTriggered(event, type, typeDesc) {
553
+ removeImageLoadListener(event.target);
554
+ sendSize(type, typeDesc + ": " + event.target.src);
555
+ }
556
+ function imageLoaded(event) {
557
+ imageEventTriggered(event, "imageLoad", "Image loaded");
558
+ }
559
+ function imageError(event) {
560
+ imageEventTriggered(event, "imageLoadFailed", "Image load failed");
561
+ }
562
+ function mutationObserved(mutations) {
563
+ sendSize("mutationObserver", "mutationObserver: " + mutations[0].target + " " + mutations[0].type);
564
+ // Deal with WebKit / Blink asyncing image loading when tags are injected into the page
565
+ mutations.forEach(addImageLoadListners);
566
+ }
567
+ function createMutationObserver() {
568
+ var target = document.querySelector("body"), config = {
569
+ attributes: true,
570
+ attributeOldValue: false,
571
+ characterData: true,
572
+ characterDataOldValue: false,
573
+ childList: true,
574
+ subtree: true
575
+ };
576
+ observer = new MutationObserver(mutationObserved);
577
+ log("Create body MutationObserver");
578
+ observer.observe(target, config);
579
+ return observer;
580
+ }
581
+ var elements = [], MutationObserver = window.MutationObserver || window.WebKitMutationObserver, observer = createMutationObserver();
582
+ return {
583
+ disconnect: function() {
584
+ if ("disconnect" in observer) {
585
+ log("Disconnect body MutationObserver");
586
+ observer.disconnect();
587
+ elements.forEach(removeImageLoadListener);
588
+ }
589
+ }
590
+ };
591
+ }
592
+ function setupMutationObserver() {
593
+ var forceIntervalTimer = 0 > interval;
594
+ // Not testable in PhantomJS
595
+ /* istanbul ignore if */ if (window.MutationObserver || window.WebKitMutationObserver) {
596
+ if (forceIntervalTimer) initInterval();
597
+ else bodyObserver = setupBodyMutationObserver();
598
+ } else {
599
+ log("MutationObserver not supported in this browser!");
600
+ initInterval();
601
+ }
602
+ }
603
+ // document.documentElement.offsetHeight is not reliable, so
604
+ // we have to jump through hoops to get a better value.
605
+ function getComputedStyle(prop, el) {
606
+ var retVal = 0;
607
+ el = el || document.body // Not testable in phantonJS
608
+ ;
609
+ retVal = document.defaultView.getComputedStyle(el, null);
610
+ retVal = null === retVal ? 0 : retVal[prop];
611
+ return parseInt(retVal, base);
612
+ }
613
+ function chkEventThottle(timer) {
614
+ if (timer > throttledTimer / 2) {
615
+ throttledTimer = 2 * timer;
616
+ log("Event throttle increased to " + throttledTimer + "ms");
617
+ }
618
+ }
619
+ // Idea from https://github.com/guardian/iframe-messenger
620
+ function getMaxElement(side, elements) {
621
+ var elementsLength = elements.length, elVal = 0, maxVal = 0, Side = capitalizeFirstLetter(side), timer = Date.now();
622
+ for(var i = 0; i < elementsLength; i++){
623
+ elVal = elements[i].getBoundingClientRect()[side] + getComputedStyle("margin" + Side, elements[i]);
624
+ if (elVal > maxVal) maxVal = elVal;
625
+ }
626
+ timer = Date.now() - timer;
627
+ log("Parsed " + elementsLength + " HTML elements");
628
+ log("Element position calculated in " + timer + "ms");
629
+ chkEventThottle(timer);
630
+ return maxVal;
631
+ }
632
+ function getAllMeasurements(dimensions) {
633
+ return [
634
+ dimensions.bodyOffset(),
635
+ dimensions.bodyScroll(),
636
+ dimensions.documentElementOffset(),
637
+ dimensions.documentElementScroll()
638
+ ];
639
+ }
640
+ function getTaggedElements(side, tag) {
641
+ function noTaggedElementsFound() {
642
+ warn("No tagged elements (" + tag + ") found on page");
643
+ return document.querySelectorAll("body *");
644
+ }
645
+ var elements = document.querySelectorAll("[" + tag + "]");
646
+ if (elements.length === 0) noTaggedElementsFound();
647
+ return getMaxElement(side, elements);
648
+ }
649
+ function getAllElements() {
650
+ return document.querySelectorAll("body *");
651
+ }
652
+ var getHeight = {
653
+ bodyOffset: function getBodyOffsetHeight() {
654
+ return document.body.offsetHeight + getComputedStyle("marginTop") + getComputedStyle("marginBottom");
655
+ },
656
+ offset: function() {
657
+ return getHeight.bodyOffset() // Backwards compatibility
658
+ ;
659
+ },
660
+ bodyScroll: function getBodyScrollHeight() {
661
+ return document.body.scrollHeight;
662
+ },
663
+ custom: function getCustomWidth() {
664
+ return customCalcMethods.height();
665
+ },
666
+ documentElementOffset: function getDEOffsetHeight() {
667
+ return document.documentElement.offsetHeight;
668
+ },
669
+ documentElementScroll: function getDEScrollHeight() {
670
+ return document.documentElement.scrollHeight;
671
+ },
672
+ max: function getMaxHeight() {
673
+ return Math.max.apply(null, getAllMeasurements(getHeight));
674
+ },
675
+ min: function getMinHeight() {
676
+ return Math.min.apply(null, getAllMeasurements(getHeight));
677
+ },
678
+ grow: function growHeight() {
679
+ return getHeight.max() // Run max without the forced downsizing
680
+ ;
681
+ },
682
+ lowestElement: function getBestHeight() {
683
+ return Math.max(getHeight.bodyOffset() || getHeight.documentElementOffset(), getMaxElement("bottom", getAllElements()));
684
+ },
685
+ taggedElement: function getTaggedElementsHeight() {
686
+ return getTaggedElements("bottom", "data-iframe-height");
687
+ }
688
+ }, getWidth = {
689
+ bodyScroll: function getBodyScrollWidth() {
690
+ return document.body.scrollWidth;
691
+ },
692
+ bodyOffset: function getBodyOffsetWidth() {
693
+ return document.body.offsetWidth;
694
+ },
695
+ custom: function getCustomWidth() {
696
+ return customCalcMethods.width();
697
+ },
698
+ documentElementScroll: function getDEScrollWidth() {
699
+ return document.documentElement.scrollWidth;
700
+ },
701
+ documentElementOffset: function getDEOffsetWidth() {
702
+ return document.documentElement.offsetWidth;
703
+ },
704
+ scroll: function getMaxWidth() {
705
+ return Math.max(getWidth.bodyScroll(), getWidth.documentElementScroll());
706
+ },
707
+ max: function getMaxWidth() {
708
+ return Math.max.apply(null, getAllMeasurements(getWidth));
709
+ },
710
+ min: function getMinWidth() {
711
+ return Math.min.apply(null, getAllMeasurements(getWidth));
712
+ },
713
+ rightMostElement: function rightMostElement() {
714
+ return getMaxElement("right", getAllElements());
715
+ },
716
+ taggedElement: function getTaggedElementsWidth() {
717
+ return getTaggedElements("right", "data-iframe-width");
718
+ }
719
+ };
720
+ function sizeIFrame(triggerEvent, triggerEventDesc, customHeight, customWidth) {
721
+ function resizeIFrame() {
722
+ height = currentHeight;
723
+ width = currentWidth;
724
+ sendMsg(height, width, triggerEvent);
725
+ }
726
+ function isSizeChangeDetected() {
727
+ function checkTolarance(a, b) {
728
+ var retVal = Math.abs(a - b) <= tolerance;
729
+ return !retVal;
730
+ }
731
+ currentHeight = undefined === customHeight ? getHeight[heightCalcMode]() : customHeight;
732
+ currentWidth = undefined === customWidth ? getWidth[widthCalcMode]() : customWidth;
733
+ return checkTolarance(height, currentHeight) || calculateWidth && checkTolarance(width, currentWidth);
734
+ }
735
+ function isForceResizableEvent() {
736
+ return !(triggerEvent in {
737
+ init: 1,
738
+ interval: 1,
739
+ size: 1
740
+ });
741
+ }
742
+ function isForceResizableCalcMode() {
743
+ return heightCalcMode in resetRequiredMethods || calculateWidth && widthCalcMode in resetRequiredMethods;
744
+ }
745
+ function logIgnored() {
746
+ log("No change in size detected");
747
+ }
748
+ function checkDownSizing() {
749
+ if (isForceResizableEvent() && isForceResizableCalcMode()) resetIFrame(triggerEventDesc);
750
+ else if (!(triggerEvent in {
751
+ interval: 1
752
+ })) logIgnored();
753
+ }
754
+ var currentHeight, currentWidth;
755
+ if (isSizeChangeDetected() || "init" === triggerEvent) {
756
+ lockTrigger();
757
+ resizeIFrame();
758
+ } else checkDownSizing();
759
+ }
760
+ var sizeIFrameThrottled = throttle(sizeIFrame);
761
+ function sendSize(triggerEvent, triggerEventDesc, customHeight, customWidth) {
762
+ function recordTrigger() {
763
+ if (!(triggerEvent in {
764
+ reset: 1,
765
+ resetPage: 1,
766
+ init: 1
767
+ })) log("Trigger event: " + triggerEventDesc);
768
+ }
769
+ function isDoubleFiredEvent() {
770
+ return triggerLocked && triggerEvent in doubleEventList;
771
+ }
772
+ if (isDoubleFiredEvent()) log("Trigger event cancelled: " + triggerEvent);
773
+ else {
774
+ recordTrigger();
775
+ if (triggerEvent === "init") sizeIFrame(triggerEvent, triggerEventDesc, customHeight, customWidth);
776
+ else sizeIFrameThrottled(triggerEvent, triggerEventDesc, customHeight, customWidth);
777
+ }
778
+ }
779
+ function lockTrigger() {
780
+ if (!triggerLocked) {
781
+ triggerLocked = true;
782
+ log("Trigger event lock on");
783
+ }
784
+ clearTimeout(triggerLockedTimer);
785
+ triggerLockedTimer = setTimeout(function() {
786
+ triggerLocked = false;
787
+ log("Trigger event lock off");
788
+ log("--");
789
+ }, eventCancelTimer);
790
+ }
791
+ function triggerReset(triggerEvent) {
792
+ height = getHeight[heightCalcMode]();
793
+ width = getWidth[widthCalcMode]();
794
+ sendMsg(height, width, triggerEvent);
795
+ }
796
+ function resetIFrame(triggerEventDesc) {
797
+ var hcm = heightCalcMode;
798
+ heightCalcMode = heightCalcModeDefault;
799
+ log("Reset trigger event: " + triggerEventDesc);
800
+ lockTrigger();
801
+ triggerReset("reset");
802
+ heightCalcMode = hcm;
803
+ }
804
+ function sendMsg(height, width, triggerEvent, msg, targetOrigin) {
805
+ function setTargetOrigin() {
806
+ if (undefined === targetOrigin) targetOrigin = targetOriginDefault;
807
+ else log("Message targetOrigin: " + targetOrigin);
808
+ }
809
+ function sendToParent() {
810
+ var size = height + ":" + width, message = myID + ":" + size + ":" + triggerEvent + (undefined === msg ? "" : ":" + msg);
811
+ log("Sending message to host page (" + message + ")");
812
+ target.postMessage(msgID + message, targetOrigin);
813
+ }
814
+ if (true === sendPermit) {
815
+ setTargetOrigin();
816
+ sendToParent();
817
+ }
818
+ }
819
+ function receiver(event) {
820
+ var processRequestFromParent = {
821
+ init: function initFromParent() {
822
+ initMsg = event.data;
823
+ target = event.source;
824
+ init();
825
+ firstRun = false;
826
+ setTimeout(function() {
827
+ initLock = false;
828
+ }, eventCancelTimer);
829
+ },
830
+ reset: function resetFromParent() {
831
+ if (initLock) log("Page reset ignored by init");
832
+ else {
833
+ log("Page size reset by host page");
834
+ triggerReset("resetPage");
835
+ }
836
+ },
837
+ resize: function resizeFromParent() {
838
+ sendSize("resizeParent", "Parent window requested size check");
839
+ },
840
+ moveToAnchor: function moveToAnchorF() {
841
+ inPageLinks.findTarget(getData());
842
+ },
843
+ inPageLink: function inPageLinkF() {
844
+ this.moveToAnchor();
845
+ },
846
+ pageInfo: function pageInfoFromParent() {
847
+ var msgBody = getData();
848
+ log("PageInfoFromParent called from parent: " + msgBody);
849
+ onPageInfo(JSON.parse(msgBody));
850
+ log(" --");
851
+ },
852
+ message: function messageFromParent() {
853
+ var msgBody = getData();
854
+ log("onMessage called from parent: " + msgBody);
855
+ // eslint-disable-next-line sonarjs/no-extra-arguments
856
+ onMessage(JSON.parse(msgBody));
857
+ log(" --");
858
+ }
859
+ };
860
+ function isMessageForUs() {
861
+ return msgID === ("" + event.data).slice(0, msgIdLen) // ''+ Protects against non-string messages
862
+ ;
863
+ }
864
+ function getMessageType() {
865
+ return event.data.split("]")[1].split(":")[0];
866
+ }
867
+ function getData() {
868
+ return event.data.slice(event.data.indexOf(":") + 1);
869
+ }
870
+ function isMiddleTier() {
871
+ return !(0, $b2e1fd3e30ab1f5c$exports) && "iFrameResize" in window || window.jQuery !== undefined && "iFrameResize" in window.jQuery.prototype;
872
+ }
873
+ function isInitMsg() {
874
+ // Test if this message is from a child below us. This is an ugly test, however, updating
875
+ // the message format would break backwards compatibility.
876
+ return event.data.split(":")[2] in {
877
+ true: 1,
878
+ false: 1
879
+ };
880
+ }
881
+ function callFromParent() {
882
+ var messageType = getMessageType();
883
+ if (messageType in processRequestFromParent) processRequestFromParent[messageType]();
884
+ else if (!isMiddleTier() && !isInitMsg()) warn("Unexpected message (" + event.data + ")");
885
+ }
886
+ function processMessage() {
887
+ if (false === firstRun) callFromParent();
888
+ else if (isInitMsg()) processRequestFromParent.init();
889
+ else log('Ignored message of type "' + getMessageType() + '". Received before initialization.');
890
+ }
891
+ if (isMessageForUs()) processMessage();
892
+ }
893
+ // Normally the parent kicks things off when it detects the iFrame has loaded.
894
+ // If this script is async-loaded, then tell parent page to retry init.
895
+ function chkLateLoaded() {
896
+ if ("loading" !== document.readyState) window.parent.postMessage("[iFrameResizerChild]Ready", "*");
897
+ }
898
+ addEventListener(window, "message", receiver);
899
+ addEventListener(window, "readystatechange", chkLateLoaded);
900
+ chkLateLoaded();
901
+ })();
902
+
903
+
904
+
905
+ })();
906
+ //# sourceMappingURL=iframe.js.map