|
209 | 209 | statusCode: "cly_hc_status_code",
|
210 | 210 | errorMessage: "cly_hc_error_message"
|
211 | 211 | });
|
212 |
| - var SDK_VERSION = "24.11.3"; |
| 212 | + var SDK_VERSION = "24.11.4"; |
213 | 213 | var SDK_NAME = "javascript_native_web";
|
214 | 214 |
|
215 | 215 | // Using this on document.referrer would return an array with 17 elements in it. The 12th element (array[11]) would be the path we are looking for. Others would be things like password and such (use https://regex101.com/ to check more)
|
|
4386 | 4386 | if (e) {
|
4387 | 4387 | return;
|
4388 | 4388 | }
|
4389 |
| - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, received content: [" + resp + "]"); |
4390 |
| - _classPrivateFieldGet2(_displayContent, _this).call(_this, resp); |
| 4389 | + if (!resp) { |
| 4390 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.VERBOSE, "sendContentRequest, no content to display"); |
| 4391 | + return; |
| 4392 | + } |
| 4393 | + try { |
| 4394 | + var response = JSON.parse(resp); |
| 4395 | + } catch (error) { |
| 4396 | + // verbose log |
| 4397 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.VERBOSE, "sendContentRequest, No content to display or an error while parsing content: " + error); |
| 4398 | + return; |
| 4399 | + } |
| 4400 | + if (!response.html || !response.geo) { |
| 4401 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.VERBOSE, "sendContentRequest, no html content or orientation to display"); |
| 4402 | + return; |
| 4403 | + } |
| 4404 | + _classPrivateFieldGet2(_displayContent, _this).call(_this, response); |
4391 | 4405 | clearInterval(_classPrivateFieldGet2(_contentZoneTimer, _this)); // prevent multiple content requests while one is on
|
4392 | 4406 | window.addEventListener('message', function (event) {
|
4393 | 4407 | _classPrivateFieldGet2(_interpretContentMessage, _this).call(_this, event);
|
|
4399 | 4413 | var width = window.innerWidth;
|
4400 | 4414 | var height = window.innerHeight;
|
4401 | 4415 | var iframe = document.getElementById(_classPrivateFieldGet2(_contentIframeID, _this));
|
| 4416 | + if (!iframe) { |
| 4417 | + return; |
| 4418 | + } |
4402 | 4419 | iframe.contentWindow.postMessage({
|
4403 | 4420 | type: 'resize',
|
4404 | 4421 | width: width,
|
|
4408 | 4425 | });
|
4409 | 4426 | }, true);
|
4410 | 4427 | });
|
4411 |
| - _classPrivateFieldInitSpec(this, _displayContent, function (content) { |
4412 |
| - if (!content) { |
4413 |
| - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "displayContent, no content to display"); |
4414 |
| - return; |
| 4428 | + _classPrivateFieldInitSpec(this, _displayContent, function (response) { |
| 4429 | + try { |
| 4430 | + var iframe = document.createElement("iframe"); |
| 4431 | + iframe.id = _classPrivateFieldGet2(_contentIframeID, _this); |
| 4432 | + iframe.src = response.html; |
| 4433 | + iframe.style.position = "absolute"; |
| 4434 | + var dimensionToUse = response.geo.p; |
| 4435 | + var resInfo = _classPrivateFieldGet2(_getResolution, _this).call(_this, true); |
| 4436 | + if (resInfo.width >= resInfo.height) { |
| 4437 | + dimensionToUse = response.geo.l; |
| 4438 | + } |
| 4439 | + ; |
| 4440 | + iframe.style.left = dimensionToUse.x + "px"; |
| 4441 | + iframe.style.top = dimensionToUse.y + "px"; |
| 4442 | + iframe.style.width = dimensionToUse.w + "px"; |
| 4443 | + iframe.style.height = dimensionToUse.h + "px"; |
| 4444 | + iframe.style.border = "none"; |
| 4445 | + iframe.style.zIndex = "999999"; |
| 4446 | + document.body.appendChild(iframe); |
| 4447 | + } catch (error) { |
| 4448 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "displayContent, Error while creating iframe for the content: " + error); |
4415 | 4449 | }
|
4416 |
| - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "displayContent, displaying content"); |
4417 |
| - var response = JSON.parse(content); |
4418 |
| - var iframe = document.createElement("iframe"); |
4419 |
| - iframe.id = _classPrivateFieldGet2(_contentIframeID, _this); |
4420 |
| - iframe.src = response.html; |
4421 |
| - iframe.style.position = "absolute"; |
4422 |
| - var dimensionToUse = response.geo.p; |
4423 |
| - var resInfo = _classPrivateFieldGet2(_getResolution, _this).call(_this, true); |
4424 |
| - if (resInfo.width >= resInfo.height) { |
4425 |
| - dimensionToUse = response.geo.l; |
4426 |
| - } |
4427 |
| - iframe.style.left = dimensionToUse.x + "px"; |
4428 |
| - iframe.style.top = dimensionToUse.y + "px"; |
4429 |
| - iframe.style.width = dimensionToUse.w + "px"; |
4430 |
| - iframe.style.height = dimensionToUse.h + "px"; |
4431 |
| - iframe.style.border = "none"; |
4432 |
| - iframe.style.zIndex = "999999"; |
4433 |
| - document.body.appendChild(iframe); |
4434 | 4450 | });
|
4435 | 4451 | _classPrivateFieldInitSpec(this, _interpretContentMessage, function (messageEvent) {
|
4436 | 4452 | if (messageEvent.origin !== _this.url) {
|
4437 |
| - // this.#log(logLevelEnums.ERROR, "sendContentRequest, Received message from invalid origin"); |
| 4453 | + // this.#log(logLevelEnums.ERROR, "interpretContentMessage, Received message from invalid origin"); |
4438 | 4454 | // silent ignore
|
4439 | 4455 | return;
|
4440 | 4456 | }
|
4441 |
| - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received message from: [" + messageEvent.origin + "] with data: [" + JSON.stringify(messageEvent.data) + "]"); |
| 4457 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Received message from: [" + messageEvent.origin + "] with data: [" + JSON.stringify(messageEvent.data) + "]"); |
4442 | 4458 | var _messageEvent$data = messageEvent.data,
|
4443 | 4459 | close = _messageEvent$data.close,
|
4444 | 4460 | link = _messageEvent$data.link,
|
4445 | 4461 | event = _messageEvent$data.event,
|
4446 | 4462 | resize_me = _messageEvent$data.resize_me;
|
4447 | 4463 | if (event) {
|
4448 |
| - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Received event"); |
| 4464 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Received event"); |
4449 | 4465 | if (close === 1) {
|
4450 |
| - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Closing content frame for event"); |
| 4466 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Closing content frame for event"); |
4451 | 4467 | _classPrivateFieldGet2(_closeContentFrame, _this).call(_this);
|
4452 | 4468 | }
|
4453 | 4469 | if (!Array.isArray(event)) {
|
4454 | 4470 | if (_typeof(event) === "object") {
|
4455 | 4471 | _readOnlyError("event");
|
4456 | 4472 | } else {
|
4457 |
| - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "sendContentRequest, Invalid event type: [" + _typeof(event) + "]"); |
| 4473 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "interpretContentMessage, Invalid event type: [" + _typeof(event) + "]"); |
4458 | 4474 | return;
|
4459 | 4475 | }
|
4460 | 4476 | }
|
4461 | 4477 | // event is expected to be an array of events
|
4462 | 4478 | for (var i = 0; i < event.length; i++) {
|
4463 |
| - _classPrivateFieldGet2(_add_cly_events, _this).call(_this, event[i]); |
| 4479 | + _classPrivateFieldGet2(_add_cly_events, _this).call(_this, event[i]); // let this method handle the event |
4464 | 4480 | }
|
4465 | 4481 | }
|
4466 | 4482 | if (link) {
|
4467 | 4483 | if (close === 1) {
|
4468 |
| - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Closing content frame for link"); |
| 4484 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Closing content frame for link"); |
4469 | 4485 | _classPrivateFieldGet2(_closeContentFrame, _this).call(_this);
|
4470 | 4486 | }
|
4471 | 4487 | window.open(link, "_blank");
|
4472 |
| - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Opened link in new tab: [".concat(link, "]")); |
| 4488 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Opened link in new tab: [".concat(link, "]")); |
4473 | 4489 | }
|
4474 | 4490 | if (resize_me) {
|
4475 |
| - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, Resizing iframe"); |
| 4491 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, Resizing iframe"); |
4476 | 4492 | var resInfo = _classPrivateFieldGet2(_getResolution, _this).call(_this, true);
|
| 4493 | + if (!resize_me.l || !resize_me.p || !resize_me.l.x || !resize_me.l.y || !resize_me.l.w || !resize_me.l.h || !resize_me.p.x || !resize_me.p.y || !resize_me.p.w || !resize_me.p.h) { |
| 4494 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.ERROR, "interpretContentMessage, Invalid resize object"); |
| 4495 | + return; |
| 4496 | + } |
4477 | 4497 | var dimensionToUse = resize_me.p;
|
4478 | 4498 | if (resInfo.width >= resInfo.height) {
|
4479 | 4499 | dimensionToUse = resize_me.l;
|
|
4489 | 4509 | }
|
4490 | 4510 | });
|
4491 | 4511 | _classPrivateFieldInitSpec(this, _closeContentFrame, function () {
|
| 4512 | + // we might want to remove event listeners here too but with the current implementation, it seems unnecessary |
4492 | 4513 | var iframe = document.getElementById(_classPrivateFieldGet2(_contentIframeID, _this));
|
4493 | 4514 | if (iframe) {
|
4494 | 4515 | iframe.remove();
|
4495 |
| - _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "sendContentRequest, removed iframe"); |
| 4516 | + _classPrivateFieldGet2(_log, _this).call(_this, logLevelEnums.DEBUG, "interpretContentMessage, removed iframe"); |
4496 | 4517 | if (_classPrivateFieldGet2(_inContentZone, _this)) {
|
4497 | 4518 | // if user did not exit content zone, re-enter
|
4498 | 4519 | _classPrivateFieldGet2(_enterContentZoneInternal, _this).call(_this, true);
|
|
4846 | 4867 | }
|
4847 | 4868 | if (typeof inst[req[arg]] === "function") {
|
4848 | 4869 | inst[req[arg]].apply(inst, req.slice(arg + 1));
|
4849 |
| - } else if (req[arg].indexOf("userData.") === 0) { |
| 4870 | + } |
| 4871 | + // Add interfaces you add to here for async queue to work |
| 4872 | + else if (req[arg].indexOf("userData.") === 0) { |
4850 | 4873 | var userdata = req[arg].replace("userData.", "");
|
4851 | 4874 | if (typeof inst.userData[userdata] === "function") {
|
4852 | 4875 | inst.userData[userdata].apply(inst, req.slice(arg + 1));
|
4853 | 4876 | }
|
| 4877 | + } else if (req[arg].indexOf("content.") === 0) { |
| 4878 | + var contentMethod = req[arg].replace("content.", ""); |
| 4879 | + if (typeof inst.content[contentMethod] === "function") { |
| 4880 | + inst.content[contentMethod].apply(inst, req.slice(arg + 1)); |
| 4881 | + } |
| 4882 | + } else if (req[arg].indexOf("feedback.") === 0) { |
| 4883 | + var feedbackMethod = req[arg].replace("feedback.", ""); |
| 4884 | + if (typeof inst.feedback[feedbackMethod] === "function") { |
| 4885 | + inst.feedback[feedbackMethod].apply(inst, req.slice(arg + 1)); |
| 4886 | + } |
4854 | 4887 | } else if (typeof Countly[req[arg]] === "function") {
|
4855 | 4888 | Countly[req[arg]].apply(Countly, req.slice(arg + 1));
|
4856 | 4889 | }
|
|
0 commit comments