This is a migrated thread and some comments may be shown as answers.

Problem trying to navigate from within javascript

1 Answer 31 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ericTheGoldfish
Top achievements
Rank 1
ericTheGoldfish asked on 25 May 2016, 09:32 AM

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

1 Answer, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 27 May 2016, 02:17 PM
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
Tags
General Discussions
Asked by
ericTheGoldfish
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Share this question
or