Srch.U object (DisplayTemplatesSrch)

The Srch.Uobject provides a range of JavaScript methods and enumerations to help you in your work with display templates customization in SharePoint 2013. All of the methods and enumerations provided can be found in: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\Search.ClientControls.debug.js. The methods in Srch.U are generic helper methods that you can use across all rendering functionalities both in the Search Center and in a ContentBySearchWebPart (CSWP) that uses client side code to render the UI.

var object = new Srch.U()

Members

The U object has the following members.

Methods

The U object has the following methods.

Method

Description

addHandler

Adds an event handler for the given element.

animate

Used for animations on the hover panel.

animateResults

Used for search results animation.

appendArray

Appends an element to an array.

appendScriptsToLoad

Appends a script to a list of scripts to be loaded.

appendUrlParameter

Appends a key-value pair of parameters to the query string.

collapsibleRefinerTitle

Gets an HTML formatted String which represents the refiner’s title. This String is ready to be injected into the DOM.

concatUrl

Concatenates two URL segments together.

copyDictionary

Returns a shallow copy of the source dictionary.

copyLink

Copies a given link to the clipboard.

createErrorObjectWithExecContext

Creates an object that represents the error.

createXMLDocument

Creates an XML documentation from the given XML string.

e

Indicates whether the string is null or empty.

ensureAllowedProtocol

Ensures that the given URL protocol value is allowed.

ensureCSSClassNameExist

Ensures the element has an assigned CSS class.

ensureCSSClassNameNotExist

Ensures the element does not have an assigned CSS class.

ensureNotNullOrEmptyString

Ensures that the given value is not null, undefined or empty; throws an exception otherwise.

ensureNotNullOrUndefined

Ensures that the given value is not null or undefined; throws an exception otherwise.

fillKeywordQuery

Fills a KeywordQuery from a data provider.

findResultObjectFromDOM

Retrieves the result item/table object for a DOM element.

getArray

Splits the string into an array of strings using the semi colon (";") as a separator.

getCalendarType

Gets the calendar type as specified in the site or by the user. If no calendar type is available, None() will be returned.

getClientComponent

Gets the client control component that is the DOM ancestor of the given element.

getCookie

Retrieves an HTTP cookie for the given name.

getDeepLinks

Formats the links list into an HTML UL list.

getDisplayNameFromAuthorField

Gets the display name from the Author field of the search result.

getFieldOnObject

Gets the given field for the object.

getFolderIconUrl

Gets the image URL for a folder.

getFormattedTimeFromSeconds

Gets the formatted time from seconds.

getFriendlyNameForFileExtension

Gets a friendly name for the given file extension. For example "file_Word" instead of "DOCX".

getFriendlyTimeInterval

Gets a relative date time string using GetRelativeDateTimeString in SP.DateTime.Util.

getHideHoverPanelCallback

Gets a string that can be evaluated to hide the hover panel.

getHighlightedProperty

Gets the highlighted property for the current results based on the given key.

getHostName

Extracts the host name for the current page.

getIconUrl

Gets the URL for the HTML page’s associated PNG image.

getIconUrlByFileExtension

Gets the icon URL associated with the file extension. If no information on the file extension can be found, the icon URL associated with the HTML page will be returned.

getImageSourceWithRendition

Gets the image markup for the given height and width.

getMultipleHHXMLNodeValues

Gets multiple hit-highlighted XML nodes.

getOrCreateFieldOnObject

Gets the field value of the object. If no field exists, a field will be created with the default values provided.

getParentAttributeByName

Gets the attribute value of the closest parent element for the given attribute name.

getParentElementByName

Gets the closest parent element with the given tag name.

getRenderTemplateByName

Gets a render template by name.

getRenderTemplateCollection

Gets an array of registered render templates.

getResultObject

Gets the result object for the current element.

getResultsPageUrl

Gets the URL for the results page.

getShowHoverPanelCallback

Gets a string that can be evaluated to show the hover panel.

getShowHoverPanelCallbackWide

Gets a string that can be evaluated to show the hover panel.

getSingleHHXMLNodeValue

Gets a single hit-highlighted XML node.

getStringFieldOnObject

Gets the field value for the given object.

getTableOfType

Gets the first table of the given type in a result table collection.

getTableProperty

Gets the given property value from a property bag.

getTemplateUrlFromFunctionOrRenderCtx

Gets the template file URL for the given template function or context object.

getTrimmedProcessedHHXMLString

Trims the hit-highlighted string; adds an ellipsis at the end if required.

getTrimmedString

Trims the given string based on the given cut off value; adds an ellipsis if required.

getUnEncodedMultiValuedResults

Gets a trimmed string that is un-encoded containing multi-valued results.

getUsernameFromAuthorField

