I am new and I saw similar questions but quite old and without solution. All I want is to open new window inside activeTab and preserve the tab group. Unfortunately my code opens new window but does not keep the tabs, the window is just full screen.
I would greatly appreciate if someone could confirm if what I want to achieve is possible at all. Maybe with views somehow... Once again it should work for android. Here is the code:
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({
title:'Tab 1',
backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({
icon:'KS_nav_views.png',
title:'Tab 1',
window:win1
});
//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({
title:'Tab 2',
backgroundColor:'#fff'
});
var tab2 = Titanium.UI.createTab({
icon:'KS_nav_ui.png',
title:'Tab 2',
window:win2
});
var label2 = Titanium.UI.createLabel({
color:'#999',
text:'I am Window 2',
font:{fontSize:20,fontFamily:'Helvetica Neue'},
textAlign:'center',
width:'auto'
});
win2.add(label2);
var data = [
{title:"Sample 1",color:'black',hasChild:true,font:{fontSize:16,fontWeight:'bold'}},
{title:"Sample 2",color:'black',hasChild:true,font:{fontSize:16,fontWeight:'bold'}}
];
var table = Titanium.UI.createTableView({
data:data,
separatorColor: '#ccc',
backgroundColor:'#fff'
});
win1.add(table);
// create table view event listener
table.addEventListener('click', function(e)
{
var win = Titanium.UI.createWindow({
url:'windows/main.js'
});
// this simply opens the new created window but full screen and without original tab group.
tabGroup.activeTab.open(win,{animated:true});
});
//
// add tabs
//
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
// open tab group
tabGroup.open();
There is currently no way to do that on android:
http://developer.appcelerator.com/question/145471/application-with-strange-navigation-how-to-implement-it#answer-252500
here you can find a demo of my solution...
http://sharesend.com/kbkasavo
hope this helps
You have to create navigation group for each tab windows.
For example
//Here's the first window...
var first = Ti.UI.createWindow({
backgroundColor:"#fff",
title:"My App"
});
Next, we’ll create a NavigationGroup. This is an iPhone-only component that controls a stack of windows (reference doc) – we’ll pass it our first window to use as its initially viewable window:
//Here's the nav group that will hold them both...
var firstnavGroup = Ti.UI.iPhone.createNavigationGroup({
window:first
});
//This is the main window of the application
var mainfirst = Ti.UI.createWindow();
mainfirst.add(firstnavGroup);
then assing this mainfirst window to tab.
Repeat this prosess for all tabs
Now when you need to open new window then you have to write
var second = Ti.UI.createWindow({
background:"#fff",
title:"Child Window"
});
firstnavGroup.open(second);
I hope this will help you.
Related
I'm using php to connect to a database and get some data to create a graph with highcharts.I have done that but I want to display this graph in a new window.This window opens when the user clicks a button.How can I do that?
You can open a new window and insert there a container with a chart, for example in this way:
document.getElementById('btn').addEventListener('click', function() {
var chartWindow = window.open("", "_blank", "left=0,top=0,width=600,height=450"),
chartContainer = document.createElement("div");
chartContainer.setAttribute("id", "container");
Highcharts.chart(chartContainer, {
series: [{
data: [1, 2, 3]
}]
});
chartWindow.document.body.appendChild(chartContainer);
});
Live demo: http://jsfiddle.net/BlackLabel/a235bh1z/
I have an electron app that runs in the menubar.
Code is currently heavily based on an existing pomodoro app (https://github.com/G07cha/pomodoro)
When the timer hits a certain point, it opens up a message box:
ipc.on('end-timer', function() {
$('.timer').circleProgress('value', 1);
var isRelaxTime = remote.getGlobal('isRelaxTime');
dialog.showMessageBox({
type: 'info',
title: 'Pomodoro',
message: (isRelaxTime) ? 'Timer ended it\'s time to relax' : 'Back to work',
buttons: ['OK'],
noLink: true
}, function() {
if(isRelaxTime) {
$('.timer').circleProgress({fill: { gradient: ["blue", "skyblue"]}});
} else {
$('#counter').text(remote.getGlobal('pomodoroCount'));
$('.timer').circleProgress({fill: { gradient: ["orange", "yellow"]}});
}
ipc.send('start-timer');
});
});
Is it possible to open a new window instead of the message box, and make it full screen?
Basically, making sure the user sees it and it fills the screen when the timer is up and allowing customization of the page that comes up with css and such.
It depends if you want to fire a new renderer from an existing renderer or if you want to spin it up from the Main Process.
Either way its as easy as creating a new BrowserWindow instance and loading a URL to an HTMl file you want to load.
If you want to spin up a renderer from an existing renderer you will need to require the remote module first. Here is an example:
const remote = require('remote');
// create a new BrowserWindow and pass it an object of options
var msgWindow = new remote.BrowserWindow({
// full width & height of monitor without going into kiosk mode
width: remote.screen.getPrimaryDisplay().size.width,
height: remote.screen.getPrimaryDisplay().size.height
//, other options
});
// load your message file into new browserwindow
msgWindow.loadURL('file://' + __dirname + '/index.html');
// set variable to null when window is closed to clean it up
msgWindow.on('close', () => {
msgWindow = null;
});
If you did this from the the Main Process, then replace const remote = require('remote'); with:
const electron = require('electron');
const BrowserWindow = electron.BrowserWindow;
I am creating a famo.us app in which header footer and content area is there. In content area different views are rendering using RenderController on action of each other and in each view different sub views are there. Events are communicating through java script using document.dispatchEvent() and addEventLiserner() method instead of famo.us events. I just want to ask that whether it is worth using this listener functions.
As I have tried through famous events like setInputHandler, setOnputHandler, emit , addListener, pipe given in famo.us documentation, But I cannot able to communicate using this.
The main question is the static app created by me is taking huge time when loaded from server and animations are running very slowly. Is there any solution for this.
Actually code is too long dummy example is below. I am creating an application having header footer and content view. In Content view I am rendering different views using renderController.
Content View
define(function(require, exports, module) {
var View = require('famous/core/View');
var Surface = require('famous/core/Surface');
var LoginView = require('views/login/LoginView');
var AccountsView = require('views/login/AccountsView'); //need to call on login
function ContentView() {
View.apply(this, arguments);
var renderController = new RenderController({
inTransition: {curve: Easing.easeOut, duration: 1000},
outTransition: {curve: Easing.easeIn, duration: 1000},
overlap: true,
});
var loginview = new LoginView();
renderController.show(loginview); //rendered initially
this.add(renderController);
document.addEventListener("showAccountsView",function(){
var accoutsView = new AccountsView()
renderController.show(accoutsView);
}.bind(this));
}
});
Login View
define(function(require, exports, module) {
var View = require('famous/core/View');
var Surface = require('famous/core/Surface');
var InputSurface = require("famous/surfaces/InputSurface");
function LoginView() {
View.apply(this, arguments);
var loginBoxContainer = new ContainerSurface({
classes:["backfaceVisibility"],
size:[undefined,295],
properties: {
overflow: 'hidden',
padding:'0 10px'
}
});
this.add(loginBoxContainer);
var userInput = new InputSurface({
size: [undefined, 45],
});
var userInputModifier = new StateModifier({
transform: Transform.translate(0,53,1)
});
var pwdInput = new InputSurface({
classes:["pwdInput"],
size: [undefined, 45],
});
var pwdInputModifier = new StateModifier({
transform: Transform.translate(0,100,1)
});
loginBoxContainer.add(userInputModifier).add(userInput);
loginBoxContainer.add(pwdInputModifier).add(pwdInput);
var submit = new Surface({
content:["Submit"],
size:[100,30],
});
submit.on("click",function(){
document.dispatchEvent(new Event("showAccountsView"));
});
loginBoxContainer.add(submit);
}
});
I have to render different view on clicking ligin submit button. I have used dispatchEvent and addEventListener of Javascript to make communication between two files. I want to use famous events. I have tried various ways using setInputHandler, setOnputHandler, emit , addListener, pipebut could not able to do that as data and listener functions cannot calling. Please explain..
Inside LoginView, replace this code:
submit.on("click",function(){
document.dispatchEvent(new Event("showAccountsView"));
});
with:
submit.on("click",function(){
this._eventOutput.emit('showAccountsView', { data: someValue });
});
In ContentView, replace:
document.addEventListener("showAccountsView",function(){
var accoutsView = new AccountsView()
renderController.show(accoutsView);
}.bind(this));
with:
loginView.on('showAccountsView', function(data){
var accoutsView = new AccountsView()
renderController.show(accoutsView);
}.bind(this));
I am beginning to work with Ti, and would like to know how is it possible to do the following from the code below:
Open a new window/view with title as "New Win"
Display a back button with title "My Home" (of the previous page)
This is the code that I have so far:
var win = Ti.UI.createWindow({
title: "My Home",
backgroundColor: '#bbb'
});
var b = Ti.UI.createButton({
title:'Button',
style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
win.setToolbar([b]);
var nav = Ti.UI.iPhone.createNavigationGroup({
window:win
});
var root = Ti.UI.createWindow();
root.add(nav);
root.open();
b.addEventListener({
// open a new window with Title as "New Win"
// with a back button, that display the previous title "My Home"
});
Many Thanks.
You are going with the right approach, only piece is missing is this:
nav.open(myWindow,{animated:true});
here is your full code with the missing code
var win = Ti.UI.createWindow({
title: "My Home",
backgroundColor: '#bbb'
});
var b = Ti.UI.createButton({
title:'Button',
style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
win.setToolbar([b]);
var nav = Ti.UI.iPhone.createNavigationGroup({
window:win
});
var root = Ti.UI.createWindow();
root.add(nav);
root.open();
//This is your new window
var myWindow = Ti.UI.createWindow({
backgroundColor:'#fff',
title:'New Window'
});
// just open this new window with the navigationController you defined
b.addEventListener('click',function(){
nav.open(myWindow,{animated:true});
});
With this code you will see a new window with title "New Window" and with a back button having title as "my Home".
Hope that solve your problem
====================UPDATE:=============================================================
To solve your problem you only have to add one line i.e.
replace this
var myWindow = Ti.UI.createWindow({
backgroundColor:'#fff',
title:'New Window'
});
by
var myWindow = Ti.UI.createWindow({
backgroundColor:'#fff',
url:'/newWindow.js' // make sure you give the right path
title:'New Window'
});
hi how to use javascriptscript to open a new window and then closing the current window..
currently, i can only open a new window, however my current window is still left open.
Code:
function newfunction()
{
window.open("index.html", "myWindow", "status = 1, height = 300, width = 300, resizable = 0");
}
Opening a new window and closing the old one sounds very much like changing the current page to me. Use location.href = 'newurl'.
And if you want to change its size and so on, that can also be done.
window.innerWidth = 300;
window.innerHeight = 300;
location.href = 'newurl';
use like you said window.open and then in the main window window.close(). But if you use like this, the browser will ask you "This website wants to close this window blabla".
add window.opener.close();
function newfunction()
{
window.open("index.html", "myWindow", "status = 1, height = 300, width = 300, resizable = 0");
window.opener.close();
}
or add this on the index.html file whenever a new window open it will close the parent window
<body onload="window.opener.close()">
Here is the code you need:
function newfunction()
{
window.open("index.html", "myWindow", "status = 1, height = 300, width = 300, resizable = 0");
window.close();
}
This will work only if the current window was opened via script as well, otherwise IE show warning dialog and other browsers might simply ignore it.