@videsk/iframex
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.iFrameX=t():e.iFrameX=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();e.exports=function(){function e(t){var n=t.attr,r=t.content,o=t.append,i=t.config;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.attr=n||{},this.content=r||[],this.body=document.querySelector(o)||document.querySelector("body"),this.id=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),this.events=[],this.iframe=null,this.debug=i.debug||!1,this.action="function"==typeof i.action?i.action:function(e){}}return o(e,[{key:"init",value:function(){var e=this;this._createIframe((function(t){t&&e._addElements(e.content)}))}},{key:"_createIframe",value:function(e){var t=this;if(this.iframe)console.error("An iframe already exists, please instance a new iFrameX. Read docs here: https://github.com/matiaslopezd/iframex"),"function"==typeof e&&e(null);else{var n=document.createElement("iframe");n.setAttribute("iframe-id",this.id);var r=Object.keys(this.attr);r.length>0&&r.map((function(e){n.setAttribute(e,t.attr[e])})),this.body.appendChild(n),this.iframe=document.querySelector('[iframe-id="'+this.id+'"]'),this._addEventListener(),"function"==typeof e&&e(n)}}},{key:"_addElements",value:function(e){var t=this;function n(e){var t=document.createElement(e.type);return e.content&&""!==e.content&&("script"===e.type||"style"===e.type?t.appendChild(document.createTextNode(e.content)):t.innerHTML=e.content),e.attr&&Object.keys(e.attr).map((function(n){t.setAttribute(n,e.attr[n])})),t}if(Array.isArray(e)&&e.length>0)e.map((function(e){var r=e.append?e.append:"body";setTimeout((function(){return t.iframe.contentWindow.document.querySelector(r).appendChild(n(e))}),1)}));else if("object"===(void 0===e?"undefined":r(e))){var o=e.append?e.append:"body";setTimeout((function(){return t.iframe.contentWindow.document.querySelector(o).appendChild(n(e))}),1)}}},{key:"_addEventListener",value:function(){this._addElements({type:"script",content:this._bindEvent("window","'message'",this.action)})}},{key:"_bindEvent",value:function(e,t,n){var r=null;return e="window"===e?e:"document.querySelector("+e+")",window.addEventListener?r=e+".addEventListener("+t+", "+n+", false);":window.attachEvent&&(r=e+".attachEvent(on"+t+", "+n+");"),r}}]),e}()}])})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.iFrameX=t():e.iFrameX=t()}(window,(function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}();e.exports=function(){function e(t){var n=t.attr,o=void 0===n?{}:n,r=t.content,i=void 0===r?[]:r,a=t.append,u=void 0===a?document.querySelector("body"):a,c=t.config;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.attr=o,this.content=i,this.body="string"==typeof u?document.querySelector(u):u,this.id=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15),this.events=[],this.iframe=null,this.debug=!!(c&&"debug"in c)&&c.debug,this.action=c&&"function"==typeof c.action?c.action:function(e){}}return r(e,[{key:"init",value:function(){var e=this;this._createIframe((function(t){t&&e._addElements(e.content)}))}},{key:"_createIframe",value:function(e){var t=this;if(this.iframe)console.error("An iframe already exists, please instance a new iFrameX. Read docs here: https://github.com/matiaslopezd/iframex"),"function"==typeof e&&e(null);else{var n=document.createElement("iframe");n.setAttribute("iframe-id",this.id);var o=Object.keys(this.attr);o.length>0&&o.map((function(e){n.setAttribute(e,t.attr[e])})),this.body.appendChild(n),this.iframe=document.querySelector('[iframe-id="'+this.id+'"]'),this._addEventListener(),"function"==typeof e&&e(n)}}},{key:"_addElements",value:function(e){var t=this;function n(e){var t=document.createElement(e.type);return e.content&&""!==e.content&&("script"===e.type||"style"===e.type?t.appendChild(document.createTextNode(e.content)):t.innerHTML=e.content),e.attr&&Object.keys(e.attr).map((function(n){t.setAttribute(n,e.attr[n])})),t}if(Array.isArray(e)&&e.length>0)e.map((function(e){var o=e.append?e.append:"body";setTimeout((function(){return t.iframe.contentWindow.document.querySelector(o).appendChild(n(e))}),1)}));else if("object"===(void 0===e?"undefined":o(e))){var r=e.append?e.append:"body";setTimeout((function(){return t.iframe.contentWindow.document.querySelector(r).appendChild(n(e))}),1)}}},{key:"_addEventListener",value:function(){this._addElements({type:"script",content:this._bindEvent("window","'message'",this.action)})}},{key:"_bindEvent",value:function(e,t,n){var o=null;return e="window"===e?e:"document.querySelector("+e+")",window.addEventListener?o=e+".addEventListener("+t+", "+n+", false);":window.attachEvent&&(o=e+".attachEvent(on"+t+", "+n+");"),o}}]),e}()}])})); | ||
//# sourceMappingURL=iframex.min.js.map |
{ | ||
"name": "@videsk/iframex", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Javascript Iframe generator with dynamic content injection like HTML, Javascript, CSS, etc. and postMessage included for two ways communications iframe <-> parent.", | ||
@@ -5,0 +5,0 @@ "main": "dist/iframex.min.js", |
@@ -11,9 +11,9 @@ /* | ||
constructor ({ attr , content , append , config }) { | ||
constructor ({ attr = {} , content = [] , append = document.querySelector('body') , config }) { | ||
// Iframe attributes | ||
this.attr = attr || {}; | ||
this.attr = attr; | ||
// Elements with attributes for append in to iframe | ||
this.content = content || []; | ||
this.content = content; | ||
// Element where append the iframe, by default is body | ||
this.body = document.querySelector(append) || document.querySelector('body'); | ||
this.body = (typeof append === 'string') ? document.querySelector(append) : append; | ||
// Default id for know if exist the iframe | ||
@@ -26,5 +26,5 @@ this.id = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); | ||
// Debug mode | ||
this.debug = config.debug || false; | ||
this.debug = (config && 'debug' in config) ? config.debug : false; | ||
// Action for postMessage | ||
this.action = (typeof config.action === 'function') ? config.action : function (msg) {}; | ||
this.action = (config && typeof config.action === 'function') ? config.action : function (msg) {}; | ||
}; | ||
@@ -31,0 +31,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
34554
160