Tips and Tricks in a world of Mix

Archive for April, 2012

Jquery Mobile remove page caching solution

 

A full solution is here- https://gist.github.com/921920

 

// force certain pages to be refreshed every time.  mark such pages with
// ‘data-cache="never"’
//
jQuery(‘div’).live(‘pagehide’, function (event, ui) {
    var page = jQuery(event.target);

    if (page.attr(‘data-cache’) == ‘never’) {
        page.remove();
    };
});

// for pages marked with ‘data-cache="never"’ manually add a back button since
// JQM doesn’t.  this is *okay* because we know the browswer history stack is
// intact and goes to the correct ‘back’ location.
// specified back button – however!
//
jQuery(‘div’).live(‘pagebeforecreate’, function (event, ui) {
    var page = jQuery(event.target);

    if (page.attr(‘data-cache’) == ‘never’) {
        var header = page.find(‘[data-role="header"]’);

        if (header.jqmData("backbtn") !== false && header.find(‘[data-rel="back"]’).size() == 0) {
            var back = jQuery(‘<a href="#" data-icon="back" data-rel="back">Back</a>’);
            header.prepend(back);
        };
    };
});

 

but I didn’t want to change every page , so –

On pageHide of my current page I remove itself from Dom object.

 

$(‘#pageIndex’).live(‘pagehide’, function (event, ui) {
    var page = jQuery(event.target);

   // if (page.attr(‘data-cache’) == ‘never’) {
       
page.remove();
   // };
});

Then you can apprach the page from scretch :

 

$.mobile.changePage("index.html");

from everywhere , and it’ll rebuild it !

Advertisements

JQuery Mobile: Fire Mobileinit Event

http://weblogs.asp.net/yousefjadallah/archive/2011/06/28/jquery-mobile-fire-mobileinit-event.aspx

Many people asked that the Mobileinit event didn’t work. Simplicity just you need to follow this sequence:

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css&quot; />
    <
script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
    <
script>
       
$(document).bind("mobileinit", function () {
            alert(‘mobileinit is fired’);
        });
    </script>
    <
script src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js"></script>
Hope that helps.

Debugging in Eclipse console.log app messages

 

For you to be able to see the console you’ve been writing in your app :

 

Window->Show View-> other –> write Logcat –>

You’ll get a console window listening to every message from your device.

image

edit filter –> Web Console

 

image

 

Now you’ll see your app messages

image

JavaScript execution exceeded timeout

 

The exception was thrown when I used

navigator.geolocation.watchPosition

 

Changed it to:

function getLocation() {
            navigator.geolocation.getCurrentPosition(updatePos, locationError, { enableHighAccuracy: true, timeout: 10000 });
        }

        var intervalID = window.setInterval(getLocation, 10000);

and then it worked

Tag Cloud

%d bloggers like this: