Im working in Titanium Alloy and creating a popup window as a widget. I want to have the close - image up over the right top corner, so it stick abit out of the popup window.
So I created 2 separate window in the widget xml-file. One to just hold the close - image and one who is the popup - window.
Everythings look as I want, but I cant get the popup - window to close?!
I have tried:
$.myWindow.close();
Amd I have tried:
var win = Widget.createController('myWindow', 'myWindowID').getView();
win.close();
But nothing happens
Here is my xml - code:
<Alloy>
<Window id="popup">
<View id="myImagesViewIn" class="myImagesViewIn" onClick="closeWin">
<ImageView id="myImageIn" class="myImageIN" />
</View>
</Window>
<Window id="winImageOut" onClick="closeWindow">
<View id="myImagesViewOut" class="myImagesViewOut" >
<ImageView id="myImageOut" class="myImageOut" />
</View>
</Window>
</Alloy>
And here is my JS-code:
var args = arguments[0] || {};
$.popup.transform = args.transform || '';
/*
exports.setDataModalWindow = function(data) {
$.lblModalWinHead.text = data.title;
$.lblModalWinBody.text = data.text;
};
*/
function fnCloseClick() {
$.viewModal.close();
}
/*
$.myImagesViewOut.addEventListener('click', function(e) {
$.popup.close();
});
*/
function closeWin(e) {
$.myImagesViewOut.setVisible(false);
$.popup.close();
}
function closeWindow(e) {
//$.popup.close();
var wins = Widget.createController('widget', 'popup').getView();
wins.setVisible(false);
alert('hejsan');
//Ti.API.info('close');
}
exports.openModalWindow = function(arg) {
//$.lblModalTitle.text = arg.title || 'foo';
//$.lblModalText.text = arg.text || 'ff';
var t = Titanium.UI.create2DMatrix().scale(0);
var args = {
transform : t
};
var controller = Widget.createController('widget', args).getView();
controller.open();
// controller.animate(a2);
var t1 = Titanium.UI.create2DMatrix();
t1 = t1.scale(1.2);
var a1 = Titanium.UI.createAnimation();
a1.transform = t1;
a1.duration = 400;
controller.animate(a1);
var b1 = Titanium.UI.create2DMatrix();
var a2;
a1.addEventListener('complete', function() {
b1 = b1.scale(1.5);
a2 = Titanium.UI.createAnimation();
a2.transform = b1;
a2.duration = 400;
controller.animate(a2);
});
// create the controller a keep the reference
/*
controller.setDetails({
label: 'Are you sure you wish to log out?\n\nIf you do so you will no longer be able to take part in any challenges until you login again.',
ok: 'Log me out',
cancel: 'Cancel'
});
*/
// now get a reference to the UI inside the controller
//var win = controller.getView();
a1.addEventListener('complete', function() {
// simple reset animation
var t2 = Ti.UI.create2DMatrix();
var a3 = Titanium.UI.createAnimation();
a3.transform = t2;
a3.duration = 400;
controller.animate(a3);
$.winImageOut.open();
});
};
first thing is you are opening popup window so you should open that window...
then you should close bot the window in closeWindow function.
function closeWindow(e) {
$.popup.close();
$.winImageOut.close();
alert('hejsan');
//Ti.API.info('close');
}
I do not know your requirement but you should use only one window to show popup then its easy for you to handle open,close event of window.
Related
I'm using a responsive datatables on which I'm trying to handle click on a row, so you get redirected to a new page if you click on the row. This works fine, but if the table is collapsed I cannot show the child row, since clicking on the expand icon activates the row click and I get redirected.
So I'm trying to see if I can check whether the icon is clicked or not, but I cannot figure out how to do it
I have tried to use
$("#jobListTable").hasClass('collapsed')
in order to see, if the table is collapsed or not, but I still miss how to check what cell i clicked
Simplyfied fiddle can be found here: http://jsfiddle.net/Anja_Reeft/agouq6ts/5/
But my actually code is
$('#jobListTable tbody').on('click', 'tr', function (e) {
var data = oTable.row( this ).data();
if ( $(this).hasClass('selected') ) {
$(this).removeClass('selected');
}
else {
oTable.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
var selectedTaskID = data.taskID;
var selectedJobNumber = data.jobNumber;
var selectedReqno = data.reqno;
var selectedPriority = data.priority;
var selectedCreatedBy = data.createdBy;
var selectedEmployeeInitials = data.employeeInitials;
var selectedShortDescription = data.shortDescription;
var selectedLongDescription = data.longDescription;
var selectedSourceReference = data.sourceReference;
var selectedAktivitetstype = data.aktivitetstype;
var selectedDueDatetime = data.dueDatetime;
var selectedRecurrence = data.recurrence;
var selectedStatus = data.status;
var selectedStatusColor = encodeURIComponent(data.statusColor);
var teamID = "";
if (sessionStorage.getItem("teamID")) {
teamID = "&teamID="+sessionStorage.getItem("teamID");
}
document.location.href="jobinfo.php?taskID="+selectedTaskID+"&jobNumber="+selectedJobNumber+"&reqno="+selectedReqno+"&priority="+selectedPriority+"&createdBy="+selectedCreatedBy+"&employeeInitials="+selectedEmployeeInitials+"&shortDescription="+selectedShortDescription+"&longDescription="+selectedLongDescription+"&sourceReference="+selectedSourceReference+"&aktivitetstype="+selectedAktivitetstype+"&dueDatetime="+selectedDueDatetime+"&recurrence="+selectedRecurrence+"&status="+selectedStatus+"&statusColor="+selectedStatusColor+teamID;
} );
Please let me know if you need futher information.
In cases anyone has a simular problem:
I changed my code so I added a button to each row
"columns": [
{
data: null, // can be null or undefined
defaultContent: '<button type="button" id="jobInfoBtn" class="btn btn-sm"><i class="fa fa-info-circle" aria-hidden="true"></i></button>',
},
and then changed my on click function
$('#jobListTable tbody').on('click', 'tr', function (e) {
if ( $(this).hasClass('selected') ) {
$(this).removeClass('selected');
}
else {
oTable.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
} );
$('#jobListTable tbody').on('click', 'button', function (e) {
var data = oTable.row( $(this).parents('tr') ).data();
var selectedTaskID = data.taskID;
var selectedJobNumber = data.jobNumber;
var selectedReqno = data.reqno;
var selectedPriority = data.priority;
var selectedCreatedBy = data.createdBy;
var selectedEmployeeInitials = data.employeeInitials;
var selectedShortDescription = data.shortDescription;
var selectedLongDescription = data.longDescription;
var selectedSourceReference = data.sourceReference;
var selectedAktivitetstype = data.aktivitetstype;
var selectedDueDatetime = data.dueDatetime;
var selectedRecurrence = data.recurrence;
var selectedStatus = data.status;
var selectedStatusColor = encodeURIComponent(data.statusColor);
var teamID = "";
if (sessionStorage.getItem("teamID")) {
teamID = "&teamID="+sessionStorage.getItem("teamID");
}
document.location.href="jobinfo.php?taskID="+selectedTaskID+"&jobNumber="+selectedJobNumber+"&reqno="+selectedReqno+"&priority="+selectedPriority+"&createdBy="+selectedCreatedBy+"&employeeInitials="+selectedEmployeeInitials+"&shortDescription="+selectedShortDescription+"&longDescription="+selectedLongDescription+"&sourceReference="+selectedSourceReference+"&aktivitetstype="+selectedAktivitetstype+"&dueDatetime="+selectedDueDatetime+"&recurrence="+selectedRecurrence+"&status="+selectedStatus+"&statusColor="+selectedStatusColor+teamID;
} );
I have a image which keeps on animating in up- down direction. On clicking the image the image should pause animating and clicking it again should resume animation.
I am using image view's pause() for now but it does nothing. Its mentioned that "This method works if multiple images are specified" but how can I use this for single image.
Please find the code in below link. Thank you
index.xml :
<Alloy>
<Window id="winIos">
<View id="vOne" class='viewSize'>
<ImageView id="one" class='oval' ></ImageView>
<ImageView id="a" image= "/images/img_1.png"></ImageView>
</View>
</Window>
</Alloy>
index.js
var osname = Ti.Platform.osname;
if (osname == 'iphone') {
var ANIMATION = require('/alloy/animation');
var win = $.winIos;
var randomArray=[];
var n = 1;
var rann;
function showAnimations(){
var imgName = "img_1.png";
var ranImg = "/images" + "/" + imgName;
win.getChildren()[0].id2 = imgName;
win.getChildren()[0].touchEnabled = true;
win.getChildren()[0].zIndex = 3;
win.getChildren()[0].getChildren()[1].image = ranImg;
animation = Ti.UI.createAnimation(); //animate image up
animation.top = 20;
animation.delay = 120;
animation.duration = 1200;
win.getChildren()[0].touchEnabled = true;
win.getChildren()[0].getChildren()[1].animate(animation);
animation.addEventListener('complete', function() {
animation1 = Ti.UI.createAnimation(); //animate image down
animation1.top = 159;
animation1.delay = 900;
animation1.duration = 1200;
win.getChildren()[0].getChildren()[1].animate(animation1);
animation1.addEventListener('complete', function() {
win.getChildren()[0].touchEnabled = false;
});
});
}
setInterval(showAnimations, 4300);
win.addEventListener('click', function(e) {
console.log("imgSrc" + JSON.stringify(e.source.getChildren()[1]));
if(e.source.getChildren()[1]){
e.source.getChildren()[1].pause();
}
});
win.addEventListener('close', function() {
clearInterval(showAnimations);
});
win.open();
}
index.tss
"#winIos":{
orientationModes:[Ti.UI.LANDSCAPE_RIGHT],
backgroundColor:'white',
id2:""
}
".viewSize":{
height:150,
width:150,
}
".oval":{
image:'/images/oval.png',
height:"50",
width:"150",
left:"0",
bottom:"-2",
touchEnabled:"false"
}
"#a":{
id2:'',
height:100,
width:70,
top:149,
touchEnabled:false,
}
"#vOne":{
id2:'',
left:"80",
touchEnabled:false,
top:"10",
zIndex:0
}
The ImageView pause() only works for multiple images as you've mentioned. That is a image slideshow, it has nothing to do with Ti.UI.Animation. You actually can't stop an animation on Android but there is an open PR (https://github.com/appcelerator/titanium_mobile/pull/10130) on implementing a stop().
Depending on your animation you could try to create a Lottie animation and use Ti.Animation (https://github.com/m1ga/ti.animation) since that includes pause and resume methods.
I'm working on a project at the moment that involves a slider in an info popup. The slide constains info only needed on a touch device. On a desktop it only needs to show the first slide. So what I need to do is stop the slider when on a desktop... I've got pretty close with:
$('body').on({ 'touchstart' : function(){
} });
But as I'm only just starting in jquery I'm 'hacking' it and what I'm doing creates 'unstable' results. I know I need to only process the slider code if being viewed on a touch device - but I have no idea where I should do this...
This is the slider code:
var triggers = $('div.triggers div.trigger');
var images = $('div.slides div.slide');
var lastElem = triggers.length-1;
var mask = $('.mask div.slides');
var imgWidth = images.width();
var target;
triggers.first().addClass('selected');
mask.css('width', imgWidth*(lastElem+1) +'px');
function sliderResponse(target) {
mask.stop(true,false).animate({'left':'-'+ imgWidth*target +'px'},300);
triggers.removeClass('selected').eq(target).addClass('selected');
}
triggers.click(function() {
if ( !$(this).hasClass('selected') ) {
target = $(this).index();
sliderResponse(target);
resetTiming();
}
});
$('.clickSlide.right').click(function() {
target = $('div.triggers div.selected').index();
target === lastElem ? target = 0 : target = target+1;
sliderResponse(target);
resetTiming();
});
$('.clickSlide.left').click(function() {
target = $('div.triggers div.selected').index();
lastElem = triggers.length-1;
target === 0 ? target = lastElem : target = target-1;
sliderResponse(target);
resetTiming();
});
function sliderTiming() {
target = $('div.triggers div.selected').index();
target === lastElem ? target = 0 : target = target+1;
sliderResponse(target);
}
var timingRun = setInterval(function() { sliderTiming(); },5000);
function resetTiming() {
clearInterval(timingRun);
timingRun = setInterval(function() { sliderTiming(); },5000);
}
All help greatly received!!!!
Thanks :0)
I started off with the basic tabbed model and using KitchenSink began changing,'customizing' it to my needs. I have created 3 tableviews each which opens to its own vertical layout and tableviewrows. For some reason, something that I have not read. i cannot attach anything to the first tab. Help would be appreciated.
I have also included a part of the JS file
app.js
(function() {
//determine platform and form factor and render approproate components
var osname = Ti.Platform.osname,
version = Ti.Platform.version,
height = Ti.Platform.displayCaps.platformHeight,
width = Ti.Platform.displayCaps.platformWidth;
//considering tablet to have one dimension over 900px - this is imperfect, so you should feel free to decide
//yourself what you consider a tablet form factor for android
var isTablet = osname === 'ipad' || (osname === 'android' && (width > 899 || height > 899));
var Window;
if (isTablet) {
Window = require('ui/tablet/ApplicationWindow');
}
else {
Window = require('ui/handheld/ApplicationWindow');
}
var ApplicationTabGroup = require('ui/common/ApplicationTabGroup');
new ApplicationTabGroup(Window).open();
})();
applicationTabGroup.
function ApplicationTabGroup(Window) {
//create module instance
var self = Ti.UI.createTabGroup();
//create app tabs
var win1 = new Window(('Core Measures')),
win2 = new Window(('Patient'));
win3 = new Window(('Provider'));
var tab1 = Ti.UI.createTab({
title: ('Core Measures'),
window: win1
});
win1.containingTab = tab1;
var tab2 = Ti.UI.createTab({
title: ('Patient'),
window: win2
});
win2.containingTab = tab2;
var tab3 = Ti.UI.createTab({
title: ('Provider'),
window: win3
});
win3.containingTab = tab3;
self.addTab(tab1);
self.addTab(tab2);
self.addTab(tab3);
return self;
};
module.exports = ApplicationTabGroup;
TableView
function CoreMeasures(title) {
var self = Ti.UI.createWindow({
title:.title,
backgroundColor:'white'
});
//create table view data object
var data = [
{title: 'Pneumonia', hasChild : true, test: 'ui/common/pneumonia'},
{title: 'CHF', hasChild: true, test:ui/common/CHF'},
{title: 'Myocardial Infarction', hasChild: true, test: 'ui/common/Myocardial Infarction'};
]
// create table view
for (var i = 0; i < data.length; i++ ) {
var d = data[i];
if(d.touchEnabled !==false) {
d.color = '#000'
data:data
});
// create table view event listener
tableview.addEventListener('click', function(e)
{
if (e.rowData.test)
{
var ExampleWindow = require(e.rowData.test),
win = new ExampleWindow({title:e.rowData.title,containingTab:self.containingTab,tabGroup:self.tabGroup});
if (Ti.Platform.name == "android") {
} else {
win.backgroundColor = "#fff"
A couple of things. I don't see anywhere that you have called the function CoreMeasures. Also you might have an issue with the following code:
function CoreMeasures(title) {
var self = Ti.UI.createWindow({
title:.title,
backgroundColor:'white'
});
I noticed a dot before your title.
I open windows as follows:
app.js:
var NavigationController = require('NavigationController').NavigationController,
TestWindow = require('main_windows/tmain').TestWindow;
//create NavigationController which will drive our simple application
var controller = new NavigationController();
//open initial window
controller.open(new TestWindow(controller));
function openWindow(name, naController, event) {
var TestWindow2 = require('main_windows/t' + name).TestWindow;
var win = Titanium.UI.currentWindow;
var swin = Titanium.UI.createWindow();
if(event.bid)
swin.bid = event.bid;
if(event.uniq)
swin.uniq = event.uniq;
if (event.zipcode)
swin.zipcode = event.zipcode;
if (event.user_id)
swin.user_id = event.user_id;
if (event.service_id)
swin.service_id = event.service_id;
if (event.service_name)
swin.service_name = event.service_name;
if (event.user_uniqid)
swin.user_uniqid = event.user_uniqid;
if (event.user_name)
swin.user_name = event.user_name;
if (event.user_email)
swin.user_email = event.user_email;
if (event.provider_id)
swin.provider_id = event.provider_id;
if (event.provider_name)
swin.provider_name = event.provider_name;
if (event.total)
swin.total = event.total;
if(event.response)
swin.response = event.response;
swin.backgroundColor = '#f7f7f7';
swin.barImage = 'images/example.gif';
naController.open(new TestWindow2(naController, swin));
}
Here is the NavigationController.js
exports.NavigationController = function() {
this.windowStack = [];
};
exports.NavigationController.prototype.open = function(/*Ti.UI.Window*/windowToOpen) {
//add the window to the stack of windows managed by the controller
this.windowStack.push(windowToOpen);
//alert('open' + this.windowStack.length);
//grab a copy of the current nav controller for use in the callback
var that = this;
windowToOpen.addEventListener('close', function() {
// alert('open' + that.windowStack.length);
if(that.windowStack.length > 1)
{
//alert('pop' + that.windowStack.length);
that.windowStack.pop();
}
});
//hack - setting this property ensures the window is "heavyweight" (associated with an Android activity)
windowToOpen.navBarHidden = windowToOpen.navBarHidden || false;
//This is the first window
if(this.windowStack.length === 1) {
if(Ti.Platform.osname === 'android') {
windowToOpen.exitOnClose = true;
windowToOpen.open();
} else {
//alert('nav' + this.windowStack.length);
this.navGroup = Ti.UI.iPhone.createNavigationGroup({
window : windowToOpen
});
var containerWindow = Ti.UI.createWindow();
containerWindow.add(this.navGroup);
containerWindow.open();
}
}
//All subsequent windows
else {
if(Ti.Platform.osname === 'android') {
windowToOpen.open();
} else {
//alert('nav2' + this.windowStack.length);
this.navGroup.open(windowToOpen);
}
}
};
//go back to the initial window of the NavigationController
exports.NavigationController.prototype.home = function() {
//store a copy of all the current windows on the stack
//alert('reset' + this.windowStack.length);
var windows = this.windowStack.concat([]);
for(var i = 1, l = windows.length; i < l; i++) {
(this.navGroup) ? this.navGroup.close(windows[i]) : windows[i].close();
}
this.windowStack = [this.windowStack[0]]; //reset stack
//alert('n' + this.windowStack.length);
};
Here is tmain.js
exports.TestWindow = function(navController) {
var win = Ti.UI.createWindow({
backButtonTitleImage : 'images/backb.gif',
fullscreen : false,
navBarHidden : true,
});
var t1 = null;
win.backgroundImage = 'images/back.jpg';
var view = Titanium.UI.createView({
width : '100%',
height : '100%',
top : 270,
layout : 'vertical'
});
var b3 = Titanium.UI.createImageView({
url : 'images/login.gif',
height : 80
});
view.add(b3);
var b4 = Titanium.UI.createImageView({
url : 'images/signup.gif',
top : 0,
height : 80
});
view.add(b4);
win.add(view);
var list1 = function(e) {
openWindow('login', navController, e);
};
b3.addEventListener('click', list1);
var list2 = function(e) {
openWindow('register', navController, e);
};
b4.addEventListener('click', list2);
win.addEventListener('close', function (e) {
alert(3);
b3.removeEventListener('click', list1);
b4.removeEventListener('click', list2);
});
return win;
};
So I use the openWindow function to open windows in the app. I have a logout botton, that when people click on it, calls the function navController.home() (see Navigation Controller), but the problem is clicking on the logout link causes corrupt window state - meaning that the application crashes and when you try to open it, windows are mixed together (like buttons in window 3 show up in window 2).
What am I doing wrong?