Klipfolio Dashboard 5 API

Object Prefs

Object
   |
   +--Klip
         |
         +--Prefs

The Prefs object provides an API to store and retrieve preferences between Klipfolio Dashboard sessions. Most often, these preferences will be information entered by the user into your UI components (such as a TextField) in the Klip's Customize window.

Use setPref() to store a preference as a named pair, as in

and use getPref() to later retrieve it the value of the name, as in As stated, information you store using setPref() persist between sessions, but changing the Klip's internal preferences, such as with Prefs.refreshrate, is valid only for the current session. When Klipfolio Dashboard starts up again, it will revert to the value specified in the Klip.

You can achieve effect of making a change to Prefs.refreshrate permanent by storing the value in your own preference using setPref() and in the Klip's Klip.onLoad() handler function, retrieving the value and immediately assigning it to Prefs.refreshrate.

Example: Setting and Querying Preferences

The following Klip gives an example of setting and querying various preferences.
<klip>
   <identity>
      <title>
         API: Prefs
      </title>
   </identity>
   <locations>
      <contentsource>
         http://support.klipfolio.com/files/demo/demo.xml
      </contentsource>
      <icon>
         http://www.klipfolio.com/static/klips/klipfolio/sample_icon.png
      </icon>
      <banner>
         http://www.klipfolio.com/static/klips/klipfolio/sample_banner.png   
      </banner>
   </locations>
   <klipscript>
   <![CDATA[

 function onLoad() {
 
    //
    // Set three preferences
    //
    Prefs.setPref( "pref_A", "23" );
    Prefs.setPref( "pref_B", "true" );
    Prefs.setPref( "pref_C", "http://www.klipfolio.com" );
    
    //
    // Dump Prefs (method #1)
    //
    trace( "Value of pref_A: '" + Prefs.getPref( "pref_A" ) + "'\r\n" );
    trace( "Value of pref_B: '" + Prefs.getPref( "pref_B" ) + "'\r\n" );
    trace( "Value of pref_C: '" + Prefs.getPref( "pref_C" ) + "'\r\n" );  
    
    //
    // Update the preferences
    //
    trace( "\r\n" );
    trace( "Setting pref_A, pref_B, and pref_C.\r\n" );
    Prefs.setPref( "pref_A", "1000" );
    Prefs.setPref( "pref_B", "false" );
    Prefs.setPref( "pref_D", "A New Pref" );
    
    //
    // Dump all Prefs (method #2) 
    //
    trace( "\r\n" );
    show_all_prefs();
    
    //
    // Check the value of pref_B
    //
    trace( "\r\n" );
    trace( "First Check: " );
    if( Prefs.getPref( "pref_B" ) == "true" ) {
        trace( "Pref_B is true\r\m" );
    } else {
        trace( "Pref_B is false\r\n" );
    }
    
    //
    // This is a common idom to convert a pref's value (which is string) into a boolean
    // true or false.
    //
    var check_B = (Prefs.getPref( "pref_B" ) == "true" ? true : false );
    
    //
    // Check the value of pref_B again using check_B as a boolean
    //
    trace( "\r\n" );
    trace( "Second Check: " );
    if( check_B ) {
        trace( "Pref_B is true\r\n" );
    } else {
        trace( "Pref_B is false\r\n" );
    }
 
    //
    // When you query an non-existent preference, Klipfolio Dashboard returns 
    // the empty string.
    //
    trace( "\r\n" );
    trace( "Querying values of pref_a and pref_X\r\n" );
    trace( "Value of pref_a: '" + Prefs.getPref( "pref_a" ) + "'\r\n" );
    trace( "Value of pref_X: '" + Prefs.getPref( "pref_X" ) + "'\r\n" );
    
    
    //
    // This is another common idom: check for a preference to see if this is the
    // first time this Klip is loaded.
    //
    trace( "\r\n" );
    if (Prefs.getPref ("preconfigured") != "true")
    {
        // ... setup your prefs, default values for UI components, etc.
 
         //
         // Don't do KlipSetup next time this Klip Loads
         //
        Prefs.setPref ("preconfigured", "true");
    }
 
 }
 
 function onRefresh()
 {
    var xml = "<xml><item><link></link><description>" +
          "(See Debug Window for output)" +
          "</description></item></xml>";
             
     return Engines.Data.process( xml );
 }
 
 //
 // Iterate through your Klip's prefs by accessing Prefs[] as an array
 //
 function show_all_prefs() {
    var i;
    for (i = 0; i < Prefs.length; i++) { 
       trace("Prefs["+i+"] '"+Prefs[i].name+"' == '"+Prefs[i].value+"'\r\n"); 
    }
}


   ]]>
   </klipscript>
</klip>

     	

   
Upon loading, Klipfolio Dashboard will display the following output in the Debug Window.

 Value of pref_A: '23'
 Value of pref_B: 'true'
 Value of pref_C: 'http://www.serence.com'
 
 Setting pref_A, pref_B, and pref_C.
 
 Prefs[0] 'pref_A' == '1000'
 Prefs[1] 'pref_B' == 'false'
 Prefs[2] 'pref_C' == 'http://www.serence.com'
 Prefs[3] 'pref_D' == 'A New Pref'
 
 First Check: Pref_B is false
 
 Second Check: Pref_B is false
 
 Querying values of pref_a and pref_X
 Value of pref_a: ''
 Value of pref_X: ''
 



Properties Summary
 integer codepage
          Returns the value of the <refresh> element specified in the .klip file.
 String contentsource
          Returns the value of the <contentsource> element specified in the .klip file.
 String defaultlink
          Returns the default link activated when a user clicks on your Klip's icon.
 double firstinstall
          Returns the timestamp (in seconds) when this instance of the Klip was first added to Klipfolio Dashboard (read-only).
 double lastrefresh
          Returns the timestamp (in seconds) when the Klip last returned true from its Klip.onRefresh() handler (read-only).
 integer length
          Returns the length of the items in the Prefs collection.
 String loading
          Returns the value of the <loading> element specified in the .klip file (write-only).
 String nodata
          Returns the value of the <nodata> element specified in the .klip file (write-only).
 integer referer
          Returns the value of the <referer> element specified in the .klip file (read-only).
 integer refreshgranularity
          Specifies the number of seconds (default 60) for each count in Prefs.refreshrate.
 integer refreshrate
          Returns the value of the <refreshrate> element specified in the .klip file.
 String title
          Returns the value of the <title> element specified in the .klip file (write-only).
 integer uniqueid
          Returns the value of the <uniqueid> element specified in the .klip file (read-only).
   
Function Summary
 boolean delPref( <String> name )
           Deletes the persistent preference associated with name.
 function getContent( <String> content_tag_name )
           Returns the value of specified element within ... tags which can store multiple stylesheets.
 String getPref( <String> name )
           Returns the value associated with the preference name.

 function setPref( <String> name, <String> value )
           Stores name as a persistent preference with the value value.

Properties Detail

codepage

integer codepage

contentsource

String contentsource

defaultlink

String defaultlink

firstinstall

double firstinstall

lastrefresh

double lastrefresh

length

integer length

loading

String loading

nodata

String nodata

referer

integer referer

refreshgranularity

integer refreshgranularity

refreshrate

integer refreshrate

title

String title

uniqueid

integer uniqueid

Function Detail

delPref

boolean delPref( <String> name )

getContent

function getContent( <String> content_tag_name )

getPref

String getPref( <String> name )

setPref

function setPref( <String> name, <String> value )

Klipfolio Dashboard 5 API

© 2009 Klipfolio Inc. All Rights Reserved.