Upgrading JavaScript to V7 Patterns

Author:Amanda A
Last Updated:August 27, 2021 1:31 PM

JavaScript Function Mappings

v6.9.5 Function v7 Function Notes
DefaultButton(anEvent, button) NWS.Util.UI.DefaultButton(anEvent, button) Display side usage
SearchSubmit(baseURL, searchCtl) NWS.Util.UI.SearchSubmit(baseURL, searchCtl) Display side usage in search bar XSLs
tic_Utilities.AddStyle(ctl, style) element.classList.add(className) Browser default
tic_Utilitie.RemoveStyle(ctl, style) element.classList.remove(className) Browser default
tic_Utilities.ToggleStyle(ctl, style) element.classList.toggle(className, force) Browser default
tic_Utilities.CancelBubble(evt) NWS.Util.Event.Cancel(evt, doPrevent) Stops propagation of an event. To also prevent default, must pass in true
tic_Utilities.PackageXml(tagName, data, useCData) NWS.Xml.MakeTag(tagName, data, attributes, useCData)  
tic_Utilities.XmlWithAttributes NWS.Xml.MakeTag(tagName, data, attributes, useCData)  
tic_Utilities.MakeXmlStartTag(tagName, includeCData) NWS.Xml.MakeStartTag(tagName, attributes, doCData) Optional params: attributes, doCData
tic_Utilities.MakeXmlStartTagWithAttributes(tagName, includeCData, attributes) NWS.Xml.MakeStartTag(tagName, attributes, doCData) attributes param is an array of objects with the properties name and value
tic_Utilities.MakeXmlEndTag(tagName, includeCData) NWS.Xml.MakeEndTag(tagName, doCData) Optional params: doCData
tic_Utilities.ShowHideById(ctlID, doShow) element.classList.toggle("hide", force) Browser default
tic_Utilities.ToggleShowHide(ctlID) element.classList.toggle("hide", force) Browser default
tic_Utilities.ExecuteFunctionByName(funcName, context, argsArray) NWS.Modules.ExecuteFunctionByName(funcName, context, args) args param is an array
tic_Positioning.ScrollToElementById(id) NWS.Util.ScrollTo(element, options) Optional params: options (object)
TitanDisplayServiceWrapper.MakeWebServiceCall(name, webServiceFunction, arrayOfArgs, postOpFunction, postOpArgs, canSkip) NWS.Ajax.Post(url, jsonObj, responseType, callback) url: route for controller method
jsonObj: args array now stored in object with named properties
responseType: json, text, blob, etc
callback: of type NWS.Ajax.Callback()
PrintPage_PrintPage(printPageString) NWS.Util.Print.PrintPage(printPageString)  
PrintPage_Email(subjectLine) NWS.Util.Print.Email(subjectLine)  
PrintPage_FormatParams() NWS.Util.Print.FormatParams()  

Base Overrides

Base overrrides, particularly list block override functions, are also using a different pattern in v7.0.

v6.x

var baseDataList_AjaxComplete = DataList_AjaxComplete;
DataList_AjaxComplete = function (blockID, responseAsJSON, responseAsXml, responseAsText) {

	baseDataList_AjaxComplete(blockID, responseAsJSON, responseAsXml, responseAsText);
	//Do something else 
}

v7.0

if (NWS.Block.DataList) {
 /* Arguments for OnAjaxComplete(who, callback, callbackArgs)
  * @param {string} who - The name used to identify the callback
  * @param {Object} callback - A function object to be executed
  * @param {Object[]} callbackArgs - An array of arguments to be passed to the callback function
  */
  NWS.Block.DataList.OnAjaxComplete("LazyLoadImages", NWS.Display.LazyImages.LazyLoad, null);
}


Using V7 Utilities

Titan also includes several JavaScript libraries for developers to use in custom or package code.

Library Function Name Notes
NWS.Modules LoadResources

resourcePaths: An array of paths to resources you want to load
initList: Any callbacks you want to execute after the resources have been loaded.
If you don't have any callbacks, pass an empty array. Otherwise, an array of objects with the following structure:

{
	func: "funcName",
    args: ["array","of","args"]
}

top