How to call a iframe in a panel in firefox extension - iframe

I am trying to create a extension in Firefox using sdk addon. What i want to do is to call an iframe inside a panel.
I have already created the extension for chrome and now i am trying to do it for firefox.
I have a facebook login in the iframe. Once i click on the sign in button the iframe just goes blank. If I log in before hand then also the extension doesnt work. It is as if it can't access the session.
Here is the code of my main.js file.
var { ToggleButton } = require('sdk/ui/button/toggle');
var panels = require("sdk/panel");
var data = require("sdk/self").data;
var {Cc, Ci} = require("chrome");
var tabs = require("sdk/tabs");
var title=tabs.activeTab.title;
var button = ToggleButton({
id: "my-button",
label: "my button",
icon: {
"16": "./logo1.png",
"32": "./logo1.png",
"64": "./logo1.png"
},
onChange: handleChange
});
var panel = panels.Panel({
width:450,
height:400,
contentURL: data.url("popup.html"),
onHide: handleHide
});
function handleChange(state) {
if (state.checked) {
panel.show({
position: button
});
}
}
function handleHide() {
button.state('window', {checked: false});
}
here is the code of my main javascript file that calls the iframe
$(document).ready(function() {
document.body.style.display = 'block';
var ur='xyz';
var frame = document.createElement('iframe');
var frame_url = 'https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/page-mod';
frame.setAttribute('width', '100%');
frame.setAttribute('height', '100%');
// frame.setAttribute('margin', '-10%');
frame.setAttribute('frameborder', 'none');
frame.setAttribute('id', 'rtmframe');
$('body').height(450).width(400);
frame.setAttribute('src', frame_url);
document.body.appendChild(frame);
$('iframe#rtmframe').load(function() {
$('#loadImg').hide();
});
});
This is not the actual link i am trying to open. Can anyone suggest what i can do differently. or point me to github code that might be doing the same thing.

Related

Froala Editor on MeteorJS get editor content

Please help me on how to get the content of the froala editor. Just to display it on the console would be enough. Here is my code:
Template.myTemplate.events({
'click': function (event) {
var self = this;
return function (e, editor) {
var newHTML = editor.html.get();
console.log(newHTML);
}
}
});
I can not seem to display the content of the editor even in the console when I click the button. Thank you.
If you're not using the older version here is a working code:
Template.myTemplate.events({
'click': function (e) {
var html = $('.selector').editable('getHTML', true, true);
});
});
based on https://www.froala.com/wysiwyg-editor/docs/methods#getHTML
If you're using the v2.0 $('.selector').froalaEditor('html.get', true);
the .selector is where you initialize your froala editor, If you can show how you do that I can adjust it to it.

Google Map API, search box

I have integrated a Google Map on my page and add a search box to it with the following code:
var input = document.getElementById('pac-input');
var searchBox = new google.maps.places.SearchBox(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
// Bias the SearchBox results towards current map's viewport.
map.addListener('bounds_changed', function() {
searchBox.setBounds(map.getBounds());
});
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);
autocomplete.addListener('place_changed', function() {
var place = autocomplete.getPlace();
if (!place.geometry) {
return;
}
// If the place has a geometry, then present it on a map.
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17);
}
});
Currently this give me a search box with autocompletion list, which is good. But I have to click on a item of this list to go to the location. If I just type something in the input an hit enter, nothing happened..
Any help ?
Thanks !
Try changing
var searchBox = new google.maps.places.SearchBox(input);
to
var autocomplete = new google.maps.places.Autocomplete(input);

Button click event not working in Titanium

