new HtmlScreen()
Screen class that perform a request and extracts surface contents from
the response content.
Extends
Members
-
<protected, static> permanentResourcesInDoc :object
-
Caches permanent resource keys.
Type:
- object
-
<protected, static> selectors :object
-
Helper selectors for tracking resources.
Type:
- object
-
<protected, non-null> cache :Object
-
Holds the cached data.
Type:
- Object
- Inherited From:
- Default Value:
-
- null
-
<protected> cacheable :boolean
-
Holds whether class is cacheable.
Type:
- boolean
- Inherited From:
- Default Value:
-
- false
-
<protected, nullable> httpHeaders :Object
-
Holds default http headers to set on request.
Type:
- Object
- Inherited From:
- Default Value:
-
- { 'X-PJAX': 'true', 'X-Requested-With': 'XMLHttpRequest' }
-
<protected, non-null> httpMethod :string
-
Holds default http method to perform the request.
Type:
- string
- Inherited From:
- Default Value:
-
- RequestScreen.GET
-
<protected> id :string
-
Holds the screen id.
Type:
- string
- Inherited From:
-
<protected> request :XMLHttpRequest
-
Holds the XHR object responsible for the request.
Type:
- XMLHttpRequest
- Inherited From:
- Default Value:
-
- null
-
<protected, non-null> timeout :number
-
Holds the request timeout in milliseconds.
Type:
- number
- Inherited From:
- Default Value:
-
- 30000
-
<protected, nullable> title :string
-
Holds the screen title. Relevant when the page title should be upadated when screen is rendered.
Type:
- string
- Inherited From:
- Default Value:
-
- null
-
<protected, non-null> titleSelector :string
-
Holds the title selector. Relevant to extract the
element from request fragments to use as the screen title.Type:
- string
- Default Value:
-
- title
Methods
-
activate()
-
Fires when the screen is active. Allows a screen to perform any setup that requires its DOM to be visible. Lifecycle.
- Inherited From:
- Overrides:
-
addCache(content)
-
Adds content to the cache.
Parameters:
Name Type Description content
string Content to be cached. - Inherited From:
-
allocateVirtualDocumentForContent(htmlString)
-
Allocates virtual document for content. After allocated virtual document can be accessed by
this.virtualDocument
.Parameters:
Name Type Description htmlString
string -
appendStyleIntoDocument_(newStyle)
-
Customizes logic to append styles into document. Relevant to when tracking a style by id make sure to re-positions the new style in the same dom order.
Parameters:
Name Type Description newStyle
Element -
assertSameBodyIdInVirtualDocument()
-
If body is used as surface forces the requested documents to have same id of the initial page.
-
<protected> assertValidResponseStatusCode(status)
-
Asserts that response status code is valid.
Parameters:
Name Type Description status
number - Inherited From:
-
beforeDeactivate()
-
Gives the Screen a chance to cancel the navigation and stop itself from being deactivated. Can be used, for example, if the screen has unsaved state. Lifecycle. Clean-up should not be preformed here, since the navigation may still be cancelled. Do clean-up in deactivate.
- Inherited From:
Returns:
If returns true, the current screen is locked and the next nagivation interrupted.- Type
- boolean
-
beforeUpdateHistoryPath()
-
Gives the Screen a chance format the path before history update.
- Inherited From:
Returns:
Navigation path to use on history.- Type
- string
-
beforeUpdateHistoryState()
-
Gives the Screen a chance format the state before history update.
- Inherited From:
Returns:
History state to use on history.- Type
- object
-
clearCache()
-
Clears the cache.
- Inherited From:
-
copyNodeAttributesFromContent_()
-
Copies attributes from the tag of content to the given node.
-
deactivate()
-
Allows a screen to do any cleanup necessary after it has been deactivated, for example cancelling outstanding requests or stopping timers. Lifecycle.
- Inherited From:
-
disposeInternal()
-
Dispose a screen, either after it is deactivated (in the case of a non-cacheable view) or when the App is itself disposed for whatever reason. Lifecycle.
- Inherited From:
- Overrides:
-
disposePendingStyles()
-
Disposes pending styles if screen get disposed prior to its loading.
-
evaluateScripts(surfaces)
-
Allows a screen to evaluate scripts before the element is made visible. Lifecycle.
Parameters:
Name Type Description surfaces
object Map of surfaces to flip keyed by surface id. - Inherited From:
- Overrides:
Returns:
This can return a promise, which will pause the navigation until it is resolved.- Type
- CancellablePromise
-
evaluateStyles(surfaces)
-
Allows a screen to evaluate styles before the element is made visible. Lifecycle.
Parameters:
Name Type Description surfaces
object Map of surfaces to flip keyed by surface id. - Inherited From:
- Overrides:
Returns:
This can return a promise, which will pause the navigation until it is resolved.- Type
- CancellablePromise
-
flip(surfaces)
-
Allows a screen to perform any setup immediately before the element is made visible. Lifecycle.
Parameters:
Name Type Description surfaces
object Map of surfaces to flip keyed by surface id. - Inherited From:
- Overrides:
Returns:
This can return a promise, which will pause the navigation until it is resolved.- Type
- CancellablePromise
-
<protected> formatLoadPath(path)
-
Formats load path before invoking ajax call.
Parameters:
Name Type Description path
string - Inherited From:
Returns:
Formatted path;- Type
- string
-
<protected> getCache()
-
Gets the cached content.
- Inherited From:
Returns:
Cached content.- Type
- Object
-
getHttpHeaders()
-
Gets the http headers.
- Inherited From:
Returns:
- Type
- Object
-
getHttpMethod()
-
Gets the http method.
- Inherited From:
Returns:
- Type
- string
-
getId()
-
Gets the screen id.
- Inherited From:
Returns:
- Type
- string
-
getRequest()
-
Gets the request object.
- Inherited From:
Returns:
- Type
- Object
-
getRequestPath()
-
Gets request path.
- Inherited From:
Returns:
- Type
- string
-
getResourceKey_(resource)
-
Extracts a key to identify the resource based on its attributes.
Parameters:
Name Type Description resource
Element Returns:
Extracted key based on resource attributes in order of preference: id, href, src.- Type
- string
-
getSurfaceContent(surfaceId)
-
Returns the content for the given surface, or null if the surface isn't used by this screen. This will be called when a screen is initially constructed or, if a screen is non-cacheable, when navigated.
Parameters:
Name Type Description surfaceId
string The id of the surface DOM element. - Inherited From:
- Overrides:
Returns:
This can return a string or node representing the content of the surface. If returns falsy values surface default content is restored.- Type
- string | Element
-
getTimeout()
-
Gets the request timeout.
- Inherited From:
Returns:
- Type
- number
-
getTitle()
-
Gets the screen title.
- Inherited From:
Returns:
- Type
- string
-
getTitleSelector()
-
Gets the title selector.
Returns:
- Type
- string
-
isCacheable()
-
Whether the class is cacheable.
- Inherited From:
Returns:
Returns true when class is cacheable, false otherwise.- Type
- boolean
-
isValidResponseStatusCode(statusCode)
-
Checks if response succeeded. Any status code 2xx or 3xx is considered valid.
Parameters:
Name Type Description statusCode
number - Inherited From:
-
load( [path])
-
Returns all contents for the surfaces. This will pass the loaded content to
Screen.load
with all information you need to fulfill the surfaces. Lifecycle.Parameters:
Name Type Argument Description path
string <optional>
The requested path. - Inherited From:
- Overrides:
Returns:
This can return a string representing the contents of the surfaces or a promise, which will pause the navigation until it is resolved. This is useful for loading async content.- Type
- CancellablePromise
-
maybeExtractResponseUrlFromRequest(request)
-
The following method tries to extract the response url value by checking the custom response header 'X-Request-URL' if proper value is not present in XMLHttpRequest. The value of responseURL will be the final URL obtained after any redirects. Internet Explorer, Edge and Safari <= 7 does not yet support the feature. For more information see: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseURL https://xhr.spec.whatwg.org/#the-responseurl-attribute
Parameters:
Name Type Description request
XMLHttpRequest - Inherited From:
Returns:
Response url best match.- Type
- string
-
querySelectorAll_(selector)
-
Queries elements from document and returns an array of elements.
Parameters:
Name Type Description selector
string Returns:
- Type
- array.<Element>
-
releaseVirtualDocument()
-
Releases virtual document allocated for content.
-
resolveTitleFromVirtualDocument()
-
Resolves title from allocated virtual document.
-
setCacheable(cacheable)
-
Sets whether the class is cacheable.
Parameters:
Name Type Description cacheable
boolean - Inherited From:
-
setHttpHeaders( [httpHeaders])
-
Sets the http headers.
Parameters:
Name Type Argument Description httpHeaders
Object <optional>
<nullable>
- Inherited From:
-
setHttpMethod(httpMethod)
-
Sets the http method.
Parameters:
Name Type Description httpMethod
string - Inherited From:
-
setId(id)
-
Sets the screen id.
Parameters:
Name Type Description id
string - Inherited From:
-
setRequest(request)
-
Sets the request object.
Parameters:
Name Type Argument Description request
Object <nullable>
- Inherited From:
-
setTimeout(timeout)
-
Sets the request timeout in milliseconds.
Parameters:
Name Type Description timeout
number - Inherited From:
-
setTitle( [title])
-
Sets the screen title.
Parameters:
Name Type Argument Description title
string <optional>
<nullable>
- Inherited From:
-
setTitleSelector(titleSelector)
-
Sets the title selector.
Parameters:
Name Type Description titleSelector
string -
toString()
-
- Inherited From:
Returns:
- Type
- string
-
virtualQuerySelectorAll_(selector)
-
Queries elements from virtual document and returns an array of elements.
Parameters:
Name Type Description selector
string Returns:
- Type
- array.<Element>