Documents : Utility Libraries

Javascript Utilities

We have included few general useful libraries along with sf.preinit.js. You can add/remove/edit the functionalities as per your need. Here is the list of these files.
  • sf.preinit.js
  • /services/sf.ajaxservice.js
  • /services/sf.validationservice.js
  • /services/sf.utils.js


This is the main file that should be included right after jQuery. This serves as bootstrap to the javascript code/module that follows.This defines few configurations like detecting devices, viewport and contains publisher for basic and most common events such as document.onready, window.onload and window.onscroll. Few more details that you can get out of it is given below:


Ajax calls in your application may have few things in common, like the way you handle generic errors, freezing contnets or showing loaders. All this activities can be taken care by one single wrapper that would be act as middlewire for all your ajax requests. This file is intended for this job. Here is a sample usage:

        sf.ajaxService.get("uniqueServiceName", {
            url : "ajaxURL.json",
            success : successFunction


Validation service takes form id as input and validates the form based on rules you set in sf.validation.rules. You can also submit the form via ajax if intended by passing extra parameters. Ajax submission is controlled by the service. Here is a sample usage:

        // default
            form: "formID"
        //with ajax settings
            form : "formID",
            ajax : true,
            ajaxSettings: {
                success : successFunctionName
        //put your custom ajax handler
            form : "formID",
            customAjaxHandler : yourCustomAjaxHandler


This is where you can keep all your global utility functions. As a rule of thumb, avoid DOM specific utilities in this file