Event listener when Safari extension's popover closes - safari-extension

Is there a way to detect when the Safari extension's popover closes. Something like a event that is fired when the popover closes?
I do not see any event listener listed on the API doc but is there a workaround for it ? It would be helpful to perform clean up actions once the popover closes.

You can cleanup before next popover open:
safari.application.addEventListener('popover', function(event) {
event.target.contentWindow.location.reload();
}, true);

Related

When I tap with Detox, the button is not tapped. However it can be tapped if I just click at it

The problem is when I tap with Detox, the button is not tapped. However it can be tapped if I just click at it.
version of Detox: 16.8.2,
version of React Native: 0.57.1
Solved.
This happened because I used device.openURL({url: 'https://...' }) previously to open the app from a deep link.
Instead, it worked after opening a new instance of the app with a deep link in argument: device.launchApp({newInstance: true, url: 'https://...' });
After this, the interaction can be performed.
It looks like a bug with the method device.openURL()

DisplayReplyAllForm is showing popup blocker alert in IE and Edge

I am trying to open reply email using DisplayReplyAllForm, it is showing popup blocker alert in IE and Edge.
Office.context.mailbox.item.displayReplyAllForm(
{
'htmlBody' : emailBodyHtml,
'callback' : function(asyncResult)
{
console.log('reply mail with asyncResult.value ==> ' + asyncResult);
}
});
I am trying to execute this code in a function which will be called by button onclick handler.
Error View :
This is stopping us from app store submission. What is the fix for this?

Magnific popup - how to open it on mouseover?

I'm using Magnific popup our product product pages as a method for image hot points. Right now when you click on a hot point a popup appears with larger image and text. I received a request to open the popup on a mouseover.
Is there a way to trigger open Magnific Popup on a mouseover not on a mouse click?
I was trying to call the mouseover event on the link first, but it seems the Popup still requires a click. How to I make it so it opens up just with a mouseover?
<!-- Popup link -->
Show inline popup
<!-- Popup itself -->
<div id="test-popup" class="white-popup mfp-hide">
Popup content
</div>
Javascript:
$('.open-popup-link').mouseover(function(){
$(this).magnificPopup({
type: 'inline'
});
});
Answering my own question. After a bit more research I found that I needed to open the popup directly via API. It works now:
$('.open-popup-link').mouseover(function(){
$.magnificPopup.open({
items: {
src: '.white-popup' // can be a HTML string, jQuery object, or CSS selector
}
})
});
Working example: https://codepen.io/pen/ZKrVNK
Taking it further with multiple links opening separate slides of a gallery, using event delegation:
http://codepen.io/pen/EmEOMa

UIWebView and unload event

I'm loading local html contents into a UIWebView.
The javascript code of the loaded contents includes this event listener:
window.addEventListener("unload", function(){
// do something here;
});
That javascript code it is only executed when (before) the UIWebView component is released (e.g. when navigating back to another view controller) but it is not executed when another page is loaded. For example:
document.addEventListener("click", function(){ document.location = "www.google.com"; });
window.addEventListener("unload", function(){ alert("bye bye"); });
If executing this piece of code in safari, when I click on the document, before navigating to google.com, it would display the alert box. If I run the same code in UIWebView, the unload listener it is not executed. However, If I delete the UIWebView, the code is then executed.
My need is to have the same as in Safari, that is the unload method to be executed also when navigating away from the page.
I too have had problems in the past with JavaScript code that doesn't behave the same way in a desktop browser than in a UIWebView. I honestly don't know why it isn't working the way you want it to, but here I offer you a work around:
Instead of using the unload listener you have in JavaScript, try using UIWebViewDelegate's method webView:shouldStartLoadWithRequest:navigationType:. This method gets called whenever the user requests to load a new page (or content).
If you then need to execute more JavaScript code you could use UIWebView's method stringByEvaluatingJavaScriptFromString:.
Hope this helps!
Thanks to LuisCien solution above (please vote his post if you like the solution), I managed to solve the issue by manually generating and dispatching the unload event from objective-c side. This does not require any modification on my client side code (javascript) that now behaves the same in UIWebView and any other web browser. Here is the piece of code to add to your view controller:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
[webView stringByEvaluatingJavaScriptFromString:#"var e=document.createEvent('Event'); e.initEvent('unload', true, true); window.dispatchEvent(e);"];
return YES;
}

Having videos autoplay in modal window

I am using a modal window to display multiple videos, but my autoplay seems to be ignored in the modal window. If I have the video on the page and it is not hidden the autoplay is fine. Do I need to do something else to trigger the autoplay in a modal window?
I am using SimpleModal to do the modal window. For the video I am using a simple video tag and an mp4 video with the autoplay boolean on.
Any help would be appreciated.
I was only able to get this to work by using a javascript play() call in the 'open' handler for a jQuery UI dialog. No other method would work.. maybe simplemodal has an analog? Here is the solution for jQuery UI:
$('div#mydialog').dialog({
open: function(event, ui) {
$('video#myvideo').get(0).play();
}
});