From 7e9e4a2effefd800c569eb9602197c43a2cf3375 Mon Sep 17 00:00:00 2001 From: "David J. Bradshaw" Date: Sun, 24 Feb 2019 16:23:21 +0000 Subject: [PATCH] Prettier --- .prettierrc | 13 +- CHANGELOG.md | 180 +++++----- CONTRIBUTING.md | 17 +- README.md | 63 ++-- bower.json | 17 +- docs/getting_started.md | 11 +- docs/jquery.md | 2 +- docs/readme.md | 26 +- docs/troubleshooting.md | 38 +- example/frame.absolute.html | 216 ++++++----- example/frame.content.html | 179 ++++++---- example/frame.hover.html | 115 +++--- example/frame.nested.html | 158 +++++---- example/frame.textarea.html | 93 +++-- example/frame.tolerance.html | 192 +++++----- example/index.html | 144 ++++---- example/two.html | 149 ++++---- js/iframeResizer.contentWindow.min.js | 2 +- js/iframeResizer.min.js | 2 +- karma.conf.js | 4 +- spec/_initSpec.js | 44 +-- spec/anchorSpec.js | 56 +-- spec/childSpec.js | 492 +++++++++++++------------- spec/closeSpecSpec.js | 32 +- spec/initCssSpec.js | 22 +- spec/initDomSpec.js | 22 +- spec/initDoubleCallSpec.js | 32 +- spec/initErrorSpec.js | 42 +-- spec/initJQuerySpec.js | 24 +- spec/initUndefinedDomSpec.js | 22 +- spec/parentSpec.js | 86 ++--- spec/scrollSpec.js | 44 +-- spec/sendMessageSpec.js | 52 +-- test-main.js | 12 +- test/_init.html | 84 +++-- test/_init_once.html | 88 ++--- test/_init_once_async.html | 122 ++++--- test/background.html | 89 +++-- test/changePage.html | 98 ++--- test/close.html | 83 +++-- test/getId.html | 87 ++--- test/interval.html | 108 +++--- test/jqueryNoConflict.html | 87 +++-- test/lateImageLoad.html | 159 +++++---- test/margin.html | 121 +++---- test/mutationObserver.html | 118 +++--- test/nested.html | 87 +++-- test/removeIFrame.html | 158 +++++---- test/resize.contentWidth.html | 95 +++-- test/resize.width.html | 130 ++++--- test/scrolling.html | 208 ++++++----- test/sendMessage.html | 115 +++--- test/setHeightCalculationMethod.html | 89 +++-- test/size.html | 122 ++++--- test/v1.html | 332 ++++++++--------- 55 files changed, 2704 insertions(+), 2479 deletions(-) diff --git a/.prettierrc b/.prettierrc index f8dec5b18..db185d645 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,10 @@ { - "tabWidth": 2, - "semi": false, - "singleQuote": true -} + "printWidth": 80, + "tabWidth": 2, + "useTabs": false, + "semi": false, + "singleQuote": true, + "trailingComma": "none", + "bracketSpacing": true, + "jsxBracketSameLine": false + } diff --git a/CHANGELOG.md b/CHANGELOG.md index 9284e7af4..c1125279c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,92 +1,92 @@ ## Version History -* v4.0.0 Drop support for IE8-10 and Andriod 4, renamed event handlers from `fooCallback` to `onFoo` and restructure documentation. -* v3.6.5 [#658](https://github.com/davidjbradshaw/iframe-resizer/pull/658) Add `.npmignore` to project [[Sebastian Lamelas]](smulesoft). -* v3.6.4 [#651](https://github.com/davidjbradshaw/iframe-resizer/pull/651) Fix issue resource leak when iframe removed from the page [[Steffen Eckardt](seckardt)]. [#651](https://github.com/davidjbradshaw/iframe-resizer/pull/651) Make Require.js optional when it is included on the page before iframe-resizer [[Dahmian Owen](dahmian)]. -* v3.6.3 [#635](https://github.com/davidjbradshaw/iframe-resizer/pull/635) Fix issue with undefined ID [[Henry Schein](ddxdental)]. [#582](https://github.com/davidjbradshaw/iframe-resizer/pull/582) Add `omit` option to `scrolling` config [[Matt Ryan](mryand)]. -* v3.6.2 [#596](https://github.com/davidjbradshaw/iframe-resizer/pull/596) Add Passive Event Listener for Performance [[Henrik Vendelbo](thepian)]. [#613](https://github.com/davidjbradshaw/iframe-resizer/pull/613) Check if the iFrameResize function is attached to the prototype of jQuery [[Paul Antal](paul-antal)]. [#620](https://github.com/davidjbradshaw/iframe-resizer/pull/620) Fixed an issue where host page fires init before iframe receiver setup [[Mark Zhou](mrmarktyy)]. [#620](https://github.com/davidjbradshaw/iframe-resizer/pull/620) Add `removeListeners` method to better support React [[Khang Nguyen](khangiskhan)]. -* v3.6.1 [#576](https://github.com/davidjbradshaw/iframe-resizer/pull/576) Fix race condition caused by react-iframe-resizer removing the domNode and calling `close()`. -* v3.6.0 [#562](https://github.com/davidjbradshaw/iframe-resizer/pull/562) Fix issue with debounce getPageInfo when their is more than one iFrame on the page [[Thomas Pringle](thomaspringle)]. [#568](https://github.com/davidjbradshaw/iframe-resizer/pull/568) Fix bug in Chrome 65 when iframe parent element has `display:none` set [[Steve Hong](aniude)]. -* v3.5.16 [#554](https://github.com/davidjbradshaw/iframe-resizer/issues/554) Fix throttling of init event [[SHOTA](senta)]. [#553](https://github.com/davidjbradshaw/iframe-resizer/issues/553) Prevents unhandled exception in IE11 [[vitoss](vitoss)]. [#555](https://github.com/davidjbradshaw/iframe-resizer/issues/555) Fix IE PolyFil and make grunt-cli local [[Jan Schmidle](bitcloud)]. -* v3.5.15 [#498](https://github.com/davidjbradshaw/iframe-resizer/issues/498) Fix bug "Cannot read property 'firstRun' of undefined" [[Shaun Johansen](shaunjohansen)]. [#517] Fix readyState issue in iFrame [[lostincomputer](lostincomputer)]. -* v3.5.14 [#477](https://github.com/davidjbradshaw/iframe-resizer/issues/477) Fix bug when iFrame closed before first resize. -* v3.5.13 [#473](https://github.com/davidjbradshaw/iframe-resizer/issues/473) Improve no response from iFrame warning message. -* v3.5.12 [#475](https://github.com/davidjbradshaw/iframe-resizer/issues/475) Delay onResize until after the iFrame has resized [[Codener](codener)]. -* v3.5.11 [#470](https://github.com/davidjbradshaw/iframe-resizer/issues/470) Fix jQuery reference error [[Russell Schick](rschick)]. -* v3.5.10 [#461](https://github.com/davidjbradshaw/iframe-resizer/issues/461) Don't run for server-side render -* v3.5.9 Show warning message if no response from iFrame. [#463](https://github.com/davidjbradshaw/iframe-resizer/issues/463) Suppress warning message when code loaded via module [[Sergey Pereskokov](SerjoPepper)]. -* v3.5.8 [#315](https://github.com/davidjbradshaw/iframe-resizer/issues/315) Allow Scrolling to be set to 'auto'. -* v3.5.7 [#438](https://github.com/davidjbradshaw/iframe-resizer/issues/438) Check jQuery pluging wrapper not already loaded. [#423](https://github.com/davidjbradshaw/iframe-resizer/issues/423) Properly remove event listeners [[Aaron Hardy](Aaronius)]. [#401](https://github.com/davidjbradshaw/iframe-resizer/issues/401) Make tagged element fall back to all elements if tag not found. [#381](https://github.com/davidjbradshaw/iframe-resizer/issues/381) Fixing disconnect when iframe is missing temporarly [[Jeff Hicken](jhicken)]. Added warnings for missing iFrame and deprecated options. -* v3.5.5 [#373](https://github.com/davidjbradshaw/iframe-resizer/issues/373) Add option for custom size calculation methods in iFrame. [#374](https://github.com/davidjbradshaw/iframe-resizer/issues/374) Fix bug with in page links called from parent page. -* v3.5.4 [#362](https://github.com/davidjbradshaw/iframe-resizer/issues/362) Handle jQuery being loaded in odd ways. [#297](https://github.com/davidjbradshaw/iframe-resizer/issues/297) Ensure document ready before resizing -* v3.5.3 [#283](https://github.com/davidjbradshaw/iframe-resizer/issues/283) Added *readystatechange* event listener. -* v3.5.2 [#314](https://github.com/davidjbradshaw/iframe-resizer/pull/314) Add iframeHeight and iframeWidth properties to pageInfo [[Pierre Olivier](https://github.com/pomartel)]. [#303](https://github.com/davidjbradshaw/iframe-resizer/issues/303) Fix issue with IE8 polyFils. -* v3.5.1 [#286](https://github.com/davidjbradshaw/iframe-resizer/issues/286) Fixed *taggedElement / lowestElement / rightMostElement* to calculate correct margin [[Dan Ballance](danballance)]. -* v3.5.0 Recall getPageInfo callback when parent page position changes. Added *Array.prototype.forEach* to IE8 polyfils. -* v3.4.2 Only teardown events on close if currently enabled. -* v3.4.1 [#271](https://github.com/davidjbradshaw/iframe-resizer/issues/271) Fix bower.json to point to *js* folder, rather then *src* [[Yachi](https://github.com/yachi)]. -* v3.4.0 [#262](https://github.com/davidjbradshaw/iframe-resizer/issues/262) Add *getPageInfo* method to *parentIFrame* [[Pierre Olivier](https://github.com/pomartel)]. [#263](https://github.com/davidjbradshaw/iframe-resizer/issues/263) Change *leftMostElement* to rightMostElement [[Luiz Panariello](https://github.com/LuizPanariello)]. [#265](https://github.com/davidjbradshaw/iframe-resizer/issues/265) Fix issue when no options being passed and added test for this. -* v3.3.1 Point index.js to the JS folder, instead of the src folder. Added touch event listeners. *AutoResize* method now returns current state. -* v3.3.0 [#97](https://github.com/davidjbradshaw/iframe-resizer/issues/97) Add *autoResize* method to *parentIFrame*. Fix bug when *setHeightCalculationMethod* is called with invalid value. Add interval timer to event teardown. Log targetOrigin*. [#253](https://github.com/davidjbradshaw/iframe-resizer/issues/253) Work around bug with MooTools interfering with system objects. -* v3.2.0 Added calculation of margin to *LowestElement*, *LeftMostElement* and *taggedElement* calculation modes. Check callback function is a function before calling it. [#246](https://github.com/davidjbradshaw/iframe-resizer/issues/246) Fixed issue when *onScroll* changes the page position. [#247](https://github.com/davidjbradshaw/iframe-resizer/issues/247) Fix rounding issue when page is zoomed in Chrome [[thenewguy](https://github.com/thenewguy)]. -* v3.1.1 Added *onReady* to iFrame. Create *iFrameResizer* object on iFrame during setup, rather than waiting for init message to be returned from iFrame. Add ref to iFrame in host page log messages. [#245](https://github.com/davidjbradshaw/iframe-resizer/issues/245) Fix issue with iFrame not correctly resizing when multiple images are injected into the page [[mdgbayly](https://github.com/mdgbayly)]. [#246](https://github.com/davidjbradshaw/iframe-resizer/issues/246) Fix issue with including ':' in messages passed to iFrames. -* v3.1.0 [#101](https://github.com/davidjbradshaw/iframe-resizer/issues/101) Support async loading of iFrame script. [#239](https://github.com/davidjbradshaw/iframe-resizer/issues/239) Throttle size checking to once per screen refresh (16ms). Fixed issue with hidden iFrames in FireFox. Improved handling of parent page events. [#236](https://github.com/davidjbradshaw/iframe-resizer/issues/236) Cope with iFrames that don't have a *src* value. [#242](https://github.com/davidjbradshaw/iframe-resizer/issues/242) Fix issue where iFrame is removed and then put back with same ID [[Alban Mouton](https://github.com/albanm)]. -* v3.0.0 Added *taggedElement* size calculation method. [#199](https://github.com/davidjbradshaw/iframe-resizer/issues/199) Added in page options to iFrame. [#70](https://github.com/davidjbradshaw/iframe-resizer/issues/70) Added width calculation method options. Added methods to bound iFrames to comunicate from parent to iFrame. Ignore calls to setup an already bound iFrame. Improved event handling. Refactored MutationObserver functions. Moved IE8 polyfil from docs to own JS file and added *Funtion.prototype.bind()*. Added detection for tab focus. Fixed bug with nested inPageLinks. Public methods in iFrame now always enabled and option removed. Renamed enableInPageLinks to inPageLinks. Added double iFrame example. -* v2.8.10 Fixed bug with resizeFrom option not having default value in iFrame, if called from old version in parent page. -* v2.8.9 [#220](https://github.com/davidjbradshaw/iframe-resizer/issues/220) Switched from using *deviceorientation* to *orientationchange* event listner [[Brandon Kobel](https://github.com/kobelb)]. -* v2.8.8 [#213](https://github.com/davidjbradshaw/iframe-resizer/issues/213) Ensure onInit fires when iFrame not sized during initialisation. Check autoResize option before resizing from parent. Lower message about resize before initialisation from 'warn' to 'log'. Updated hover example. -* v2.8.7 [#205](https://github.com/davidjbradshaw/iframe-resizer/issues/205) Fix race condition when page resized during page init [[Ian Caunce](https://github.com/IanCaunce)]. [#203](https://github.com/davidjbradshaw/iframe-resizer/issues/203) Added option for *checkOrigin* to have list of allowed domains for the iFrame [[Andrej Golcov](https://github.com/andrej2k)]. [#202](https://github.com/davidjbradshaw/iframe-resizer/issues/202) Handle script being loaded more than once [[Nickolay Ribal](https://github.com/elektronik2k5)]. -[#167](https://github.com/davidjbradshaw/iframe-resizer/issues/167) Added WebPack support [[Stephan Salat](https://github.com/ssalat)]. -* v2.8.6 [#163](https://github.com/davidjbradshaw/iframe-resizer/issues/163) Moved window resize event detection from iFrame to parent page. [#160](https://github.com/davidjbradshaw/iframe-resizer/issues/160) Warn, rather than error, if iFrame has been unexpectantly removed from page. The *parentIFrame.close()* method nolonger calls *onResized()*. -* v2.8.5 [#173](https://github.com/davidjbradshaw/iframe-resizer/issues/173) Scope settings to iFrame. [#171](https://github.com/davidjbradshaw/iframe-resizer/issues/171) Fixed *parentIFrame.close()* to work with 0 height iframes [Both [Reed Dadoune](https://github.com/ReedD)]. -* v2.8.4 Added switch for inPageLinking support. -* v2.8.3 Throw error if passed a non-DOM object. -* v2.8.2 [#145](https://github.com/davidjbradshaw/iframe-resizer/issues/145) Fixed in page links, to work with HTML IDs that are not valid CSS IDs [[Erin Millard](https://github.com/ezzatron)]. Moved map files from src to js folder. Added to NPM. -* v2.8.1 [#138](https://github.com/davidjbradshaw/iframe-resizer/issues/138) Added option to pass in iFrame object, instead of selector. -* v2.8.0 [#68](https://github.com/davidjbradshaw/iframe-resizer/issues/68) Added support for in page links and *onScroll()* function. [#140](https://github.com/davidjbradshaw/iframe-resizer/issues/140) Added listener for *transitionend* event [[Mat Brown](https://github.com/outoftime)]. Added listeners for animation events. Added listener for *deviceorientation* event. Improved logging for nested iFrames. -* v2.7.1 [#131](https://github.com/davidjbradshaw/iframe-resizer/issues/131) Fix code that works out position of iFrame on host page. -* v2.7.0 [#129](https://github.com/davidjbradshaw/iframe-resizer/issues/129) Parse data passed to *parentIFrame.sendMessage()* into JSON to allow complex data types to be sent to *onMessage()*. -* v2.6.5 [#107](https://github.com/davidjbradshaw/iframe-resizer/issues/107) Added Node support for use with Browserify. -* v2.6.4 [#115](https://github.com/davidjbradshaw/iframe-resizer/issues/115) Added *parentIFrame.scrollToOffset()* method. -* v2.6.3 [#115](https://github.com/davidjbradshaw/iframe-resizer/issues/115) Fixed issue with the range check sometimes causing non-resizing messages to be rejected. -* v2.6.2 [#104](https://github.com/davidjbradshaw/iframe-resizer/issues/104) Fixed issue with jQuery.noConflict [[Dmitry Mukhutdinov](https://github.com/flyingleafe)]. -* v2.6.1 [#91](https://github.com/davidjbradshaw/iframe-resizer/issues/91) Fixed issue with jQuery version requiring empty object if no options are being set. -* v2.6.0 Added *parentIFrame.scrollTo()* method. Added *Tolerance* option. [#85](https://github.com/davidjbradshaw/iframe-resizer/issues/85) Update troubleshooting guide [[Kevin Sproles](https://github.com/kevinsproles)]. -* v2.5.2 [#67](https://github.com/davidjbradshaw/iframe-resizer/issues/67) Allow lowercase ` - + ``` **Note:** Using _min-width_ to set the width of the iFrame, works around an issue in iOS that can prevent the iFrame from sizing correctly. @@ -58,25 +66,26 @@ To see this working take a look at this [example](http://davidjbradshaw.com/ifra IFrame-Resizer provides an extensive range of options and APIs for both the parent page and the iframed page. -* **Parent Page API** - * [Options](https://github.com/davidjbradshaw/iframe-resizer/docs/parent_page/options.md) - * [Events](https://github.com/davidjbradshaw/iframe-resizer/docs/parent_page/events.md) - * [Methods](https://github.com/davidjbradshaw/iframe-resizer/docs/parent_page/methods.md) -* **IFramed Page API** - * [Options](https://github.com/davidjbradshaw/iframe-resizer/docs/iframed_page/options.md) - * [Events](https://github.com/davidjbradshaw/iframe-resizer/docs/iframed_page/events.md) - * [Methods](https://github.com/davidjbradshaw/iframe-resizer/docs/iframed_page/methods.md) -* [Use with jQuery](https://github.com/davidjbradshaw/iframe-resizer/docs/jquery.md) -* [Troubleshooting](https://github.com/davidjbradshaw/iframe-resizer/docs/troubleshooting.md) -* [Upgrade from version 3](https://github.com/davidjbradshaw/iframe-resizer/docs/upgrade.md) -* [Version history](https://github.com/davidjbradshaw/iframe-resizer/CHANGELOG.md) +- **Parent Page API** + - [Options](https://github.com/davidjbradshaw/iframe-resizer/docs/parent_page/options.md) + - [Events](https://github.com/davidjbradshaw/iframe-resizer/docs/parent_page/events.md) + - [Methods](https://github.com/davidjbradshaw/iframe-resizer/docs/parent_page/methods.md) +- **IFramed Page API** + - [Options](https://github.com/davidjbradshaw/iframe-resizer/docs/iframed_page/options.md) + - [Events](https://github.com/davidjbradshaw/iframe-resizer/docs/iframed_page/events.md) + - [Methods](https://github.com/davidjbradshaw/iframe-resizer/docs/iframed_page/methods.md) +- [Use with jQuery](https://github.com/davidjbradshaw/iframe-resizer/docs/jquery.md) +- [Troubleshooting](https://github.com/davidjbradshaw/iframe-resizer/docs/troubleshooting.md) +- [Upgrade from version 3](https://github.com/davidjbradshaw/iframe-resizer/docs/upgrade.md) +- [Version history](https://github.com/davidjbradshaw/iframe-resizer/CHANGELOG.md) ## License Copyright © 2013-19 [David J. Bradshaw](https://github.com/davidjbradshaw).\ Licensed under the [MIT License](LICENSE). + - - - - - -
- - -
- - - - - \ No newline at end of file + + + + + +
+ + +
+ + + + diff --git a/example/frame.nested.html b/example/frame.nested.html index c17514633..863c62875 100644 --- a/example/frame.nested.html +++ b/example/frame.nested.html @@ -1,76 +1,100 @@ - + + + iFrame message passing test + + + + - - - - Back to page 1 -

