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 = AZClientStorage("get", "Customers");

Objects and Arrays will be automatically parsed to JavaScript Objects or Arrays.

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



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

Level The function is recursive, ie it does a multi level search in the array. If you specify the level, e.g. 1, it will only search for the object in level 1.



[{"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");

The function is recursive, ie it does a multi level search in the array.



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


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

For more advanced sorting, we can recommend looking at the module thenBy.js which is part of the AZ system.



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


AZIsEmpty (IsEmpty) Type: Function Parameters: object{} og array[] Return: true or false
AZIsEmpty(object/array);

The function returns false if you are testing an Object/Array and the Object/Array is not empty and the Object has at least one property.



AZ Get URL Parameters Type: Function Parameters: String Default: window.location.href Return: object
var _URL = "https://cdn.web2net.no/lib-2.0.1/default.html?id=1&guid=23j4j223k54k235k";
AZGetURLParameters(_URL);




AZ Bytes Converter Type: Function Parameters: Bytes - Decimal Default: 2 decimal Return: String
AZBytesConverter(123456, 2);
AZBytesConverter(987654321, 2);



AZ Guid Type: Function Return: String
AZGuid();



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



Set AZ Page Type: Function Return: object
function SetAZPage()
{
    $.subscribeonce("functionlib/AZPage", function (e, data)
    {
        data:
        {
            $Form: i.fn.init
            Location: ""
            PageName: ""
            PageFirstName: ""
            Language: ""
            ObjLanguage: {}
            ObjValidation: {}
            AppName: ""
            AppVersion: ""
            ApiVersion: ""
            AZSettings: {}
        }
    });
    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 Set Input Type Events Type: Function
AZSetInputTypeEvents()




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 Set Page Element Type: Function Parameters: String - Array Return: ObjPageData.Elements
var PageElement = ["SetPageElement", "AZSetPageElement"];
AZSetPageElement(PageElement);

ObjPageData.Elements.$SetPageElement;
ObjPageData.Elements.$AZSetPageElement;


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();