Problem trying to navigate from within javascript

2 posts, 0 answers
  1. ericTheGoldfish
    ericTheGoldfish avatar
    10 posts
    Member since:
    May 2007

    Posted 25 May Link to this post

    Good evening all

     

    I am having a small problem trying to get my app to navigate to the selected remote location. The method is being called but the redirection is not happening.

    I am trying to get the app to redirect to a page once the user has stopped shaking the device.

    Here is the code being used:

    (function () {
        // Initialize variables
        var watchID;
        var previousAcceleration = {
            x: null,
            y: null,
            z: null
        };
        var shakeStarted = false;

        window.Home = {
            // Function when page loaded
            show: function () {
                var spanTimeStamp = document.getElementById("spanTimeStamp");
                spanTimeStamp.textContent = "Started";

                var options = {
                    frequency: 500
                }; // Update every .5 seconds

                watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
            },
            // Function when page unloaded
            hide: function () {
                if (watchID) {
                    navigator.accelerometer.clearWatch(watchID);
                    watchID = null;
                }
            }
        };
        
        // Function when the accelerometer is initialized
        function onSuccess(acceleration) {
            var accelerationChange = {};
            
            // See if there is a previous acceleration
            if (previousAcceleration.x !== null) {
                accelerationChange.x = Math.abs(previousAcceleration.x - acceleration.x);
                accelerationChange.y = Math.abs(previousAcceleration.y - acceleration.y);
                accelerationChange.z = Math.abs(previousAcceleration.z - acceleration.z);
            }

            // Set the previous acceleration
            previousAcceleration = {
                x: acceleration.x,
                y: acceleration.y,
                z: acceleration.z
            };

            // See if the acceleration is a shake
            if (accelerationChange.x + accelerationChange.y + accelerationChange.z > 30) {
                shakeStarted = true;
                var spanDirectionX = document.getElementById("spanDirectionX");
                spanDirectionX.textContent = acceleration.timestamp + " :: " + (accelerationChange.x + accelerationChange.y + accelerationChange.z) + " :: ";            
            } else if (accelerationChange.x + accelerationChange.y + accelerationChange.z < 30 && shakeStarted == true) {
                // Call the function when the shaking stops
                shakeStarted = false;
                ShakeStopped();
            }

        }
        
        // Function to be called when the shaking stopped
        function ShakeStopped() {
            var app = new kendo.mobile.Application();
            var id = Math.floor(Math.random() * 20) + 1;
            
            var spanTimeStamp = document.getElementById("spanTimeStamp");
            spanTimeStamp.textContent = "Stopped from function :: " + id;
            
            app.navigate("views/details.html?##id=" + id);
        }

        // Function if an error occurs with the accelerometer
        function onError() {
            alert('onError!');
        }
    }());

     

    Nay help would be greatly appreicated

     

    Many thanks

     

    Eric

  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 27 May Link to this post

    Hi Eric,

    I believe the navigation is attempted but a JavaScript error may be preventing the process from completing. Perhaps there is an error in the Developer Console which you can examine using the methods explained here.

    On a first sight it appears that the token '##' in the navigation URL query string may be preventing the correct navigation or the way the new page is parsing the query string.

    I hope that this helps.

    Regards,
    Anton Dobrev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top