Nested iFrame

-

Resize window or click one of the links in the nested iFrame to watch it resize.

-
- -
-

-

- - - - - + + + - + $('iframe') + .attr('id', 'nestedIFrame' + level) + .attr('src', 'frame.content.html?' + level) - + /* + * If you do not understand what the code below does, then please just use the + * following call in your own code. + * + * iFrameResize({log:true}); + * + * Once you have it working, set the log option to false. + */ + iFrameResize({ + log: true, // Enable console logging + inPageLinks: true, + onResized: function(messageData) { + // Callback fn when message is received + $('p#callback').html( + 'Frame ID: ' + + messageData.iframe.id + + ' Height: ' + + messageData.height + + ' Width: ' + + messageData.width + + ' Event type: ' + + messageData.type + ) + }, + onMessage: function(messageData) { + // Callback fn when message is received + parentIFrame.sendMessage( + messageData.message + ' (via ' + $('iframe').attr('id') + ')' + ) + }, + onClosed: function(id) { + /// Callback fn when iFrame is closed + $('p#callback').html( + 'IFrame (' + id + ') removed from page.' + ) + } + }) + + + diff --git a/example/frame.textarea.html b/example/frame.textarea.html index c6b18d177..e288743ce 100644 --- a/example/frame.textarea.html +++ b/example/frame.textarea.html @@ -1,52 +1,45 @@ - - - - iFrame message passing test - - - - - - - - iFrame TextArea Example - Back to page 1 - - -

- Resize the textarea below. -

- - - - - - - - - - - \ No newline at end of file + + + iFrame message passing test + + + + + + + iFrame TextArea Example + Back to page 1 + +

+ Resize the textarea below. +

+ + + + + + + + + diff --git a/example/frame.tolerance.html b/example/frame.tolerance.html index cba1bb976..c5d4c9fa4 100644 --- a/example/frame.tolerance.html +++ b/example/frame.tolerance.html @@ -1,91 +1,113 @@ - + + + iFrame message passing test + + + - - - iFrame message passing test - - - - - - -

- iFrame - - Back to page 1 -   - Bottom -

-

- This page has an absolute position elemnt that take it out side the normal document body, which is marked with a red - border on this page. This prevents the normal height calculation, which is based on the body tag from returning the - correct height. To work around this you can set the heightCalculationMethod option to use one of the other - page height propeties. -

-

- Use the dropdown to change the sizing method of the page, select the different sizing options to see how the effect - the page. Note that they can have different effects in different browsers, so you are normally best off selecting max - if you need to change away from the default bodyOffset option. -

-

- Height Calculation Method - -

-

- This option should be used sparingly, as the alternate methods can be less acurate at working out the correct page - size, can cause screen flicker and can sometimes fail to reduce in size when the frame content changes in browsers - that do not support mutationObservers (See caniuse.com for - details). -

- -
- Absolute positioned element - Top -
- - - - + Back to page 1 +   + Bottom +

+

+ This page has an absolute position elemnt that take it out side the normal + document body, which is marked with a red border on this page. This + prevents the normal height calculation, which is based on the body tag + from returning the correct height. To work around this you can set the + heightCalculationMethod option to use one of the other page height + propeties. +

+

+ Use the dropdown to change the sizing method of the page, select the + different sizing options to see how the effect the page. Note that they + can have different effects in different browsers, so you are normally best + off selecting max if you need to change away from the default + bodyOffset option. +

+

+ Height Calculation Method + +

+

+ This option should be used sparingly, as the alternate methods can be + less acurate at working out the correct page size, can cause screen + flicker and can sometimes fail to reduce in size when the frame content + changes in browsers that do not support mutationObservers (See + caniuse.com for + details). +

- +
+ Absolute positioned element + Top +
- \ No newline at end of file + + + + + diff --git a/example/index.html b/example/index.html index 4fe60fc70..262a5084f 100644 --- a/example/index.html +++ b/example/index.html @@ -1,75 +1,83 @@ - + + + iFrame message passing test + + + + - - - iFrame message passing test - - - - - - -

Automagically resizing iFrame

-

Resize window or click one of the links in the iFrame to watch it resize. Or try with two iFrames.

-
- -
-

-

-
- For details on how this works, see - http://davidjbradshaw.github.io/iframe-resizer/. -
- - - - - - - - + + + + diff --git a/example/two.html b/example/two.html index 193633f81..e6ddbf97c 100644 --- a/example/two.html +++ b/example/two.html @@ -1,75 +1,88 @@ + + + iFrame message passing test + + + + - - - iFrame message passing test - - - - + +

Automagically resizing iFrame

+

+ Resize window or click one of the links in the iFrame to watch it resize. + Or go back to a + single iFrame. +

+
+ + +
+

+
+ For details on how this works, see + http://davidjbradshaw.github.io/iframe-resizer/. +
- -

Automagically resizing iFrame

-

Resize window or click one of the links in the iFrame to watch it resize. Or go back to a single iFrame.

-
- - -
-

-

-
- For details on how this works, see - http://davidjbradshaw.github.io/iframe-resizer/. -
+ + - - - - - - - + + + + diff --git a/js/iframeResizer.contentWindow.min.js b/js/iframeResizer.contentWindow.min.js index 1a39fa37d..6abf567d2 100644 --- a/js/iframeResizer.contentWindow.min.js +++ b/js/iframeResizer.contentWindow.min.js @@ -1,4 +1,4 @@ -/*! iFrame Resizer (iframeSizer.contentWindow.min.js) - v3.6.5 - 2019-02-15 +/*! iFrame Resizer (iframeSizer.contentWindow.min.js) - v3.6.5 - 2019-02-24 * Desc: Include this file in any page being loaded into an iframe * to force the iframe to resize to the content size. * Requires: iframeResizer.min.js on host page. diff --git a/js/iframeResizer.min.js b/js/iframeResizer.min.js index de03f651a..73273f447 100644 --- a/js/iframeResizer.min.js +++ b/js/iframeResizer.min.js @@ -1,4 +1,4 @@ -/*! iFrame Resizer (iframeSizer.min.js ) - v3.6.5 - 2019-02-15 +/*! iFrame Resizer (iframeSizer.min.js ) - v3.6.5 - 2019-02-24 * Desc: Force cross domain iframes to size to content. * Requires: iframeResizer.contentWindow.min.js to be loaded into the target frame. * Copyright: (c) 2019 David J. Bradshaw - dave@bradshaw.net diff --git a/karma.conf.js b/karma.conf.js index 640db34cd..ff2c26a0a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -76,5 +76,5 @@ module.exports = function(config) { // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits singleRun: true - }); -}; + }) +} diff --git a/spec/_initSpec.js b/spec/_initSpec.js index 74a520ac7..0ae362e8b 100644 --- a/spec/_initSpec.js +++ b/spec/_initSpec.js @@ -1,10 +1,10 @@ define(['iframeResizer'], function(iFrameResize) { describe('iFrame init', function() { - var iframe; - var id = 'initTest'; + var iframe + var id = 'initTest' beforeEach(function(done) { - loadIFrame('iframe600.html'); + loadIFrame('iframe600.html') iframe = iFrameResize({ log: LOG, @@ -23,39 +23,39 @@ define(['iframeResizer'], function(iFrameResize) { sizeWidth: true, tolerance: 1, onInit: function() { - setTimeout(done, 1); + setTimeout(done, 1) } - })[0]; - }); + })[0] + }) afterEach(function() { //tearDown(iframe); - }); + }) it('should add an ID', function() { - expect(iframe.id.split('-')[0]).toBe(id); - }); + expect(iframe.id.split('-')[0]).toBe(id) + }) describe('methods', function() { it('should create iFrameResizer object', function() { - expect(iframe.iFrameResizer).toBeDefined(); - }); + expect(iframe.iFrameResizer).toBeDefined() + }) it('should create a close method', function() { - expect(iframe.iFrameResizer.close).toBeDefined(); - }); + expect(iframe.iFrameResizer.close).toBeDefined() + }) it('should create a resize method', function() { - expect(iframe.iFrameResizer.resize).toBeDefined(); - }); + expect(iframe.iFrameResizer.resize).toBeDefined() + }) it('should create a moveToAnchor method', function() { - expect(iframe.iFrameResizer.moveToAnchor).toBeDefined(); - }); + expect(iframe.iFrameResizer.moveToAnchor).toBeDefined() + }) it('should create a sendMessage method', function() { - expect(iframe.iFrameResizer.sendMessage).toBeDefined(); - }); - }); - }); -}); + expect(iframe.iFrameResizer.sendMessage).toBeDefined() + }) + }) + }) +}) diff --git a/spec/anchorSpec.js b/spec/anchorSpec.js index 64317ce9b..807df0aba 100644 --- a/spec/anchorSpec.js +++ b/spec/anchorSpec.js @@ -1,62 +1,62 @@ define(['iframeResizer'], function(iFrameResize) { describe('jump to anchor', function() { - var iframe; - var log = LOG; - var testId = 'anchor'; + var iframe + var log = LOG + var testId = 'anchor' beforeEach(function() { - loadIFrame('iframe600.html'); - }); + loadIFrame('iframe600.html') + }) afterEach(function() { - tearDown(iframe); - }); + tearDown(iframe) + }) it('requested from host page', function(done) { var iframe1 = iFrameResize({ log: log, id: 'anchor1' - })[0]; + })[0] - spyOnIFramePostMessage(iframe1); + spyOnIFramePostMessage(iframe1) setTimeout(function() { - iframe1.iFrameResizer.moveToAnchor('testAnchor'); + iframe1.iFrameResizer.moveToAnchor('testAnchor') expect(iframe1.contentWindow.postMessage).toHaveBeenCalledWith( '[iFrameSizer]moveToAnchor:testAnchor', getTarget(iframe1) - ); - tearDown(iframe1); - done(); - }, 100); - }); + ) + tearDown(iframe1) + done() + }, 100) + }) it('mock incoming message', function(done) { iframe2 = iFrameResize({ log: log, id: 'anchor2', onScroll: function(position) { - expect(position.x).toBe(8); - expect(position.y).toBeGreaterThan(8); - done(); + expect(position.x).toBe(8) + expect(position.y).toBeGreaterThan(8) + done() } - })[0]; + })[0] - mockMsgFromIFrame(iframe2, 'inPageLink:#anchorParentTest'); - }); + mockMsgFromIFrame(iframe2, 'inPageLink:#anchorParentTest') + }) it('mock incoming message to parent', function(done) { iframe3 = iFrameResize({ log: log, id: 'anchor3' - })[0]; + })[0] window.parentIFrame = { moveToAnchor: function() { - done(); + done() } - }; + } - mockMsgFromIFrame(iframe3, 'inPageLink:#anchorParentTest2'); - }); - }); -}); + mockMsgFromIFrame(iframe3, 'inPageLink:#anchorParentTest2') + }) + }) +}) diff --git a/spec/childSpec.js b/spec/childSpec.js index d1722d4e3..f62233222 100644 --- a/spec/childSpec.js +++ b/spec/childSpec.js @@ -5,499 +5,499 @@ define(['iframeResizerContent', 'jquery'], function(mockMsgListener, $) { source: { postMessage: function(msg) { if (log) { - console.log('PostMessage: ' + msg); + console.log('PostMessage: ' + msg) } } } - }; + } } window.iFrameResizer = { onMessage: function(msg) { - msgCalled = msg; + msgCalled = msg }, onReady: function() { - this.readyCalled = true; + this.readyCalled = true }, targetOrigin: '*' - }; + } - $(window.document.body).append(''); + $(window.document.body).append('') //test early message is ignored - mockMsgListener(createMsg('resize')); + mockMsgListener(createMsg('resize')) var id = 'parentIFrameTests', log = true, childMsg = '8:true:' + log + - ':9999:true:false:-8px:max:wheat:null:0:true:child:scroll'; - (msgObject = createMsg(id + ':' + childMsg)), - (win = mockMsgListener(msgObject)); + ':9999:true:false:-8px:max:wheat:null:0:true:child:scroll' + ;(msgObject = createMsg(id + ':' + childMsg)), + (win = mockMsgListener(msgObject)) //test reset is ignored during init - mockMsgListener(createMsg('reset')); + mockMsgListener(createMsg('reset')) - window.msgCalled = null; + window.msgCalled = null //window.readyCalled = null; beforeEach(function() { - spyOn(msgObject.source, 'postMessage'); - spyOn(window.iFrameResizer, 'onMessage'); - spyOn(window.iFrameResizer, 'onReady'); - spyOn(console, 'log'); - spyOn(console, 'warn'); - }); + spyOn(msgObject.source, 'postMessage') + spyOn(window.iFrameResizer, 'onMessage') + spyOn(window.iFrameResizer, 'onReady') + spyOn(console, 'log') + spyOn(console, 'warn') + }) afterAll(function() { - win.parentIFrame.close(); - }); + win.parentIFrame.close() + }) describe('ParentIFrame methods: ', function() { it('autoResize', function() { - win.parentIFrame.autoResize(true); + win.parentIFrame.autoResize(true) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Add event listener: Animation Start' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Add event listener: Animation Iteration' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Add event listener: Animation End' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Add event listener: Orientation Change' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Add event listener: Input' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Add event listener: Print' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Add event listener: Transition End' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Add event listener: Mouse Up' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Add event listener: Mouse Down' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Add event listener: IFrame Resized' - ); - win.parentIFrame.autoResize(false); + ) + win.parentIFrame.autoResize(false) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Remove event listener: Animation Start' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Remove event listener: Animation Iteration' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Remove event listener: Animation End' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Remove event listener: Orientation Change' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Remove event listener: Input' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Remove event listener: Print' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Remove event listener: Transition End' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Remove event listener: Mouse Up' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Remove event listener: Mouse Down' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Remove event listener: IFrame Resized' - ); - }); + ) + }) it('Get ID of iFrame is same as iFrame', function() { - expect(win.parentIFrame.getId()).toBe(id); - }); + expect(win.parentIFrame.getId()).toBe(id) + }) it('move to anchor', function() { - win.parentIFrame.moveToAnchor('foo'); + win.parentIFrame.moveToAnchor('foo') expect(msgObject.source.postMessage).toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:0:0:inPageLink:#foo', '*' - ); - win.parentIFrame.moveToAnchor('bar'); + ) + win.parentIFrame.moveToAnchor('bar') expect(msgObject.source.postMessage.calls.argsFor(1)[0]).toContain( ':scrollToOffset' - ); - }); + ) + }) it('reset', function() { - win.parentIFrame.reset(); + win.parentIFrame.reset() expect(msgObject.source.postMessage.calls.argsFor(0)[0]).toContain( ':reset' - ); - }); + ) + }) it('getPageInfo', function(done) { win.parentIFrame.getPageInfo(function(pageInfo) { - expect(pageInfo.iframeHeight).toBe(500); - expect(pageInfo.iframeWidth).toBe(300); - expect(pageInfo.clientHeight).toBe(645); - expect(pageInfo.clientWidth).toBe(1295); - expect(pageInfo.offsetLeft).toBe(20); - expect(pageInfo.offsetTop).toBe(85); - expect(pageInfo.scrollTop).toBe(0); - expect(pageInfo.scrollLeft).toBe(0); - done(); - }); + expect(pageInfo.iframeHeight).toBe(500) + expect(pageInfo.iframeWidth).toBe(300) + expect(pageInfo.clientHeight).toBe(645) + expect(pageInfo.clientWidth).toBe(1295) + expect(pageInfo.offsetLeft).toBe(20) + expect(pageInfo.offsetTop).toBe(85) + expect(pageInfo.scrollTop).toBe(0) + expect(pageInfo.scrollLeft).toBe(0) + done() + }) expect(msgObject.source.postMessage).toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:0:0:pageInfo', '*' - ); + ) mockMsgListener( createMsg( 'pageInfo:{"iframeHeight":500,"iframeWidth":300,"clientHeight":645,"clientWidth":1295,"offsetLeft":20,"offsetTop":85,"scrollLeft":0,"scrollTop":0}' ) - ); - }); + ) + }) it('getPageInfoStop', function() { - win.parentIFrame.getPageInfo(); + win.parentIFrame.getPageInfo() expect(msgObject.source.postMessage).toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:0:0:pageInfoStop', '*' - ); - }); + ) + }) it('scrollTo', function() { - win.parentIFrame.scrollTo(10, 10); + win.parentIFrame.scrollTo(10, 10) expect(msgObject.source.postMessage).toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:10:10:scrollTo', '*' - ); - }); + ) + }) it('scrollToOffset', function() { - win.parentIFrame.scrollToOffset(10, 10); + win.parentIFrame.scrollToOffset(10, 10) expect(msgObject.source.postMessage).toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:10:10:scrollToOffset', '*' - ); - }); + ) + }) it('sendMessage (string)', function() { - win.parentIFrame.sendMessage('foo:bar'); + win.parentIFrame.sendMessage('foo:bar') expect(msgObject.source.postMessage).toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:0:0:message:"foo:bar"', '*' - ); - }); + ) + }) it('sendMessage (object)', function() { - win.parentIFrame.sendMessage({ foo: 'bar' }, 'http://foo.bar:1337'); + win.parentIFrame.sendMessage({ foo: 'bar' }, 'http://foo.bar:1337') expect(msgObject.source.postMessage).toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:0:0:message:{"foo":"bar"}', 'http://foo.bar:1337' - ); - }); + ) + }) xit('setTargetOrigin', function() { - var targetOrigin = 'http://foo.bar:1337'; - win.parentIFrame.setTargetOrigin(targetOrigin); - win.parentIFrame.size(10, 10); - win.parentIFrame.setTargetOrigin('*'); + var targetOrigin = 'http://foo.bar:1337' + win.parentIFrame.setTargetOrigin(targetOrigin) + win.parentIFrame.size(10, 10) + win.parentIFrame.setTargetOrigin('*') expect(msgObject.source.postMessage).toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:10:10:size', targetOrigin - ); - }); - }); + ) + }) + }) describe('inbound message: ', function() { it('readyCallack', function() { - expect(window.readyCalled).toEqual(true); - }); + expect(window.readyCalled).toEqual(true) + }) it('message (String)', function() { - var msg = 'foo'; - mockMsgListener(createMsg('message:' + JSON.stringify(msg))); - expect(msgCalled).toBe(msg); - }); + var msg = 'foo' + mockMsgListener(createMsg('message:' + JSON.stringify(msg))) + expect(msgCalled).toBe(msg) + }) it('message (Object)', function() { - var msg = { foo: 'bar' }; - mockMsgListener(createMsg('message:' + JSON.stringify(msg))); - expect(msgCalled.foo).toBe('bar'); - }); + var msg = { foo: 'bar' } + mockMsgListener(createMsg('message:' + JSON.stringify(msg))) + expect(msgCalled.foo).toBe('bar') + }) xit('reset', function(done) { // timing issue in Chrome setTimeout(function() { //Wait for init lock to clear - mockMsgListener(createMsg('reset')); - console.log('>> ', msgObject.source.postMessage.calls.argsFor(0)); + mockMsgListener(createMsg('reset')) + console.log('>> ', msgObject.source.postMessage.calls.argsFor(0)) expect(msgObject.source.postMessage.calls.argsFor(0)[0]).toContain( ':reset' - ); - done(); - }, 200); - }); + ) + done() + }, 200) + }) it('resize(max)', function() { - win.parentIFrame.setHeightCalculationMethod('max'); - mockMsgListener(createMsg('resize')); + win.parentIFrame.setHeightCalculationMethod('max') + mockMsgListener(createMsg('resize')) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Trigger event: Parent window requested size check' - ); - }); + ) + }) it('resize(lowestElement)', function() { - win.parentIFrame.setHeightCalculationMethod('lowestElement'); - mockMsgListener(createMsg('resize')); + win.parentIFrame.setHeightCalculationMethod('lowestElement') + mockMsgListener(createMsg('resize')) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Trigger event: Parent window requested size check' - ); - }); + ) + }) it('resize(rightMostElement)', function() { - win.parentIFrame.setWidthCalculationMethod('rightMostElement'); - mockMsgListener(createMsg('resize')); + win.parentIFrame.setWidthCalculationMethod('rightMostElement') + mockMsgListener(createMsg('resize')) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Trigger event: Parent window requested size check' - ); - }); + ) + }) it('move to anchor', function() { - mockMsgListener(createMsg('moveToAnchor:foo')); + mockMsgListener(createMsg('moveToAnchor:foo')) expect(msgObject.source.postMessage).toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:0:0:inPageLink:#foo', '*' - ); - }); + ) + }) xit('unexpected message', function() { - mockMsgListener(createMsg('foo')); + mockMsgListener(createMsg('foo')) expect(console.warn).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] Unexpected message ([iFrameSizer]foo)' - ); - }); - }); + ) + }) + }) describe('performance: ', function() { it('trottles', function(done) { - win.parentIFrame.size(10, 10); - win.parentIFrame.size(20, 10); - win.parentIFrame.size(30, 10); - win.parentIFrame.size(40, 10); - win.parentIFrame.size(50, 10); - win.parentIFrame.size(60, 10); + win.parentIFrame.size(10, 10) + win.parentIFrame.size(20, 10) + win.parentIFrame.size(30, 10) + win.parentIFrame.size(40, 10) + win.parentIFrame.size(50, 10) + win.parentIFrame.size(60, 10) setTimeout(function() { // expect(msgObject.source.postMessage).toHaveBeenCalledWith('[iFrameSizer]parentIFrameTests:10:10:size', '*'); expect(msgObject.source.postMessage).not.toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:20:10:size', '*' - ); + ) expect(msgObject.source.postMessage).not.toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:30:10:size', '*' - ); + ) expect(msgObject.source.postMessage).not.toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:40:10:size', '*' - ); + ) expect(msgObject.source.postMessage).not.toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:50:10:size', '*' - ); + ) expect(msgObject.source.postMessage).toHaveBeenCalledWith( '[iFrameSizer]parentIFrameTests:60:10:size', '*' - ); - done(); - }, 17); - }); - }); + ) + done() + }, 17) + }) + }) describe('height calculation methods: ', function() { it('invalid', function() { - win.parentIFrame.setHeightCalculationMethod('foo'); + win.parentIFrame.setHeightCalculationMethod('foo') expect(console.warn).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] foo is not a valid option for heightCalculationMethod.' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] height calculation method set to "bodyOffset"' - ); - win.parentIFrame.size(); - }); + ) + win.parentIFrame.size() + }) it('bodyOffset', function(done) { setTimeout(function() { - win.parentIFrame.setHeightCalculationMethod('bodyOffset'); - win.parentIFrame.size(); - done(); - }, 10); - }); + win.parentIFrame.setHeightCalculationMethod('bodyOffset') + win.parentIFrame.size() + done() + }, 10) + }) it('offset', function(done) { setTimeout(function() { - win.parentIFrame.setHeightCalculationMethod('offset'); - win.parentIFrame.size(); - done(); - }, 20); - }); + win.parentIFrame.setHeightCalculationMethod('offset') + win.parentIFrame.size() + done() + }, 20) + }) it('bodyScroll', function(done) { setTimeout(function() { - win.parentIFrame.setHeightCalculationMethod('bodyScroll'); - win.parentIFrame.size(); - done(); - }, 30); - }); + win.parentIFrame.setHeightCalculationMethod('bodyScroll') + win.parentIFrame.size() + done() + }, 30) + }) it('documentElementOffset', function(done) { setTimeout(function() { - win.parentIFrame.setHeightCalculationMethod('documentElementOffset'); - win.parentIFrame.size(); - done(); - }, 40); - }); + win.parentIFrame.setHeightCalculationMethod('documentElementOffset') + win.parentIFrame.size() + done() + }, 40) + }) it('documentElementScroll', function(done) { setTimeout(function() { - win.parentIFrame.setHeightCalculationMethod('documentElementScroll'); - win.parentIFrame.size(); - done(); - }, 50); - }); + win.parentIFrame.setHeightCalculationMethod('documentElementScroll') + win.parentIFrame.size() + done() + }, 50) + }) it('max', function(done) { setTimeout(function() { - win.parentIFrame.setHeightCalculationMethod('max'); - win.parentIFrame.size(); - done(); - }, 60); - }); + win.parentIFrame.setHeightCalculationMethod('max') + win.parentIFrame.size() + done() + }, 60) + }) it('min', function(done) { setTimeout(function() { - win.parentIFrame.setHeightCalculationMethod('min'); - win.parentIFrame.size(); - done(); - }, 70); - }); + win.parentIFrame.setHeightCalculationMethod('min') + win.parentIFrame.size() + done() + }, 70) + }) it('grow', function(done) { setTimeout(function() { - win.parentIFrame.setHeightCalculationMethod('grow'); - win.parentIFrame.size(); - done(); - }, 80); - }); + win.parentIFrame.setHeightCalculationMethod('grow') + win.parentIFrame.size() + done() + }, 80) + }) it('lowestElement', function(done) { setTimeout(function() { - win.parentIFrame.setHeightCalculationMethod('lowestElement'); - win.parentIFrame.size(); - done(); - }, 90); - }); + win.parentIFrame.setHeightCalculationMethod('lowestElement') + win.parentIFrame.size() + done() + }, 90) + }) it('taggedElement', function(done) { setTimeout(function() { - win.parentIFrame.setHeightCalculationMethod('taggedElement'); - win.parentIFrame.size(); - done(); - }, 100); - }); - }); + win.parentIFrame.setHeightCalculationMethod('taggedElement') + win.parentIFrame.size() + done() + }, 100) + }) + }) describe('width calculation methods: ', function() { it('invalid', function() { - win.parentIFrame.setWidthCalculationMethod('foo'); + win.parentIFrame.setWidthCalculationMethod('foo') expect(console.warn).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] foo is not a valid option for widthCalculationMethod.' - ); + ) expect(console.log).toHaveBeenCalledWith( '[iFrameSizer][parentIFrameTests] width calculation method set to "scroll"' - ); - win.parentIFrame.size(); - }); + ) + win.parentIFrame.size() + }) it('bodyOffset', function(done) { setTimeout(function() { - win.parentIFrame.setWidthCalculationMethod('bodyOffset'); - win.parentIFrame.size(); - done(); - }, 110); - }); + win.parentIFrame.setWidthCalculationMethod('bodyOffset') + win.parentIFrame.size() + done() + }, 110) + }) it('bodyScroll', function(done) { setTimeout(function() { - win.parentIFrame.setWidthCalculationMethod('bodyScroll'); - win.parentIFrame.size(); - done(); - }, 120); - }); + win.parentIFrame.setWidthCalculationMethod('bodyScroll') + win.parentIFrame.size() + done() + }, 120) + }) it('documentElementOffset', function(done) { setTimeout(function() { - win.parentIFrame.setWidthCalculationMethod('documentElementOffset'); - win.parentIFrame.size(); - done(); - }, 130); - }); + win.parentIFrame.setWidthCalculationMethod('documentElementOffset') + win.parentIFrame.size() + done() + }, 130) + }) it('documentElementScroll:', function(done) { setTimeout(function() { - win.parentIFrame.setWidthCalculationMethod('documentElementScroll:'); - win.parentIFrame.size(); - done(); - }, 140); - }); + win.parentIFrame.setWidthCalculationMethod('documentElementScroll:') + win.parentIFrame.size() + done() + }, 140) + }) it('scroll', function(done) { setTimeout(function() { - win.parentIFrame.setWidthCalculationMethod('scroll'); - win.parentIFrame.size(); - done(); - }, 150); - }); + win.parentIFrame.setWidthCalculationMethod('scroll') + win.parentIFrame.size() + done() + }, 150) + }) it('max', function(done) { setTimeout(function() { - win.parentIFrame.setWidthCalculationMethod('max'); - win.parentIFrame.size(); - done(); - }, 160); - }); + win.parentIFrame.setWidthCalculationMethod('max') + win.parentIFrame.size() + done() + }, 160) + }) it('min', function(done) { setTimeout(function() { - win.parentIFrame.setWidthCalculationMethod('min'); - win.parentIFrame.size(); - done(); - }, 170); - }); + win.parentIFrame.setWidthCalculationMethod('min') + win.parentIFrame.size() + done() + }, 170) + }) it('leftMostElement', function(done) { setTimeout(function() { - win.parentIFrame.setWidthCalculationMethod('leftMostElement'); - win.parentIFrame.size(); - done(); - }, 180); - }); + win.parentIFrame.setWidthCalculationMethod('leftMostElement') + win.parentIFrame.size() + done() + }, 180) + }) it('taggedElement', function(done) { setTimeout(function() { - win.parentIFrame.setWidthCalculationMethod('taggedElement'); - win.parentIFrame.size(); - done(); - }, 190); - }); - }); -}); + win.parentIFrame.setWidthCalculationMethod('taggedElement') + win.parentIFrame.size() + done() + }, 190) + }) + }) +}) diff --git a/spec/closeSpecSpec.js b/spec/closeSpecSpec.js index 657485e17..57588fd80 100644 --- a/spec/closeSpecSpec.js +++ b/spec/closeSpecSpec.js @@ -1,40 +1,40 @@ define(['iframeResizer'], function(iFrameResize) { describe('Close iFrame', function() { - var iframe; + var iframe beforeEach(function() { - loadIFrame('iframe600.html'); - }); + loadIFrame('iframe600.html') + }) it('closes from parent', function(done) { - var evtCounter = 0; + var evtCounter = 0 iframe = iFrameResize({ log: LOG, id: 'close1', onClosed: function() { - setTimeout(done, 0); + setTimeout(done, 0) } - })[0]; + })[0] - setTimeout(iframe.iFrameResizer.close, 1); - }); + setTimeout(iframe.iFrameResizer.close, 1) + }) it('closes from iframe', function(done) { - var evtCounter = 0; + var evtCounter = 0 iframe = iFrameResize({ log: LOG, id: 'close2', onClosed: function() { - setTimeout(done, 0); + setTimeout(done, 0) }, onInit: function(iframe) { - iframe.iFrameResizer.sendMessage('close'); + iframe.iFrameResizer.sendMessage('close') } - })[0]; + })[0] - mockMsgFromIFrame(iframe, 'close'); - }); - }); -}); + mockMsgFromIFrame(iframe, 'close') + }) + }) +}) diff --git a/spec/initCssSpec.js b/spec/initCssSpec.js index 6ced4c680..0a4bc8a1c 100644 --- a/spec/initCssSpec.js +++ b/spec/initCssSpec.js @@ -1,13 +1,13 @@ /* jshint undef: false, unused: true */ -'use strict'; +'use strict' define(['iframeResizer'], function(iFrameResize) { describe('iFrame init(CSS Selector)', function() { - var iframe; + var iframe beforeAll(function(done) { - loadIFrame('iframe600.html'); + loadIFrame('iframe600.html') iframe = iFrameResize( { @@ -24,15 +24,15 @@ define(['iframeResizer'], function(iFrameResize) { ] }, 'iframe' - )[0]; - }); + )[0] + }) afterAll(function() { - tearDown(iframe); - }); + tearDown(iframe) + }) it('should create iFrameResizer object', function() { - expect(iframe.iFrameResizer).toBeDefined(); - }); - }); -}); + expect(iframe.iFrameResizer).toBeDefined() + }) + }) +}) diff --git a/spec/initDomSpec.js b/spec/initDomSpec.js index 451f06a41..338ee7f80 100644 --- a/spec/initDomSpec.js +++ b/spec/initDomSpec.js @@ -1,28 +1,28 @@ /* jshint undef: false, unused: true */ -'use strict'; +'use strict' define(['iframeResizer'], function(iFrameResize) { describe('iFrame init(DOM Object)', function() { - var iframe; + var iframe beforeAll(function() { - loadIFrame('iframe600.html'); + loadIFrame('iframe600.html') iframe = iFrameResize( { log: LOG }, document.getElementsByTagName('iframe')[0] - )[0]; - }); + )[0] + }) afterAll(function() { - tearDown(iframe); - }); + tearDown(iframe) + }) it('should create iFrameResizer object', function() { - expect(iframe.iFrameResizer).toBeDefined(); - }); - }); -}); + expect(iframe.iFrameResizer).toBeDefined() + }) + }) +}) diff --git a/spec/initDoubleCallSpec.js b/spec/initDoubleCallSpec.js index 43106f7d1..1663a70b5 100644 --- a/spec/initDoubleCallSpec.js +++ b/spec/initDoubleCallSpec.js @@ -1,31 +1,31 @@ /* jshint undef: false, unused: true */ -'use strict'; +'use strict' define(['iframeResizer'], function(iFrameResize) { describe('iFrame init(Double)', function() { - var iframe; + var iframe beforeAll(function() { - loadIFrame('iframe600WithId.html'); + loadIFrame('iframe600WithId.html') //spyOn(console,'warn'); - }); + }) afterAll(function() { - tearDown(iframe); - }); + tearDown(iframe) + }) it('should create iFrameResizer object', function() { window.parentIFrame = { getId: function() { - return 'getIdTest'; + return 'getIdTest' } - }; - iframe = iFrameResize({ log: LOG }, '#doubleTest')[0]; - iFrameResize({ log: LOG }, '#doubleTest'); - expect(iframe.iFrameResizer).toBeDefined(); - expect(console.warn).toHaveBeenCalled(); - delete window.parentIFrame; - }); - }); -}); + } + iframe = iFrameResize({ log: LOG }, '#doubleTest')[0] + iFrameResize({ log: LOG }, '#doubleTest') + expect(iframe.iFrameResizer).toBeDefined() + expect(console.warn).toHaveBeenCalled() + delete window.parentIFrame + }) + }) +}) diff --git a/spec/initErrorSpec.js b/spec/initErrorSpec.js index 5b0115964..7394bbfdf 100644 --- a/spec/initErrorSpec.js +++ b/spec/initErrorSpec.js @@ -1,11 +1,11 @@ define(['iframeResizer'], function(iFrameResize) { describe('Setup error', function() { - var iframe; - var log = LOG; + var iframe + var log = LOG beforeEach(function() { - loadIFrame('iframe600.html'); - }); + loadIFrame('iframe600.html') + }) it('min > max', function() { expect(function() { @@ -14,11 +14,11 @@ define(['iframeResizer'], function(iFrameResize) { id: 'error1', maxHeight: 100, minHeight: 999 - }); + }) }).toThrow( new Error('Value for minHeight can not be greater than maxHeight') - ); - }); + ) + }) it('Unexpected data type', function() { expect(function() { @@ -28,9 +28,9 @@ define(['iframeResizer'], function(iFrameResize) { id: 'error2' }, 1 - ); - }).toThrow(new TypeError('Unexpected data type (number)')); - }); + ) + }).toThrow(new TypeError('Unexpected data type (number)')) + }) it('Expected + + + QUnit LoadHide + + + + +
+
+
+ +
- - - - - - - - - + + + + + + diff --git a/test/_init_once.html b/test/_init_once.html index 01104c7fc..25f7bbac0 100644 --- a/test/_init_once.html +++ b/test/_init_once.html @@ -1,48 +1,52 @@ + + + QUnit LoadHide + + - - - QUnit LoadHide - - - - -
-
- -
- + +
+
+
+ +
- -
- - - - - + + + + - - + }) + }) + + diff --git a/test/_init_once_async.html b/test/_init_once_async.html index e8953762d..dbf1fd691 100644 --- a/test/_init_once_async.html +++ b/test/_init_once_async.html @@ -1,75 +1,73 @@ + + + QUnit LoadHide + + - - - QUnit LoadHide - - - - -
-
- -
- + +
+
+
+ +
- -
- - - - - + + + + - - + }) + }) + + diff --git a/test/background.html b/test/background.html index 5edb66acb..9b1e4fd62 100644 --- a/test/background.html +++ b/test/background.html @@ -1,50 +1,47 @@ - - - - QUnit LoadHide - - - - -
-
- -
- + + + QUnit LoadHide + + + + +
+
+
+ +
- -
- - - - - - - - + + + + + + + diff --git a/test/changePage.html b/test/changePage.html index 4f28b6d3a..8e1074b6a 100644 --- a/test/changePage.html +++ b/test/changePage.html @@ -1,53 +1,55 @@ - - - - QUnit LoadHide - - - - -
-
- -
- + + + QUnit LoadHide + + + + +
+
+
+ +
- -
- - - - - - + + + + + - - + }) + }) + + diff --git a/test/close.html b/test/close.html index 7805d7f40..73b389ed8 100644 --- a/test/close.html +++ b/test/close.html @@ -1,47 +1,44 @@ - - - - QUnit LoadHide - - - - -
-
- -
- + + + QUnit LoadHide + + + + +
+
+
+ +
- -
- - - - - - - - + + + + + + + diff --git a/test/getId.html b/test/getId.html index dda3c12bc..a88322ade 100644 --- a/test/getId.html +++ b/test/getId.html @@ -1,47 +1,48 @@ - - - - QUnit LoadHide - - - - -
-
- -
- + + + QUnit LoadHide + + + + +
+
+
+ +
- -
- - - - - - - - + + + + + + + diff --git a/test/interval.html b/test/interval.html index f16cce639..b0d05897c 100644 --- a/test/interval.html +++ b/test/interval.html @@ -1,59 +1,59 @@ - - - - QUnit LoadHide - - - - -
-
- -
- + + + QUnit LoadHide + + + + +
+
+
+ +
- -
- - - - - - + + + + + - - + }) + }) + + diff --git a/test/jqueryNoConflict.html b/test/jqueryNoConflict.html index 9efc3324d..8e3f6dff5 100644 --- a/test/jqueryNoConflict.html +++ b/test/jqueryNoConflict.html @@ -1,50 +1,49 @@ + + + QUnit LoadHide + + - - - QUnit LoadHide - - - - -
-
- -
- + +
+
+
+ +
+ + + + + - - - - - - + asyncTest('init with jQuery.noConflict', function() { + try { + $('iframe').iFrameResize({ + //log:true, + bodyBackground: 'wheat', + heightCalculationMethod: 'max', + onInit: function(iframe) { + ok(true, 'Receive init message back from iFrame.') + start() + } + }) + } catch (e) { + console.log(e) + ok(false) + start() + } + }) + + diff --git a/test/lateImageLoad.html b/test/lateImageLoad.html index 7fe73eea3..2ca9a767b 100644 --- a/test/lateImageLoad.html +++ b/test/lateImageLoad.html @@ -1,93 +1,92 @@ + + + QUnit LoadHide + + - - - QUnit LoadHide - - - - -
-
- -
- + +
+
+
+ +
+ + + + + + - - - - - - + }) + }) + } + // if (MutationObserver) + // mutationObserverTest() + // else{ + // console.warn('(MutationObserver not supported in this browser! Unable to run test)'); + // test('iFrame MutationObserver',function(){ + // ok(true,'MutationObserver not supported in this browser! Unable to run test.'); + // }); + // } + + diff --git a/test/margin.html b/test/margin.html index d370263a8..ad18fb426 100644 --- a/test/margin.html +++ b/test/margin.html @@ -1,76 +1,67 @@ + + + QUnit LoadHide + + - - - QUnit LoadHide - - - - -
-
- -
- + +
+
+
+ +
+ + + + + + - - - - - - + iFrameResize({ + //log:true, + bodyMargin: margin, + onResized: function(messageData) { + ok(true, 'Receive message back from iFrame.') + height = parseInt(messageData.height, 10) + sendMessage('chkHeight') + }, + onMessage: function(messageData) { + var marginCheck = 2 * parseInt(margin, 10), + bodyHeight = parseInt(messageData.message, 10) + ok(height === marginCheck + bodyHeight, 'Margin = ' + margin) + console.log('.') + start() + } + }) + }) + } + + diff --git a/test/mutationObserver.html b/test/mutationObserver.html index badd7dd8e..a0d6cece1 100644 --- a/test/mutationObserver.html +++ b/test/mutationObserver.html @@ -1,66 +1,74 @@ + + + QUnit LoadHide + + - - - QUnit LoadHide - - - - -
-
- -
- + +
+
+
+ +
+ + + + + - - - - - + var MutationObserver = + window.MutationObserver || + window.WebKitMutationObserver || + window.MozMutationObserver + if (MutationObserver) mutationObserverTest() + else { + console.warn( + '(MutationObserver not supported in this browser! Unable to run test)' + ) + test('iFrame MutationObserver', function() { + ok( + true, + 'MutationObserver not supported in this browser! Unable to run test.' + ) + }) + } + + diff --git a/test/nested.html b/test/nested.html index ee3258925..5173c804c 100644 --- a/test/nested.html +++ b/test/nested.html @@ -1,49 +1,46 @@ - - - - QUnit LoadHide - - - - -
-
- -
- + + + QUnit LoadHide + + + + +
+
+
+ +
- -
- - - - - - - - + + + + + + + diff --git a/test/removeIFrame.html b/test/removeIFrame.html index 077f579ba..ade5f1886 100644 --- a/test/removeIFrame.html +++ b/test/removeIFrame.html @@ -1,83 +1,105 @@ - - + + QUnit LoadHide - - + + - -
-
-
+ +
+
+
- + +
-
- - - - - + + + + - + if ( + window.MutationObserver || + window.WebKitMutationObserver || + window.MozMutationObserver + ) { + removeIFrameTest() + } else { + console.warn( + '(MutationObserver not supported in this browser! Unable to run test)' + ) + test('Remove iFrame', function() { + ok( + true, + 'MutationObserver not supported in this browser! Unable to run test.' + ) + }) + } + + diff --git a/test/resize.contentWidth.html b/test/resize.contentWidth.html index b4b905455..405c2361c 100644 --- a/test/resize.contentWidth.html +++ b/test/resize.contentWidth.html @@ -1,54 +1,51 @@ - - - - QUnit LoadHide - - - - -
-
- -
- + + + QUnit LoadHide + + + + +
+
+
+ +
- -
- - - - - - + + + + + - - + }) + }) + + diff --git a/test/resize.width.html b/test/resize.width.html index 040e58372..d3dd5f3e8 100644 --- a/test/resize.width.html +++ b/test/resize.width.html @@ -1,66 +1,82 @@ + + + QUnit LoadHide + + - - - QUnit LoadHide - - - - -
-
- -
- + +
+
+
+ +
+ + + + - - - - - + }) + }) + + diff --git a/test/scrolling.html b/test/scrolling.html index a1f238fd7..fc144801a 100644 --- a/test/scrolling.html +++ b/test/scrolling.html @@ -1,95 +1,133 @@ + + + QUnit LoadHide + + - - - QUnit LoadHide - - - - -
-
- -
- + +
+
+
+ +
+ + + + - - - - + asyncTest('scrolling = auto', function() { + $('iframe').iFrameResize({ + //log:true, + scrolling: 'auto', + onResized: function(messageData) { + ok(true, 'Receive message back from iFrame.') + ok( + 'auto' === messageData.iframe.style.overflow, + 'iFrame overflow = ' + + messageData.iframe.style.overflow + + ". Expected 'auto'." + ) + ok( + 'auto' === messageData.iframe.scrolling, + 'iFrame scrolling = ' + + messageData.iframe.scrolling + + ". Expected 'auto'." + ) + start() + } + }) + }) + // asyncTest( "scrolling = omit", function() { + // $('iframe').removeAttr('scrolling'); + // $('iframe').iFrameResize({ + // //log:true, + // scrolling:'omit', + // onResized:function(messageData){ + // ok( true, 'Receive message back from iFrame.' ); + // ok( 'auto' === messageData.iframe.style.overflow, 'iFrame overflow = ' + messageData.iframe.style.overflow + '. Expected \'auto\'.' ); + // ok( false === ('scrolling' in messageData.iframe), 'iFrame scrolling attribute exists. Expected to be omitted.' ); + // start(); + // } + // }); + // }); + + diff --git a/test/sendMessage.html b/test/sendMessage.html index 7d6e080a5..d14335497 100644 --- a/test/sendMessage.html +++ b/test/sendMessage.html @@ -1,64 +1,65 @@ + + + QUnit LoadHide + + - - - QUnit LoadHide - - - - -
-
- -
- + +
+
+
+ +
+ + + + + + - - - - - - + asyncTest('sendMessage (string)', function() { + iFrameResize({ + //log:true, + onResized: function(messageData) { + ok(true, 'Receive init message back from iFrame.') + sendMessage('chkSendMsg') + }, + onMessage: function(messageData) { + ok( + 'message: test string' === messageData.message, + 'Receive string message back from iFrame via sendMessage function.' + ) + start() + } + }) + }) + asyncTest('sendMessage (object)', function() { + iFrameResize({ + //log:true, + onResized: function(messageData) { + ok(true, 'Receive init message back from iFrame.') + sendMessage('chkSendObj') + }, + onMessage: function(messageData) { + ok( + 'test object' === messageData.message.message, + 'Receive object message back from iFrame via sendMessage function.' + ) + start() + } + }) + }) + + diff --git a/test/setHeightCalculationMethod.html b/test/setHeightCalculationMethod.html index 0a3e223fa..aa0586bf1 100644 --- a/test/setHeightCalculationMethod.html +++ b/test/setHeightCalculationMethod.html @@ -1,51 +1,48 @@ - - - QUnit LoadHide - - - -
-
- -
- + + + QUnit LoadHide + + + +
+
+
+ +
- -
- - - - - - + + + + + - + }) + }) + + diff --git a/test/size.html b/test/size.html index f0beb91c2..9310f5a89 100644 --- a/test/size.html +++ b/test/size.html @@ -1,64 +1,74 @@ - - - QUnit LoadHide - - - -
-
- -
- + + + QUnit LoadHide + + + +
+
+
+ +
+ + + + + + - - - - - - + }) + }) + + diff --git a/test/v1.html b/test/v1.html index e0f1c103d..30cdfa8e6 100644 --- a/test/v1.html +++ b/test/v1.html @@ -1,189 +1,203 @@ - - - QUnit LoadHide - - - -
-
- -
- + + + QUnit LoadHide + + + +
+
+
+ +
- -
- - - + + - - - \ No newline at end of file + })(window.jQuery) + + + +