Friday, February 17, 2017

Ext.js - Methods

Below are few inbuilt functions which are used mostly in Ext JS:
Ext.is class:
This class checks the platform you are using, whether it is a phone or desktop, a mac or windows operating system. These are the following methods related to Ext.is class

S.N. Methods & Description
1 Ext.is.Platforms
This function returns the platform available for this version.
E.g. When you run following function it returns something like this:
[Object { property="platform", regex=RegExp, identity="iPhone"}, Object { property="platform", regex=RegExp, identity="iPod"}, Object { property="userAgent", regex=RegExp, identity="iPad"}, Object { property="userAgent", regex=RegExp, identity="Blackberry"}, Object { property="userAgent", regex=RegExp, identity="Android"}, Object { property="platform", regex=RegExp, identity="Mac"}, Object { property="platform", regex=RegExp, identity="Windows"}, Object { property="platform", regex=RegExp, identity="Linux"}]
2 Ext.is.Android
This function will return true if you are using Android operating system else it returns false.
3 Ext.is.Desktop
This function will return true if you are using a desktop for the application else it returns false.
4 Ext.is.Phone
This function will return true if you are using a mobile else it returns false.
5 Ext.is.iPhone
This function will return true if you are using iPhone else it returns false.
6 Ext.is.iPod
This function will return true if you are using iPod else it returns false.
7 Ext.is.iPad
This function will return true if you are using iPad else it returns false.
8 Ext.is.Windows
This function will return true if you are using windows operating system else it returns false.
9 Ext.is.Linux
This function will return true if you are using linux operating system else it returns false.
10 Ext.is.Blackberry
This function will return true if you are using Blackberry else it returns false.
11 Ext.is.Mac
This function will return true if you are using mac operating system else it returns false.
Ext.supports class:
As the name indicates this class gives information about the feature is supported by the browser/ device basically current environment or not.
S.N. Methods & Description
1 Ext.supports.History
This return the Boolean value based in the device supports HTML 5 history as window.history or not. If the device supports history then it returns true else false.
2 Ext.supports.GeoLocation
This return the Boolean value based in the device supports geolocation method or not. Internally it checks for navigator.geolocation method.
3 Ext.supports.Svg
This return the Boolean value based in the device supports HTML 5 feature scalable vector graphics (svg) method or not. Internally it checks for doc.createElementNS && !!doc.createElementNS( "http:/" + "/www.w3.org/2000/svg", "svg").createSVGRect.
4 Ext.supports.Canvas
This return the Boolean value based in the device supports HTML 5 feature canvas to draw method or not. Internally it checks for doc.createElement('canvas').getContext and return value based on the output of this method.
5 Ext.supports.Range
This return the Boolean value based in the browser supports document.createRange method or not.
Ext.String class:
Ext.String class has various methods to work with string data, most used method are encoding decoding, trim, toggle, urlAppend eyc.
Encoding Decoding function: These are the function available in Ext.String class to encode and decode HTML values.
S.N. Methods & Description
1 Ext.String.htmlEncode
This function is used to encode html value to make it parsable.
 
E.g. Ext.String.htmlEncode("< p > Hello World < /p >"); 
Output - "&lt; p &gt; Hello World &lt; /p &gt;".
2 Ext.String.htmlDecode
This function is used to decode the encoded html value
                 
E.g. Ext.String.htmlDecode("&lt; p &gt; Hello World &lt; /p &gt;");
Output -  "< p > Hello World < /p >"
3 Ext.String.trim
This function is to trim unwanted space in the string.
E.g. Ext.String.trim(' hello ');
Output – "hello"
4 Ext.String.urlAppend
This method is used to append value in URL string
E.g. Ext.String.urlAppend('https://www.google.com' , 'hello');
Output - "https://www.google.com?hello"
Ext.String.urlAppend('https://www.google.com?index=1' , 'hello');
Output – "https://www.google.com?index=1&hello"
5 Ext.String.toggle
This function is to toggle the value between two different values.
E.g. var toggleString = 'ASC'
toggleString = Ext.String.toggle(a, 'ASC', 'DESC');
Output – DESC as toggleString had value ASC. Now again if we print the same we will get toggleString = “ASC” this time as it had value 'DESC'.
It is similar to ternary operator
toggleString = ((toggleString =='ASC')? 'DESC' : 'ASC' );
Miscellaneous methods
S.N. Methods & Description
1 Ext.userAgent()
This function gives information about browser userAgent. UserAgent is to identify the browser and operating system to the web server.
E.g. If you are working in Mozilla it returns some thing like : "mozilla/5.0 (windows nt 6.1; wow64; rv:43.0) gecko/20100101 firefox/43.0"
2 Version related function
These function returns the version of the browser currently in use if the function is called related to IE in firefox browser it return 0. These functions are Ext.firefoxVersion, Ext.ieVersion etc.
E.g. if we are using firefox browser and we call method Ext.ieVersion for fetching version of IE then it returns 0 or if we are using the same method in IE browser then it will return the version we are using such as 8,9 etc.
3 Ext.getVersion()
This function return the current Ext JS version in use.
E.g. If we call Ext.getVersion() it return an array of values such as version , short version etc.
Ext.getVersion().version return the current version of Ext JS used in program such as “4.2.2".
4 Browser related functions
These function returns Boolean values based on the browser in use. This method are Ext.isIE, Ext.isIE6, Ext.isFF06, Ext.isChrome.
E.g. If we are using Chrome browser then function Ext.isChrome will return true all other will return false.
5 Ext.typeOf()
This function return the datatype of the variable such as
E.g. var a = 5;  
   var b  = 'hello';
   Ext.typeOf(a);
   Output  Number
   Ext.typeOf(b);
   Output - String
6 DataType related methods: These function returns boolean value based on the datatype of variable.
E.g. var a = ['a', 'bc'];
   var b = 'hello';
   var c = 123;
   var emptyVariable;
   var definedVariable;
   function extraFunction(){return true;}
Ext.isArray(a);//returns true
Ext.isString(b);//return true
Ext.isNumber(c);//return true
Ext.isEmpty(emptyVariable);//return true
Ext.isEmpty(b);//return false
Ext.isDefined(definedVariable);//return true
Ext.isfunction(extraFunction);//return true

No comments:

Post a Comment