function attachNavigationEvents()

in src/windows/InAppBrowserProxy.js [43:105]


function attachNavigationEvents (element, callback) {
    if (isWebViewAvailable) {
        element.addEventListener('MSWebViewNavigationStarting', function (e) {
            callback({ type: 'loadstart', url: e.uri }, { keepCallback: true });
        });

        element.addEventListener('MSWebViewNavigationCompleted', function (e) {
            if (e.isSuccess) {
                callback({ type: 'loadstop', url: e.uri }, { keepCallback: true });
            } else {
                callback(
                    {
                        type: 'loaderror',
                        url: e.uri,
                        code: e.webErrorStatus,
                        message: 'Navigation failed with error code ' + e.webErrorStatus
                    },
                    { keepCallback: true }
                );
            }
        });

        element.addEventListener('MSWebViewUnviewableContentIdentified', function (e) {
            // WebView found the content to be not HTML.
            // http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx
            callback(
                { type: 'loaderror', url: e.uri, code: e.webErrorStatus, message: 'Navigation failed with error code ' + e.webErrorStatus },
                { keepCallback: true }
            );
        });

        element.addEventListener('MSWebViewContentLoading', function (e) {
            if (navigationButtonsDiv && popup) {
                if (popup.canGoBack) {
                    backButton.removeAttribute('disabled');
                } else {
                    backButton.setAttribute('disabled', 'true');
                }

                if (popup.canGoForward) {
                    forwardButton.removeAttribute('disabled');
                } else {
                    forwardButton.setAttribute('disabled', 'true');
                }
            }
        });
    } else {
        var onError = function () {
            callback({ type: 'loaderror', url: this.contentWindow.location }, { keepCallback: true });
        };

        element.addEventListener('unload', function () {
            callback({ type: 'loadstart', url: this.contentWindow.location }, { keepCallback: true });
        });

        element.addEventListener('load', function () {
            callback({ type: 'loadstop', url: this.contentWindow.location }, { keepCallback: true });
        });

        element.addEventListener('error', onError);
        element.addEventListener('abort', onError);
    }
}