I'm not talking about doing anything fancy. I'd just like the standard windows and views to rotate when the user rotates the device.
You need to tell the window which orientations it should support:
var window = Ti.UI.createWindow({
orientationModes: [
Ti.UI.LANDSCAPE_LEFT,
Ti.UI.LANDSCAPE_RIGHT,
Ti.UI.PORTRAIT,
Ti.UI.UPSIDE_PORTRAIT
]
});
window.open();
You can then listen on the orientation changes with a listener like so:
Ti.Gesture.addEventListener('orientationchange', function(e) {
Titanium.API.info('Orientation changed');
});
Edit: I think (though I've never tried it) you can also set this in tiapp.xml, which has the added benefit of applying to all windows automatically.
<orientations device="iphone">
<orientation>Ti.UI.LANDSCAPE_LEFT</orientation>
<orientation>Ti.UI.LANDSCAPE_RIGHT</orientation>
<orientation>Ti.UI.PORTRAIT</orientation>
<orientation>Ti.UI.UPSIDE_PORTRAIT</orientation>
</orientations>
Titanium.Gesture.addEventListener('orientationchange', function(e) {
Titanium.API.info('Gesture Change Detected');
Ti.App.fireEvent('orientationchange', {eventObject:e});
});
this is work on android default. But not work on iphone, so just write this code
var win1 = Ti.UI.createWindow({
title : 'Tab 1',
orientationModes: [
Ti.UI.LANDSCAPE_LEFT,
Ti.UI.LANDSCAPE_RIGHT,
Ti.UI.PORTRAIT,
Ti.UI.UPSIDE_PORTRAIT
],
});
win1.open();
Ti.Gesture.addEventListener('orientationchange', function(e) {
Titanium.API.info(Ti.Gesture.orientation);
});
I, THINK THIS IS USEFUL TO YOU.
Related
I noticed when using Owl Carousel 2, while slide the item in mobile viewing, the browser also can be move up and down. Try to disabling the scroll function when trigger the Owl Carousel 2 prev and next function in mobile but it still doesn't work.
$('.owl-carousel').owlCarousel({
loop:true,
margin:5,
nav:true,
items:2,
});
// $('.owl-carousel').bind("mousewheel", function() {return false;});
$('.owl-carousel').bind('touchmove', function(e){e.stopPropagation(); alert('allow scroll');});
Appreciated the answer from expert out here.
Thank you.
I made this work with the help of OwlCarousel2 events.
There are 2 events we can use together for this purpose:
drag.owl.carousel fires when user start to drag
dragged.owl.carousel fires when dragging finished
And this make it work like how we want it:
var owl = $('.owl-carousel');
owl.owlCarousel({
// your options
});
owl.on('drag.owl.carousel', function(event) {
$('body').css('overflow', 'hidden');
});
owl.on('dragged.owl.carousel', function(event) {
$('body').css('overflow', 'auto');
});
So; it use css overflow to disable scrolling when dragging started and enables it back when it finished.
This works on iOS & VueJS.
var owl = $('.owl-carousel');
owl.owlCarousel({
// your options
})
// disable scroll
owl.on('drag.owl.carousel', function(event) {
document.ontouchmove = function (e) {
e.preventDefault()
}
})
// enable scroll
owl.on('dragged.owl.carousel', function(event) {
document.ontouchmove = function (e) {
return true
}
})
look for the below piece of code in custom.js file of your project
Owl.Defaults = {
items: 3,
loop: false,
center: false,
rewind: false,
mouseDrag: true,
touchDrag: true,}
change the things to below:-
touchDrag:false,
and owl-carousel will simply stop scrolling horizontally both on mobile and desktop drag!
For owlcarousel2, you can use mouseDrag option.
$('.owl-carousel').owlCarousel({
mouseDrag:false
});
Reference https://owlcarousel2.github.io/OwlCarousel2/docs/api-options.html
in owl.js
mouseDrag: false,
touchDrag: false,
pullDrag: false,
freeDrag: false,
I have been building an app in Adobe AIR using HTML/JavaScript.
The windows are all Chromeless and use CSS to style them to look like an application.
How can I detect if the window is focused by the user so I can alter the colours of the windows in the same way that native windows have more subtle shadows etc.
An example might be:
var active = false;
$(document).ready(function() {
active = nativeWindow.active;
if(active) {
$('body').addClass('active');
} else {
$('body').removeClass('active');
}
});
But how do I properly handle the change of active event?
You can do this with: air.NativeWindow.active. See: http://help.adobe.com/en_US/air/reference/html/flash/display/NativeWindow.html#active
UPDATE:
window.nativeWindow.addEventListener(air.Event.ACTIVATE, function() {
$('body').addClass('active');
});
window.nativeWindow.addEventListener(air.Event.DEACTIVATE, function() {
$('body').removeClass('active');
});
I am now using dojo 1.8.3 and now have a BorderContainer with 2 ContentPane on my page. I would like to listen the resize event, the code like this
dojo.ready(function(){
dojo.connect(dijit.byId("Container"), "resize", function(changeSize, resultSize){
// do my stuff here...
});
});
However, is there anyway to let me know if the resize (splitting) is end? Please advice, thanks!
First of all, I'd recommend using "modern dojo", since you're using dojo 1.8 anyway. dojo/connect is deprecated and the way to "monitor" function calls is now by using dojo/aspect.
So you'd end up with something like:
require(["dojo/ready", "dojo/aspect", "dijit/registry"], function(ready, aspect, registry) {
ready(function() {
aspect.after(registry.byId("Container"), "resize", function() {
// do something after resize has been called...
});
});
});
If you want to have access to the arguments that have been passed to the resize function, call aspect.after with true as the last argument like:
aspect.after(registry.byId("Container"), "resize", function(changeSize, resultSize) {
// do something with changeSize and resultSize after resize has been called...
}, true);
I'm trying to implement a list filter in a text field in sencha touch. For example, I'd have a bunch of contacts, and when I typed in the field, it might filter by name. When I click the circular X button to clear the textfield, I'd like to reset the filter to filter none of the contacts.
The problem is, I can't seem to figure out a way to detect the click on the clear button. There doesn't appear to be any type of event, and I can't seem to hack in a workaround.
If anyone has any idea how to detect a textfield clearing in sencha touch, I'd be much obliged.
I've tried in safari and xcode simulator, and am using sencha touch 1.1.0. Am I missing something? Is this not an issue when it's actually a mobile app?
You can listen for tap events on clearIconContainerEl inside the text field or override the onClearIconTap method.
Ext.setup({
icon: 'icon.png',
tabletStartupScreen: 'tablet_startup.png',
phoneStartupScreen: 'phone_startup.png',
glossOnIcon: false,
onReady: function() {
var searchField = new Ext.form.Search({
name : 'search',
placeHolder: 'Search',
useClearIcon: true,
onClearIconTap: function() {
if (!this.disabled) {
this.setValue('');
console.log('onClearTap: Clear button tapped!');
}
}
});
var viewport = new Ext.Panel({
fullscreen: true,
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [searchField]
}]
});
console.log(searchField.useClearIcon);
searchField.mon(searchField.clearIconContainerEl, {
scope: searchField,
tap: function() {
if (!this.disabled) {
console.log('clearIconContainerEl: Clear button tapped!');
}
}
});
}
});
For sencha touch 2.0 users:
If your using new mvc structure, you can use this in the controller init
this.control({
'#yourTextFieldId clearicon': {
tap: function(){console.log('ClearICON tapped');}
}
....
)};
The problem is the little X is not added in by sencha touch. It is a feature of the "search" input with html5. To capture this event you need to look for the search event. How I solved this was I edited sencha-touch.js
I modified -
if (this.fieldEl) {
this.mon(this.fieldEl, {
focus: this.onFocus,
blur: this.onBlur,
keyup: this.onKeyUp,
paste: this.updateClearIconVisibility,
mousedown: this.onBeforeFocus,
scope: this
});
to be -
if (this.fieldEl) {
this.mon(this.fieldEl, {
focus: this.onFocus,
blur: this.onBlur,
keyup: this.onKeyUp,
paste: this.updateClearIconVisibility,
mousedown: this.onBeforeFocus,
search: this.onSearch,
scope: this
});
inside of Ext.form.Text = Ext.extend(Ext.form.Field, { ...
Now in my implementation of the searchfield I can make a function called onSearch which will be called when the "search" event is called. Note that the "search" event is not only called for the X but for some things like the enter key. The bottom line is sencha touch 1.1 does not check for this event at all and it is the only time the X fires an event so the only solution is to modify sencha-touch.js.
I wanto to add a tool (search, help, gear, ...) in a window dynamically, like this:
http://www.rahulsingla.com/sites/default/files/content/blog/extjs/extjs-panel-add-tool.htm
And I need to create more than one instance of UIMyWindow at the same time.
However, I'm using Ext Designer which generates 2 files:
MyWindow.ui.js: class declaration.
MyWindow.js: methods implementation.
Besides Ext Designer hasn't an option Tools at design time (I didn't find).
I was adding the tool outside MyWindow.js and MyWindow.ui.js, like this:
var winMyWindow = new UIMyWindow({
autoShow: 'true',
tools: [{
type:'gear',
handler: function(){
// Some code...
}
}]
});
But I want to put this block inside MyWindow.js. So, I did this:
UIMyWindow = Ext.extend(UIMyWindowUi, {
tools: [{
type:'gear',
handler: function(){
// Some code...
}
}],
initComponent: function() {
UImenuDock.superclass.initComponent.call(this);
If you ask me "Why not to put this code inside MyWindow.ui.js?", I would answer "because I don't want to put this code manually every time I make changes in the design file (Ext Designer)".
Well, if I open one window, it's seems work ok, but if I open a second at the same time, the tools are duplicated in the second window...
So, any idea how to add tools dynamically in MyWindow.js in this specific case?
put 'tools' into initComponent
UIMyWindow = Ext.extend(UIMyWindowUi, {
initComponent: function() {
this.tools = [{
type:'gear',
handler: function(){
// Some code...
}
}],
UImenuDock.superclass.initComponent.call(this);