NG Utils (ref)

(part of package 'Core NG only Services')

You can access it in code via: plugins.ngclientutils

Properties

VIEWPORT_MOBILE_DEFAULT

Type: int Default Value: 1


VIEWPORT_MOBILE_DENY_ZOOM

Type: int Default Value: 2


VIEWPORT_MOBILE_DENY_ZOOM_IN

Type: int Default Value: 4


VIEWPORT_MOBILE_DENY_ZOOM_OUT

Type: int Default Value: 3


contributedTags

Type: tag[]


API

addClassToDOMElement(cssSelector,className)

Utility method for manipulating any DOM element's style classes. It will add the given class to the DOM element identified via the css selector param.

NOTE: This operation is not persistent; it executes client-side only; so for example when the browser is reloaded (F5/Ctrl+F5) by the user classes added by this method are lost. If you need this to be persistent - you can do that directly via server side scripting elements.myelement.addStyleClass(...) if the DOM element is a Servoy component. If the DOM element is not a component then you probably lack something in terms of UI and you could build what you need as a new custom component or use another approach/set of components when building the UI.

Parameters:

  • {string} cssSelector CssSelector the css selector string that is used to find the DOM element.

  • {string} className ClassName the class to be added to the element.


addFormStyleClass(formname,styleclass)

Utility method for manipulating form style classes. It will add a style class to a certain form, similar as a design style class would work.

Parameters:

  • {string} formname Formname the form name to add to.

  • {string} styleclass The styleclass to be added to form tag.


getAbsoluteLocation(component)

Retrieves the screen location of a specific element. Returns the location as point (object with x and y properties).

@deprecated replaced by clientutils.getBounds()

Parameters:

Returns: point Location of the component.


getFormStyleClass(formname)

Utility method for manipulating form style classes. It will get styleclasses assigned to a certain form, multiple styleclasses are separated by space.

NOTE: this call will only get style classes that were added via this plugin/service, not others that were previously set at design time or via solution model.

Parameters:

  • {string} formname Formname the form name to get style classes.

Returns: string The styleclass of that form.


getUserAgent()

This will return the user agent string of the clients browser.

Returns: string


printDocument(url)

Print a document from specific URL. This will open browser specific print dialog.

NOTE: url should be from same domain, otherwise a temp file on server should be created and served

@sample // if url is not from same domain we must create a temporary file var file = plugins.http.getMediaData(url); var remoteFileName = application.getUUID().toString() + '.pdf'; var remoteFile = plugins.file.convertToRemoteJSFile('/'+remoteFileName) remoteFile.setBytes(file,true); //Convert the remote file to a url, and print it var remoteUrl = plugins.file.getUrlForRemoteFile('/'+remoteFileName); plugins.ngclientutils.printDocument(remoteUrl)

Parameters:

  • {string} url The URL of document to be printed.


removeArguments()

This method removes the arguments from the client url. This is used for bookmark url to be correct or for back button behavior.


removeClassFromDOMElement(cssSelector,className)

Utility method for manipulating any DOM element's style classes. It will remove the given class from the DOM element identified via the css selector param.

NOTE: This operation is not persistent; it executes client-side only; so for example when the browser is reloaded (F5/Ctrl+F5) by the user classes removed by this method are lost; If you need this to be persistent - you can do that directly via server side scripting elements.myelement.removeStyleClass(...) if the DOM element is a Servoy component. If the DOM element it is not a component then you probably lack something in terms of UI and you could build what you need as a new custom component or use another approach/set of components when building the UI.

Parameters:

  • {string} cssSelector CssSelector the css selector string that is used to find the DOM element.

  • {string} className ClassName the class to be added to the element.


removeFormStyleClass(formname,styleclass)

Utility method for manipulating form style classes. It will remove a styleclasse assigned to a certain form.

NOTE: this call will only remove style classes that were added via this plugin/service, not others that were previously set at design time or via solution model.

Parameters:

  • {string} formname Formname the form name to remove from.

  • {string} styleclass The styleclass to be removed from form tag.


replaceHeaderTag(tagName,attrNameToFind,attrValueToFind,newTag)

Utility method for manipulating 'contributedTags' array. It searches for an existing 'tag' that has the given 'tagName' and attribute ('attrNameToFind' & 'attrValueToFind'). If found it will replace it with 'newTag'. If not found it will just append 'newTag' to 'contributedTags'.

NOTE: this call will only replace/remove tags that were added via this plugin/service, not others that were previously present in the DOM.

Parameters:

  • {string} tagName TagName the tag name to find for replacement.

  • {string} attrNameToFind AttrNameToFind the attribute to find on that tag name for replacement. If null it will just find the first by 'tagName' and use that one.

  • {string} attrValueToFind AttrValueToFind the value the given attribute must have to match for replacement.

  • {tag} newTag NewTag the new tag that replaces the old one. If null/undefined it will just remove what it finds.