Gets the username from the Author field. The username is expected to be either in NT Auth, FBA, or Windows claims format.

getVideoImageWithFallbackSource

Gets the IMG formatted tag for a video.

getWorkspace

Gets the default workspace (s4-workspace) element.

hideElement

Hides the given DOM element by setting its display attribute to hidden.

includeCSS

Registers the style link.

includeLanguageScript

Registers the language script.

includeScript

Registers the script.

isArray

Indicates whether the specified object is an array or not.

isDefaultSiteLogo

Indicates whether the specified URL contains an image path for the site logo.

isDefaultSiteSearchPage

Indicates whether the current page is the default site search page (osssearchresults.aspx).

isDescendant

Indicates whether the specified element is a descendant for the container.

isEnterKey

Indicates whether the specified key code is the Enter button’s code or not.

isFirstPromotedBlock

Indicates whether the first result in the result table is promoted.

isFirstRankedBlock

Indicates whether the first result in the result table is ranked.

isInArray

Indicates whether the specified item is in the array.

isIntentTable

Indicates whether the specified table is an intent table.

isPageInEditMode

Indicates whether the current page is in edit mode.

isPageInMdsMode

Indicates whether the current page is in MDS mode.

isPagePartialLoad

Indicates whether the current page is in partial load mode.

isPrimitive

Indicates whether the given object is a function, complex project.

isProtocolAllowed

Indicates whether the specified protocol is allowed.

isRTL

Indicates whether the document has the RTL attribute.

isSameHost

Indicates whether the given URL contains the same hostname.

isSPFSKU

isSubstrateTable

Indicates whether the given table is a substrate table.

isTableTypeof

Indicates whether the given table matches tableTypeName.

isUrlPagelRelative

Indicates whether the given page URL is relative.

isUrlRelative

Indicates whether the given URL is relative.

isUrlServerRelative

Indicates whether the given URL is server-relative.

isWebPage

Indicates whether the given file extension is a web page.

loadResource

Gets the string value from the given string resource.

loadResourceForTemplate

Gets the string value from the given string resource.

loadScripts

Batch loads the given list of scripts.

logClick

A helper for object click logging.

logRenderingErrorMessageToContext

Appends the error message to the list of errors for the context object.

modifyMediaDurationRefinementName

Parses and translates the MediaDuration refiner value so that it can be correctly used by the standard refiner.

n

Indicates whether the given object is null or undefined.

parseTypedRangeToken

positionElement

Moves the element to the right or to the left as specified by offset.

processHHXML

Converts hit-highlighted XML string to HTML.

registerLoadedScripts

Registers the given scripts as loaded.

registerRenderTemplateByName

Registers the render template.

registerResourceDictionary

Registers the resource dictionary. If a dictionary with the same name exists, the new dictionary will be appended; otherwise a new dictionary will be created.

removeArray

Removes an item from the array.

removeHandler

Removes the attached event handler for the given element.

renderFriendlyTimeIntervalString

replaceUrlTokens

resetElement

resolveRenderTemplate

restorePath

restoreText

selectPath

selectText

setCookie

Sets the cookie.

setFieldOnObject

Sets the field value for the given object.

setItemRenderWrapper

setPath

In a tabbing scenario, expands and selects the shortened URL in the search result item when you press Enter; restores the URL to its shortened form when you press Tab.

setResultObject

Stores the result item or table for the current element.

shouldAnimate

Indicates whether the animation should occur or not.

showElement

Shows the DOM element.

toFileSizeDisplay

Converts the file size to either Kilobytes (KB), Megabytes (MB), or Gigabytes (GB).

toFormattedDate

Converts the date format to the given format. The default format is LongDatePattern. For more information see DateOptions.

toFormattedNumber

Converts the number format to the given format.

toFriendlyNumber

Formats the number based on ranges from 0-999, 1000-99,999 and >99,999 by inserting commas.

trace

Writes a trace message to the trace console.

traceFormatted

Writes a formatted trace message to the trace console.

trimExtraSpaces

Trims extra space characters from the string.

trimTitle

Trims the given title. If the title’s length is more than maximumLengthInChars, the title will be trimmed and an ellipsis will be appended.

truncateEnd

Trims the given string based on the given cut off value; adding an ellipsis if required.

truncateHighlightedUrl

Truncates the highlighted URL. The URL should be encoded.

truncateUrl

Truncates the given URL. The URL should not be encoded.

urlTokenExpansion

Expands the URL token for JavaScript or CSS links.

w

Indicates whether the given string is null, undefined, or empty.

Objects

The U object has the following objects.

Object

Description

Ids

Specifies the suffixes for elements.

LoadScriptsProgress

Specifies the script loading states.

LoadScriptsState

Specifies the scripts that are loading and their corresponding states.

PropNames

Specifies the property names.