rice-framework/krad-web/src/main/webapp/krad/scripts/krad.url.js
/**
 * Invoked on page setup to update the request URL to reflect the current page
 *
 * <p>
 * To support the use of back button for page changes and bookmarking pages the request is updated
 * to include the id for the current page. If the HTML 5 history API is supported the page id is added
 * as a request parameter, otherwise we fall back to using the URL hash.
 *
 * The URL is also updated to include the form key so the latest changes are pulled when the user
 * goes back, and a cache key to bust browser caching
 * </p>
 *
 * @param pageId id for the page currently loaded
 */
Invoked on page setup to update the request URL to reflect the current page


To support the use of back button for page changes and bookmarking pages the request is updated
to include the id for the current page. If the HTML 5 history API is supported the page id is added
as a request parameter, otherwise we fall back to using the URL hash.

The URL is also updated to include the form key so the latest changes are pulled when the user
goes back, and a cache key to bust browser caching


@param pageId id for the page currently loaded
Invoked on page setup to update the request URL to reflect the current page To support the use of back button for page changes and bookmarking pages the request is updated to include the id for the current page . If the HTML 5 history API is supported the page id is added as a request parameter otherwise we fall back to using the URL hash . The URL is also updated to include the form key so the latest changes are pulled when the user goes back and a cache key to bust browser caching @param pageId id for the page currently loaded
function updateRequestUrl(pageId) {
    var formKeyField = jQuery("input[name='" + kradVariables.FORM_KEY + "']");
    var disableCache = (jQuery("input[name='" + kradVariables.DISABLE_BROWSER_CACHE + "']").val() == "true");
    var cacheKey;
    var urlPageId = getUrlParameter(kradVariables.PAGE_ID, window.location.search.substring(1));
    if (disableCache) {
        cacheKey = generateQuickGuid();
    }
    var singlePageView = (jQuery("input[name='" + kradVariables.SINGLE_PAGE_VIEW + "']").val() == "true");
    if (!disableCache && singlePageView) {
        return;
    }
    if (history.replaceState) {
        var queryString = "";
        if (formKeyField.length && formKeyField.val()) {
            queryString = getUrlQueryString(kradVariables.FORM_KEY, formKeyField.val());
        }
        if (disableCache) {
            queryString = getUrlQueryString(kradVariables.CACHE_KEY, cacheKey, queryString);
        }
        if (!singlePageView) {
            queryString = getUrlQueryString(kradVariables.PAGE_ID, pageId, queryString);
        }
        var updatedPageUrl = "?" + queryString + window.location.hash;
        if (!(getContext().fancybox.isOpen())){
            updatedPageUrl = updatedPageUrl.replace("&" + kradVariables.LIGHTBOX_PARAM + "=true", "");
        }
        if (urlPageId && pageId && (urlPageId != pageId)) {
            history.pushState({pageId: pageId}, null, updatedPageUrl);
        }
        else {
            history.replaceState({pageId: pageId}, null, updatedPageUrl);
        }
    } else {
        var urlSearch = window.location.search.substring(1);
        var search = urlSearch;
        var hash = window.location.hash;
        var delineatedHash;
        if (!singlePageView) {
            search = getUrlQueryString(kradVariables.PAGE_ID, pageId, search);
        }
        if (formKeyField.length && formKeyField.val()) {
            hash = getUrlQueryString(kradVariables.FORM_KEY, formKeyField.val(), hash);
        }
        if (disableCache) {
            hash = getAppendedUrlHashKey(kradVariables.CACHE_KEY, cacheKey, hash);
        }
        if (hash) {
            delineatedHash = "#" + hash;
        }
        if (urlPageId && pageId && (urlPageId != pageId)) {
            window.location.replace("?" + search + delineatedHash);
        } else {
            if (hash) {
                window.location.replace("?" + search + delineatedHash);
            }
        }
    }
}
function updateRequestUrl ( pageId ) { var formKeyField = jQuery ( "input[name='" + kradVariables . FORM_KEY + "']" ) ; var disableCache = ( jQuery ( "input[name='" + kradVariables . DISABLE_BROWSER_CACHE + "']" ) . val ( ) == "true" ) ; var cacheKey ; var urlPageId = getUrlParameter ( kradVariables . PAGE_ID , window . location . search . substring ( 1 ) ) ; if ( disableCache ) { cacheKey = generateQuickGuid ( ) ; } var singlePageView = ( jQuery ( "input[name='" + kradVariables . SINGLE_PAGE_VIEW + "']" ) . val ( ) == "true" ) ; if ( ! disableCache && singlePageView ) { return ; } if ( history . replaceState ) { var queryString = "" ; if ( formKeyField . length && formKeyField . val ( ) ) { queryString = getUrlQueryString ( kradVariables . FORM_KEY , formKeyField . val ( ) ) ; } if ( disableCache ) { queryString = getUrlQueryString ( kradVariables . CACHE_KEY , cacheKey , queryString ) ; } if ( ! singlePageView ) { queryString = getUrlQueryString ( kradVariables . PAGE_ID , pageId , queryString ) ; } var updatedPageUrl = "?" + queryString + window . location . hash ; if ( ! ( getContext ( ) . fancybox . isOpen ( ) ) ) { updatedPageUrl = updatedPageUrl . replace ( "&" + kradVariables . LIGHTBOX_PARAM + "=true" , "" ) ; } if ( urlPageId && pageId && ( urlPageId != pageId ) ) { history . pushState ( { pageId : pageId } , null , updatedPageUrl ) ; } else { history . replaceState ( { pageId : pageId } , null , updatedPageUrl ) ; } } else { var urlSearch = window . location . search . substring ( 1 ) ; var search = urlSearch ; var hash = window . location . hash ; var delineatedHash ; if ( ! singlePageView ) { search = getUrlQueryString ( kradVariables . PAGE_ID , pageId , search ) ; } if ( formKeyField . length && formKeyField . val ( ) ) { hash = getUrlQueryString ( kradVariables . FORM_KEY , formKeyField . val ( ) , hash ) ; } if ( disableCache ) { hash = getAppendedUrlHashKey ( kradVariables . CACHE_KEY , cacheKey , hash ) ; } if ( hash ) { delineatedHash = "#" + hash ; } if ( urlPageId && pageId && ( urlPageId != pageId ) ) { window . location . replace ( "?" + search + delineatedHash ) ; } else { if ( hash ) { window . location . replace ( "?" + search + delineatedHash ) ; } } } }
Invoked on page setup to update the request URL to reflect the current page
Invoked on page setup to update the request URL to reflect the current page
// generate unique cache key (only has to be unique with a given form key)
 // check for single page views in which case we don't need to update URL with page id
 // no URL updates needed
 // with HTML 5 history API we can update URL parameters, otherwise fall back to using the hash
 // add cache busting key
 // update page parameter in URL for multi-page views
 // push state if new page
 // otherwise replace state
 // add keys hash if no HTML5 history support (old IE support)
