In my jQuery Mobile App i have used Notification plugin in order to use custom Alert , and the problem is that all alerts appear at the same time One behind the other ,how can i prevent that? what should i do to solve this problem?
please help me ....
this is my code
if( $.trim($('#Name').attr('value') ).length== 0 )
{
navigator.notification.alert(' Insert your Name',alertDismissed,'Missed Value', 'OK');
}
if( $.trim($('#PhoneNum').attr('value') ).length== 0 )
{
navigator.notification.alert(' Insert your Phone Number',alertDismissed,'Missed Value', 'OK');
}
if( $.trim($('#Address').attr('value') ).length== 0 )
{
navigator.notification.alert(' Insert your Address',alertDismissed,'Missed Value', 'OK');
}
function alertDismissed()
{
}
Collect all of your alertmessages in an array and iterate over it, starting the next call on the close event of the previous alertwindow.
Related
I made a simple page with some divs being sortable by the jQuery UI Sortable, with a little help from Touch Punch to get it working on an iPad running iOS 7.1.2.
Inside each of these divs, I included a text input tag. On desktop browsers the inputs work fine, but the iPad doesn't recognize the click on the input component. The keyboard isn't launched and I can't type into it. Any lights?
My page is here: https://www.dropbox.com/s/5crp55r9jw98var/sortableTest.zip?dl=0
Well, here's what worked for me.
I edited the jquery.js. On jQuery.Event.prototype, inside the preventDefault function, there is:
if ( e.preventDefault ) {
e.preventDefault();
} else {
e.returnValue = false;
}
Basically, I changed the if condition to e.preventDefault && e.target.tagName != "INPUT". It solved the example, but in the real life I needed to add some more conditions to ensure that other input fields won't get caught by this.
Change in jquery.ui.touch-punch.js worked for me.
JS: jquery.ui.touch-punch.js
Method to modify:
//line: 31
function simulateMouseEvent(event, simulatedType) {
//...
}
//changes to add ++
if ($(event.target).is("input") || $(event.target).is("textarea")) {
return;
} else {
event.preventDefault();
}
I know this is an old question but got the following to work for me without modifying the JS files:
let detectTap = false;
$('body').on('touchstart', '#sortableMenu input', () => {
detectTap = true;
});
$('body').on('touchmove', '#sortableMenu input', () => {
detectTap = false;
});
$('body').on('touchend', '#sortableMenu input', (e) => {
if (detectTap) $(e.target).focus();
});
Basically just adding a tap listener on the inputs, and when it gets the tap, focus on that input.
If I get multiple push notifications whilst app is in foreground. The callback method will execute every push notification one by one.
callback : function(e) {
if (e.inBackground == 1) {
//came from background - do something.
} else {
// Titanium.UI.iPhone.setAppBadge(null);
//check type, if it is chat.
if (type == 'chat') {
//check if window is already opened or not, if so fire event handler
if (currentWindow == '_chatWindow') {
//update view directly after entering app from the background. Fire event handler
Ti.App.fireEvent('_updateChat', {});
} else if (currentWindow == '_messages') {
//refresh messages screen if on messages screen and chat message arrives
//update view directly after entering app from the background. Fire event handler
Ti.App.fireEvent('_updateMessages', {});
} else {
//display local notification
}
}
If the push notification has come from the background it is easy to deal with, as the push notification that is activated is the one the user chooses to swipe. However, if multiple push notifications come into the foreground and say it's chat, it will execute them multiple times.
How can I handle push notifications in the foreground better? Thanks
Update:
tried this code without much luck
Ti.App.addEventListener('_displayNotification', function(e) {
//store all push notifications in array
var pushArray = [];
var countPushNotifications;
//currentTime to cross reference
var currentTime = new Date();
if (currentTime - Alloy.Globals.pushTime < 3000) {
//do something
pushArray.add(e.PushNotificationData);
} else {
//after 3 seconds remove event handler
//fire event to filter array and process notification, reset time for next event
Alloy.Globals.pushTime = null;
Ti.App.removeEventListener('_displayNotification', {});
}
//first push notification, will be the current time
if(Alloy.Globals.pushTime==null){
Alloy.Globals.pushTime = currentTime;
}
});
Trying to get all the push notifications inside the array, for further filtering.
Update 2:
if (Alloy.Globals.countPushNotificationsFlag == 1) {
Alloy.Globals.countPushNotificationsFlag = null;
setTimeout(function() {
Ti.App.fireEvent('_displayNotification', {
PushMessage : message
});
}, 6000);
} else {
Alloy.Globals.countPushNotificationsFlag = 1;
Ti.App.fireEvent('_displayNotification', {
PushMessage : message
});
}
I have tried to execute push notifications alternatively.
1st notification - fires instantly.
2nd notification - fires after 6 seconds.
3rd notification - instantly.
4th notification - fires after 6 seconds.
and so on...
however the code only works for
notification 1 and 2.
Fails when it hits the 3rd notification.
you can check if Push is received in foreground or background using inBackground Property of push here is the documentation
Hope it helps.
I haven't got the Titanium experience to give you actual code, but this is the approach you need to take:
When you receive a notification, check to see if a (global) boolean receivedNotification is false
If it is false, set it to true, store the event into a global and schedule a setTimeout function for, say, 3 seconds, to process the event and reset receivedNotification to false
If receivedNotification is true, update the global event to the newer notification
In the process event method that is triggered via the timer your will do what you currently do in the first section of code.
This will ensure that the event is processed no longer than 3 seconds after it is received and that events will be processed, at most, once every three seconds.
Your code looks pretty close, except you are trying to fire the first event immediately and then subsequent events after a delay. Unfortunately I don't believe that this is possible, because you have no way of seeing if there are events queued immediately. I think that you are always going to have to incur the delay, but you can tune the delay to find a balance between responsiveness and reduced API calls -
if (Alloy.Globals.countPushNotificationsFlag == null) {
Alloy.Globals.countPushNotificationsFlag = 1;
Alloy.Globals.messageToPush=message;
setTimeout(function() {
Alloy.Globals.countPushNotificationsFlag = null;
Ti.App.fireEvent('_displayNotification', {
PushMessage : Alloy.Globals.messageToPush
});
}, 3000);
}
else {
Alloy.Globals.messageToPush=message;
}
I use jstree and jquery-ui v1.10.1 .I use context menu on tree and i want before delete node show confirm dialog(like jquery-ui dialog).
I use dialog in "before.jstree" event, but when show dialog box, before an option is selected(yes or no) ,the selected node is deleted.
How to solve this problem?
.bind("before.jstree", function(e, data) {
if (data.func === "remove") {
if (!confirmRemove()) {
e.stopImmediatePropagation();
return false;
}
}
}
function confirmRemove() {
return $confirmDialog.dialog('open');
}
I'm using the 2.1.0 version and there is another solution for this functionality.
What you have to do is add a function to the check_callback option.
Like this:
$("#your_tree").jstree({
"core": {
"check_callback": function (operation, node, node_parent, node_position, more) {
// operation can be 'create_node', 'rename_node', 'delete_node', 'move_node', 'copy_node' or 'edit'
// in case of 'rename_node' node_position is filled with the new node name
if (operation === 'delete_node') {
if (!confirmRemove()) {
return false;
}
}
return true;
}
}
I know that this is an old question, but i looked for a more recent question/answer and didn't find it.
Hope it helps to other people that will have the same question :)
The JQuery-UI-Dialog is asynchronous; If you call it, your eventhandler does not stop execution and waits, but goes on and deletes the Node.
Try the JavaScript-Dialog confirm() since this is synchronous and stops further execution until the User confirmed or declined the Dialog.
Is there any way to handle back button (device backbutton) as default functionality to move back page? I need to implement the same functionality on back button goes to previous page. If there is no previous page (first page) it exit the application. Is this possible in PhoneGap?
I also need to pop page before going to push another page is this posible in jQuery?
Checking window.location.length would be the easiest way to determine if you're on the first page, but this isn't available in Phonegap.
But since you're using JQM, you can either use the navigate event as Omar suggests or could manually count the number of pages shown and the number of pages gone back (same thing) and use this to determine if the first page is being shown and whether to exit the app. Something like this would work:
var pageHistoryCount = 0;
var goingBack = false;
$(document).bind("pageshow", function(e, data) {
if (goingBack) {
goingBack = false;
} else {
pageHistoryCount++;
console.log("Showing page #"+pageHistoryCount);
}
});
function exitApp() {
console.log("Exiting app");
navigator.app.exitApp();
}
function onPressBack(e) {
e.preventDefault();
if(pageHistoryCount > 0) pageHistoryCount--;
if (pageHistoryCount == 0) {
navigator.notification.confirm("Are you sure you want to quit?", function(result){
if(result == 2){
exitApp();
}else{
pageHistoryCount++;
}
}, 'Quit My App', 'Cancel,Ok');
} else {
goingBack = true;
console.log("Going back to page #"+pageHistoryCount);
window.history.back();
}
}
function deviceready() {
$(document).bind('backbutton', onPressBack);
}
$(document).bind('deviceready', deviceready);
As for the second part of your question:
Secondly i need to pop page before going to push another page is this
posible in jquery ?
It's not clear what you're asking here. Do you mean you want to show some kind of popup content like a dialog between every page change? Please clarify then I can help you :-)
I wish to add some sort of a "Write a Review" or "Rate Us" feature to my app so my customers can easily rate and review my app.
The problem is that the app is implemented using phone gap. Is it possible to implement this feature using html5-phone gap?
Thanks!
I use navigator.notification.confirm and have it called when the user reaches a certain point or uses your app so much. Of course you need to add your own links in.
Note this snippet references other parts of my app so customize to meet your needs.
if (settings.core.rate_app_counter === 10) {
navigator.notification.confirm(
'If you enjoy using domainsicle, whould you mind taking a moment to rate it? It won\'t take more than a minute. Thanks for your support!',
function(button) {
// yes = 1, no = 2, later = 3
if (button == '1') { // Rate Now
if (device_ios) {
window.open('itms-apps://itunes.apple.com/us/app/domainsicle-domain-name-search/id511364723?ls=1&mt=8'); // or itms://
} else if (device_android) {
window.open('market://details?id=<package_name>');
} else if (device_bb){
window.open('http://appworld.blackberry.com/webstore/content/<applicationid>');
}
this.core.rate_app = false;
} else if (button == '2') { // Later
this.core.rate_app_counter = 0;
} else if (button == '3') { // No
this.core.rate_app = false;
}
}, 'Rate domainsicle', ['Rate domainsicle', 'Remind me later', 'No Thanks']);
}
You can checkout http://itunes.apple.com/linkmaker
Also see the section about creating a URL directly to the review page of your app.
http://www.manicgaming.com/2010/12/make-your-app-easy-to-rate/
And finally:
App store link for "rate/review this app"
FYI, rate this app alerts were specifically discouraged in the wwdc '11 talks.
You must call window.open as follows
window.open("market://details?id=com.your.app","_system");
There is now a plugin just for that https://github.com/pushandplay/cordova-plugin-apprate