I am new to Titanium appcelerator programming.My doubt is button click is event is working well in first screen after that when I click that button go to second screen.Second screen consisting of one button ,when I click that button it navigates to third screen .But button click event is not working in second screen.
I wrote the same code in two screens as follows:
Please tell where I did mistake.
First Screen:
Ti.include("Files/MainScreen.js");
var win = Titanium.UI.createWindow({
title:'My Window',
backgroundColor:'#cccccc'
});
win.open();
var itemView = Titanium.UI.createView({
title:'',
backgroundImage:'splash.png',
height:'768',
width:'1024'
});
// Eventlistener
itemView.addEventListener('click',function(e) {
var newWindow = Ti.UI.createWindow({
background : "#000",
title : "Image View",
url:"Files/MainScreen.js"
});
newWindow.open(win,{animated:true});
});
win.add(itemView);
win.orientationModes=[Titanium.UI.LANDSCAPE_LEFT];
win.open();
MainScreen.js:
Ti.include("CustomerScreen.js");
var win = Titanium.UI.createWindow({
title:'My Window',
backgroundColor:'#cccccc',
leftNavButton:btnCancel
});
var btnCancel = Titanium.UI.createButton({
title:'Cancel'
});
var image = Ti.UI.createImageView({
image:'main_screen.png'
});
win.add(image);
win.open();
var custbutton=Titanium.UI.createButton({
title:'customer',
top:200,
bottom:300,
left:90,
height:'235',
width:'235',
backgroundColor:"#000"
});
custbutton.addEventListener('click',function alertingcustomer () {
var newWindow1 = Ti.UI.createWindow({
background : "#000",
title : "",
url:"Files/CustomerScreen.js"
});
newWindow1.open(win,{animated:true});
});
win.add(custbutton);
win.open();
CustomerScreen.js
var win = Titanium.UI.createWindow({
title:'Window',
backgroundColor:'#cccccc',
modal:true
});
win.open();
Try the following code. I have created a sample application from your code. Try it out
app.js
var win = Titanium.UI.createWindow({
title:'My Window',
backgroundColor:'#cccccc'
});
var itemView = Titanium.UI.createView({
title:'Splash screen',
backgroundColor:'yellow',
height:'768',
width:'1024'
});
// Eventlistener
itemView.addEventListener('click',function(e) {
var newWindow = Ti.UI.createWindow({
background : "#000",
title : "Image View",
url:"MainScreen.js",
backgroundColor:'#cccccc',
leftNavButton:btnCancel
});
newWindow.open(win,{animated:true});
});
var btnCancel = Titanium.UI.createButton({
title:'Cancel'
});
win.add(itemView);
win.orientationModes=[Titanium.UI.LANDSCAPE_LEFT];
win.open();
MainScreen.js
var win = Ti.UI.currentWindow;
win.title = 'My Window';
var image = Ti.UI.createImageView({
backgroundColor:'red'
});
win.add(image);
var custbutton=Titanium.UI.createButton({
title:'customer',
top:200,
bottom:300,
left:90,
height:'235',
width:'235',
backgroundColor:"#000"
});
custbutton.addEventListener('click',function alertingcustomer () {
var newWindow1 = Ti.UI.createWindow({
title : "Customer screen",
url:"CustomerScreen.js",
title:'Window',
backgroundColor:'#cccccc',
modal:true
});
newWindow1.open(win,{animated:true});
});
win.add(custbutton);
CustomerScreen.js
var win = Ti.UI.currentWindow;
//Do stuff here
There are a lot of things you have to notice.
It is wrong approach include a file in another file and opening a window which has property url set to included file.
Opening a window multiple time is a wrong approach[You have written win.open() twice in the firts file, it is trying to open same window]
You're opening a window using url property, it'll be better to use Ti.UI.currentWindow property than creating a new window inside that.

Google Places API autocomplete not working

Right now, the autocomplete box works just fine when I click on the location, but when I press down, highlight the location that I want to go to, and press enter, it simply goes back to the home location of the map. Any insights on this? I call this function in initialize(). I'm lost as to what I possibly did wrong. Is this just a google api bug? If so, any insights as to how to work around it?
function setupAutoComplete() {
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(-90, -180),
new google.maps.LatLng(90, 180));
var input = document.getElementById('placeSearch');
var options = {
bounds: defaultBounds,
types: ['(regions)']
};
autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
alert('hi');
removeAllOverlays();
var place = autocomplete.getPlace();
var mapCenter = place.geometry.location;
var colLat = mapCenter.lat() - (halfPoints)*latSeparation;
var colLng = mapCenter.lng() - (halfPoints)*lngSeparation;
var tempStart = new google.maps.LatLng(colLat, colLng);
map.setCenter(mapCenter);
pointArray[0][0] = tempStart;
reService();
mapSearch();
drawBounds();
});
}
Thanks so much!
I guess the input#placeSearch is placed inside a <form>.
You submit the form when you press [ENTER].
You may either remove the surrounding form or cancel the submission by adding:
onsubmit="return false"
...to the form-element.
I just hit this issue and went with the following, as I do want to submit the form at a later stage. This code is from google groups.
var input = document.getElementById('create-location');
var options = {
//types: ['(cities)'],
};
autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addDomListener(input, 'keydown', function(e) {
if (e.keyCode == 13)
{
if (e.preventDefault)
{
e.preventDefault();
}
else
{
// Since the google event handler framework does not handle early IE versions, we have to do it by our self. :-(
e.cancelBubble = true;
e.returnValue = false;
}
}
});

Google Maps API v3 - click event not firing when marker is clicked while another InfoWindow is open

I've got a setup in which multiple markers present, each loading in content to a single InfoWindow when it's clicked.
Unfortunately, it seems that the marker's click event is not being fired when it's clicked while another window is open.
This seems like an odd behavior. Has anyone else found this to be the case?
Thanks
My code below:
var infoWindow = new google.maps.InfoWindow();
if(markers) {
var length = markers.length;
for(var i = 0; i < length; i++) {
var details = markers[i];
markers[i] = new google.maps.Marker({
title: details.name,
position: new google.maps.LatLng(details.location[0],details.location[1]),
locCode: details.locCode
});
markers[i].setMap(map);
var thisMarker = markers[i];
google.maps.event.addListener(thisMarker, 'click', (function(thisMarker, i, details) {
// self calling function was the key to get this to work
return function() {
$.ajax({
url: 'js/locations/'+details.locCode+'.js',
dataType: 'script',
success: function(data) {
// do my specific stuff here, basically adding html to the info-window div via jQuery
// set the content, and open the info window
infoWindow.setContent($("#info-window").html());
infoWindow.open(map, thisMarker);
}
});
}
})(thisMarker, i, details));
}
}
Check out my answer here:
Jquery Google Maps V3 - Information window is always fixed to one marker
I think this will help resolve your issue.
Bob

Resources