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.
Related
I'm scraping dynamic content with PhantomJS. I want to load this website: https://www.instagram.com/explore/tags/fun/, and click the button at the bottom of the screen "load more" to load more pictures, and save the HAR content. This code works:
var page require('webpage').create();
page.open('http://www.milliondollarhomepage.com', function(status) {
setTimeout(function(){
page.sendEvent('click', 240, 210, button='left') }, 200);
setTimeout(function(){
page.render("screensho1.png");
phantom.exit();
}, 5000);
});
It clicks a --link-- on the screen. But when I use my URL of interest, https://www.instagram.com/explore/tags/fun/ the same code with the proper coordinates won’t click the ---button---.
Any help would be much appreciated.
Positioning of elements is often relative, so I would recommend to avoid absolute click events; instead work with selectors and trigger a click event on the element:
var page = require('webpage').create();
var fs = require('fs');
var system = require('system');
var url = "https://www.instagram.com/explore/tags/fun/";
page.open(url, function(status) {
console.log("Status: " + status);
if(status === "success") {
setTimeout(
function(){
page.evaluate(
function(){document.querySelector("#react-root > section > main > article > div > div > a").click();}
);
}, 200);
setTimeout(
function(){
path = 'hardcoded.png';
page.render(path, {format: 'png', quality: '100'});
phantom.exit();
}, 1000);
}else{
phantom.exit();
}
});
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);
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.
How to intercept when dommarker appears on the map?
I noticed that if the marker is not visible on the screen, there is not even its html code, I have to change a couple of styles, I need to know when they reappear
I use JavaScript API 3.0
This is a well-hidden feature which is documented here: http://developer.here.com/javascript-apis/documentation/v3/maps/topics_api_nlp/h-map-domicon.html#h-map-domicon
The idea is to add onAttach (and/or onDetach) callbacks to the DOM icon to be notified when a marker comes into the viewport using that icon. Watch out though because the DOM icon you create is always cloned before being put into a marker (because you can use the same DOM icon on multiple markers). The link should already show how it is done, but I'm adding a snippet below.
//Initialization business
var platform = new H.service.Platform({
app_id: 'DemoAppId01082013GAL',
app_code: 'AJKnXv84fjrb0KIHawS0Tg',
useCIT: true
});
var defaultLayers = platform.createDefaultLayers();
var map = new H.Map(document.getElementById('mapp'), defaultLayers.normal.map, {
center: {
lat: 52.3,
lng: 13.8
},
zoom: 10
});
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
//The onAttach function receives the DomElement, the icon object and the
//marker. The element can now be styled...
var onAttach = function(element, icon, marker) {
console.log("marker entering", element, icon, marker);
};
//Create a DomElement to use as marker icon...
var domIconEl = document.createElement("div");
domIconEl.style.width = "32px";
domIconEl.style.height = "32px";
domIconEl.style.marginLeft = "-16px";
domIconEl.style.marginTop = "-16px";
domIconEl.style.borderRadius = "20px";
domIconEl.style.background = "#006";
//Create icon with icon element adding onAttach to the options
var domIcon = new H.map.DomIcon(domIconEl, {
onAttach: onAttach
});
//Creare marker and add to map
var domMarker = new H.map.DomMarker({
lat: 52.3,
lng: 13.8
}, {
icon: domIcon
});
map.addObject(domMarker);
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;
}
}
});