nirvana-msu / yii2-iframe-resizer
Yii2 extension for javascript-based iFrame Resizer
Installs: 1 770
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 2
Forks: 3
Open Issues: 0
Type:yii2-extension
Requires
- bower-asset/iframe-resizer: *
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2021-11-27 03:11:56 UTC
README
Yii2 extension for javascript-based iframe-resizer. It enables automatic resizing of height and width of both same and cross domain iFrames to fit their contained content, provided that you have control of pages both serving and hosting iFrames.
Resources
- Yii2 extension page
- iFrame Resizer library documentation
Installation
Composer
Add extension to your composer.json
and update your dependencies as usual, e.g. by running composer update
{ "require": { "nirvana-msu/yii2-iframe-resizer": "1.0.*@dev" } }
##Sample Usage
###Page Serving iFrame You need to embed one of the library scripts into the iFrame. Extension provides two shortcuts for doing this, depending on your use-case.
- If the rendered page itself is served as an iFrame content, simply register
IFrameResizer
widget in your view:
IFrameResizer::widget();
- If you need to embed the script into existing iFrame HTML code generated elsewhere, there is a convinient shortcut you can use to inject the script before closing
</body>
tag:
$injectedHtml = IFrameResizer::embed($html);
###Page Hosting iFrame
First, register IFrameResizerAsset
bundle:
IFrameResizerAsset::register($this);
Finally, call the library to enable dynamic resizing. As described in the documentation, you can do this by either using native JavaScript:
var iframes = iFrameResize( [{options}], [css selector] || [iframe] );
or via jQuery:
$('iframe').iFrameResize( [{options}] );
Note that jQuery is not specified as a dependency for this extension, since you may choose to use native version instead. Therefore if you want to use jQuery, make sure it is registered in your view.
##License
Extension is released under MIT license, same as underlying iFrame Resizer library.