FB.XFBML.parse does not reparse FB widgets - parsing

I have a function call back on auth.login and would like to reparse my fb:like elements. Other actions are performed during the auth.login callback, and they execute just fine, but the .parse does not! I try executing FB.XFBML.parse(); in the console and it shows undefined and then after three seconds a console message saying 2 XFBML tags failed to render in 30000ms.
Any ideas?

For anyone who happens to run across this question running into the same problem I did...
Basically what I wanted to do was after a user logged into my website, I wanted to refresh the 'Like' button iFrame to reflect such. FB.XFBML.parse(); was only resulting in errors...so I thought "Maybe I'll just refresh the iFrame?" and since I am using jQuery as my framework - I figured I'd stick with it.
So, here's what I ended up doing:
FB.Event.subscribe('auth.login', function(response) {
if(response.status == 'connected') {
$("#login_fb").hide(); // was already doing this part
$('#like_fb > span > iframe').attr('src', function(i,val) { return val; }); // this is what I wanted to refresh
//FB.XFBML.parse(); -- THIS WAS GENERATING AN ERROR
}
});
Hopefully this will help someone else!

Related

How do I use showOpenDialog withe Electron’s IPC?

I am learning to live without remote in my electron app. I have got to the point where I need to open a file from the renderer, which I understand required the main process to show the file dialog and send back the results.
In my main.js, I have the following:
ipcMain.on('open-file',(event,data)=>{
dialog.showOpenDialog(null, data, (filePaths) => {
event.sender.send('open-file-paths', filePaths);
});
});
In my render process, which I call pager.js, I have the following:
ipcRenderer.send('open-file',{
title: 'Title',
defaultPath: localStorage.getItem('defaultPath')
});
ipcRenderer.on('open-file-paths',(event,data)=>{
console.log(event);
console.log(data);
});
The file open dialog works well enough, but I don’t know how to get the results. the ipcRenderer.on('open-file-paths',…) doesn’t get called, so that’s obviously not the right way to do it. I would like to get either the selected path(s) or a cancelled message.
How do I get the results for showOpenDialog in the render process?
OK, I think I’ve got it.
Thanks to an answer in ShowOpenDialog not working on recent versions of electron-js, I see that showOpenDialog now returns a promise, which means reworking the code in main.js. Here is a working solution:
// main.js
ipcMain.on('open-file',(event,data)=>{
dialog.showOpenDialog(null, data).then(filePaths => {
event.sender.send('open-file-paths', filePaths);
});
});
// pager.js (render)
ipcRenderer.send('open-file',{
title: 'Title',
defaultPath: localStorage.getItem('defaultPath')
});
ipcRenderer.on('open-file-paths',(event,data)=>{
console.log(`Canceled? ${data.canceled}`);
console.log(`File Paths: ${data.filePaths.join(';')`);
});

Updating panel contents in a Firefox extension

I'm trying to go by the suggestion in https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/panel of using a contentScript to update the contents in my panel. Currently, I have a server that returns the html that I want to display in my panel. I do panel.postMessage("update_panel", contents); when I have the response ready, and have a contentScriptFile associated with the panel that contains
self.port.on("update_panel", handleMessage);
function handleMessage(message) {
document.write(message);
}
However, I don't see anything being updated, and I'm also unable to debug the contentScriptFile (is there an way to do so?).
What am I doing wrong?
I ended up figuring something out.
panel.port.on("updating_done", function(response) {
console.log(response);
});
panel.port.emit("update_panel", contents);
If anyone can explain why this works and postMessage doesn't, that would be great.

Rails 3, bootstrap modal multiple layers of remote calling