Returns: tag The tag that was removed if any.


scrollIntoView(anchorSelector,scrollIntoViewOptions)

Move the scrollbar to the position of the given anchorSelector. The target anchorSelector can be a Servoy Form, Layout Container or element in a responsive form or any element in a form. You can use styleClass as selector. For example: you can add 'scroll-element' to an element of the form. Examples of usage: - plugins.ngclientutils.scrollIntoView(".toScroll-To"); - plugins.ngclientutils.scrollIntoView(".toScroll-To", { behavior: "smooth", block: "start", inline: "nearest" });

Parameters:

  • {string} anchorSelector ** anchorSelector {string} the selector to which the scrollbar should be moved to.

  • {object} [scrollIntoViewOptions] ** scrollIntoViewOptions option argument used for scrolling animation (example: { behavior: "smooth", block: "start", inline: "nearest" }).


scrollToTop(selector)

Move the scrollbar to top position of the given selector. The target selector can be a Servoy Form, Layout Container or element in a responsive form or any element in a form. You can use styleClass as selector. For example: you can add 'scroll-element' to an element of the form. Examples of usage: - plugins.ngclientutils.scrollToTop(".toScroll-To");

Parameters:

  • {string} selector ** selector {string} the selector to which the scrollbar should be moved to top.


setBackActionCallback(callback)

This will register a callback that will be triggered on all history/window popstate events (back,forward but also next main form). If this is registered then we will try to block the application from going out of the application. The callback gets 1 argument and that is the hash of the url, that represents at this time the form where the back button would go to. If this hash argument is an empty string then that means the backbutton was hit to the first loaded page and we force a forward again.

Parameters:


setLangAttribute(lang)

Set lang attribute on html tag.

Parameters:

  • {string} lang ShowConfirmation boolean for whether to show confirmation message


setOnUnloadConfirmation(showConfirmation)

Set whether browser default warning message will be shown when the browser tab is closed or the users navigates away, this can be used to let users know they have data modifications that are not yet saved.

Parameters:

  • {boolean} showConfirmation ShowConfirmation boolean for whether to show confirmation message


setOnUnloadConfirmationMessage(message)

Set the message that will be shown when the browser tab is closed or the users navigates away, this can be used to let users know they have data modifications that are not yet saved. Note: We deprecated this api because browsers removed support for custom messages of beforeunload event. Now most browsers display a standard message.

@deprecated

Parameters:

  • {string} message The message to show when the user navigates away, null if nothing should be shown anymore.


setViewportMetaDefaultForMobileAwareSites()

Call this when a solution can handle mobile device layouts (responsive design, can handle nicely width < height). This call is equivalent to calling setViewportMetaForMobileAwareSites(plugins.htmlHeaders.VIEWPORT_MOBILE_DEFAULT).

It should be what most solutions that are able layout correctly on smaller mobile screens need; it will still allow the user to zoom-in and zoom-out.


setViewportMetaForMobileAwareSites(viewportDefType)

Call this when a solution can handle mobile device layouts (responsive design, can handle nicely width < height). It will tell the device via the "viewport" meta header that it doesn't need to automatically zoom-out and use a big viewport to allow the page to display correctly as it would on a desktop.

'viewportDefType' can be one of:

  • plugins.ngclientutils.VIEWPORT_MOBILE_DEFAULT - will show content correctly, allow zoom-in and zoom-out; the generated meta tag will be <meta name="viewport" content="width=device-width, initial-scale=1.0" />

  • plugins.ngclientutils.VIEWPORT_MOBILE_DENY_ZOOM - will show content correctly, denies zoom-in and zoom-out; the generated meta tag will be <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />

  • plugins.ngclientutils.VIEWPORT_MOBILE_DENY_ZOOM_OUT - will show content correctly, allows zoom-in but denies zoom-out; the generated meta tag will be <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />

  • plugins.ngclientutils.VIEWPORT_MOBILE_DENY_ZOOM_IN - will show content correctly, denies zoom-in but allows zoom-out; the generated meta tag will be <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />

This method actually uses replaceHeaderTag. For example plugins.ngclientutils.VIEWPORT_MOBILE_DEFAULT would call

  replaceHeaderTag("meta", "name", "viewport", {
       tagName: "meta",
       attrs: [ { name: "name", value: "viewport" }
                { name: "content", value: "width=device-width, initial-scale=1.0" } ]
 });

Parameters:

  • {int} viewportDefType ViewportDefType one of the constants listed above.


Types

attribute

scripting type: CustomType<ngclientutils.attribute>

tag

scripting type: CustomType<ngclientutils.tag>


Last updated