@iframe-resizer/jquery
Version:
Keep iframes sized to their content.
119 lines (94 loc) • 3.43 kB
JavaScript
/*!
* @preserve
*
* @module iframe-resizer/jquery 5.5.7 (cjs) - 2025-09-23
*
* @license GPL-3.0 for non-commercial use only.
* For commercial use, you must purchase a license from
* https://iframe-resizer.com/pricing
*
* @description Keep same and cross domain iFrames sized to their content
*
* @author David J. Bradshaw <info@iframe-resizer.com>
*
* @see {@link https://iframe-resizer.com}
*
* @copyright (c) 2013 - 2025, David J. Bradshaw. All rights reserved.
*/
;
const connectResizer = require('@iframe-resizer/core');
const acg = require('auto-console-group');
const LABEL = 'iframeResizer';
const PARENT = 'parent';
const deprecate = (advise) =>
(type, change = 'renamed to') =>
(old, replacement, info = '', iframeId = '') =>
advise(
iframeId,
`<rb>Deprecated ${type}(${old.replace('()', '')})</>\n\nThe <b>${old}</> ${type.toLowerCase()} has been ${change} <b>${replacement}</>. ${info}Use of the old ${type.toLowerCase()} will be removed in a future version of <i>iframe-resizer</>.`,
);
const encode = (s) =>
s
.replaceAll('<br>', '\n')
.replaceAll('<rb>', '\u001B[31;1m')
.replaceAll('</>', '\u001B[m')
.replaceAll('<b>', '\u001B[1m')
.replaceAll('<i>', '\u001B[3m')
.replaceAll('<u>', '\u001B[4m');
const remove = (s) => s.replaceAll('<br>', '\n').replaceAll(/<[/a-z]+>/gi, '');
const formatAdvise = (formatLogMsg) => (msg) =>
window.chrome // Only show formatting in Chrome as not supported in other browsers
? formatLogMsg(encode(msg))
: formatLogMsg(remove(msg));
const id = (x) => x;
const esModuleInterop = (mod) =>
// eslint-disable-next-line no-underscore-dangle
mod?.__esModule ? mod.default : mod;
const settings = {};
// Deal with UMD not converting default exports to named exports
const createConsoleGroup = esModuleInterop(acg);
const parent = createConsoleGroup({
expand: false,
label: PARENT,
});
const output =
(type) =>
(iframeId, ...args) =>
settings[iframeId]
? settings[iframeId].console[type](...args)
: parent[type](...args);
const warn = output('warn');
const formatLogMsg =
(iframeId) =>
(...args) =>
[`${LABEL}(${iframeId})`, ...args].join(' ');
const advise = (iframeId, ...args) =>
settings[iframeId]
? settings[iframeId].console.warn(formatAdvise(id)(...args))
: queueMicrotask(
// eslint-disable-next-line no-console
() => console?.warn(formatAdvise(formatLogMsg(iframeId))(...args)),
);
const deprecateAdvise = deprecate(advise);
const deprecateMethod = deprecateAdvise('Method');
switch (true) {
case window.jQuery === undefined:
warn('', 'Unable to bind to jQuery, it is not available.');
break
case !window.jQuery.fn:
warn('', 'Unable to bind to jQuery, it is not fully loaded.');
break
case window.jQuery.fn.iframeResize:
warn('', 'iframeResize is already assigned to jQuery.fn.');
break
default:
window.jQuery.fn.iframeResize = function (options) {
const connectWithOptions = connectResizer(options);
const init = (i, el) => connectWithOptions(el);
return this.filter('iframe').each(init).end()
};
window.jQuery.fn.iFrameResize = function (options) {
deprecateMethod('iFrameResize()', 'iframeResize()', '', 'jQuery');
return this.iframeResize(options)
};
}