I've been racking my head against this for 2 days now. I'm massively frustrated, and I can't seem to find any information on this with searching.
The issue. I'm using a :remote => true link to load some html from a different controller.
$('.managed_locations').bind('ajax:complete', function(evt, xhr, status){
$('#locations_modal').modal('show')
$('#locations_modal').html(xhr.responseText);
});
So it gets the html, dumps it into the bootstrap modal and displays the modal. This is working fine.
But inside of the modal I ALSO have a form which also uses :remote => true. Now to make life harder, when a button is pressed I clone the form and display it. So the user could have many forms.
Now the issue. Whenever the form is submitted it just loads it like a normal page. It's as if the :remote => true is being ignored. But this only in the modal. If I just load the modal controller by itself it works just fine. I also had this developed before using another jquery lightbox where it was working fine. I'm just switching in bootstrap for consistency.
So my initial thoughts are that the jquery_ujs.js isn't finding the new forms. So I added some code to output the form elements.
$("#log_events").click(function () {
$(document).find(".new_stored_physical_location").each(function() {
console.log( $(this).data() );
console.log( $(this).data('events') );
});
return false;
});
Which outputs in the console:
Object { type="html", remote=true}
Object { ajax:complete=[1]}
So I see that the events are being set in jQuery. Each of these forms has :remote => true and has the ajax event for when the request is complete. But it's just not doing an ajax request when I hit submit.
Is there something I'm missing that is required to make sure an ajax request will happen from the form???? The data() looks fine, the data('events') look fine. But is there some other event/binding that I need to look at?
The html that is loaded in from the modal right now is loading a layout. But i've done it both with a layout, without a layout. It's driving me nuts. Thanks for the help guys.
Edit: Some extra weirdness. The modal also loads some additional remote links, all of which are working correctly. It's only the form links which don't seem to work.
I got a solution. The big issue was within jquery_ujs.js Especially this line:
$(document).delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
FYI, rails.formSubmitSelector = 'form'. So this code found all of the forms in the document, overwrote the submit with this function. But the issue was that once you loaded in some ajax, and that ajax contained a it wouldn't add this fancy event to it. You need to re-add it.
So this is what I did.
Inside of jquery_ujs there is a bunch of functions that are accessible outside of it using $.rails. So things like: $.rails.enableElement, $.rails.nonBlankInputs. And the code for the submit event was sitting around all willy nilly. It only executes once when the page is loaded. So I put that in a function addSubmitEvent():
// Add the form submit event
addSubmitEvent: function(element) {
//$(element) was before $(document) but I changed it
$(element).delegate(rails.formSubmitSelector, 'submit.rails', function(e) {
var form = $(this),
remote = form.data('remote') !== undefined,
blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
if (!rails.allowAction(form)) return rails.stopEverything(e);
// skip other logic when required values are missing or file upload is present
if (blankRequiredInputs && form.attr("novalidate") == undefined && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
return rails.stopEverything(e);
}
if (remote) {
if (nonBlankFileInputs) {
return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
}
// If browser does not support submit bubbling, then this live-binding will be called before direct
// bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
if (!$.support.submitBubbles && $().jquery < '1.7' && rails.callFormSubmitBindings(form, e) === false) return rails.stopEverything(e);
rails.handleRemote(form);
return false;
} else {
// slight timeout so that the submit button gets properly serialized
setTimeout(function(){ rails.disableFormElements(form); }, 13);
}
});
}
This is basically the exact same code. But now it's $(element) instead of $(document). This was changed because now I can sniff for when the modal has loaded in the html. Then I can call:
$.rails.addSubmitEvent('#my_modal');
I then had an issue of it adding the event too many times from when I opened/closed the modal multiple times. So I just put a simple true/false if around it to call it once only.

chrome.tabs.executeScript shows unknown error

This is my code which I use for geolocation.
It does not log the coordinates to the console even though I have console.log. It shows an error saying "chrome/ExtensionProcessBindings:95 Error during tabs.executeScript: Unknown error."
However, when asked to alert; it alerts the right coordinates
background.html
<script>
chrome.tabs.executeScript(null, {file: "content_script.js"});
</script>
content_script.js
navigator.geolocation.getCurrentPosition(function(position) {
console.log(position.coords.latitude+" "+position.coords.longitude);
});
manifest.json
{
"name" : "Geolocation",
"version" : "0.1",
"background_page" : "background.html",
"permissions":["tabs","http://*/*", "https://*/*","*://*/*"]
}
Your code works fine for me.
I think the problem is that you are calling chrome.tabs.executeScript() right in the beginning of a background page, which means it probably tries to inject this script right into chrome://extensions/ when you are enabling your extension.
You need to make sure you are injecting the script to a regular loaded tab. For example I tried injecting it when a user clicks on browser action icon, and it worked:
chrome.browserAction.onClicked.addListener(function() {
chrome.tabs.executeScript(null, {file: "content_script.js"});
});

ie9: annoying pops-up while debugging: "Error: '__flash__removeCallback' is undefined"

I am working on a asp.net mvc site that uses facebook social widgets. Whenever I launch the debugger (ie9 is the browser) I get many error popups with: Error: '__flash__removeCallback' is undefined.
To verify that my code was not responsible I just created a brand new asp.net mvc site and hit F5.
If you navigate to this url: http://developers.facebook.com/docs/guides/web/#plugins you will see the pop-ups appearing.
When using other browsers the pop-up does not appear.
I had been using the latest ie9 beta before updating to ie9 RTM yesterday and had not run into this issue.
As you can imagine it is extremely annoying...
How can I stop those popups?
Can someone else reproduce this?
Thank you!
I can't seem to solve this either, but I can at least hide it for my users:
$('#video iframe').attr('src', '').hide();
try {
$('#video').remove();
} catch(ex) {}
The first line prevents the issue from screwing up the page; the second eats the error when jquery removes it from the DOM explicitly. In my case I was replacing the HTML of a container several parents above this tag and exposing this exception to the user until this fix.
I'm answering this as this drove me up the wall today.
It's caused by flash, usually when you haven't put a unique id on your embed object so it selects the wrong element.
The quickest (and best) way to solve this is to just:
add a UNIQUE id to your embed/object
Now this doesn't always seem to solve it, I had one site where it just would not go away no matter what elements I set the id on (I suspect it was the video player I was asked to use by the client).
This javascript code (using jQuery's on document load, replace with your favourite alternative) will get rid of it. Now this obviously won't remove the callback on certain elements. They must want to remove it for a reason, perhaps it will lead to a gradual memory leak on your site in javascript, but it's probably trivial.
this is a secondary (and non-optimal) solution
$(function () {
setTimeout(function () {
if (typeof __flash__removeCallback != "undefined") {
__flash__removeCallback = __flash__removeCallback__replace;
} else {
setTimeout(arguments.callee, 50);
}
}, 50);
});
function __flash__removeCallback__replace(instance, name) {
if(instance != null)
instance[name] = null;
}
I got the solution.
try {
ytplayer.getIframe().src='';
} catch(ex) {
}
It's been over a months since I last needed to debug the project.
Facebook has now fixed this issue. The annoying pop-up no longer shows up.
I have not changed anything.

Resources