AZ Standard Functions

AZ Promise Type: Functions
    $.publish()
    $.subscribe()
    $.subscribeonce()
    $.unsubscribe()

Based on jQuery Promise, we have created several functions you can subscribe on that will help you get a better flow in your code. The principles are based on Events & Delegates, which is a good form of programming practice and should replace all forms of use of Callback.

$.publish("Location - Name", Data);

$.subscribe("Location - Name", function (e, data) { });

$.subscribeonce("Location - Name", function (e, data) { });

$.unsubscribe("Location - Name", function (e, data) { });

AZ Window Scroll Type: Function
$.subscribe("functionlib/azWindowScroll", function (e, data)
{
    data.azWindowScrollTop
    data.azWindowScrollDir
});


This function is triggered every time you scroll.

azWindowScrollTop:
azWindowScrollDir:
AZ Window Resize Type: Function
$.subscribe("functionlib/azWindowResize", function (e, data)
{
    data.azWindowWidth
    data.azWindowHeight
    data.azWindowScrollTop
    data.azWindowScrollLeft
    data.azWindowOrientation
});


This function is triggered when the page loads and every time the page resizes.

azWindowWidth:
azWindowHeight:
azWindowScrollTop:
azWindowScrollLeft:
azWindowOrientation:
AZ Client Storage Type: Function Parameters: ActionType - Name - Value Return: Objects, Arrays, String, Integer...
AZClientStorage(ActionType, Name, Value);

This function is used to store and retrieve data, (Items) from the browser. AZClientStorage will automatically test if your browser supports storage. First Local Storage is tested, and if your browser supports this, your data will be stored in Local Storage. However, if your browser does not support Local Storage, it will try to store data in Cookies.

ActionType Name Value
set Item Name Varying data types
get Item Name
delete (remove) Item Name


Store data
var _Customers = [{"Name": "Hansen"}, {"Name": "Olsen"}, {"Name": "Andersen"}];
AZClientStorage("set", "Customers", _Customers);

In addition to Item Name, the function adds the site's domain name - www.yourdomain.no-itemname. You can store virtually any type of data. Objects and Arrays will be automatically stringified.

Get data
var _Customers = $.parseJSON(AZClientStorage("get", "Customers"));

If you have stored an Object or an Array, you will need to parse this from a string to a JavaScript Object. For example, you can use JSON Parse.

Delete data
AZClientStorage("delete", "Customers");



AZ Get Obj Type: Function Parameters: Array - Key - Val Return: object
AZGetObj(Array, "Name", "Olsen");

[{"Name": "Hansen"}, {"Name": "Olsen"}, {"Name": "Andersen"}]


AZ Remove Obj Type: Function Parameters: Array - Key - Val
AZRemoveObj(Array, "Name", "Olsen");

[{"Name": "Hansen"}, {"Name": "Olsen"}, {"Name": "Andersen"}]


AZ Exist Obj Type: Function Parameters: Array - Key - Val Return: true or false
AZExistObj(Array, "Name", "Olsen");

[{"Name": "Hansen"}, {"Name": "Olsen"}, {"Name": "Andersen"}]


AZ Sort Array Type: Function Parameters: Array - Key - Sort
AZSortArray(Array, "Name", "asc");

Unsorted
[{"Name": "Hansen"}, {"Name": "Olsen"}, {"Name": "Andersen"}]


IsEmpty Type: Function Parameters: object Return: true or false
IsEmpty(Object);

The function returns false if you are testing an Object and the Object is not empty and has at least one property.
AZ Get URL Parameters Type: Function Parameters: String Default: window.location.href
AZGetURLParameters(Url);

https://cdn.web2net.no/lib-2.0.0/default.html?id=1&guid=23j4j223k54k235k


Before testing the function, open the console in your browser and find the tab - Console
AZ Bytes Converter Type: Function Parameters: Bytes - Decimal Default: 2 decimal
AZBytesConverter(Bytes, Decimal);

123456 - 987654321


Set AZ Page Type: Function Return: object
function SetAZPage()
{
    $.subscribeonce("functionlib/AZPage", function (e, data)
    {
        data:
        {
            $Form: i.fn.init
            ApiVersion: "_1"
            AppName: "AZ Team"
            AppVersion: "1.0.0"
            AppVersionCode: "1.0.0"
            Language: "nb-NO"
            Location: "localhost"
            PageFirstName: "index"
            PageName: "index.html"
            AZSettings: {},
            ObjLanguage: {}
            ObjValidation: {}
        }
    });
    new AZPage(
    {
        azPageArea: {},
        azPageElement: [],
        azPageInputTypeEvents: false,
        azPageLanguage: false,
        azPageLanguageUrl: "",
        azPageValidation: false,
        azPageValidationUrl: ""
    });
}




AZ Set Language Type: Function
var _AZSetLanguageOptions =
{
    $Area: Selector,
    ObjLanguage: {}
}
new AZSetLanguage(_AZSetLanguageOptions);




AZ Set Validation Type: Function
var _AZSetValidationOptions =
{
    $Area: Selector,
    ObjValidation: {}
}
new AZSetValidation(_AZSetValidationOptions);




AZ Serialize Form Type: Function Return: object
var _AZSerializeFormOptions =
{
    $Area: Selector,
    ObjLanguage: {},
    ObjValidation: {}
}
AZSerializeForm(_AZSerializeFormOptions);




AZ Populate Form Type: Function
var _AZPopulateFormOptions =
{
    $Area: Selector,
    ObjInputData: {},
    ObjValidation: {}
}
AZPopulateForm(_AZPopulateFormOptions);




AZ Standard Alert Type: Function
var _AZStandardAlertOptions =
{
    $Area: Selector,
    Title: String,
    Text: String
}
new AZStandardAlert(_AZStandardAlertOptions);




AZ Set Page Element Type: Function Parameters: String - Array Return: ObjPageData.Elements
var PageElement = ["CustomerName", "Submit"];
AZSetPageElement(PageElement);

ObjPageData.Elements.$CustomerName;
ObjPageData.Elements.$Submit;


The function looks for elements with ID or CLASS that match the elements in the list you submit in the function. When an element is found, the element is created as a jQuery object and added to the variable ObjPageData.Elements.



AZ Promise
Below you also see an example of using Promise using the feature $.when

Animation...



function Effect()
{
    return $("div.az-anim-rect").each(function (i)
    {
        $(this).fadeOut(1000 * (i + 1));
    });
};

$.when(Effect()).done(function () { // Do Something });


AZ Show/Hide CoverSpin Type: Function Input: string
AZShowCoverSpin();


AZShowCoverSpin("Show Cover Spin");


AZHideCoverSpin();