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

sf.preinit.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:

/modules/sf.ajaxservice.js

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
        })
    

/modules/sf.validationservice.js

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 sf.ajaxservice.post service. Here is a sample usage:

        // default
        sf.validationService.submit({
            form: "formID"
        });
        //with ajax settings
        sf.validationService.submit({
            form : "formID",
            ajax : true,
            ajaxSettings: {
                success : successFunctionName
            }
        });
        //put your custom ajax handler
        sf.validationService.submit({
            form : "formID",
            customAjaxHandler : yourCustomAjaxHandler
        });
    

/modules/sf.utils.js

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