Disable double tap on Web App - android

I'm using JQuery Mobile + PhoneGap for my mobile app.
I have some links and buttons with onClick event attached
<li onclick="func();"></li>
I having problems when user double tap, can I somehow disabled it for current DIV ?

Give a id to your <li id="someid">
Then
$('#someid').dblclick(function(e){
e.preventDefault();
})
To prevent double click on multiple tags, just use a class on those li tags, and use the same code
$('.someClass').dblclick(function(e){
e.preventDefault();
});

Related

Passing value from html to javascript in phonegap

I am trying to develop a shopping cart system using kendo-ui mobile and phonegap. First I am listing all the items in a list view. In each listview item, there will be one plus button, minus button and a label.I am using this combination for selecting the quantity of items.So, if we click plus button, the label value should be 0+1=> 1 and when we click minus, it should be like 1-1=>0 .To change the value of label when clicking button, I am passing the id of label to change the corresponding label value. But I am not able to pass the id form html to javascript, like I do in web development. Here is my code,
My listview item template,
<script type="text/x-kendo-tmpl" id="endless-scrolling-template">
<div class="product">
<img src="images/image.jpg" alt="#=ProductName# image" class="pullImage"/>
<h3>#:ProductName#</h3>
<p>$#:kendo.toString(UnitPrice, "c")#</p>
<a id="minus" data-role="button" data-click="minus(#:ProductID#)" >-</a>
<label id=#:ProductID#>0</label>
<a id="plus" data-role="button" data-click="plus(#:ProductID#)" data-name="plus">+</a>
<a id="loginButton" data-role="button" data-click="login">Add to Cart</a>
<div class="console"></div>
</div>
and my javascript functions,
<script>
function plus(itemid) {
var quantity=document.getElementById(itemid).innerHTML;
document.getElementById(itemid).textContent = parseInt(quantity)+1;
}
function minus(itemid) {
var quantity=document.getElementById(itemid).innerHTML;
document.getElementById(itemid).textContent = parseInt(quantity)-1;
}
</script>
Can anyone please tell me what Iam doing wrong here? Or can you provide an alternate solution?
When using Kendo, you can use Kendo MVVM. When JS objects are wired up in views using Kendo MVVM, when the value of the input elements change, the value of the JS objects reflects the change automatically. So what you need to do is to create a JS model for your view and set it as your view's model using data-model="yourModel". See this link: http://docs.kendoui.com/getting-started/mobile/mvvm
In your scenario here I think this link will help you: http://demos.kendoui.com/web/mvvm/source.html
This behavior is explained in the Kendo mobile book I wrote and you can see the checkout screen of the sample application built for the book here: http://movies.kendomobilebook.com/

How do I mimick Google Play's horizontal div scrolling using jQuery mobile?

I am currently exploring jQuery Mobile's functionalities. I am quite intrigued by the way Google Play Store handles horizontal sliding, hence, when the user slide taps to the right, the view should slide to the next page and when the user slide taps to the left the view should scroll to the previous page, if any. I know this can be done using native jQuery but I'm not yet familiar with events on mobile devices and I'm sure there is already a built-in functionality for this.
I'd like to try this first with Android devices and if possible with iPad and iPhone. Can anybody guide me on ways to accomplish this?
BTW, I'm not talking about browser history here, probably just some div, pages, if possible.
It can be done but you will be sadly disappointed.
It can be achieved like this:
Multiple page's inside one single HTML. Every page will have swipeleft and swipe right binded to it. When event is triggered changePage() function will make a transition to previous/next page. This sounds excellent and works just fine on desktop browser but fails miserable when executed with phonegap on android phones. Transitions are still a huge problem on android phones, iOS fares better but not to much.
Something like this:
$('#page-two').on('#page-two', 'swipeleft', function () {
//next page
$.mobile.changePage($('#page-three'));
}).on('#page-two', 'swiperight', function () {
//prev page
$.mobile.changePage($('#page-one'), { reverse : true });
});
Swipe events are supported with jQuery Mobile so no need for 3rd party plugins.
Use a jQuery Mobile carousel plugin like this example: http://jsfiddle.net/blackdynamo/yxhzU/
Original plugin: https://github.com/blackdynamo/jQuery-Mobile-Carousel
Unlike page transitions this plugin will give you much better feeling on mobile phones.
What ever path you choose android tab look will be achieved with navbar inside a second header:
<div data-theme="a" data-role="header">
<h3>
First Page
</h3>
Next
</div>
<div data-theme="a" data-role="header">
<div data-role="navbar">
<ul>
<li>Page One</li>
<li>Page Two</li>
<li>Page Three</li>
</ul>
</div><!-- /navbar -->
</div>
Solution #1 -- This should be the easy way to do it:
<script>
$(document).delegate("#homepage", 'pageinit', function (evt) {
$(this).bind("swipeleft", function (e) {
$.mobile.changePage("#anotherpage", {
transition : 'slide'
});
});
}).delegate("#anotherpage", 'pageinit', function (evt) {
$(this).bind("swiperight", function (e) {
$.mobile.changePage("#homepage", {
transition : 'slide',
reverse : true
});
});
});
</script>
Solution #2 -- This one is even much simpler:
$('#homepage').bind('swipeleft', function() {
$.mobile.changePage('#anotherpage', {transition: 'slide', reverse: false});
});
$('#anotherpage').bind('swiperight', function() {
$.mobile.changePage('#homepage', {transition: 'slide', reverse: true});
});

Jquery mobile, remove previous page

