Useful Javascript Functions and objects in SharePoint – Part 2

In my last article “Useful Javascript Functions and objects in SharePoint – Part 1”  I listed some useful javascript objects in SharePoint.
Today I will continue exploring useful functions.
DOM Management
  1. byid(id) = Return element for the given id
  2. newE(tag) = Create a new dom element of the given tag e.g. div etc.
  3. wpf() = return ASP.net form object for the current web part page
  4. GetEventSrcElement(e) = return source element for the given event object
  5. GetEventKeyCode(e) = Return key code of the currently pressed key for the given object
  6. GetInnerText(e) = Return inner html for the given object

HTML Encoding and Decoding

  1. escapeProperlyCoreCore(str, bAsUrl, bForFilterQuery, bForCallback) = Very useful function to perform any type of string escaping. Last three parameters are flags to perform deifferent type of escaping i.e.
    • bAsUrl = true, for url escaping
    • bForFilterQuery = true, for filter query escaping
    • bForCallback = true, for call back escaping
  2. escapeProperly(str) = Escapes the given string to make it valid SharePoint compatible string. It internally calls escapeProperlyCoreCore to perform the actual escaping
  3. escapeUrlForCallback(str) = Escapes the given string to make it valid url for call back
  4. encodeScriptQuote(str) = Replace the apostrophe i.e. ‘ to %27 in the given string
  5. STSHtmlEncode(str) = Encodes the reserved characters to their respective HTML entities in the given string. For example “<div>” will become &lt;div&gt;
  6. StAttrQuote(st) = Encodes the “&”, “ “ ” and carriage return to their respective HTML entities in the given string.
  7. STSScriptEncode(str) = Encodes the given string for use in script. It has the same functionality as SPEncode.ScriptEncode defined here
  8. STSScriptEncodeWithQuote = Encodes the specified string so that characters in embedded HTML tags are displayed as text in the browser, and writes the string in quotation marks
  9. escapeForSync(str) = Encodes the given string for syncing. Need further clarification.
  10. Vutf8ToUnicode(rgBytes) = Converts the given utf8 string to unicode
  11. unescapeProperly(str) = Unescapes the given escaped string

Validations

  1. PageUrlValidation(url) = Checks if the given string is a valid url or not.
  2. IndexOfIllegalCharInUrlLeafName(strLeafName) = Return the index of character in the given string which is illegal to be used in url leaf name.
  3. IndexOfIllegalCharInUrlPath(strPath) = Return the index of character in the given string which is illegal to be used in url leaf name.
  4. UrlContainsIllegalStrings(strPath) = Returns true if the given string contains an illegal character which can not be used in a url. Otherwise, return false.
  5. UrlLeafNameValidate(source, args) = Validates the url leaf name. Returns true if valid otherwise, false. Need further clarification.
  6. UrlPathValidate (source, args) = Validates the url path. Returns true if valid otherwise, false. Need further clarification.
  7. IsCheckBoxListSelected(checkboxlist) = Returns true, if the given checkbox is either null or at least one check box is checked in it.
  8. IsAccessibilityFeatureEnabled() = Returns true, if the accessibility feature is enabled by checking the cookie called “WSS_AccessibilityFeature”

Cookie Management

  1. DeleteCookie(sName) = Deletes the given cookie by setting its expiry date to 01-Jan-1970
  2. GetCookie(sName) = Returns the given cookie

Navigation

  1. navigateMailToLink(strUrl, strUrlNew) = Creates a mail to link for the given url
  2. GetUrlFromWebUrlAndWebRelativeUrl(webUrl, webRelativeUrl) = Creates a url by combining webUrl and relative url. It takes care of checking null webUrl and slash character at the end.

Syncing with other applications

  1. GetStssyncAppNameForType(strType,strDefault) = Returns an string similar to “Connect to Outlook” etc. depending on the given type.
  2. GetStssyncIconPath(strDefault, strPrefix) = Returns the path of icon image for the given syncing application type.
  3. ExportHailStorm ( ….. ) = Creates connection to Outlook. Check here for further details.

Miscellaneous

  1. DeferCall() = Not sure.
  2. AdmBuildParam(stPattern) = Not sure.

To be continued….

Share