webpg.utils

Provides reusable, generic methods for browser specific tasks.

Summary
webpg.utilsProvides reusable, generic methods for browser specific tasks.
Functions
initInitializes the webpg.utils object and setups up required overrides.
detectedBrowserDetermines current running browser and returns the a string containing the friendly name.
resourcePathDetermines the base path for extension resources.
getParameterByNameSearches the location.search query string for a named parameter
parseUrlReturns an object containing the many various elements of a URL
isValidEmailAddressParses a given string to ensure it is a valid email address; Returns true/false
_onRequest.addListenerThis function creates a listener object for interaction between privileged and non-privileged pages
sendRequestSends a request event to the background page or content script
tabs.sendRequestSends a request to a given tab/frame
getFrameByIdIterates through the windows to find a frame matching the given ID
copyToClipboardProvides a unified method to put data into the clipboard
openNewTabOpens a new tab with the location specified and if possible opens the tab at specified index.
getSelectedTextGets the selected text for the various types of selections; returns a JSON Object.
contextMenus.removeAllRemoves or hides all items in the context menu.
contextMenus.addAdds items to the context menu

Functions

init

init: function()

Initializes the webpg.utils object and setups up required overrides.

detectedBrowser

Determines current running browser and returns the a string containing the friendly name.

resourcePath

resourcePath: function()

Determines the base path for extension resources.  This is a self executing method.

getParameterByName

getParameterByName: function(parameterName)

Searches the location.search query string for a named parameter

Parameters

parameterName<str> The name of the parameter to return

parseUrl

parseUrl: function(url)

Returns an object containing the many various elements of a URL

Parameters

url<str> The URL to parse

Returns

<obj>An object containing the many various elements of a URL

isValidEmailAddress

isValidEmailAddress: function(emailAddress)

Parses a given string to ensure it is a valid email address; Returns true/false

Parameters

emailAddress<str> The email address parse

Returns

<bool>(true/false)

_onRequest.addListener

This function creates a listener object for interaction between privileged and non-privileged pages

Parameters

callback<func> The callback to be called upon completion

sendRequest

sendRequest: function(data,
callback,
doc)

Sends a request event to the background page or content script

Parameters

data<json obj> A JSON object with parameters and data to pass
callback<func> The callback to be called upon completion
doc<document> The document to add the listener to

tabs.sendRequest

Sends a request to a given tab/frame

Parameters

target<obj> An object that contains at minimum, the id for target
request<json obj> A JSON object with parameters and data to send

getFrameById

getFrameById: function(id)

Iterates through the windows to find a frame matching the given ID

Parameters

id<str> The unique ID of the frame to locate

copyToClipboard

copyToClipboard: function(win,
doc)

Provides a unified method to put data into the clipboard

Parameters

win<window> The window that hosts the element that contains the data to copy
doc<document> The specific documnet of <window> with the element

openNewTab

openNewTab: function(url,
tabIndex)

Opens a new tab with the location specified and if possible opens the tab at specified index.

Parameters

url<str> The URL to open
tabIndex<int> The desired index number (position) for the tab

getSelectedText

getSelectedText: function()

Gets the selected text for the various types of selections; returns a JSON Object.

Returns

{‘selectionText’: <str>, ‘pre_selection’: <str>, ‘post_selection’: <str>}

contextMenus.removeAll

Removes or hides all items in the context menu.

Parameters

callback<func> A function to execute when completed.

contextMenus.add

Adds items to the context menu

Parameters

action<int> The webpg.constants.overlayAction to add
init: function()
Initializes the webpg.utils object and setups up required overrides.
resourcePath: function()
Determines the base path for extension resources.
getParameterByName: function(parameterName)
Searches the location.search query string for a named parameter
parseUrl: function(url)
Returns an object containing the many various elements of a URL
isValidEmailAddress: function(emailAddress)
Parses a given string to ensure it is a valid email address; Returns true/false
sendRequest: function(data,
callback,
doc)
Sends a request event to the background page or content script
getFrameById: function(id)
Iterates through the windows to find a frame matching the given ID
copyToClipboard: function(win,
doc)
Provides a unified method to put data into the clipboard
openNewTab: function(url,
tabIndex)
Opens a new tab with the location specified and if possible opens the tab at specified index.
getSelectedText: function()
Gets the selected text for the various types of selections; returns a JSON Object.
Close