top

SF.UTIL

** This class will not be supported in 2015.

   All functionalities of sf.util class are more improved, integrating with CAPH. Therefore sf.util class is not supported since 2015 Smart TV. To use functions of sf.util class, refer to here.


This class defines the Apps Framework utility functions.

Add the following line for sf.util class into a html file your own :

  script type="text/javascript" src="$MANAGER_WIDGET/Common/af/2.0.0/loader.js">/script>

You can declare sf.util class like this :

  ex) var util = sf.util;


Methods

dateFormat

Description
This function converts a JavaScript Date instance to a formatted string.
Parameters
■date 
  - Date
  - Date instance to be converted 
■formatStr 
  - String
  - Formatted string
Return■String
  - Formatted string
Emulator SupportN
SDK ConstraintNone
Example
sf.util.dateFormat(new Date(), 'Y-m-d'); 
// returns '2013-01-01' that indicates current date

obj2json

Description
This function converts a JavaScript Object to JSON string.
Parameters
■obj 
  - Object
  - Object to be converted
Return■String
  - Converted JSON string
Emulator SupportN
SDK ConstraintNone
Example
var json = sf.util.obj2json({a: 123, b: 'test'});
console.log(json);// prints '{"a":123, "b": "test"}'

xml2json

Description
This function converts the XML DOM object to a JSON string.
Parameters
■dom 
  - Object
  - The XML Dom object to be converted
Return■String
  - Converted JSON string
Emulator SupportN
SDK ConstraintNone
Example
var json = sf.util.xml2json(xhr.responseXML);

xml2obj

Description
This function converts an XML DOM object to Object.
Parameters
■dom 
  - Object
  - The XML Dom object to be converted
   * example
     //XML
     <?xml version="1.0" encoding="UTF-8"?>
     <title><![CDATA[TEST TITLE]]></title>
     <link>http://www.samsung.com</link> 
     <description><![CDATA[Samsung]]></description>
     <items>
         <item id="1">ITEM1</item>
         <item id="2">ITEM2</item>
     </items>
Return■Object
  - Converted object
   * example
    //JSON of converted object
    {
        "title" : "TEST TITLE",
        "link" : "http://www.samsung.com",
        "description" : "Samsung",
        "items" : {
             "item" : [
                {
                    "id" : "1",
                    "text" : "ITEM1"
                 }, {
                    "id" : "2",
                    "text" : "ITEM2"
                 }
             ]
        }
    }
Emulator SupportN
SDK ConstraintNone
Example
var object = sf.util.xml2obj(dom);