官术网_书友最值得收藏!

  • Sencha Touch Cookbook
  • Ajit Kumar
  • 537字
  • 2021-08-20 15:56:07

Finding information about features that are supported in the current environment

Each device and platform offers a rich set of functionality. However, it is difficult to identify a set of features which are available across devices and platforms. In addition, even if we happen to find out the list of common features, there may be reasons where you may want to use a feature on a device which is not present on other devices and you would make your application work on those devices by performing the best approximation of that specific feature. For example, on a device if SVG is supported, you may want to make use of that feature in your application to render images using it, so that they are scalable. However, if another device does not support SVG, you may want to fall back to rendering your image into JPEG/PNG, so that the image will be visible to the user. This recipe describes how an application can detect the different features that a device supports. This comes in very handy to enable/disable certain application features based on the device-supported features.

How to do it...

Carry out the following steps:

  1. Create and open a new file named ch01_03.js in the ch01 folder and paste the following code into it:
    Ext.setup({
      onReady: function() {
        var supportedFeatures = "Ext.supports.AudioTag : " + (Ext.supports.AudioTag ? "On" : "Off");
        supportedFeatures += "\nExt.supports.CSS3BorderRadius : " + (Ext.supports.CSS3BorderRadius ? "On" : "Off");
        supportedFeatures += "\nExt.supports.CSS3DTransform : " + (Ext.supports.CSS3DTransform ? "On" : "Off");
        supportedFeatures += "\nExt.supports.CSS3LinearGradient : " + (Ext.supports.CSS3LinearGradient ? "On" : "Off");
        supportedFeatures += "\nExt.supports.Canvas : " + (Ext.supports.Canvas ? "On" : "Off");
        supportedFeatures += "\nExt.supports.DeviceMotion : " + (Ext.supports.DeviceMotion ? "On" : "Off");
        supportedFeatures += "\nExt.supports.Float : " + (Ext.supports.Float ? "On" : "Off");
        supportedFeatures += "\nExt.supports.GeoLocation : " + (Ext.supports.GeoLocation ? "On" : "Off");
        supportedFeatures += "\nExt.supports.History : " + (Ext.supports.History ? "On" : "Off");
        supportedFeatures += "\nExt.supports.OrientationChange : " + (Ext.supports.OrientationChange ? "On" : "Off");
        supportedFeatures += "\nExt.supports.RightMargin : " + (Ext.supports.RightMargin ? "On" : "Off");
        supportedFeatures += "\nExt.supports.SVG : " + (Ext.supports.SVG ? "On" : "Off");
        supportedFeatures += "\nExt.supports.Touch : " + (Ext.supports.Touch ? "On" : "Off");
        supportedFeatures += "\nExt.supports.Transitions : " + (Ext.supports.Transitions ? "On" : "Off");
        supportedFeatures += "\nExt.supports.TransparentColor : " + (Ext.supports.TransparentColor ? "On" : "Off");
        supportedFeatures += "\nExt.supports.VML : " + (Ext.supports.VML ? "On" : "Off");
        
        Ext.Msg.alert("INFO", supportedFeatures);
      }
    });
  2. Remove the following line from index.html:
    <script type="text/javascript" charset="utf-8" src="ch01/ch01_02.js"></script>
  3. Include the following line in index.html:
    <script type="text/javascript" charset="utf-8" src="ch01/ch01_03.js"></script>
  4. Deploy and run the application.

How it works...

Check that the support for different features is encapsulated inside the Sencha Touch's Ext.supports class. This class applies different mechanisms to find out whether a requested feature is supported by the target platform/device. For example, to find out whether the device supports touch, this class checks whether ontouchstart is present in the window object. Another example is, to find out whether SVG is supported on the target platform, it tries to add an SVG element (which it removes after successful creation and setting the flag to indicate that the device supports SVG) to the document.

See also

  • The recipe named Setting up the browser-based development environment in this chapter
  • The recipe named Setting up the production environment in this chapter
主站蜘蛛池模板: 江山市| 莆田市| 金溪县| 葫芦岛市| 信宜市| 堆龙德庆县| 突泉县| 无锡市| 洛阳市| 德保县| 噶尔县| 资中县| 防城港市| 安陆市| 登封市| 望江县| 大石桥市| 巧家县| 阳城县| 吉隆县| 定安县| 武义县| 永平县| 蒙城县| 高阳县| 文山县| 临江市| 屯昌县| 普洱| 揭东县| 武邑县| 凤冈县| 钟山县| 通辽市| 德阳市| 大洼县| 江阴市| 昌图县| 黄冈市| 江油市| 锦屏县|