Options
All
  • Public
  • Public/Protected
  • All
Menu

Module History

JMap.History

This is where you can find browser history relative methods

Index

Functions

getHashParameter

  • getHashParameter(parameterName: string): string
  • JMap.History.getHashParameter

    Returns a JS object that contains all key / value entries present in the hash of the url.

    Returns an empty string if parameter's not found.

    throws

    Error if parameterName is not a valid string

    example
    
    // Ex. url = ***http://localhost:8080/services/ng#ngProjectId=0&myvar=test***
    
    JMap.History.getHashParameter("myvar")
    // returns "test"
    
    JMap.History.getHashParameter("myvardoesntexist")
    // returns ""

    Parameters

    • parameterName: string

    Returns string

getHashParameters

  • getHashParameters(): object
  • JMap.History.getHashParameters

    Returns a JS object that contains all key / value entries present in the hash of the url.

    example
    
    // get all parameters in the url hash
    JMap.History.getHashParameters()
    
    // Ex. url = ***http://localhost:8080/services/ng#ngProjectId=0&myvar=test***
    // Will return this object :
    {
       ngProjectId: 0,
       myvar: "test"
    }

    Returns object

    • [key: string]: string

goBack

  • goBack(): void
  • JMap.History.goBack

    The same as clicking the back button of the browser

    example
    
    // go to previous page
    JMap.History.goBack()

    Returns void

goForward

  • goForward(): void
  • JMap.History.goForward

    The same as clicking the forward button of the browser

    example
    
    // go to the next page if exist
    JMap.History.goForward()

    Returns void

onParameterChange

  • onParameterChange(parameterName: string, fn: function): string
  • JMap.History.onParameterChange

    You can attach a listener that listen for url hash params change.

    The function returns the listener id that can be used after to remove the listener.

    throws

    Error if parameterName is not a valid string or fn is not a function

    example
    
    const listenerId = JMap.History.onParameterChange("ngProjectId", (oldValue, newValue) => {
       console.log(`In the url hash the parameter "ngProjectId" has changed from "${oldValue}" to "${newValue}"`)
    })

    Parameters

    • parameterName: string
    • fn: function
        • (oldValue: string, newValue: string | undefined): void
        • Parameters

          • oldValue: string
          • newValue: string | undefined

          Returns void

    Returns string

    the listener id, can be used to remove the listener with JMap.History.removePropertyChangeListener

popHashParameters

  • popHashParameters(parameterName: string): void
  • JMap.History.popHashParameters

    You can remove a parameter in the url hash.

    Don't throw an error if the parameter doesn't exist.

    throws

    Error if parameterName is not a valid string

    example
    
    // Ex. url is = ***http://localhost:8080/services/ng#ngProjectId=0&myvar=test***
    
    JMap.History.popHashParameters("myvar")
    
    // The url is now = ***http://localhost:8080/services/ng#ngProjectId=0***

    Parameters

    • parameterName: string

    Returns void

pushHashParameters

  • pushHashParameters(parameterName: string, parameterValue: string): void
  • JMap.History.pushHashParameters

    You can add or update a parameter in the url hash.

    throws

    Error if parameterName is not a valid string

    example
    
    // Ex. url is = ***http://localhost:8080/services/ng#ngProjectId=0***
    
    JMap.History.pushHashParameters("myvar", "test")
    
    // The url is now = ***http://localhost:8080/services/ng#ngProjectId=0&myvar=test***

    Parameters

    • parameterName: string
    • parameterValue: string

    Returns void

removePropertyChangeListener

  • removePropertyChangeListener(listenerId: string): void
  • JMap.History.removePropertyChangeListener

    You can detach a property listener by its id that has been returned when it has been created with function JMap.History.onParameterChange.

    After that the listener will be destroyed.

    throws

    Error if parameterName is not a valid string or fn is not a function

    example
    
    const listenerId = JMap.History.onParameterChange(...)
    // the listener is working
    
    // ...
    
    JMap.History.removePropertyChangeListener(listenerId)
    // here the listener has stopped

    Parameters

    • listenerId: string

    Returns void

transformSearchParamsIntoHashParams

  • transformSearchParamsIntoHashParams(paramNames: string | string[]): void
  • JMap.History.transformSearchParamsIntoHashParams

    Get all specified search params in the url and transform them into hash params without refreshing the page.

    example
    
    // Ex. url is = ***http://localhost:8080/services/ng?foreign=true&ngProjectId=0&myvar=test***
    
    JMap.History.transformSearchParamsIntoHashParams(["ngProjectId", "myvar"])
    
    // The url is now = ***http://localhost:8080/services/ng?foreign=true#ngProjectId=0&myvar=test***

    Parameters

    • paramNames: string | string[]

      list of params to transform.

    Returns void