StructureJS
0.15.2A class based utility library for building modular and scalable web platform applications. Features opt-in classes and utilities which provide a solid foundation and toolset to build your next project.
A helper class to detect network changes.
_eventDispatcher
EventDispatcher
private
static
A reference to the EventDispatcher object.
_initialized
Boolean
private
A flag to determine if this class has already been initialized.
_dispatchEvent
event
Dispatches an event within the NetworkMonitorEvent object.
event
NetworkMonitorEvent
The Event object that is dispatched into the event flow. You can create custom events, the only requirement is all events must extend the NetworkMonitorEvent.
_onNetworkMonitorEvent
event
An event handler method when the native Window 'online' and 'offline' events are triggered.
event
Object
_start
()
private
static
Adds the necessary event listeners to listen for the 'online' and 'offline' events.
addEventListener
type
callback
scope
[priority=0]
Registers an event listener object with an NetworkMonitor object so that the listener receives notification of an event.
type
String
The type of event.
callback
Function
The listener function that processes the event. This function must accept an Event object as its only parameter and must return nothing, as this example shows.
scope
Any
Binds the scope to a particular object (scope is basically what "this" refers to in your function). This can be very useful in JavaScript because scope isn't generally maintained.
[priority=0]
Int
optional
Influences the order in which the listeners are called. Listeners with lower priorities are called after ones with higher priorities.
NetworkMonitor.addEventListener(NetworkMonitorEvent.STATUS, this._handlerMethod, this);
_handlerMethod(event) {
console.log(event.status, event.connected);
}
connected
()
Boolean
public
static
Returns the online status of the browser. The property returns a boolean value, with true for being online and false for being offline.
NetworkMonitor.connected();
getStatus
()
String
public
static
Returns if the status type ('online' or 'offline') if computer or device is connected to the internet.
Returns 'online' or 'offline'.
NetworkMonitor.getStatus();
removeEventListener
type
callback
scope
Removes a specified listener from the NetworkMonitor object.
NetworkMonitor.removeEventListener(NetworkMonitorEvent.STATUS, this._handlerMethod, this);
_handlerMethod(event) {
console.log(event.status, event.connected);
}