Comparing version 0.2.5 to 0.3.0
@@ -0,1 +1,14 @@ | ||
<a name="0.3.0"></a> | ||
## [0.3.0](https://github.com/nfl/react-gpt/compare/v0.2.5...v0.3.0) (2017-09-18) | ||
### Code Refactoring | ||
* Throttles scroll-check to render ad faster ([7130060a](https://github.com/nfl/react-gpt/commit/7130060a)) | ||
* Use smaller invariant / canUseDom dependencies ([b187381](https://github.com/nfl/react-gpt/commit/b187381)) | ||
### Features | ||
* Check bundle-size on PR ([8e51e26](https://github.com/nfl/react-gpt/commit/8e51e26)) | ||
* Upgrade eslint and introduce prettier ([17c8b89](https://github.com/nfl/react-gpt/commit/17c8b89)) | ||
<a name="0.2.5"></a> | ||
@@ -2,0 +15,0 @@ ## [0.2.5](https://github.com/nfl/react-gpt/compare/v0.2.4...v0.2.5) (2017-07-31) |
@@ -1,1 +0,6 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],t):"object"==typeof exports?exports.ReactGPT=t(require("react"),require("react-dom")):e.ReactGPT=t(e.React,e.ReactDOM)}(this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(3);Object.defineProperty(t,"Bling",{enumerable:!0,get:function(){return r(o).default}});var a=n(1);Object.defineProperty(t,"Events",{enumerable:!0,get:function(){return r(a).default}})},function(e,t){Object.defineProperty(t,"__esModule",{value:!0});var n={READY:"ready",RENDER:"render",SLOT_RENDER_ENDED:"slotRenderEnded",IMPRESSION_VIEWABLE:"impressionViewable",SLOT_VISIBILITY_CHANGED:"slotVisibilityChanged"};t.default=n},function(e,t,n){"use strict";function r(e,t,n,r,a,i,s,u){if(o(t),!e){var l;if(void 0===t)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,a,i,s,u],d=0;l=new Error(t.replace(/%s/g,function(){return c[d++]})),l.name="Invariant Violation"}throw l.framesToPop=1,l}}var o=function(e){};e.exports=r},function(e,t,n){function r(e){return e&&e.__esModule?e:{default:e}}function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var u,l,c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},d="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},f=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}}(),p=n(18),g=r(p),h=n(16),y=r(h),v=n(19),_=r(v),b=n(2),m=r(b),w=n(8),S=r(w),M=n(14),P=r(M),E=n(1),O=r(E),k=n(5),x=r(k),C=n(4),R=(l=u=function(e){function t(){var e,n,r,o;a(this,t);for(var s=arguments.length,u=Array(s),l=0;l<s;l++)u[l]=arguments[l];return n=r=i(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(u))),r.state={scriptLoaded:!1,inViewport:!1},o=n,i(r,o)}return s(t,e),f(t,[{key:"componentDidMount",value:function(){t._adManager.addInstance(this),t._adManager.load(t._config.seedFileUrl).then(this.onScriptLoaded.bind(this)).catch(this.onScriptError.bind(this))}},{key:"componentWillReceiveProps",value:function(e){var n=t._config.propsEqual,r=this.props.sizeMapping;!e.sizeMapping&&!r||n(e.sizeMapping,r)||t._adManager.removeMQListener(this,e)}},{key:"shouldComponentUpdate",value:function(e,n){var r=n.scriptLoaded,o=n.inViewport,a=this.notInViewport(e,n),i=this.state.inViewport!==o,s=this.state.scriptLoaded!==r;if(a)return!1;if(i)return!0;var u=t._config,l=u.filterProps,c=u.propsEqual,d=l(t.refreshableProps,this.props,e),f=l(t.reRenderProps,this.props,e),p=!c(f.props,f.nextProps),g=!p&&!c(d.props,d.nextProps);if(g&&this.configureSlot(this._adSlot,e),t._adManager._syncCorrelator)g?t._adManager.refresh():(p||s)&&t._adManager.renderAll();else{if(g)return this.refresh(),!1;if(p||s)return!0}return!1}},{key:"componentDidUpdate",value:function(){this.notInViewport(this.props,this.state)||this._divId&&(t._adManager._initialRender?t._adManager.render():this.renderAd())}},{key:"componentWillUnmount",value:function(){t._adManager.removeInstance(this),this._adSlot&&(t._adManager.googletag.destroySlots([this._adSlot]),this._adSlot=null)}},{key:"onScriptLoaded",value:function e(){var e=this.props.onScriptLoaded;this.getRenderWhenViewable()&&this.foldCheck(),this.setState({scriptLoaded:!0},e)}},{key:"onScriptError",value:function(e){console.warn("Ad: Failed to load gpt for "+t._config.seedFileUrl,e)}},{key:"getRenderWhenViewable",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.props;return void 0!==e.renderWhenViewable?e.renderWhenViewable:t._config.renderWhenViewable}},{key:"foldCheck",value:function(){if(!this.state.inViewport){var e=this.getSlotSize();Array.isArray(e)&&Array.isArray(e[0])&&(e=e[0]),"fluid"===e&&(e=[0,0]);var n=t._adManager.isInViewport(_.default.findDOMNode(this),e,this.viewableThreshold);n&&this.setState({inViewport:!0})}}},{key:"defineSizeMapping",value:function(e,n){if(n){t._adManager.addMQListener(this,this.props);var r=n.reduce(function(e,t){return e.addSize(t.viewport,t.slot)},t._adManager.googletag.sizeMapping()).build();e.defineSizeMapping(r)}}},{key:"setAttributes",value:function(e,t){var n=e.getAttributeKeys();n.forEach(function(t){e.set(t,null)}),t&&Object.keys(t).forEach(function(n){e.set(n,t[n])})}},{key:"setTargeting",value:function(e,t){e.clearTargeting(),t&&Object.keys(t).forEach(function(n){e.setTargeting(n,t[n])})}},{key:"addCompanionAdService",value:function(e,n){var r=t._adManager.googletag.companionAds();n.addService(r),"object"===("undefined"==typeof e?"undefined":d(e))&&(e.hasOwnProperty("enableSyncLoading")&&r.enableSyncLoading(),e.hasOwnProperty("refreshUnfilledSlots")&&r.setRefreshUnfilledSlots(e.refreshUnfilledSlots))}},{key:"getSlotSize",value:function(){var e=this.props,t=e.slotSize,n=e.sizeMapping,r=void 0;if(t)r=t;else if(n){var o=n;r=o[0]&&o[0].slot}return r}},{key:"renderAd",value:function(){this.defineSlot(),this.display()}},{key:"notInViewport",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.props,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.state,n=t.inViewport;return this.getRenderWhenViewable(e)&&!n}},{key:"defineSlot",value:function(){var e=this.props,n=e.adUnitPath,r=e.outOfPage,o=this._divId,a=this.getSlotSize();this._adSlot||(r?this._adSlot=t._adManager.googletag.defineOutOfPageSlot(n,o):this._adSlot=t._adManager.googletag.defineSlot(n,a||[],o)),this.configureSlot(this._adSlot)}},{key:"configureSlot",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.props,r=n.sizeMapping,a=n.attributes,i=n.targeting,s=n.companionAdService,u=n.categoryExclusion,l=n.collapseEmptyDiv,c=n.safeFrameConfig,d=n.content,f=n.clickUrl,p=n.forceSafeFrame;if(this.defineSizeMapping(e,r),void 0!==l)if(Array.isArray(l)){var g;(g=e.setCollapseEmptyDiv).call.apply(g,[e].concat(o(l)))}else e.setCollapseEmptyDiv(l);if(f&&e.setClickUrl(f),u){var h=u;"string"==typeof h&&(h=[h]),e.clearCategoryExclusions(),h.forEach(function(t){e.setCategoryExclusion(t)})}this.setAttributes(e,a),this.setTargeting(e,i),c&&e.setSafeFrameConfig(c),p&&e.setForceSafeFrame(p),s&&this.addCompanionAdService(s,e),d?e.addService(t._adManager.googletag.content()):e.addService(t._adManager.googletag.pubads())}},{key:"display",value:function(){var e=this.props.content,n=this._divId,r=this._adSlot;e?t._adManager.googletag.content().setContent(r,e):(t._adManager._disableInitialLoad||t._adManager._syncCorrelator||t._adManager.updateCorrelator(),t._adManager.googletag.display(n),t._adManager._disableInitialLoad&&!t._adManager._initialRender&&this.refresh())}},{key:"clear",value:function(){var e=this._adSlot;if(e&&e.hasOwnProperty("getServices")){var n=e.getServices();if(this._divId&&n.some(function(e){return!!e.setContent}))return void(document.getElementById(this._divId).innerHTML="");t._adManager.clear([e])}}},{key:"refresh",value:function(e){var n=this._adSlot;n&&(this.clear(),t._adManager.refresh([n],e))}},{key:"render",value:function(){var e=this.state.scriptLoaded,n=this.props,r=n.id,o=n.outOfPage,a=n.style,i=this.notInViewport(this.props,this.state);if(!e||i){var s=this.getSlotSize();o||(0,m.default)(s,"Either 'slotSize' or 'sizeMapping' prop needs to be set."),Array.isArray(s)&&Array.isArray(s[0])&&(s=s[0]),"fluid"===s&&(s=["auto","auto"]);var u=s&&{width:s[0],height:s[1]};return g.default.createElement("div",{style:u})}return this.clear(),this._adSlot&&(t._adManager.googletag.destroySlots([this._adSlot]),this._adSlot=null),this._divId=r||t._adManager.generateDivId(),g.default.createElement("div",{id:this._divId,style:a})}},{key:"adSlot",get:function(){return this._adSlot}},{key:"viewableThreshold",get:function(){return this.props.viewableThreshold>=0?this.props.viewableThreshold:t._config.viewableThreshold}}],[{key:"on",value:function(e,n){t._on("on",e,n)}},{key:"once",value:function(e,n){t._on("once",e,n)}},{key:"removeListener",value:function(){var e;(e=t._adManager).removeListener.apply(e,arguments)}},{key:"removeAllListeners",value:function(){var e;(e=t._adManager).removeAllListeners.apply(e,arguments)}},{key:"_on",value:function(e,n,r){"function"==typeof r&&(n===O.default.READY&&t._adManager.isReady?r.call(t._adManager,t._adManager.googletag):t._adManager[e](n,r))}},{key:"configure",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t._config=c({},t._config,e)}},{key:"getGPTVersion",value:function(){return t._adManager.getGPTVersion()}},{key:"getPubadsVersion",value:function(){return t._adManager.getPubadsVersion()}},{key:"syncCorrelator",value:function(e){t._adManager.syncCorrelator(e)}},{key:"render",value:function(){t._adManager.renderAll()}},{key:"refresh",value:function(e,n){t._adManager.refresh(e,n)}},{key:"clear",value:function(e){t._adManager.clear(e)}},{key:"updateCorrelator",value:function(){t._adManager.updateCorrelator()}},{key:"testManager",set:function(e){(0,m.default)(e,"Pass in createManagerTest to mock GPT"),t._adManager=e}}]),t}(p.Component),u.propTypes={id:y.default.string,adUnitPath:y.default.string.isRequired,targeting:y.default.object,slotSize:y.default.oneOfType([y.default.array,y.default.string]),sizeMapping:y.default.arrayOf(y.default.shape({viewport:y.default.array,slot:y.default.array})),outOfPage:y.default.bool,companionAdService:y.default.oneOfType([y.default.bool,y.default.object]),content:y.default.string,clickUrl:y.default.string,categoryExclusion:y.default.oneOfType([y.default.string,y.default.array]),attributes:y.default.object,collapseEmptyDiv:y.default.oneOfType([y.default.bool,y.default.array]),forceSafeFrame:y.default.bool,safeFrameConfig:y.default.object,onSlotRenderEnded:y.default.func,onImpressionViewable:y.default.func,onSlotVisibilityChanged:y.default.func,renderWhenViewable:y.default.bool,viewableThreshold:y.default.number,onScriptLoaded:y.default.func,onMediaQueryChange:y.default.func,style:y.default.object},u.refreshableProps=["targeting","sizeMapping","clickUrl","categoryExclusion","attributes","collapseEmptyDiv","companionAdService","forceSafeFrame","safeFrameConfig"],u.reRenderProps=["adUnitPath","slotSize","outOfPage","content"],u._adManager=(0,C.createManager)(),u._config={seedFileUrl:"//www.googletagservices.com/tag/js/gpt.js",renderWhenViewable:!0,viewableThreshold:.5,filterProps:x.default,propsEqual:S.default},l);t.default=(0,P.default)(R,C.pubadsAPI.reduce(function(e,t){return e[t]=function(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];return R._adManager.pubadsProxy({method:t,args:n})},e},{}))},function(e,t,n){function r(e){return e&&e.__esModule?e:{default:e}}function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function u(e){return new w(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.AdManager=t.APIToCallBeforeServiceEnabled=t.pubadsAPI=void 0;var l=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}}();t.createManager=u;var c=n(11),d=r(c),f=n(7),p=r(f),g=n(2),h=(r(g),n(12)),y=n(1),v=r(y),_=n(6),b=r(_),m=(t.pubadsAPI=["enableAsyncRendering","enableSingleRequest","enableSyncRendering","disableInitialLoad","collapseEmptyDivs","enableVideoAds","set","get","getAttributeKeys","setTargeting","clearTargeting","setCategoryExclusion","clearCategoryExclusions","setCentering","setCookieOptions","setLocation","setPublisherProvidedId","setTagForChildDirectedTreatment","clearTagForChildDirectedTreatment","setVideoContent","setForceSafeFrame"],t.APIToCallBeforeServiceEnabled=["enableAsyncRendering","enableSingleRequest","enableSyncRendering","disableInitialLoad","collapseEmptyDivs","setCentering"]),w=t.AdManager=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t);var n=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n._adCnt=0,n._initialRender=!0,n._syncCorrelator=!1,n._testMode=!1,n._foldCheck=(0,p.default)(function(e){var t=n.getMountedInstances();t.forEach(function(t){t.getRenderWhenViewable()&&t.foldCheck(e)})},66),n._handleMediaQueryChange=function(e){if(n._syncCorrelator)return void n.refresh();var t=/min-width:\s?(\d+)px/.exec(e.media),r=t&&t[1];r&&n._mqls[r]&&n._mqls[r].listeners.forEach(function(t){t.refresh(),t.props.onMediaQueryChange&&t.props.onMediaQueryChange(e)})},n.render=(0,p.default)(function(){if(n._initialRender){var e=function e(t){n.pubadsReady?t():setTimeout(e,50,t)},t=n.getMountedInstances(),r=!1,o=void 0;t.forEach(function(e){if(!e.notInViewport()){e.defineSlot();var t=e.adSlot;if(t&&t.hasOwnProperty("getServices")){var n=t.getServices();r||(r=n.filter(function(e){return!!e.enableAsyncRendering}).length>0)}}}),r||(o=n.googletag.defineSlot("/",[]),o.addService(n.googletag.pubads())),n._processPubadsQueue(),n.googletag.enableServices(),e(function(){o&&n.googletag.destroySlots([o]),n._processPubadsQueue(),n._listen(),n._isReady=!0,n.emit(v.default.READY,n.googletag),t.forEach(function(e){e.notInViewport()||e.display()}),n.emit(v.default.RENDER,n.googletag),n._initialRender=!1})}},4),n.renderAll=(0,p.default)(function(){if(!n.apiReady)return!1;var e=n.getMountedInstances();return e.forEach(function(e,t){0===t&&n.updateCorrelator(),e.forceUpdate()}),!0},4),e.test&&(n.testMode=e),n}return s(t,e),l(t,[{key:"_processPubadsQueue",value:function(){var e=this;this._pubadsProxyQueue&&(Object.keys(this._pubadsProxyQueue).forEach(function(t){(e.googletag&&!e.googletag.pubadsReady&&m.indexOf(t)>-1||e.pubadsReady)&&(e._pubadsProxyQueue[t].forEach(function(t){return e.pubadsProxy(t)}),delete e._pubadsProxyQueue[t])}),Object.keys(this._pubadsProxyQueue).length||(this._pubadsProxyQueue=null))}},{key:"_callPubads",value:function(e){var t=e.method,n=e.args,r=e.resolve,a=e.reject;if("function"!=typeof this.googletag.pubads()[t])a(new Error("googletag.pubads does not support "+t+", please update pubadsAPI"));else try{var i,s=(i=this.googletag.pubads())[t].apply(i,o(n));r(s)}catch(e){a(e)}}},{key:"_toggleListener",value:function(e){var t=this;["scroll","resize"].forEach(function(n){window[e?"addEventListener":"removeEventListener"](n,t._foldCheck)})}},{key:"_listen",value:function(){var e=this;this._listening||([v.default.SLOT_RENDER_ENDED,v.default.IMPRESSION_VIEWABLE,v.default.SLOT_VISIBILITY_CHANGED].forEach(function(t){["pubads","content","companionAds"].forEach(function(n){e.googletag[n]().addEventListener(t,e._onEvent.bind(e,t))})}),this._listening=!0)}},{key:"_onEvent",value:function(e,t){this.listeners(e,!0)&&this.emit(e,t);var n=this.getMountedInstances(),r=t.slot,o="on"+e.charAt(0).toUpperCase()+e.substr(1),a=n.filter(function(e){return r===e.adSlot})[0];a&&a.props[o]&&a.props[o](t)}},{key:"syncCorrelator",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this._syncCorrelator=e}},{key:"generateDivId",value:function(){return"bling-"+ ++this._adCnt}},{key:"getMountedInstances",value:function(){return this.mountedInstances||(this.mountedInstances=[]),this.mountedInstances}},{key:"addInstance",value:function(e){var t=this.getMountedInstances(),n=t.indexOf(e);n===-1&&(0===t.length&&this._toggleListener(!0),this.addMQListener(e,e.props),t.push(e))}},{key:"removeInstance",value:function(e){var t=this.getMountedInstances(),n=t.indexOf(e);n>=0&&(t.splice(n,1),0===t.length&&this._toggleListener(!1),this.removeMQListener(e,e.props))}},{key:"addMQListener",value:function(e,t){var n=this,r=t.sizeMapping;r&&Array.isArray(r)&&r.forEach(function(t){var r=t.viewport&&t.viewport[0];if(void 0!==r){if(n._mqls||(n._mqls={}),!n._mqls[r]){var o=window.matchMedia("(min-width: "+r+"px)");o.addListener(n._handleMediaQueryChange),n._mqls[r]={mql:o,listeners:[]}}n._mqls[r].listeners.indexOf(e)===-1&&n._mqls[r].listeners.push(e)}})}},{key:"removeMQListener",value:function(e){var t=this;this._mqls&&Object.keys(this._mqls).forEach(function(n){var r=t._mqls[n].listeners.indexOf(e);r>-1&&t._mqls[n].listeners.splice(r,1),0===t._mqls[n].listeners.length&&(t._mqls[n].mql.removeListener(t._handleMediaQueryChange),delete t._mqls[n])})}},{key:"isInViewport",value:function(){return b.default.apply(void 0,arguments)}},{key:"refresh",value:function(e,t){return!!this.pubadsReady&&(this.googletag.pubads().refresh(e,t),!0)}},{key:"clear",value:function(e){return!!this.pubadsReady&&(this.googletag.pubads().clear(e),!0)}},{key:"getGPTVersion",value:function(){return!!this.apiReady&&this.googletag.getVersion()}},{key:"getPubadsVersion",value:function(){return!!this.pubadsReady&&this.googletag.pubads().getVersion()}},{key:"updateCorrelator",value:function(){return!!this.pubadsReady&&(this.googletag.pubads().updateCorrelator(),!0)}},{key:"load",value:function(e){var t=this;return this._loadPromise||(this._loadPromise=new Promise(function(n,r){if(t.testMode)return void n(t.googletag);if(!h.canUseDOM)return void r(new Error("DOM not available"));if(!e)return void r(new Error("url is missing"));var o=function(){window.googletag?(t._googletag=window.googletag,t.googletag.cmd.push(function(){t._isLoaded=!0,n(t.googletag)})):r(new Error("window.googletag is not available"))};if(window.googletag&&window.googletag.apiReady)o();else{var a=document.createElement("script");a.async=!0,a.onload=o,a.onerror=function(){r(new Error("failed to load script"))},a.src=e,document.head.appendChild(a)}}))}},{key:"pubadsProxy",value:function(e){var t=this,n=e.method,r=e.args,o=void 0===r?[]:r,a=e.resolve,i=e.reject;return a?(this._callPubads({method:n,args:o,resolve:a,reject:i}),Promise.resolve()):(m.indexOf(n)>-1&&(this["_"+n]=o&&o.length&&o[0]||!0),new Promise(function(e,r){var a={method:n,args:o,resolve:e,reject:r};t.pubadsReady?t._callPubads(a):(t._pubadsProxyQueue||(t._pubadsProxyQueue={}),t._pubadsProxyQueue[n]||(t._pubadsProxyQueue[n]=[]),t._pubadsProxyQueue[n].push(a))}))}},{key:"googletag",get:function(){return this._googletag}},{key:"isLoaded",get:function(){return!!this._isLoaded}},{key:"isReady",get:function(){return!!this._isReady}},{key:"apiReady",get:function(){return this.googletag&&this.googletag.apiReady}},{key:"pubadsReady",get:function(){return this.googletag&&this.googletag.pubadsReady}},{key:"testMode",get:function(){return this._testMode},set:function(e){return}}]),t}(d.default)},function(e,t){function n(e,t,n){return e.reduce(function(e,r){return e.props[r]=t[r],e.nextProps[r]=n[r],e},{props:{},nextProps:{}})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n},function(e,t){function n(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[0,0],n=r(t,2),o=n[0],a=n[1],i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(!e||1!==e.nodeType)return!1;var s=e.getBoundingClientRect(),u={top:s.top,left:s.left,bottom:s.bottom,right:s.right},l={top:0,left:0,bottom:window.innerHeight,right:window.innerWidth},c=u.bottom>=l.top+a*i&&u.right>=l.left+o*i&&u.top<=l.bottom-a*i&&u.left<=l.right-o*i;return c}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){var n=[],r=!0,o=!1,a=void 0;try{for(var i,s=e[Symbol.iterator]();!(r=(i=s.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){o=!0,a=e}finally{try{!r&&s.return&&s.return()}finally{if(o)throw a}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.default=n},function(e,t){e.exports=function(e,t,n){function r(){var l=Date.now()-s;l<t&&l>=0?o=setTimeout(r,t-l):(o=null,n||(u=e.apply(i,a),i=a=null))}var o,a,i,s,u;null==t&&(t=100);var l=function(){i=this,a=arguments,s=Date.now();var l=n&&!o;return o||(o=setTimeout(r,t)),l&&(u=e.apply(i,a),i=a=null),u};return l.clear=function(){o&&(clearTimeout(o),o=null)},l}},function(e,t,n){function r(e){return null===e||void 0===e}function o(e){return!(!e||"object"!=typeof e||"number"!=typeof e.length)&&("function"==typeof e.copy&&"function"==typeof e.slice&&!(e.length>0&&"number"!=typeof e[0]))}function a(e,t,n){var a,c;if(r(e)||r(t))return!1;if(e.prototype!==t.prototype)return!1;if(u(e))return!!u(t)&&(e=i.call(e),t=i.call(t),l(e,t,n));if(o(e)){if(!o(t))return!1;if(e.length!==t.length)return!1;for(a=0;a<e.length;a++)if(e[a]!==t[a])return!1;return!0}try{var d=s(e),f=s(t)}catch(e){return!1}if(d.length!=f.length)return!1;for(d.sort(),f.sort(),a=d.length-1;a>=0;a--)if(d[a]!=f[a])return!1;for(a=d.length-1;a>=0;a--)if(c=d[a],!l(e[c],t[c],n))return!1;return typeof e==typeof t}var i=Array.prototype.slice,s=n(10),u=n(9),l=e.exports=function(e,t,n){return n||(n={}),e===t||(e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():!e||!t||"object"!=typeof e&&"object"!=typeof t?n.strict?e===t:e==t:a(e,t,n))}},function(e,t){function n(e){return"[object Arguments]"==Object.prototype.toString.call(e)}function r(e){return e&&"object"==typeof e&&"number"==typeof e.length&&Object.prototype.hasOwnProperty.call(e,"callee")&&!Object.prototype.propertyIsEnumerable.call(e,"callee")||!1}var o="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();t=e.exports=o?n:r,t.supported=n,t.unsupported=r},function(e,t){function n(e){var t=[];for(var n in e)t.push(n);return t}t=e.exports="function"==typeof Object.keys?Object.keys:n,t.shim=n},function(e,t,n){"use strict";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function a(){this._events=new r,this._eventsCount=0}var i=Object.prototype.hasOwnProperty,s="~";Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(s=!1)),a.prototype.eventNames=function(){var e,t,n=[];if(0===this._eventsCount)return n;for(t in e=this._events)i.call(e,t)&&n.push(s?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},a.prototype.listeners=function(e,t){var n=s?s+e:e,r=this._events[n];if(t)return!!r;if(!r)return[];if(r.fn)return[r.fn];for(var o=0,a=r.length,i=new Array(a);o<a;o++)i[o]=r[o].fn;return i},a.prototype.emit=function(e,t,n,r,o,a){var i=s?s+e:e;if(!this._events[i])return!1;var u,l,c=this._events[i],d=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),d){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,r),!0;case 5:return c.fn.call(c.context,t,n,r,o),!0;case 6:return c.fn.call(c.context,t,n,r,o,a),!0}for(l=1,u=new Array(d-1);l<d;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var f,p=c.length;for(l=0;l<p;l++)switch(c[l].once&&this.removeListener(e,c[l].fn,void 0,!0),d){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,t);break;case 3:c[l].fn.call(c[l].context,t,n);break;case 4:c[l].fn.call(c[l].context,t,n,r);break;default:if(!u)for(f=1,u=new Array(d-1);f<d;f++)u[f-1]=arguments[f];c[l].fn.apply(c[l].context,u)}}return!0},a.prototype.on=function(e,t,n){var r=new o(t,n||this),a=s?s+e:e;return this._events[a]?this._events[a].fn?this._events[a]=[this._events[a],r]:this._events[a].push(r):(this._events[a]=r,this._eventsCount++),this},a.prototype.once=function(e,t,n){var r=new o(t,n||this,!0),a=s?s+e:e;return this._events[a]?this._events[a].fn?this._events[a]=[this._events[a],r]:this._events[a].push(r):(this._events[a]=r,this._eventsCount++),this},a.prototype.removeListener=function(e,t,n,o){var a=s?s+e:e;if(!this._events[a])return this;if(!t)return 0===--this._eventsCount?this._events=new r:delete this._events[a],this;var i=this._events[a];if(i.fn)i.fn!==t||o&&!i.once||n&&i.context!==n||(0===--this._eventsCount?this._events=new r:delete this._events[a]);else{for(var u=0,l=[],c=i.length;u<c;u++)(i[u].fn!==t||o&&!i[u].once||n&&i[u].context!==n)&&l.push(i[u]);l.length?this._events[a]=1===l.length?l[0]:l:0===--this._eventsCount?this._events=new r:delete this._events[a]}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=s?s+e:e,this._events[t]&&(0===--this._eventsCount?this._events=new r:delete this._events[t])):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prototype.setMaxListeners=function(){return this},a.prefixed=s,a.EventEmitter=a,e.exports=a},function(e,t){"use strict";var n=!("undefined"==typeof window||!window.document||!window.document.createElement),r={canUseDOM:n,canUseWorkers:"undefined"!=typeof Worker,canUseEventListeners:n&&!(!window.addEventListener&&!window.attachEvent),canUseViewport:n&&!!window.screen,isInWorker:!n};e.exports=r},function(e,t){"use strict";function n(e){return function(){return e}}var r=function(){};r.thatReturns=n,r.thatReturnsFalse=n(!1),r.thatReturnsTrue=n(!0),r.thatReturnsNull=n(null),r.thatReturnsThis=function(){return this},r.thatReturnsArgument=function(e){return e},e.exports=r},function(e,t){"use strict";var n={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},r={name:!0,length:!0,prototype:!0,caller:!0,arguments:!0,arity:!0},o="function"==typeof Object.getOwnPropertySymbols;e.exports=function(e,t,a){if("string"!=typeof t){var i=Object.getOwnPropertyNames(t);o&&(i=i.concat(Object.getOwnPropertySymbols(t)));for(var s=0;s<i.length;++s)if(!(n[i[s]]||r[i[s]]||a&&a[i[s]]))try{e[i[s]]=t[i[s]]}catch(e){}}return e}},function(e,t,n){"use strict";var r=n(13),o=n(2),a=n(17);e.exports=function(){function e(e,t,n,r,i,s){s!==a&&o(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t};return n.checkPropTypes=r,n.PropTypes=n,n}},function(e,t,n){e.exports=n(15)()},function(e,t){"use strict";var n="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";e.exports=n},function(t,n){t.exports=e},function(e,n){e.exports=t}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],t):"object"==typeof exports?exports.ReactGPT=t(require("react"),require("react-dom")):e.ReactGPT=t(e.React,e.ReactDOM)}(this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(4);Object.defineProperty(t,"Bling",{enumerable:!0,get:function(){return r(o).default}});var a=n(1);Object.defineProperty(t,"Events",{enumerable:!0,get:function(){return r(a).default}})},function(e,t){Object.defineProperty(t,"__esModule",{value:!0});var n={READY:"ready",RENDER:"render",SLOT_RENDER_ENDED:"slotRenderEnded",IMPRESSION_VIEWABLE:"impressionViewable",SLOT_VISIBILITY_CHANGED:"slotVisibilityChanged"};t.default=n},function(e,t,n){"use strict";var r=function(e,t,n,r,o,a,i,s){if(!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var l=[n,r,o,a,i,s],c=0;u=new Error(t.replace(/%s/g,function(){return l[c++]})),u.name="Invariant Violation"}throw u.framesToPop=1,u}};e.exports=r},function(e,t){e.exports=function(e,t,n,r){function o(){function o(){i=Number(new Date),n.apply(u,c)}function s(){a=void 0}var u=this,l=Number(new Date)-i,c=arguments;r&&!a&&o(),a&&clearTimeout(a),void 0===r&&l>e?o():t!==!0&&(a=setTimeout(r?s:o,void 0===r?e-l:e))}var a,i=0;return"boolean"!=typeof t&&(r=n,n=t,t=void 0),o}},function(e,t,n){function r(e){return e&&e.__esModule?e:{default:e}}function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var u,l,c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},d="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},f=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}}(),p=n(21),g=r(p),h=n(17),y=r(h),v=n(22),_=r(v),b=n(2),m=r(b),w=n(8),S=r(w),M=n(15),P=r(M),E=n(1),O=r(E),k=n(6),x=r(k),C=n(5),R=(l=u=function(e){function t(){var e,n,r,o;a(this,t);for(var s=arguments.length,u=Array(s),l=0;l<s;l++)u[l]=arguments[l];return n=r=i(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(u))),r.state={scriptLoaded:!1,inViewport:!1},o=n,i(r,o)}return s(t,e),f(t,[{key:"componentDidMount",value:function(){t._adManager.addInstance(this),t._adManager.load(t._config.seedFileUrl).then(this.onScriptLoaded.bind(this)).catch(this.onScriptError.bind(this))}},{key:"componentWillReceiveProps",value:function(e){var n=t._config.propsEqual,r=this.props.sizeMapping;!e.sizeMapping&&!r||n(e.sizeMapping,r)||t._adManager.removeMQListener(this,e)}},{key:"shouldComponentUpdate",value:function(e,n){var r=n.scriptLoaded,o=n.inViewport,a=this.notInViewport(e,n),i=this.state.inViewport!==o,s=this.state.scriptLoaded!==r;if(a)return!1;if(i)return!0;var u=t._config,l=u.filterProps,c=u.propsEqual,d=l(t.refreshableProps,this.props,e),f=l(t.reRenderProps,this.props,e),p=!c(f.props,f.nextProps),g=!p&&!c(d.props,d.nextProps);if(g&&this.configureSlot(this._adSlot,e),t._adManager._syncCorrelator)g?t._adManager.refresh():(p||s)&&t._adManager.renderAll();else{if(g)return this.refresh(),!1;if(p||s)return!0}return!1}},{key:"componentDidUpdate",value:function(){this.notInViewport(this.props,this.state)||this._divId&&(t._adManager._initialRender?t._adManager.render():this.renderAd())}},{key:"componentWillUnmount",value:function(){t._adManager.removeInstance(this),this._adSlot&&(t._adManager.googletag.destroySlots([this._adSlot]),this._adSlot=null)}},{key:"onScriptLoaded",value:function e(){var e=this.props.onScriptLoaded;this.getRenderWhenViewable()&&this.foldCheck(),this.setState({scriptLoaded:!0},e)}},{key:"onScriptError",value:function(e){console.warn("Ad: Failed to load gpt for "+t._config.seedFileUrl,e)}},{key:"getRenderWhenViewable",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.props;return void 0!==e.renderWhenViewable?e.renderWhenViewable:t._config.renderWhenViewable}},{key:"foldCheck",value:function(){if(!this.state.inViewport){var e=this.getSlotSize();Array.isArray(e)&&Array.isArray(e[0])&&(e=e[0]),"fluid"===e&&(e=[0,0]);var n=t._adManager.isInViewport(_.default.findDOMNode(this),e,this.viewableThreshold);n&&this.setState({inViewport:!0})}}},{key:"defineSizeMapping",value:function(e,n){if(n){t._adManager.addMQListener(this,this.props);var r=n.reduce(function(e,t){return e.addSize(t.viewport,t.slot)},t._adManager.googletag.sizeMapping()).build();e.defineSizeMapping(r)}}},{key:"setAttributes",value:function(e,t){var n=e.getAttributeKeys();n.forEach(function(t){e.set(t,null)}),t&&Object.keys(t).forEach(function(n){e.set(n,t[n])})}},{key:"setTargeting",value:function(e,t){e.clearTargeting(),t&&Object.keys(t).forEach(function(n){e.setTargeting(n,t[n])})}},{key:"addCompanionAdService",value:function(e,n){var r=t._adManager.googletag.companionAds();n.addService(r),"object"===("undefined"==typeof e?"undefined":d(e))&&(e.hasOwnProperty("enableSyncLoading")&&r.enableSyncLoading(),e.hasOwnProperty("refreshUnfilledSlots")&&r.setRefreshUnfilledSlots(e.refreshUnfilledSlots))}},{key:"getSlotSize",value:function(){var e=this.props,t=e.slotSize,n=e.sizeMapping,r=void 0;if(t)r=t;else if(n){var o=n;r=o[0]&&o[0].slot}return r}},{key:"renderAd",value:function(){this.defineSlot(),this.display()}},{key:"notInViewport",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.props,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.state,n=t.inViewport;return this.getRenderWhenViewable(e)&&!n}},{key:"defineSlot",value:function(){var e=this.props,n=e.adUnitPath,r=e.outOfPage,o=this._divId,a=this.getSlotSize();this._adSlot||(r?this._adSlot=t._adManager.googletag.defineOutOfPageSlot(n,o):this._adSlot=t._adManager.googletag.defineSlot(n,a||[],o)),this.configureSlot(this._adSlot)}},{key:"configureSlot",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.props,r=n.sizeMapping,a=n.attributes,i=n.targeting,s=n.companionAdService,u=n.categoryExclusion,l=n.collapseEmptyDiv,c=n.safeFrameConfig,d=n.content,f=n.clickUrl,p=n.forceSafeFrame;if(this.defineSizeMapping(e,r),void 0!==l)if(Array.isArray(l)){var g;(g=e.setCollapseEmptyDiv).call.apply(g,[e].concat(o(l)))}else e.setCollapseEmptyDiv(l);if(f&&e.setClickUrl(f),u){var h=u;"string"==typeof h&&(h=[h]),e.clearCategoryExclusions(),h.forEach(function(t){e.setCategoryExclusion(t)})}this.setAttributes(e,a),this.setTargeting(e,i),c&&e.setSafeFrameConfig(c),p&&e.setForceSafeFrame(p),s&&this.addCompanionAdService(s,e),d?e.addService(t._adManager.googletag.content()):e.addService(t._adManager.googletag.pubads())}},{key:"display",value:function(){var e=this.props.content,n=this._divId,r=this._adSlot;e?t._adManager.googletag.content().setContent(r,e):(t._adManager._disableInitialLoad||t._adManager._syncCorrelator||t._adManager.updateCorrelator(),t._adManager.googletag.display(n),t._adManager._disableInitialLoad&&!t._adManager._initialRender&&this.refresh())}},{key:"clear",value:function(){var e=this._adSlot;if(e&&e.hasOwnProperty("getServices")){var n=e.getServices();if(this._divId&&n.some(function(e){return!!e.setContent}))return void(document.getElementById(this._divId).innerHTML="");t._adManager.clear([e])}}},{key:"refresh",value:function(e){var n=this._adSlot;n&&(this.clear(),t._adManager.refresh([n],e))}},{key:"render",value:function(){var e=this.state.scriptLoaded,n=this.props,r=n.id,o=n.outOfPage,a=n.style,i=this.notInViewport(this.props,this.state);if(!e||i){var s=this.getSlotSize();o||(0,m.default)(s,"Either 'slotSize' or 'sizeMapping' prop needs to be set."),Array.isArray(s)&&Array.isArray(s[0])&&(s=s[0]),"fluid"===s&&(s=["auto","auto"]);var u=s&&{width:s[0],height:s[1]};return g.default.createElement("div",{style:u})}return this.clear(),this._adSlot&&(t._adManager.googletag.destroySlots([this._adSlot]),this._adSlot=null),this._divId=r||t._adManager.generateDivId(),g.default.createElement("div",{id:this._divId,style:a})}},{key:"adSlot",get:function(){return this._adSlot}},{key:"viewableThreshold",get:function(){return this.props.viewableThreshold>=0?this.props.viewableThreshold:t._config.viewableThreshold}}],[{key:"on",value:function(e,n){t._on("on",e,n)}},{key:"once",value:function(e,n){t._on("once",e,n)}},{key:"removeListener",value:function(){var e;(e=t._adManager).removeListener.apply(e,arguments)}},{key:"removeAllListeners",value:function(){var e;(e=t._adManager).removeAllListeners.apply(e,arguments)}},{key:"_on",value:function(e,n,r){"function"==typeof r&&(n===O.default.READY&&t._adManager.isReady?r.call(t._adManager,t._adManager.googletag):t._adManager[e](n,r))}},{key:"configure",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t._config=c({},t._config,e)}},{key:"getGPTVersion",value:function(){return t._adManager.getGPTVersion()}},{key:"getPubadsVersion",value:function(){return t._adManager.getPubadsVersion()}},{key:"syncCorrelator",value:function(e){t._adManager.syncCorrelator(e)}},{key:"render",value:function(){t._adManager.renderAll()}},{key:"refresh",value:function(e,n){t._adManager.refresh(e,n)}},{key:"clear",value:function(e){t._adManager.clear(e)}},{key:"updateCorrelator",value:function(){t._adManager.updateCorrelator()}},{key:"testManager",set:function(e){(0,m.default)(e,"Pass in createManagerTest to mock GPT"),t._adManager=e}}]),t}(p.Component),u.propTypes={id:y.default.string,adUnitPath:y.default.string.isRequired,targeting:y.default.object,slotSize:y.default.oneOfType([y.default.array,y.default.string]),sizeMapping:y.default.arrayOf(y.default.shape({viewport:y.default.array,slot:y.default.array})),outOfPage:y.default.bool,companionAdService:y.default.oneOfType([y.default.bool,y.default.object]),content:y.default.string,clickUrl:y.default.string,categoryExclusion:y.default.oneOfType([y.default.string,y.default.array]),attributes:y.default.object,collapseEmptyDiv:y.default.oneOfType([y.default.bool,y.default.array]),forceSafeFrame:y.default.bool,safeFrameConfig:y.default.object,onSlotRenderEnded:y.default.func,onImpressionViewable:y.default.func,onSlotVisibilityChanged:y.default.func,renderWhenViewable:y.default.bool,viewableThreshold:y.default.number,onScriptLoaded:y.default.func,onMediaQueryChange:y.default.func,style:y.default.object},u.refreshableProps=["targeting","sizeMapping","clickUrl","categoryExclusion","attributes","collapseEmptyDiv","companionAdService","forceSafeFrame","safeFrameConfig"],u.reRenderProps=["adUnitPath","slotSize","outOfPage","content"],u._adManager=(0,C.createManager)(),u._config={seedFileUrl:"//www.googletagservices.com/tag/js/gpt.js",renderWhenViewable:!0,viewableThreshold:.5,filterProps:x.default,propsEqual:S.default},l);t.default=(0,P.default)(R,C.pubadsAPI.reduce(function(e,t){return e[t]=function(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];return R._adManager.pubadsProxy({method:t,args:n})},e},{}))},function(e,t,n){function r(e){return e&&e.__esModule?e:{default:e}}function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function u(e){return new m(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.AdManager=t.APIToCallBeforeServiceEnabled=t.pubadsAPI=void 0;var l=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}}();t.createManager=u;var c=n(11),d=r(c),f=n(20),p=n(2),g=(r(p),n(12)),h=n(1),y=r(h),v=n(7),_=r(v),b=(t.pubadsAPI=["enableAsyncRendering","enableSingleRequest","enableSyncRendering","disableInitialLoad","collapseEmptyDivs","enableVideoAds","set","get","getAttributeKeys","setTargeting","clearTargeting","setCategoryExclusion","clearCategoryExclusions","setCentering","setCookieOptions","setLocation","setPublisherProvidedId","setTagForChildDirectedTreatment","clearTagForChildDirectedTreatment","setVideoContent","setForceSafeFrame"],t.APIToCallBeforeServiceEnabled=["enableAsyncRendering","enableSingleRequest","enableSyncRendering","disableInitialLoad","collapseEmptyDivs","setCentering"]),m=t.AdManager=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,t);var n=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n._adCnt=0,n._initialRender=!0,n._syncCorrelator=!1,n._testMode=!1,n._foldCheck=(0,f.throttle)(20,function(e){var t=n.getMountedInstances();t.forEach(function(t){t.getRenderWhenViewable()&&t.foldCheck(e)}),n.testMode&&n._getTimer()}),n._handleMediaQueryChange=function(e){if(n._syncCorrelator)return void n.refresh();var t=/min-width:\s?(\d+)px/.exec(e.media),r=t&&t[1];r&&n._mqls[r]&&n._mqls[r].listeners.forEach(function(t){t.refresh(),t.props.onMediaQueryChange&&t.props.onMediaQueryChange(e)})},n.render=(0,f.debounce)(4,function(){if(n._initialRender){var e=function e(t){n.pubadsReady?t():setTimeout(e,50,t)},t=n.getMountedInstances(),r=!1,o=void 0;t.forEach(function(e){if(!e.notInViewport()){e.defineSlot();var t=e.adSlot;if(t&&t.hasOwnProperty("getServices")){var n=t.getServices();r||(r=n.filter(function(e){return!!e.enableAsyncRendering}).length>0)}}}),r||(o=n.googletag.defineSlot("/",[]),o.addService(n.googletag.pubads())),n._processPubadsQueue(),n.googletag.enableServices(),e(function(){o&&n.googletag.destroySlots([o]),n._processPubadsQueue(),n._listen(),n._isReady=!0,n.emit(y.default.READY,n.googletag),t.forEach(function(e){e.notInViewport()||e.display()}),n.emit(y.default.RENDER,n.googletag),n._initialRender=!1})}}),n.renderAll=(0,f.debounce)(4,function(){if(!n.apiReady)return!1;var e=n.getMountedInstances();return e.forEach(function(e,t){0===t&&n.updateCorrelator(),e.forceUpdate()}),!0}),e.test&&(n.testMode=e),n}return s(t,e),l(t,[{key:"_processPubadsQueue",value:function(){var e=this;this._pubadsProxyQueue&&(Object.keys(this._pubadsProxyQueue).forEach(function(t){(e.googletag&&!e.googletag.pubadsReady&&b.indexOf(t)>-1||e.pubadsReady)&&(e._pubadsProxyQueue[t].forEach(function(t){return e.pubadsProxy(t)}),delete e._pubadsProxyQueue[t])}),Object.keys(this._pubadsProxyQueue).length||(this._pubadsProxyQueue=null))}},{key:"_callPubads",value:function(e){var t=e.method,n=e.args,r=e.resolve,a=e.reject;if("function"!=typeof this.googletag.pubads()[t])a(new Error("googletag.pubads does not support "+t+", please update pubadsAPI"));else try{var i,s=(i=this.googletag.pubads())[t].apply(i,o(n));r(s)}catch(e){a(e)}}},{key:"_toggleListener",value:function(e){var t=this;["scroll","resize"].forEach(function(n){window[e?"addEventListener":"removeEventListener"](n,t._foldCheck)})}},{key:"_getTimer",value:function(){return Date.now()}},{key:"_listen",value:function(){var e=this;this._listening||([y.default.SLOT_RENDER_ENDED,y.default.IMPRESSION_VIEWABLE,y.default.SLOT_VISIBILITY_CHANGED].forEach(function(t){["pubads","content","companionAds"].forEach(function(n){e.googletag[n]().addEventListener(t,e._onEvent.bind(e,t))})}),this._listening=!0)}},{key:"_onEvent",value:function(e,t){this.listeners(e,!0)&&this.emit(e,t);var n=this.getMountedInstances(),r=t.slot,o="on"+e.charAt(0).toUpperCase()+e.substr(1),a=n.filter(function(e){return r===e.adSlot})[0];a&&a.props[o]&&a.props[o](t)}},{key:"syncCorrelator",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this._syncCorrelator=e}},{key:"generateDivId",value:function(){return"bling-"+ ++this._adCnt}},{key:"getMountedInstances",value:function(){return this.mountedInstances||(this.mountedInstances=[]),this.mountedInstances}},{key:"addInstance",value:function(e){var t=this.getMountedInstances(),n=t.indexOf(e);n===-1&&(0===t.length&&this._toggleListener(!0),this.addMQListener(e,e.props),t.push(e))}},{key:"removeInstance",value:function(e){var t=this.getMountedInstances(),n=t.indexOf(e);n>=0&&(t.splice(n,1),0===t.length&&this._toggleListener(!1),this.removeMQListener(e,e.props))}},{key:"addMQListener",value:function(e,t){var n=this,r=t.sizeMapping;r&&Array.isArray(r)&&r.forEach(function(t){var r=t.viewport&&t.viewport[0];if(void 0!==r){if(n._mqls||(n._mqls={}),!n._mqls[r]){var o=window.matchMedia("(min-width: "+r+"px)");o.addListener(n._handleMediaQueryChange),n._mqls[r]={mql:o,listeners:[]}}n._mqls[r].listeners.indexOf(e)===-1&&n._mqls[r].listeners.push(e)}})}},{key:"removeMQListener",value:function(e){var t=this;this._mqls&&Object.keys(this._mqls).forEach(function(n){var r=t._mqls[n].listeners.indexOf(e);r>-1&&t._mqls[n].listeners.splice(r,1),0===t._mqls[n].listeners.length&&(t._mqls[n].mql.removeListener(t._handleMediaQueryChange),delete t._mqls[n])})}},{key:"isInViewport",value:function(){return _.default.apply(void 0,arguments)}},{key:"refresh",value:function(e,t){return!!this.pubadsReady&&(this.googletag.pubads().refresh(e,t),!0)}},{key:"clear",value:function(e){return!!this.pubadsReady&&(this.googletag.pubads().clear(e),!0)}},{key:"getGPTVersion",value:function(){return!!this.apiReady&&this.googletag.getVersion()}},{key:"getPubadsVersion",value:function(){return!!this.pubadsReady&&this.googletag.pubads().getVersion()}},{key:"updateCorrelator",value:function(){return!!this.pubadsReady&&(this.googletag.pubads().updateCorrelator(),!0)}},{key:"load",value:function(e){var t=this;return this._loadPromise||(this._loadPromise=new Promise(function(n,r){if(t.testMode)return void n(t.googletag);if(!g.canUseDOM)return void r(new Error("DOM not available"));if(!e)return void r(new Error("url is missing"));var o=function(){window.googletag?(t._googletag=window.googletag,t.googletag.cmd.push(function(){t._isLoaded=!0,n(t.googletag)})):r(new Error("window.googletag is not available"))};if(window.googletag&&window.googletag.apiReady)o();else{var a=document.createElement("script");a.async=!0,a.onload=o,a.onerror=function(){r(new Error("failed to load script"))},a.src=e,document.head.appendChild(a)}}))}},{key:"pubadsProxy",value:function(e){var t=this,n=e.method,r=e.args,o=void 0===r?[]:r,a=e.resolve,i=e.reject;return a?(this._callPubads({method:n,args:o,resolve:a,reject:i}),Promise.resolve()):(b.indexOf(n)>-1&&(this["_"+n]=o&&o.length&&o[0]||!0),new Promise(function(e,r){var a={method:n,args:o,resolve:e,reject:r};t.pubadsReady?t._callPubads(a):(t._pubadsProxyQueue||(t._pubadsProxyQueue={}),t._pubadsProxyQueue[n]||(t._pubadsProxyQueue[n]=[]),t._pubadsProxyQueue[n].push(a))}))}},{key:"googletag",get:function(){return this._googletag}},{key:"isLoaded",get:function(){return!!this._isLoaded}},{key:"isReady",get:function(){return!!this._isReady}},{key:"apiReady",get:function(){return this.googletag&&this.googletag.apiReady}},{key:"pubadsReady",get:function(){return this.googletag&&this.googletag.pubadsReady}},{key:"testMode",get:function(){return this._testMode},set:function(e){return}}]),t}(d.default)},function(e,t){function n(e,t,n){return e.reduce(function(e,r){return e.props[r]=t[r],e.nextProps[r]=n[r],e},{props:{},nextProps:{}})}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n},function(e,t){function n(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[0,0],n=r(t,2),o=n[0],a=n[1],i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(!e||1!==e.nodeType)return!1;var s=e.getBoundingClientRect(),u={top:s.top,left:s.left,bottom:s.bottom,right:s.right},l={top:0,left:0,bottom:window.innerHeight,right:window.innerWidth},c=u.bottom>=l.top+a*i&&u.right>=l.left+o*i&&u.top<=l.bottom-a*i&&u.left<=l.right-o*i;return c}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){var n=[],r=!0,o=!1,a=void 0;try{for(var i,s=e[Symbol.iterator]();!(r=(i=s.next()).done)&&(n.push(i.value),!t||n.length!==t);r=!0);}catch(e){o=!0,a=e}finally{try{!r&&s.return&&s.return()}finally{if(o)throw a}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();t.default=n},function(e,t,n){function r(e){return null===e||void 0===e}function o(e){return!(!e||"object"!=typeof e||"number"!=typeof e.length)&&("function"==typeof e.copy&&"function"==typeof e.slice&&!(e.length>0&&"number"!=typeof e[0]))}function a(e,t,n){var a,c;if(r(e)||r(t))return!1;if(e.prototype!==t.prototype)return!1;if(u(e))return!!u(t)&&(e=i.call(e),t=i.call(t),l(e,t,n));if(o(e)){if(!o(t))return!1;if(e.length!==t.length)return!1;for(a=0;a<e.length;a++)if(e[a]!==t[a])return!1;return!0}try{var d=s(e),f=s(t)}catch(e){return!1}if(d.length!=f.length)return!1;for(d.sort(),f.sort(),a=d.length-1;a>=0;a--)if(d[a]!=f[a])return!1;for(a=d.length-1;a>=0;a--)if(c=d[a],!l(e[c],t[c],n))return!1;return typeof e==typeof t}var i=Array.prototype.slice,s=n(10),u=n(9),l=e.exports=function(e,t,n){return n||(n={}),e===t||(e instanceof Date&&t instanceof Date?e.getTime()===t.getTime():!e||!t||"object"!=typeof e&&"object"!=typeof t?n.strict?e===t:e==t:a(e,t,n))}},function(e,t){function n(e){return"[object Arguments]"==Object.prototype.toString.call(e)}function r(e){return e&&"object"==typeof e&&"number"==typeof e.length&&Object.prototype.hasOwnProperty.call(e,"callee")&&!Object.prototype.propertyIsEnumerable.call(e,"callee")||!1}var o="[object Arguments]"==function(){return Object.prototype.toString.call(arguments)}();t=e.exports=o?n:r,t.supported=n,t.unsupported=r},function(e,t){function n(e){var t=[];for(var n in e)t.push(n);return t}t=e.exports="function"==typeof Object.keys?Object.keys:n,t.shim=n},function(e,t,n){"use strict";function r(){}function o(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function a(){this._events=new r,this._eventsCount=0}var i=Object.prototype.hasOwnProperty,s="~";Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(s=!1)),a.prototype.eventNames=function(){var e,t,n=[];if(0===this._eventsCount)return n;for(t in e=this._events)i.call(e,t)&&n.push(s?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},a.prototype.listeners=function(e,t){var n=s?s+e:e,r=this._events[n];if(t)return!!r;if(!r)return[];if(r.fn)return[r.fn];for(var o=0,a=r.length,i=new Array(a);o<a;o++)i[o]=r[o].fn;return i},a.prototype.emit=function(e,t,n,r,o,a){var i=s?s+e:e;if(!this._events[i])return!1;var u,l,c=this._events[i],d=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),d){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,r),!0;case 5:return c.fn.call(c.context,t,n,r,o),!0;case 6:return c.fn.call(c.context,t,n,r,o,a),!0}for(l=1,u=new Array(d-1);l<d;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var f,p=c.length;for(l=0;l<p;l++)switch(c[l].once&&this.removeListener(e,c[l].fn,void 0,!0),d){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,t);break;case 3:c[l].fn.call(c[l].context,t,n);break;case 4:c[l].fn.call(c[l].context,t,n,r);break;default:if(!u)for(f=1,u=new Array(d-1);f<d;f++)u[f-1]=arguments[f];c[l].fn.apply(c[l].context,u)}}return!0},a.prototype.on=function(e,t,n){var r=new o(t,n||this),a=s?s+e:e;return this._events[a]?this._events[a].fn?this._events[a]=[this._events[a],r]:this._events[a].push(r):(this._events[a]=r,this._eventsCount++),this},a.prototype.once=function(e,t,n){var r=new o(t,n||this,!0),a=s?s+e:e;return this._events[a]?this._events[a].fn?this._events[a]=[this._events[a],r]:this._events[a].push(r):(this._events[a]=r,this._eventsCount++),this},a.prototype.removeListener=function(e,t,n,o){var a=s?s+e:e;if(!this._events[a])return this;if(!t)return 0===--this._eventsCount?this._events=new r:delete this._events[a],this;var i=this._events[a];if(i.fn)i.fn!==t||o&&!i.once||n&&i.context!==n||(0===--this._eventsCount?this._events=new r:delete this._events[a]);else{for(var u=0,l=[],c=i.length;u<c;u++)(i[u].fn!==t||o&&!i[u].once||n&&i[u].context!==n)&&l.push(i[u]);l.length?this._events[a]=1===l.length?l[0]:l:0===--this._eventsCount?this._events=new r:delete this._events[a]}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=s?s+e:e,this._events[t]&&(0===--this._eventsCount?this._events=new r:delete this._events[t])):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prototype.setMaxListeners=function(){return this},a.prefixed=s,a.EventEmitter=a,e.exports=a},function(e,t,n){var r;/*! | ||
Copyright (c) 2015 Jed Watson. | ||
Based on code that is Copyright 2013-2015, Facebook, Inc. | ||
All rights reserved. | ||
*/ | ||
!function(){"use strict";var o=!("undefined"==typeof window||!window.document||!window.document.createElement),a={canUseDOM:o,canUseWorkers:"undefined"!=typeof Worker,canUseEventListeners:o&&!(!window.addEventListener&&!window.attachEvent),canUseViewport:o&&!!window.screen};r=function(){return a}.call(t,n,t,e),!(void 0!==r&&(e.exports=r))}()},function(e,t){"use strict";function n(e){return function(){return e}}var r=function(){};r.thatReturns=n,r.thatReturnsFalse=n(!1),r.thatReturnsTrue=n(!0),r.thatReturnsNull=n(null),r.thatReturnsThis=function(){return this},r.thatReturnsArgument=function(e){return e},e.exports=r},function(e,t,n){"use strict";function r(e,t,n,r,a,i,s,u){if(o(t),!e){var l;if(void 0===t)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,a,i,s,u],d=0;l=new Error(t.replace(/%s/g,function(){return c[d++]})),l.name="Invariant Violation"}throw l.framesToPop=1,l}}var o=function(e){};e.exports=r},function(e,t){"use strict";var n={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},r={name:!0,length:!0,prototype:!0,caller:!0,arguments:!0,arity:!0},o="function"==typeof Object.getOwnPropertySymbols;e.exports=function(e,t,a){if("string"!=typeof t){var i=Object.getOwnPropertyNames(t);o&&(i=i.concat(Object.getOwnPropertySymbols(t)));for(var s=0;s<i.length;++s)if(!(n[i[s]]||r[i[s]]||a&&a[i[s]]))try{e[i[s]]=t[i[s]]}catch(e){}}return e}},function(e,t,n){"use strict";var r=n(13),o=n(14),a=n(18);e.exports=function(){function e(e,t,n,r,i,s){s!==a&&o(!1,"Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types")}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t};return n.checkPropTypes=r,n.PropTypes=n,n}},function(e,t,n){e.exports=n(16)()},function(e,t){"use strict";var n="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";e.exports=n},function(e,t,n){var r=n(3);e.exports=function(e,t,n){return void 0===n?r(e,t,!1):r(e,n,t!==!1)}},function(e,t,n){var r=n(3),o=n(19);e.exports={throttle:r,debounce:o}},function(t,n){t.exports=e},function(e,n){e.exports=t}])}); |
@@ -26,3 +26,3 @@ Object.defineProperty(exports, "__esModule", { | ||
var _invariant = require("fbjs/lib/invariant"); | ||
var _invariant = require("invariant"); | ||
@@ -92,7 +92,7 @@ var _invariant2 = _interopRequireDefault(_invariant); | ||
/** | ||
* An array of prop names which can reflect to the ad by calling `refresh`. | ||
* | ||
* @property refreshableProps | ||
* @static | ||
*/ | ||
* An array of prop names which can reflect to the ad by calling `refresh`. | ||
* | ||
* @property refreshableProps | ||
* @static | ||
*/ | ||
@@ -115,7 +115,7 @@ /** | ||
/** | ||
* | ||
* @property | ||
* @private | ||
* @static | ||
*/ | ||
* | ||
* @property | ||
* @private | ||
* @static | ||
*/ | ||
@@ -500,3 +500,6 @@ | ||
} | ||
var emptyStyle = slotSize && { width: slotSize[0], height: slotSize[1] }; | ||
var emptyStyle = slotSize && { | ||
width: slotSize[0], | ||
height: slotSize[1] | ||
}; | ||
// render node element instead of script element so that `inViewport` check works. | ||
@@ -570,8 +573,8 @@ return _react2.default.createElement("div", { style: emptyStyle }); | ||
/** | ||
* Returns the GPT version. | ||
* | ||
* @method getGPTVersion | ||
* @returns {Number|boolean} a version or false if GPT is not yet ready. | ||
* @static | ||
*/ | ||
* Returns the GPT version. | ||
* | ||
* @method getGPTVersion | ||
* @returns {Number|boolean} a version or false if GPT is not yet ready. | ||
* @static | ||
*/ | ||
@@ -597,8 +600,8 @@ }, { | ||
/** | ||
* Sets a flag to indicate whether the correlator value should always be same across the ads in the page or not. | ||
* | ||
* @method syncCorrelator | ||
* @param {boolean} value | ||
* @static | ||
*/ | ||
* Sets a flag to indicate whether the correlator value should always be same across the ads in the page or not. | ||
* | ||
* @method syncCorrelator | ||
* @param {boolean} value | ||
* @static | ||
*/ | ||
@@ -636,8 +639,8 @@ }, { | ||
/** | ||
* Clears the ads for the specified ad slots, if no slots are provided, all the ads will be cleared. | ||
* | ||
* @method clear | ||
* @param {Array} slots An optional array of slots to clear. | ||
* @static | ||
*/ | ||
* Clears the ads for the specified ad slots, if no slots are provided, all the ads will be cleared. | ||
* | ||
* @method clear | ||
* @param {Array} slots An optional array of slots to clear. | ||
* @static | ||
*/ | ||
@@ -822,3 +825,4 @@ }, { | ||
*/ | ||
style: _propTypes2.default.object }, _class.refreshableProps = ["targeting", "sizeMapping", "clickUrl", "categoryExclusion", "attributes", "collapseEmptyDiv", "companionAdService", "forceSafeFrame", "safeFrameConfig"], _class.reRenderProps = ["adUnitPath", "slotSize", "outOfPage", "content"], _class._adManager = (0, _createManager.createManager)(), _class._config = { | ||
style: _propTypes2.default.object | ||
}, _class.refreshableProps = ["targeting", "sizeMapping", "clickUrl", "categoryExclusion", "attributes", "collapseEmptyDiv", "companionAdService", "forceSafeFrame", "safeFrameConfig"], _class.reRenderProps = ["adUnitPath", "slotSize", "outOfPage", "content"], _class._adManager = (0, _createManager.createManager)(), _class._config = { | ||
/** | ||
@@ -825,0 +829,0 @@ * An optional string for GPT seed file url to override. |
@@ -14,11 +14,9 @@ Object.defineProperty(exports, "__esModule", { | ||
var _debounce = require("debounce"); | ||
var _throttleDebounce = require("throttle-debounce"); | ||
var _debounce2 = _interopRequireDefault(_debounce); | ||
var _invariant = require("invariant"); | ||
var _invariant = require("fbjs/lib/invariant"); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
var _ExecutionEnvironment = require("fbjs/lib/ExecutionEnvironment"); | ||
var _exenv = require("exenv"); | ||
@@ -62,3 +60,3 @@ var _Events = require("./Events"); | ||
_this._testMode = false; | ||
_this._foldCheck = (0, _debounce2.default)(function (event) { | ||
_this._foldCheck = (0, _throttleDebounce.throttle)(20, function (event) { | ||
var instances = _this.getMountedInstances(); | ||
@@ -70,4 +68,8 @@ instances.forEach(function (instance) { | ||
}); | ||
}, 66); | ||
if (_this.testMode) { | ||
_this._getTimer(); | ||
} | ||
}); | ||
_this._handleMediaQueryChange = function (event) { | ||
@@ -79,2 +81,3 @@ if (_this._syncCorrelator) { | ||
// IE returns `event.media` value differently, need to use regex to evaluate. | ||
// eslint-disable-next-line wrap-regex | ||
var res = /min-width:\s?(\d+)px/.exec(event.media); | ||
@@ -93,3 +96,3 @@ var viewportWidth = res && res[1]; | ||
_this.render = (0, _debounce2.default)(function () { | ||
_this.render = (0, _throttleDebounce.debounce)(4, function () { | ||
if (!_this._initialRender) { | ||
@@ -164,4 +167,4 @@ return; | ||
}); | ||
}, 4); | ||
_this.renderAll = (0, _debounce2.default)(function () { | ||
}); | ||
_this.renderAll = (0, _throttleDebounce.debounce)(4, function () { | ||
if (!_this.apiReady) { | ||
@@ -181,3 +184,3 @@ return false; | ||
return true; | ||
}, 4); | ||
}); | ||
@@ -241,2 +244,7 @@ | ||
}, { | ||
key: "_getTimer", | ||
value: function _getTimer() { | ||
return Date.now(); | ||
} | ||
}, { | ||
key: "_listen", | ||
@@ -457,3 +465,3 @@ value: function _listen() { | ||
} | ||
if (!_ExecutionEnvironment.canUseDOM) { | ||
if (!_exenv.canUseDOM) { | ||
reject(new Error("DOM not available")); | ||
@@ -510,3 +518,8 @@ return; | ||
return new Promise(function (resolve2, reject2) { | ||
var params = { method: method, args: args, resolve: resolve2, reject: reject2 }; | ||
var params = { | ||
method: method, | ||
args: args, | ||
resolve: resolve2, | ||
reject: reject2 | ||
}; | ||
if (!_this8.pubadsReady) { | ||
@@ -513,0 +526,0 @@ if (!_this8._pubadsProxyQueue) { |
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
@@ -4,0 +4,0 @@ // DO NOT MODIFY THIS FILE MANUALLY. |
238
package.json
{ | ||
"name": "react-gpt", | ||
"version": "0.2.5", | ||
"description": "A react display ad component using Google Publisher Tag", | ||
"main": "lib/index.js", | ||
"contributors": [ | ||
{ | ||
"name": "NFL Engineering" | ||
} | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/nfl/react-gpt" | ||
}, | ||
"keywords": [ | ||
"react-gpt", | ||
"nfl", | ||
"react", | ||
"ad", | ||
"gpt", | ||
"google publisher tags" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/nfl/react-gpt/issues" | ||
}, | ||
"files": [ | ||
"*.md", | ||
"docs", | ||
"src", | ||
"dist", | ||
"lib" | ||
], | ||
"dependencies": { | ||
"debounce": "^1.0.0", | ||
"deep-equal": "^1.0.1", | ||
"eventemitter3": "^2.0.2", | ||
"fbjs": "^0.8.1", | ||
"hoist-non-react-statics": "^1.0.5" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.5.1", | ||
"babel-core": "^6.5.1", | ||
"babel-eslint": "^7.0.0", | ||
"babel-loader": "^6.2.3", | ||
"babel-plugin-transform-decorators-legacy": "^1.3.4", | ||
"babel-plugin-webpack-alias": "^2.1.1", | ||
"babel-preset-es2015-without-strict": "^0.0.4", | ||
"babel-preset-react": "^6.5.0", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"babel-register": "^6.7.2", | ||
"chai": "^3.4.1", | ||
"codecov.io": "^0.1.6", | ||
"commitizen": "^2.8.1", | ||
"conventional-changelog-cli": "^1.2.0", | ||
"core-js": "^2.2.2", | ||
"cz-conventional-changelog": "^1.1.6", | ||
"eslint": "3.7.1", | ||
"eslint-config-nfl": "10.0.0", | ||
"eslint-plugin-import": "2.0.1", | ||
"eslint-plugin-mocha": "4.7.0", | ||
"eslint-plugin-react": "6.4.1", | ||
"express": "^4.13.4", | ||
"history": "^4.3.0", | ||
"isparta-loader": "^2.0.0", | ||
"karma": "^1.3.0", | ||
"karma-chai-sinon": "^0.1.5", | ||
"karma-chrome-launcher": "^2.0.0", | ||
"karma-cli": "^1.0.1", | ||
"karma-coverage": "^1.1.1", | ||
"karma-mocha": "^1.2.0", | ||
"karma-mocha-reporter": "^2.0.0", | ||
"karma-sourcemap-loader": "^0.3.6", | ||
"karma-tap-reporter": "0.0.6", | ||
"karma-webpack": "^1.7.0", | ||
"mocha": "^3.1.2", | ||
"phantom": "^2.0.4", | ||
"prop-types": "^15.5.10", | ||
"querystring": "^0.2.0", | ||
"radium": "^0.18.1", | ||
"react": "^15.0.1", | ||
"react-addons-test-utils": "^15.0.1", | ||
"react-dom": "^15.0.1", | ||
"rimraf": "^2.5.2", | ||
"serve-static": "^1.10.2", | ||
"sinon": "^1.17.2", | ||
"sinon-chai": "^2.8.0", | ||
"webpack": "^1.4.13", | ||
"webpack-dev-middleware": "^1.5.1", | ||
"webpack-dev-server": "^1.14.1" | ||
}, | ||
"scripts": { | ||
"commit": "git-cz", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"build": "npm run clean && npm run compile", | ||
"build:umd": "NODE_ENV=development webpack src/index.js dist/react-gpt.js", | ||
"build:umd:min": "NODE_ENV=production webpack -p src/index.js dist/react-gpt.min.js", | ||
"clean": "rimraf lib coverage", | ||
"compile": "babel src --out-dir lib", | ||
"examples": "webpack-dev-server --config examples/webpack.config.js --content-base examples/apps --inline", | ||
"lint": "eslint src test examples", | ||
"start": "npm run build && env BABEL_ENV=examples node examples/server/index.js", | ||
"pretest": "npm run build", | ||
"prepublish": "npm run build && npm run build:umd && npm run build:umd:min", | ||
"test": "npm run lint && karma start", | ||
"update-apilist": "node ./scripts/updateAPIList.js" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
} | ||
"name": "react-gpt", | ||
"version": "0.3.0", | ||
"description": "A react display ad component using Google Publisher Tag", | ||
"main": "lib/index.js", | ||
"contributors": [ | ||
{ | ||
"name": "NFL Engineering" | ||
} | ||
], | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/nfl/react-gpt" | ||
}, | ||
"keywords": [ | ||
"react-gpt", | ||
"nfl", | ||
"react", | ||
"ad", | ||
"gpt", | ||
"google publisher tags" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/nfl/react-gpt/issues" | ||
}, | ||
"files": ["*.md", "docs", "src", "dist", "lib"], | ||
"dependencies": { | ||
"deep-equal": "^1.0.1", | ||
"eventemitter3": "^2.0.2", | ||
"exenv": "^1.2.2", | ||
"hoist-non-react-statics": "^1.0.5", | ||
"invariant": "^2.2.2", | ||
"prettier": "^1.7.0", | ||
"throttle-debounce": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.5.1", | ||
"babel-core": "^6.5.1", | ||
"babel-eslint": "^8.0.0", | ||
"babel-loader": "^6.2.3", | ||
"babel-plugin-transform-decorators-legacy": "^1.3.4", | ||
"babel-plugin-webpack-alias": "^2.1.1", | ||
"babel-preset-es2015-without-strict": "^0.0.4", | ||
"babel-preset-react": "^6.5.0", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"babel-register": "^6.7.2", | ||
"bundlesize": "^0.14.4", | ||
"chai": "^3.4.1", | ||
"codecov.io": "^0.1.6", | ||
"commitizen": "^2.8.1", | ||
"conventional-changelog-cli": "^1.2.0", | ||
"core-js": "^2.2.2", | ||
"cz-conventional-changelog": "^1.1.6", | ||
"eslint": "4.7.0", | ||
"eslint-config-prettier": "^2.5.0", | ||
"eslint-plugin-prettier": "^2.2.0", | ||
"eslint-config-nfl": "12.0.0", | ||
"eslint-plugin-import": "2.7.0", | ||
"eslint-plugin-mocha": "4.11.0", | ||
"eslint-plugin-react": "7.3.0", | ||
"express": "^4.13.4", | ||
"history": "^4.3.0", | ||
"isparta-loader": "^2.0.0", | ||
"karma": "^1.3.0", | ||
"karma-chai-sinon": "^0.1.5", | ||
"karma-chrome-launcher": "^2.0.0", | ||
"karma-cli": "^1.0.1", | ||
"karma-coverage": "^1.1.1", | ||
"karma-mocha": "^1.2.0", | ||
"karma-mocha-reporter": "^2.0.0", | ||
"karma-sourcemap-loader": "^0.3.6", | ||
"karma-tap-reporter": "0.0.6", | ||
"karma-webpack": "^1.7.0", | ||
"mocha": "^3.1.2", | ||
"phantom": "^2.0.4", | ||
"prop-types": "^15.5.10", | ||
"querystring": "^0.2.0", | ||
"radium": "^0.18.1", | ||
"react": "^15.0.1", | ||
"react-addons-test-utils": "^15.0.1", | ||
"react-dom": "^15.0.1", | ||
"rimraf": "^2.5.2", | ||
"serve-static": "^1.10.2", | ||
"sinon": "^1.17.2", | ||
"sinon-chai": "^2.8.0", | ||
"webpack": "^1.4.13", | ||
"webpack-dev-middleware": "^1.5.1", | ||
"webpack-dev-server": "^1.14.1" | ||
}, | ||
"peerDepencencies": { | ||
"prop-types": "^15.5.10", | ||
"react": "^15.0.1", | ||
"react-dom": "^15.0.1" | ||
}, | ||
"scripts": { | ||
"commit": "git-cz", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", | ||
"build": "npm run clean && npm run compile", | ||
"build:umd": | ||
"NODE_ENV=development webpack src/index.js dist/react-gpt.js", | ||
"build:umd:min": | ||
"NODE_ENV=production webpack -p src/index.js dist/react-gpt.min.js", | ||
"bundlesize": "npm run build:umd:min && bundlesize", | ||
"clean": "rimraf lib coverage", | ||
"compile": "babel src --out-dir lib", | ||
"examples": | ||
"webpack-dev-server --config examples/webpack.config.js --content-base examples/apps --inline", | ||
"lint": "eslint --fix src test examples", | ||
"start": | ||
"npm run build && env BABEL_ENV=examples node examples/server/index.js", | ||
"pretest": "npm run build", | ||
"prepublish": | ||
"npm run build && npm run build:umd && npm run build:umd:min", | ||
"test": "npm run lint && karma start", | ||
"update-apilist": "node ./scripts/updateAPIList.js" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
"path": "./node_modules/cz-conventional-changelog" | ||
} | ||
}, | ||
"bundlesize": [ | ||
{ | ||
"path": "./dist/react-gpt.min.js", | ||
"maxSize": "8.5 kB" | ||
} | ||
] | ||
} |
152
src/Bling.js
@@ -5,3 +5,3 @@ /* eslint-disable react/sort-comp */ | ||
import ReactDOM from "react-dom"; | ||
import invariant from "fbjs/lib/invariant"; | ||
import invariant from "invariant"; | ||
import deepEqual from "deep-equal"; | ||
@@ -51,6 +51,3 @@ import hoistStatics from "hoist-non-react-statics"; | ||
*/ | ||
slotSize: PropTypes.oneOfType([ | ||
PropTypes.array, | ||
PropTypes.string | ||
]), | ||
slotSize: PropTypes.oneOfType([PropTypes.array, PropTypes.string]), | ||
/** | ||
@@ -73,6 +70,8 @@ * An optional array of object which contains an array of viewport size and slot size. | ||
*/ | ||
sizeMapping: PropTypes.arrayOf(PropTypes.shape({ | ||
viewport: PropTypes.array, | ||
slot: PropTypes.array | ||
})), | ||
sizeMapping: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
viewport: PropTypes.array, | ||
slot: PropTypes.array | ||
}) | ||
), | ||
/** | ||
@@ -192,5 +191,5 @@ * An optional flag to indicate whether an ad slot should be out-of-page slot. | ||
style: PropTypes.object | ||
} | ||
}; | ||
/** | ||
/** | ||
* An array of prop names which can reflect to the ad by calling `refresh`. | ||
@@ -211,3 +210,3 @@ * | ||
"safeFrameConfig" | ||
] | ||
]; | ||
/** | ||
@@ -219,8 +218,3 @@ * An array of prop names which requires to create a new ad slot and render as a new ad. | ||
*/ | ||
static reRenderProps = [ | ||
"adUnitPath", | ||
"slotSize", | ||
"outOfPage", | ||
"content" | ||
] | ||
static reRenderProps = ["adUnitPath", "slotSize", "outOfPage", "content"]; | ||
/** | ||
@@ -233,4 +227,4 @@ * An instance of ad manager. | ||
*/ | ||
static _adManager = createManager() | ||
/** | ||
static _adManager = createManager(); | ||
/** | ||
* | ||
@@ -263,3 +257,3 @@ * @property | ||
propsEqual: deepEqual | ||
} | ||
}; | ||
@@ -299,3 +293,3 @@ static on(eventType, cb) { | ||
} | ||
/** | ||
/** | ||
* Returns the GPT version. | ||
@@ -320,3 +314,3 @@ * | ||
} | ||
/** | ||
/** | ||
* Sets a flag to indicate whether the correlator value should always be same across the ads in the page or not. | ||
@@ -350,3 +344,3 @@ * | ||
} | ||
/** | ||
/** | ||
* Clears the ads for the specified ad slots, if no slots are provided, all the ads will be cleared. | ||
@@ -379,3 +373,3 @@ * | ||
inViewport: false | ||
} | ||
}; | ||
@@ -387,3 +381,5 @@ get adSlot() { | ||
get viewableThreshold() { | ||
return this.props.viewableThreshold >= 0 ? this.props.viewableThreshold : Bling._config.viewableThreshold; | ||
return this.props.viewableThreshold >= 0 | ||
? this.props.viewableThreshold | ||
: Bling._config.viewableThreshold; | ||
} | ||
@@ -393,3 +389,6 @@ | ||
Bling._adManager.addInstance(this); | ||
Bling._adManager.load(Bling._config.seedFileUrl).then(this.onScriptLoaded.bind(this)).catch(this.onScriptError.bind(this)); | ||
Bling._adManager | ||
.load(Bling._config.seedFileUrl) | ||
.then(this.onScriptLoaded.bind(this)) | ||
.catch(this.onScriptError.bind(this)); | ||
} | ||
@@ -400,3 +399,6 @@ | ||
const {sizeMapping} = this.props; | ||
if ((nextProps.sizeMapping || sizeMapping) && !propsEqual(nextProps.sizeMapping, sizeMapping)) { | ||
if ( | ||
(nextProps.sizeMapping || sizeMapping) && | ||
!propsEqual(nextProps.sizeMapping, sizeMapping) | ||
) { | ||
Bling._adManager.removeMQListener(this, nextProps); | ||
@@ -411,4 +413,4 @@ } | ||
const notInViewport = this.notInViewport(nextProps, nextState); | ||
const inViewportChanged = (this.state.inViewport !== inViewport); | ||
const isScriptLoaded = (this.state.scriptLoaded !== scriptLoaded); | ||
const inViewportChanged = this.state.inViewport !== inViewport; | ||
const isScriptLoaded = this.state.scriptLoaded !== scriptLoaded; | ||
@@ -423,6 +425,19 @@ // Exit early for visibility change, before executing deep equality check. | ||
const {filterProps, propsEqual} = Bling._config; | ||
const refreshableProps = filterProps(Bling.refreshableProps, this.props, nextProps); | ||
const reRenderProps = filterProps(Bling.reRenderProps, this.props, nextProps); | ||
const shouldRender = !propsEqual(reRenderProps.props, reRenderProps.nextProps); | ||
const shouldRefresh = !shouldRender && !propsEqual(refreshableProps.props, refreshableProps.nextProps); | ||
const refreshableProps = filterProps( | ||
Bling.refreshableProps, | ||
this.props, | ||
nextProps | ||
); | ||
const reRenderProps = filterProps( | ||
Bling.reRenderProps, | ||
this.props, | ||
nextProps | ||
); | ||
const shouldRender = !propsEqual( | ||
reRenderProps.props, | ||
reRenderProps.nextProps | ||
); | ||
const shouldRefresh = | ||
!shouldRender && | ||
!propsEqual(refreshableProps.props, refreshableProps.nextProps); | ||
// console.log(`shouldRefresh: ${shouldRefresh}, shouldRender: ${shouldRender}, isScriptLoaded: ${isScriptLoaded}, syncCorrelator: ${Bling._adManager._syncCorrelator}`); | ||
@@ -486,7 +501,12 @@ | ||
onScriptError(err) { | ||
console.warn(`Ad: Failed to load gpt for ${Bling._config.seedFileUrl}`, err); | ||
console.warn( | ||
`Ad: Failed to load gpt for ${Bling._config.seedFileUrl}`, | ||
err | ||
); | ||
} | ||
getRenderWhenViewable(props = this.props) { | ||
return props.renderWhenViewable !== undefined ? props.renderWhenViewable : Bling._config.renderWhenViewable; | ||
return props.renderWhenViewable !== undefined | ||
? props.renderWhenViewable | ||
: Bling._config.renderWhenViewable; | ||
} | ||
@@ -507,3 +527,7 @@ | ||
const inViewport = Bling._adManager.isInViewport(ReactDOM.findDOMNode(this), slotSize, this.viewableThreshold); | ||
const inViewport = Bling._adManager.isInViewport( | ||
ReactDOM.findDOMNode(this), | ||
slotSize, | ||
this.viewableThreshold | ||
); | ||
if (inViewport) { | ||
@@ -517,5 +541,7 @@ this.setState({inViewport: true}); | ||
Bling._adManager.addMQListener(this, this.props); | ||
const sizeMappingArray = sizeMapping.reduce((mapping, size) => { | ||
return mapping.addSize(size.viewport, size.slot); | ||
}, Bling._adManager.googletag.sizeMapping()).build(); | ||
const sizeMappingArray = sizeMapping | ||
.reduce((mapping, size) => { | ||
return mapping.addSize(size.viewport, size.slot); | ||
}, Bling._adManager.googletag.sizeMapping()) | ||
.build(); | ||
adSlot.defineSizeMapping(sizeMappingArray); | ||
@@ -555,3 +581,5 @@ } | ||
if (serviceConfig.hasOwnProperty("refreshUnfilledSlots")) { | ||
companionAdsService.setRefreshUnfilledSlots(serviceConfig.refreshUnfilledSlots); | ||
companionAdsService.setRefreshUnfilledSlots( | ||
serviceConfig.refreshUnfilledSlots | ||
); | ||
} | ||
@@ -588,6 +616,3 @@ } | ||
defineSlot() { | ||
const { | ||
adUnitPath, | ||
outOfPage | ||
} = this.props; | ||
const {adUnitPath, outOfPage} = this.props; | ||
const divId = this._divId; | ||
@@ -598,5 +623,12 @@ const slotSize = this.getSlotSize(); | ||
if (outOfPage) { | ||
this._adSlot = Bling._adManager.googletag.defineOutOfPageSlot(adUnitPath, divId); | ||
this._adSlot = Bling._adManager.googletag.defineOutOfPageSlot( | ||
adUnitPath, | ||
divId | ||
); | ||
} else { | ||
this._adSlot = Bling._adManager.googletag.defineSlot(adUnitPath, slotSize || [], divId); | ||
this._adSlot = Bling._adManager.googletag.defineSlot( | ||
adUnitPath, | ||
slotSize || [], | ||
divId | ||
); | ||
} | ||
@@ -684,7 +716,13 @@ } | ||
} else { | ||
if (!Bling._adManager._disableInitialLoad && !Bling._adManager._syncCorrelator) { | ||
if ( | ||
!Bling._adManager._disableInitialLoad && | ||
!Bling._adManager._syncCorrelator | ||
) { | ||
Bling._adManager.updateCorrelator(); | ||
} | ||
Bling._adManager.googletag.display(divId); | ||
if (Bling._adManager._disableInitialLoad && !Bling._adManager._initialRender) { | ||
if ( | ||
Bling._adManager._disableInitialLoad && | ||
!Bling._adManager._initialRender | ||
) { | ||
this.refresh(); | ||
@@ -738,3 +776,6 @@ } | ||
} | ||
const emptyStyle = slotSize && {width: slotSize[0], height: slotSize[1]}; | ||
const emptyStyle = slotSize && { | ||
width: slotSize[0], | ||
height: slotSize[1] | ||
}; | ||
// render node element instead of script element so that `inViewport` check works. | ||
@@ -757,5 +798,8 @@ return <div style={emptyStyle} />; | ||
// proxy pubads API through Bling | ||
export default hoistStatics(Bling, pubadsAPI.reduce((api, method) => { | ||
api[method] = (...args) => Bling._adManager.pubadsProxy({method, args}); | ||
return api; | ||
}, {})); | ||
export default hoistStatics( | ||
Bling, | ||
pubadsAPI.reduce((api, method) => { | ||
api[method] = (...args) => Bling._adManager.pubadsProxy({method, args}); | ||
return api; | ||
}, {}) | ||
); |
import EventEmitter from "eventemitter3"; | ||
import debounce from "debounce"; | ||
import invariant from "fbjs/lib/invariant"; | ||
import {canUseDOM} from "fbjs/lib/ExecutionEnvironment"; | ||
import {debounce, throttle} from "throttle-debounce"; | ||
import invariant from "invariant"; | ||
import {canUseDOM} from "exenv"; | ||
import Events from "./Events"; | ||
@@ -51,9 +51,9 @@ import isInViewport from "./utils/isInViewport"; | ||
_adCnt = 0 | ||
_adCnt = 0; | ||
_initialRender = true | ||
_initialRender = true; | ||
_syncCorrelator = false | ||
_syncCorrelator = false; | ||
_testMode = false | ||
_testMode = false; | ||
@@ -104,5 +104,11 @@ get googletag() { | ||
Object.keys(this._pubadsProxyQueue).forEach(method => { | ||
if ((this.googletag && !this.googletag.pubadsReady && APIToCallBeforeServiceEnabled.indexOf(method) > -1) || | ||
this.pubadsReady) { | ||
this._pubadsProxyQueue[method].forEach((params) => this.pubadsProxy(params)); | ||
if ( | ||
(this.googletag && | ||
!this.googletag.pubadsReady && | ||
APIToCallBeforeServiceEnabled.indexOf(method) > -1) || | ||
this.pubadsReady | ||
) { | ||
this._pubadsProxyQueue[method].forEach(params => | ||
this.pubadsProxy(params) | ||
); | ||
delete this._pubadsProxyQueue[method]; | ||
@@ -119,3 +125,7 @@ } | ||
if (typeof this.googletag.pubads()[method] !== "function") { | ||
reject(new Error(`googletag.pubads does not support ${method}, please update pubadsAPI`)); | ||
reject( | ||
new Error( | ||
`googletag.pubads does not support ${method}, please update pubadsAPI` | ||
) | ||
); | ||
} else { | ||
@@ -133,7 +143,10 @@ try { | ||
["scroll", "resize"].forEach(eventName => { | ||
window[add ? "addEventListener" : "removeEventListener"](eventName, this._foldCheck); | ||
window[add ? "addEventListener" : "removeEventListener"]( | ||
eventName, | ||
this._foldCheck | ||
); | ||
}); | ||
} | ||
_foldCheck = debounce(event => { | ||
_foldCheck = throttle(20, event => { | ||
const instances = this.getMountedInstances(); | ||
@@ -145,4 +158,12 @@ instances.forEach(instance => { | ||
}); | ||
}, 66) | ||
if (this.testMode) { | ||
this._getTimer(); | ||
} | ||
}); | ||
_getTimer() { | ||
return Date.now(); | ||
} | ||
_handleMediaQueryChange = event => { | ||
@@ -154,3 +175,4 @@ if (this._syncCorrelator) { | ||
// IE returns `event.media` value differently, need to use regex to evaluate. | ||
const res = (/min-width:\s?(\d+)px/).exec(event.media); | ||
// eslint-disable-next-line wrap-regex | ||
const res = /min-width:\s?(\d+)px/.exec(event.media); | ||
const viewportWidth = res && res[1]; | ||
@@ -166,3 +188,3 @@ | ||
} | ||
} | ||
}; | ||
@@ -178,3 +200,8 @@ _listen() { | ||
// there is no API to remove listeners. | ||
this.googletag[service]().addEventListener(eventType, this._onEvent.bind(this, eventType)); | ||
this.googletag | ||
[service]() | ||
.addEventListener( | ||
eventType, | ||
this._onEvent.bind(this, eventType) | ||
); | ||
}); | ||
@@ -194,3 +221,5 @@ }); | ||
const {slot} = event; | ||
const funcName = `on${eventType.charAt(0).toUpperCase()}${eventType.substr(1)}`; | ||
const funcName = `on${eventType | ||
.charAt(0) | ||
.toUpperCase()}${eventType.substr(1)}`; | ||
const instance = instances.filter(inst => slot === inst.adSlot)[0]; | ||
@@ -255,3 +284,5 @@ if (instance && instance.props[funcName]) { | ||
if (!this._mqls[viewportWidth]) { | ||
const mql = window.matchMedia(`(min-width: ${viewportWidth}px)`); | ||
const mql = window.matchMedia( | ||
`(min-width: ${viewportWidth}px)` | ||
); | ||
mql.addListener(this._handleMediaQueryChange); | ||
@@ -263,3 +294,5 @@ this._mqls[viewportWidth] = { | ||
} | ||
if (this._mqls[viewportWidth].listeners.indexOf(instance) === -1) { | ||
if ( | ||
this._mqls[viewportWidth].listeners.indexOf(instance) === -1 | ||
) { | ||
this._mqls[viewportWidth].listeners.push(instance); | ||
@@ -276,13 +309,14 @@ } | ||
Object.keys(this._mqls) | ||
.forEach(key => { | ||
const index = this._mqls[key].listeners.indexOf(instance); | ||
if (index > -1) { | ||
this._mqls[key].listeners.splice(index, 1); | ||
} | ||
if (this._mqls[key].listeners.length === 0) { | ||
this._mqls[key].mql.removeListener(this._handleMediaQueryChange); | ||
delete this._mqls[key]; | ||
} | ||
}); | ||
Object.keys(this._mqls).forEach(key => { | ||
const index = this._mqls[key].listeners.indexOf(instance); | ||
if (index > -1) { | ||
this._mqls[key].listeners.splice(index, 1); | ||
} | ||
if (this._mqls[key].listeners.length === 0) { | ||
this._mqls[key].mql.removeListener( | ||
this._handleMediaQueryChange | ||
); | ||
delete this._mqls[key]; | ||
} | ||
}); | ||
} | ||
@@ -322,3 +356,3 @@ | ||
render = debounce(() => { | ||
render = debounce(4, () => { | ||
if (!this._initialRender) { | ||
@@ -341,3 +375,3 @@ return; | ||
// Define all the slots | ||
instances.forEach((instance) => { | ||
instances.forEach(instance => { | ||
if (!instance.notInViewport()) { | ||
@@ -350,3 +384,6 @@ instance.defineSlot(); | ||
if (!hasPubAdsService) { | ||
hasPubAdsService = services.filter(service => !!service.enableAsyncRendering).length > 0; | ||
hasPubAdsService = | ||
services.filter( | ||
service => !!service.enableAsyncRendering | ||
).length > 0; | ||
} | ||
@@ -383,3 +420,3 @@ } | ||
// Call display | ||
instances.forEach((instance) => { | ||
instances.forEach(instance => { | ||
if (!instance.notInViewport()) { | ||
@@ -394,3 +431,3 @@ instance.display(); | ||
}); | ||
}, 4) | ||
}); | ||
@@ -404,3 +441,3 @@ /** | ||
*/ | ||
renderAll = debounce(() => { | ||
renderAll = debounce(4, () => { | ||
if (!this.apiReady) { | ||
@@ -420,3 +457,3 @@ return false; | ||
return true; | ||
}, 4) | ||
}); | ||
@@ -447,41 +484,44 @@ getGPTVersion() { | ||
load(url) { | ||
return this._loadPromise || (this._loadPromise = new Promise((resolve, reject) => { | ||
// test mode can't be enabled in production mode | ||
if (this.testMode) { | ||
resolve(this.googletag); | ||
return; | ||
} | ||
if (!canUseDOM) { | ||
reject(new Error("DOM not available")); | ||
return; | ||
} | ||
if (!url) { | ||
reject(new Error("url is missing")); | ||
return; | ||
} | ||
const onLoad = () => { | ||
if (window.googletag) { | ||
this._googletag = window.googletag; | ||
// make sure API is ready for use. | ||
this.googletag.cmd.push(() => { | ||
this._isLoaded = true; | ||
resolve(this.googletag); | ||
}); | ||
return ( | ||
this._loadPromise || | ||
(this._loadPromise = new Promise((resolve, reject) => { | ||
// test mode can't be enabled in production mode | ||
if (this.testMode) { | ||
resolve(this.googletag); | ||
return; | ||
} | ||
if (!canUseDOM) { | ||
reject(new Error("DOM not available")); | ||
return; | ||
} | ||
if (!url) { | ||
reject(new Error("url is missing")); | ||
return; | ||
} | ||
const onLoad = () => { | ||
if (window.googletag) { | ||
this._googletag = window.googletag; | ||
// make sure API is ready for use. | ||
this.googletag.cmd.push(() => { | ||
this._isLoaded = true; | ||
resolve(this.googletag); | ||
}); | ||
} else { | ||
reject(new Error("window.googletag is not available")); | ||
} | ||
}; | ||
if (window.googletag && window.googletag.apiReady) { | ||
onLoad(); | ||
} else { | ||
reject(new Error("window.googletag is not available")); | ||
const script = document.createElement("script"); | ||
script.async = true; | ||
script.onload = onLoad; | ||
script.onerror = () => { | ||
reject(new Error("failed to load script")); | ||
}; | ||
script.src = url; | ||
document.head.appendChild(script); | ||
} | ||
}; | ||
if (window.googletag && window.googletag.apiReady) { | ||
onLoad(); | ||
} else { | ||
const script = document.createElement("script"); | ||
script.async = true; | ||
script.onload = onLoad; | ||
script.onerror = () => { | ||
reject(new Error("failed to load script")); | ||
}; | ||
script.src = url; | ||
document.head.appendChild(script); | ||
} | ||
})); | ||
})) | ||
); | ||
} | ||
@@ -497,3 +537,8 @@ | ||
return new Promise((resolve2, reject2) => { | ||
const params = {method, args, resolve: resolve2, reject: reject2}; | ||
const params = { | ||
method, | ||
args, | ||
resolve: resolve2, | ||
reject: reject2 | ||
}; | ||
if (!this.pubadsReady) { | ||
@@ -500,0 +545,0 @@ if (!this._pubadsProxyQueue) { |
@@ -7,124 +7,124 @@ // DO NOT MODIFY THIS FILE MANUALLY. | ||
export const gptAPI = [ | ||
["getVersion", "function"], | ||
["cmd", "object"], | ||
["getEventLog", "function"], | ||
["enableServices", "function"], | ||
["setAdIframeTitle", "function"], | ||
["impl", "object"], | ||
["pubads", "function"], | ||
["defineOutOfPageSlot", "function"], | ||
["defineSlot", "function"], | ||
["defineUnit", "function"], | ||
["destroySlots", "function"], | ||
["display", "function"], | ||
["companionAds", "function"], | ||
["content", "function"], | ||
["debug_log", "object"], | ||
["service_manager_instance", "object"], | ||
["disablePublisherConsole", "function"], | ||
["onPubConsoleJsLoad", "function"], | ||
["openConsole", "function"], | ||
["sizeMapping", "function"], | ||
["evalScripts", "function"], | ||
["apiReady", "boolean"], | ||
["slot_manager_instance", "object"], | ||
["pubadsReady", "boolean"] | ||
["getVersion", "function"], | ||
["cmd", "object"], | ||
["getEventLog", "function"], | ||
["enableServices", "function"], | ||
["setAdIframeTitle", "function"], | ||
["impl", "object"], | ||
["pubads", "function"], | ||
["defineOutOfPageSlot", "function"], | ||
["defineSlot", "function"], | ||
["defineUnit", "function"], | ||
["destroySlots", "function"], | ||
["display", "function"], | ||
["companionAds", "function"], | ||
["content", "function"], | ||
["debug_log", "object"], | ||
["service_manager_instance", "object"], | ||
["disablePublisherConsole", "function"], | ||
["onPubConsoleJsLoad", "function"], | ||
["openConsole", "function"], | ||
["sizeMapping", "function"], | ||
["evalScripts", "function"], | ||
["apiReady", "boolean"], | ||
["slot_manager_instance", "object"], | ||
["pubadsReady", "boolean"] | ||
]; | ||
export const pubadsVersion = 110; | ||
export const pubadsAPI = [ | ||
["set", "function"], | ||
["get", "function"], | ||
["getAttributeKeys", "function"], | ||
["display", "function"], | ||
["getName", "function"], | ||
["setCookieOptions", "function"], | ||
["setTagForChildDirectedTreatment", "function"], | ||
["clearTagForChildDirectedTreatment", "function"], | ||
["setKidsFriendlyAds", "function"], | ||
["setTargeting", "function"], | ||
["clearTargeting", "function"], | ||
["getTargeting", "function"], | ||
["getTargetingKeys", "function"], | ||
["setCategoryExclusion", "function"], | ||
["clearCategoryExclusions", "function"], | ||
["disableInitialLoad", "function"], | ||
["enableSingleRequest", "function"], | ||
["enableAsyncRendering", "function"], | ||
["enableSyncRendering", "function"], | ||
["setCentering", "function"], | ||
["setPublisherProvidedId", "function"], | ||
["definePassback", "function"], | ||
["defineOutOfPagePassback", "function"], | ||
["refresh", "function"], | ||
["enableVideoAds", "function"], | ||
["setVideoContent", "function"], | ||
["getVideoContent", "function"], | ||
["getCorrelator", "function"], | ||
["setCorrelator", "function"], | ||
["updateCorrelator", "function"], | ||
["isAdRequestFinished", "function"], | ||
["collapseEmptyDivs", "function"], | ||
["clear", "function"], | ||
["setLocation", "function"], | ||
["getVersion", "function"], | ||
["forceExperiment", "function"], | ||
["markAsAmp", "function"], | ||
["setSafeFrameConfig", "function"], | ||
["setForceSafeFrame", "function"], | ||
["enableChromeInterventionSignals", "function"], | ||
["markAsGladeControl", "function"], | ||
["markAsGladeOptOut", "function"], | ||
["getName", "function"], | ||
["getVersion", "function"], | ||
["getSlots", "function"], | ||
["getSlotIdMap", "function"], | ||
["enable", "function"], | ||
["addEventListener", "function"] | ||
["set", "function"], | ||
["get", "function"], | ||
["getAttributeKeys", "function"], | ||
["display", "function"], | ||
["getName", "function"], | ||
["setCookieOptions", "function"], | ||
["setTagForChildDirectedTreatment", "function"], | ||
["clearTagForChildDirectedTreatment", "function"], | ||
["setKidsFriendlyAds", "function"], | ||
["setTargeting", "function"], | ||
["clearTargeting", "function"], | ||
["getTargeting", "function"], | ||
["getTargetingKeys", "function"], | ||
["setCategoryExclusion", "function"], | ||
["clearCategoryExclusions", "function"], | ||
["disableInitialLoad", "function"], | ||
["enableSingleRequest", "function"], | ||
["enableAsyncRendering", "function"], | ||
["enableSyncRendering", "function"], | ||
["setCentering", "function"], | ||
["setPublisherProvidedId", "function"], | ||
["definePassback", "function"], | ||
["defineOutOfPagePassback", "function"], | ||
["refresh", "function"], | ||
["enableVideoAds", "function"], | ||
["setVideoContent", "function"], | ||
["getVideoContent", "function"], | ||
["getCorrelator", "function"], | ||
["setCorrelator", "function"], | ||
["updateCorrelator", "function"], | ||
["isAdRequestFinished", "function"], | ||
["collapseEmptyDivs", "function"], | ||
["clear", "function"], | ||
["setLocation", "function"], | ||
["getVersion", "function"], | ||
["forceExperiment", "function"], | ||
["markAsAmp", "function"], | ||
["setSafeFrameConfig", "function"], | ||
["setForceSafeFrame", "function"], | ||
["enableChromeInterventionSignals", "function"], | ||
["markAsGladeControl", "function"], | ||
["markAsGladeOptOut", "function"], | ||
["getName", "function"], | ||
["getVersion", "function"], | ||
["getSlots", "function"], | ||
["getSlotIdMap", "function"], | ||
["enable", "function"], | ||
["addEventListener", "function"] | ||
]; | ||
export const slotAPI = [ | ||
["getPassbackPageUrl", "function"], | ||
["set", "function"], | ||
["get", "function"], | ||
["getAttributeKeys", "function"], | ||
["addService", "function"], | ||
["getName", "function"], | ||
["getAdUnitPath", "function"], | ||
["getInstance", "function"], | ||
["getSlotElementId", "function"], | ||
["getSlotId", "function"], | ||
["getServices", "function"], | ||
["getSizes", "function"], | ||
["defineSizeMapping", "function"], | ||
["hasWrapperDiv", "function"], | ||
["setClickUrl", "function"], | ||
["getClickUrl", "function"], | ||
["setForceSafeFrame", "function"], | ||
["setCategoryExclusion", "function"], | ||
["clearCategoryExclusions", "function"], | ||
["getCategoryExclusions", "function"], | ||
["setTargeting", "function"], | ||
["clearTargeting", "function"], | ||
["getTargetingMap", "function"], | ||
["getTargeting", "function"], | ||
["getTargetingKeys", "function"], | ||
["getOutOfPage", "function"], | ||
["getAudExtId", "function"], | ||
["gtfcd", "function"], | ||
["setCollapseEmptyDiv", "function"], | ||
["getCollapseEmptyDiv", "function"], | ||
["getDivStartsCollapsed", "function"], | ||
["fetchStarted", "function"], | ||
["getContentUrl", "function"], | ||
["fetchEnded", "function"], | ||
["renderStarted", "function"], | ||
["getResponseInformation", "function"], | ||
["renderEnded", "function"], | ||
["loaded", "function"], | ||
["impressionViewable", "function"], | ||
["visibilityChanged", "function"], | ||
["setFirstLook", "function"], | ||
["getFirstLook", "function"], | ||
["getEscapedQemQueryId", "function"], | ||
["setSafeFrameConfig", "function"], | ||
["getCsiId", "function"] | ||
["getPassbackPageUrl", "function"], | ||
["set", "function"], | ||
["get", "function"], | ||
["getAttributeKeys", "function"], | ||
["addService", "function"], | ||
["getName", "function"], | ||
["getAdUnitPath", "function"], | ||
["getInstance", "function"], | ||
["getSlotElementId", "function"], | ||
["getSlotId", "function"], | ||
["getServices", "function"], | ||
["getSizes", "function"], | ||
["defineSizeMapping", "function"], | ||
["hasWrapperDiv", "function"], | ||
["setClickUrl", "function"], | ||
["getClickUrl", "function"], | ||
["setForceSafeFrame", "function"], | ||
["setCategoryExclusion", "function"], | ||
["clearCategoryExclusions", "function"], | ||
["getCategoryExclusions", "function"], | ||
["setTargeting", "function"], | ||
["clearTargeting", "function"], | ||
["getTargetingMap", "function"], | ||
["getTargeting", "function"], | ||
["getTargetingKeys", "function"], | ||
["getOutOfPage", "function"], | ||
["getAudExtId", "function"], | ||
["gtfcd", "function"], | ||
["setCollapseEmptyDiv", "function"], | ||
["getCollapseEmptyDiv", "function"], | ||
["getDivStartsCollapsed", "function"], | ||
["fetchStarted", "function"], | ||
["getContentUrl", "function"], | ||
["fetchEnded", "function"], | ||
["renderStarted", "function"], | ||
["getResponseInformation", "function"], | ||
["renderEnded", "function"], | ||
["loaded", "function"], | ||
["impressionViewable", "function"], | ||
["visibilityChanged", "function"], | ||
["setFirstLook", "function"], | ||
["getFirstLook", "function"], | ||
["getEscapedQemQueryId", "function"], | ||
["setSafeFrameConfig", "function"], | ||
["getCsiId", "function"] | ||
]; |
export default function filterProps(propKeys, props, nextProps) { | ||
return propKeys.reduce((filtered, key) => { | ||
filtered.props[key] = props[key]; | ||
filtered.nextProps[key] = nextProps[key]; | ||
return filtered; | ||
}, { | ||
props: {}, | ||
nextProps: {} | ||
}); | ||
return propKeys.reduce( | ||
(filtered, key) => { | ||
filtered.props[key] = props[key]; | ||
filtered.nextProps[key] = nextProps[key]; | ||
return filtered; | ||
}, | ||
{ | ||
props: {}, | ||
nextProps: {} | ||
} | ||
); | ||
} |
@@ -18,9 +18,8 @@ export default function isInViewport(el, [width, height] = [0, 0], offset = 0) { | ||
}; | ||
const inViewport = ( | ||
rect.bottom >= (viewport.top + height * offset) && | ||
rect.right >= (viewport.left + width * offset) && | ||
rect.top <= (viewport.bottom - height * offset) && | ||
rect.left <= (viewport.right - width * offset) | ||
); | ||
const inViewport = | ||
rect.bottom >= viewport.top + height * offset && | ||
rect.right >= viewport.left + width * offset && | ||
rect.top <= viewport.bottom - height * offset && | ||
rect.left <= viewport.right - width * offset; | ||
return inViewport; | ||
} |
@@ -211,3 +211,5 @@ import {gptAPI, pubadsAPI, slotAPI, gptVersion, pubadsVersion} from "./apiList"; | ||
this.cmd = {}; | ||
this.cmd.push = cb => {cb();}; | ||
this.cmd.push = cb => { | ||
cb(); | ||
}; | ||
} | ||
@@ -214,0 +216,0 @@ pubadsReady = false; |
Sorry, the diff of this file is too big to display
303062
6322
7
52
+ Addedexenv@^1.2.2
+ Addedinvariant@^2.2.2
+ Addedprettier@^1.7.0
+ Addedthrottle-debounce@^1.0.1
+ Addedexenv@1.2.2(transitive)
+ Addedinvariant@2.2.4(transitive)
+ Addedprettier@1.19.1(transitive)
+ Addedthrottle-debounce@1.1.0(transitive)
- Removeddebounce@^1.0.0
- Removedfbjs@^0.8.1
- Removedasap@2.0.6(transitive)
- Removedcore-js@1.2.7(transitive)
- Removeddebounce@1.2.1(transitive)
- Removedencoding@0.1.13(transitive)
- Removedfbjs@0.8.18(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedisomorphic-fetch@2.2.1(transitive)
- Removednode-fetch@1.7.3(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedpromise@7.3.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsetimmediate@1.0.5(transitive)
- Removedua-parser-js@0.7.40(transitive)
- Removedwhatwg-fetch@3.6.20(transitive)