Crossrider API not ready to receive events? - crossrider

I'm trying to trigger an event on my crossrider extension. Using the code below the event never gets to the extension. If I put a timeout and wait 5 seconds it does. So is there a way to detect when the extension\api is ready to receive events?
$(document).ready(function () {
var x = 'xxxxx';
$('body').fireExtensionEvent('eventName', { key: 'token-' + x });
});

You can use CrossriderAPI.isAppInstalled.
<script type="text/javascript" src="https://w9u6a2p6.ssl.hwcdn.net/plugins/javascripts/crossriderAPI.js"></script>
<script type="text/javascript">
// Replace XXXXX with the extension id
var extId = "XXXXX";
// Once the page is ready
$(function() {
CrossriderAPI.isAppInstalled(extId, function(isInstalled) {
// Displays true if the extension is installed; otherwise false
var x = 'xxxxx';
$('body').fireExtensionEvent('eventName', { key: 'token-' + x });
});
});
</script>
[Disclosure: I am a Crossrider employee]

Related

a problem repeatedly occurred message happens on safari for ios 15+ (Flutter web app)

Good morning guys,
I'm building a web app using Flutter, while testing it on iphone it working good in all versions except 15+,
i good message "a problem repeatedly occurred"..
this issue only happens for this screen
i tried many solutions to know why this happens.. one of them is to remove all this images (local images) and it works fine, so i tried to find solution for images and i followed this article but nothing happened
also i tried webGL2 issue in index file but unfortunately nothing happened too
this is my index file:
<head>
<script>
// The value below is injected by flutter build, do not touch.
var serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
<script src="https://unpkg.com/platform#1.3.5/platform.js"></script>
<script type="text/javascript">
let isSafari = /^((?!chrome|android).)*safari/i.test(platform.ua);
if (isSafari) {
HTMLCanvasElement.prototype.getContext = function (orig) {
return function (type) {
return type !== "webgl2" ? orig.apply(this, arguments) : null
}
}(HTMLCanvasElement.prototype.getContext)
}
</script>
<body>
<script>
let useHtml = false;
if (useHtml) {
window.flutterWebRenderer = "html";
} else {
window.flutterWebRenderer = "canvaskit";
}
window.addEventListener('load', function (ev) {
// Download main.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
}
}).then(function (engineInitializer) {
return engineInitializer.initializeEngine();
}).then(function (appRunner) {
return appRunner.runApp();
});
});
</script>
i hope any one can give me a hand

DOMContentLoaded is not firing

I am trying to create a chrome extension but having problems with DOMContentLoaded as it is not firing.
Note: my code was taken from a different website.
Basically, I have create an HTML file with a button:
<head>
<title>GTmetrix Analyzer</title>
<script src="popup.js"></script>
</head>
<body>
<h1>GTmetrix Analyzer</h1>
<button id="checkPage">Check this page
now!</button>
</body>
And this is the JS file (popup.js):
document.addEventListener
('DOMContentLoaded',
function() {
console.log("f")
var checkPageButton =
document.getElementById('checkPage');
checkPageButton.addEventListener('click',
function() {
chrome.tabs.getSelected(null,
function(tab) {
d = document;
var f = d.createElement('form');
f.action = 'http://gtmetrix.com/analyze.html?bm';
f.method = 'post';
var i = d.createElement('input');
i.type = 'hidden';
i.name = 'url';
i.value = tab.url;
f.appendChild(i);
d.body.appendChild(f);
f.submit();
});
}, false);
}, false);
I added the console.log event in order to check if the event is executed, so this is how I verified that it isn't working.
I also added run_at": "document_start
but then I got
Uncaught TypeError: Cannot read property 'addEventListener' of null
For the "click" event, so I guess that the event was triggered before the button was created.
Help, please!

Dropzone - multiple instances get id