I'm using jquery mobile with phonegap. My app has two pages: login page and list page. When login successfully, the user will go to the list page. Afterwards, when they press the back button on their phone (android), they will go back to the login page. I don't want behavior like this. What I want is to exit the app.
As I answered in this question: page hash and backbutton issue phonegap+Jquery
You can change pages without keeping them in browser history like so:
$.mobile.changePage('#page', {reverse: false, changeHash: false});
Unfortunately, I didn't manage to prevent the initial page from staying in browser history, so I used a workaround:
Page layout:
<body>
<!-- page_1 before page_loading in source -->
<div data-role="page" id="page_1">
</div>
<!-- page_loading will be shown first -->
<div data-role="page" id="page_loading">
<div data-role="content">
<h1 >
<b>welcome</b>
</h1>
</div>
</div>
<div data-role="page" id="page_2">
</div>
</body>
jQuery:
function onBodyLoad()
{
//go to page_loading before deviceready without keeping it in browser history
$.mobile.changePage('#page_loading', {reverse: false, changeHash: false});
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady()
{
//your initialization code here...
//now go to page_1 without keeping it in browser history since the actual first page was #page_1 already
$.mobile.changePage('#page_1', {reverse: false, changeHash: false});
//your code here...
}
This should fit your needs, just try it out. "#page_loading" would be your login page, "page_1" your list page...
Keep in mind that changeHash:false refers to the destination page, not to the source. You will not be removing the source page from history. Instead, the history hash will not be updated when moving to the new page
If you use the latest version of jQuery mobile (1.4+) you can use this script:
$.mobile.pageContainer.pagecontainer('change', '#page', {reverse: false, changeHash: false});
jQuery.mobile.changePage is deprecated as of jQuery Mobile 1.4.0 and will be removed in 1.5.0.
Adding options for reverse and changeHash did not work for me. using Cordova v1.6
I ended up overriding the onTouch method in my Android Activity.
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (KeyEvent.KEYCODE_BACK == keyCode) {
// Clear browsers history if user clicks back button
clearHistory();
}
return super.onKeyUp(keyCode, event);
}

Scrolling in JQuery mobile

I am creating an application using JQuery Mobile which needs to support both iOS and Android. (I am using PhoneGap). Does scrolling on long pages work by default or do I need to set up my divs to support scrolling. How is scrolling on iOS different from an android device?
Also, is there a way to make a ajax call when the user scrolls to the bottom of the page to retrieve more content?
Any help is appreciated.
1) jQuery Mobile 1.1.0 uses the browser's native scrolling so it seems natural on every supported platform.
jQuery Mobiles does however require the following pseudo-page structure:
<div data-role="page">
<div data-role="header">
...
</div>
<div data-role="content">
...
</div>
<div data-role="footer">
...
</div>
</div>
If you follow this structure, the more you add to the data-role="content" section, the longer the page will be.
2) You can set an event handler for the scroll event to detect the user scrolling and see how far down the page the user is:
//you don't want to set a bunch of AJAX requests at once,
//so set a flag so only one will go off at a time
var ajaxOK = true;
$(window).on('scroll', function () {
var yDistance = $('html, body').scrollTop();
//here you can check how far down the user is and do your AJAX call
if ((yDistance + $(window).height()) > ($.mobile.activePage.children('.ui-content').height() - 150)) {
//the user is within 150px of the bottom of the page
if (ajaxOK === true) {
ajaxOK = false;
$.ajax({ ... });
}
}
});
Then in your callback function for the AJAX call you set ajaxOK = true; so that when the user scrolls to the bottom again it will fire.
Here's a quick break-down of the if/then statement in the scroll event handler:
(yDistance + $(window).height()) > ($.mobile.activePage.children('.ui-content').height() - 150)
(yDistance + $(window).height()): the scroll-distance plus the view-port height, to find the bottom of the page's Y coordinate.
($.mobile.activePage.children('.ui-content').height() - 150): the height of the current page minus a buffer of 150px so the user can get within 150px and the AJAX call will occur
Scrolling should happen automatically if you overflow the browser window. For infinite scrolling you can try http://www.infinite-scroll.com/.
If you are using the listview for jquery mobile you may need to call the refresh event after adding more list view items to the dom to get the filtering behavior and styling to work.

Android WebView : disable geo: for addresses

In my Android application, I am using a WebView to render a list of locations. For some reason, when I click on a list item, it interprets it as a "geo:" address and opens the default browser to show the location. How can I configure the WebView to not interprete the location's addresses.
I don't want the "geo:" handling to swallow the "normal" list item touch event. If I tap carefully just on the location name then the "normal" list item touch event is fired. The WevView must interprete addresses automatically, since I don't add the "geo:" markup.
Sample content:
Southport Open Storage
3080 Promenade St, West Sacramento, CA 95691, USA
Sample content html:
<li class="ui-li ui-li-static ui-body-c">
<span class="location-address-name">D And L Heating And Air - HVAC Contractor</span><br>
<span class="location-formatted-address">3236 Malcolm Island St, West Sacramento, CA 95691, USA</span>
</li>
Additional Info:
Using jQueryMobile 1.0-b2 to for all UI components
jQuery 1.6.2
I saw some posts about "geo:" but they mostly dealt with WebViewClient.shouldOverrideUrlLoading(...) which seems no relevant to the above issue.
Looks like you want to add this to your <head>:
<meta name="format-detection" content="address=no" />
See also this similar question:
Disable the automatic Linkify of Webview

Categories

Resources