I have multiple dropzone forms
<form action="/upload" class="dropzone" id="group1"></form>
<form action="/upload" class="dropzone" id="group2"></form>
<form action="/upload" class="dropzone" id="group3"></form>
How do I get the id of the form the file is dropped into?
To hook into a Dropzone action like a file being added, you'll need to use an event handler. From the docs:
Dropzone triggers events when processing files, to which you can register easily, by calling .on(eventName, callbackFunction) on your instance.
So you'll need to manually instantiate your Dropzones, to get access to the instance.
If you're using jQuery:
// Don't automatically instantiate, we'll do it manually
Dropzone.autoDiscover = false;
// Using the jQuery syntax shown in the docs
$("#group1, #group2, #group3").dropzone({
init: function() {
var formID = this.element.attributes.id;
this.on("addedfile", function(file) {
console.log('Image dropped on form ID', formID);
});
}
});
If you're not using jQuery:
Dropzone.autoDiscover = false;
var dz = [],
forms = document.getElementsByTagName('form');
for (var i = 0; i < forms.length; i++) {
dz[i] = new Dropzone(forms[i], {
init: function() {
var formID = this.element.attributes.id;
this.on("addedfile", function(file) {
console.log('Image dropped on form', formID);
});
}
});
}

Microsoft Bing Maps v7 Search Manager GeoCode errorCallBack

The issue happens during page refresh then browser is minimized or its tab with a map is inactive. Then Search Manager geocode function falls into errorCallback. Everything is working fine, if the page with the map is active (visible).
I checked e.request object in the errorCallback function and it contains correct "where" parameter, but no latitude and longitude nor any information about the error.
The issue can be reproduced in both Chrome and IE browsers.
HTML:
<div id="map" class="map" style="height:270px; width:100%"></div>
JavaScript:
<script type="text/javascript" src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&s=1"></script>
<script type="text/javascript">
// global variables
var apiKey = 'API_KEY_HIDDEN',
map,
searchManager;
// sample data
var siteData = [
{"Name":"Starbucks","Address":"8400 SW Nimbus Ave 120","City":"Beaverton","State":"OR","Zip":"97008","Latitude":0,"Longitude":0},
{"Name":"Subway","Address":"12160 SW Scholls Ferry Rd","City":"Tigard","State":"OR","Zip":"97223","Latitude":0,"Longitude":0}
];
$(document).ready(function () {
GetMap();
setTimeout(function() { location.reload(); }, 60000);
});
function GetMap() {
// initialize the map
map = new Microsoft.Maps.Map(document.getElementById('map'), {
credentials: apiKey,
mapTypeId: Microsoft.Maps.MapTypeId.road,
zoom: 1
});
// load search module
Microsoft.Maps.loadModule('Microsoft.Maps.Search', {
callback: function () {
searchManager = new Microsoft.Maps.Search.SearchManager(map);
$.each(siteData, function(index, clientSite) {
GeoCodeQuery(clientSite);
});
}
});
}
function GeoCodeQuery(clientSite) {
// set search parameters
var searchRequest = {
where: clientSite.Address + ', ' + clientSite.City + ', ' + clientSite.State + ' ' + clientSite.Zip,
callback: function (data) {
if (data && data.results && data.results.length > 0) {
clientSite.Latitude = data.results[0].location.latitude;
clientSite.Longitude = data.results[0].location.longitude;
}
else {
console.log('No results.');
}
},
errorCallback: function (e) {
console.log('Search error.');
}
};
// make the geocode request
searchManager.geocode(searchRequest);
}
</script>
A couple of issues;
You are missing a comma after your where parameter. This would make the searchRequest an invalid JSON object. Fixing this results in the first address being correctly geocoded. The second is throwing an error and this can be for a large number of reasons, the most likely is the next point.
The Bing Maps V7 control was retired in June and will be shut down soon. Some of its backend services are already being taken down and thus it will have issues. You should be using Bing Maps V8 which replaced V7 over a year ago. You can find a migration guide here: https://social.technet.microsoft.com/wiki/contents/articles/34563.bing-maps-v7-to-v8-migration-guide.aspx

redirect after video is finished

I'm new to mediaelements.js
at the end of my video, I wish that the user is redirected to another page
I have tried something like
<script>
$(function(){
$('audio,video').mediaelementplayer({
success: function(player, node) {
window.location = "http://google.com";
});
}
});
});
</script>
but I have not been successfull at all, maybe someone would have an idea
This worked for me. 'player1' is the id of the video
<script>
new MediaElement('player1', {
success: function (mediaElement, domObject) {
// add event listener
mediaElement.addEventListener('ended', function(e) {
//Do Stuff here
//alert("sometext");
window.location = "http://google.com";
}, false);
},
});
</script>
The code I posted was for the media element player. I looks like you're using the video.js player in the link you posted. I'm not sure how that would work but I did find this... help.videojs.com/discussions/questions/26-redirect-to-url-once-video-has-ended