|
Klipfolio Dashboard API | |||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||
Klipfolio Dashboard API OverviewKlipfolio Dashboard provides a full JavaScript runtime interpreter for your Klip to let you override Klipfolio Dashboard's default behaviour. Klipfolio Dashboard makes much of its internal default logic and data structures available through an application programming interface (API), accessible as JavaScript objects. As you read through this API document, keep in mind that, unlike Java or C++, these API objects are not a collection of classes with an inheritance hierarchy; rather, they are grouped by name to create a tree of individual objects. For example, the Klip object provides access to text manipulation functions that (among other things) assist in parsing data. The Klip.Items object provides an API for managing the visible items in your Klip, but Klip.Items is not a subclass of Klip, nor does it inherit any properties from that Klip. If this is your first time writing your own Klips, also refer to the Klip Developer Guide for Klipfolio Dashboard 5 which discusses the basics of how Klipfolio Dashboard and Klips work. What's New in Klipfolio Dashboard APINew objects and methods were introduced, in addition to new properties and methods for existing objects. Note:
Notes
Handler FunctionsThe concept of a handler function is important to understand as it is how your JavaScript responds to incoming events. A handler function is a function you define in JavaScript that Klipfolio Dashboard calls when a Klip lifecycle event occurs (such as when Klipfolio Dashboard requests your Klip to refresh) or a user event occurs (such as when the user clicks on the first item in your Klip). Lifecycle EventsFor lifecycle events, which are Klip.onDrop, Klip.onLoad, Klip.onRefresh, Klip.onSearch and Klip.onUpgrade, Klipfolio Dashboard will call a function in your JavaScript if you have created a function of the same name, such as
or you can explicitly assign an onRefresh() handler Klip.onRefresh = myOnRefresh; The first example works because your JavaScript (where you define all your functions) is running in the global scope with the Klip object as its root. Technically speaking, when you say function myfunction {...} you're actually saying (as far as Klipfolio Dashboard is concerned) Klip.myfunction = function {...} User EventsFor user events, you need to assign the handler function explicitly to a property of whichever Klipfolio Dashboard API object can receive an event. For example, if you want to have Klipfolio Dashboard call your function for every item a user clicks on in your Klip, you will have to assign your handler function to the Items.onClick property of the Items object itself: Items.onClick = myItemsOnClick; Updating a UI Component in Klip's Customize WindowIf you define a handler function for a UI component, such as Button.onClick for a Button object, Klipfolio Dashboard does not complete a UI component's behaviour until its handler function returns. This means a button, for example, will stay depressed until its associated Button.onClick function returns. Therefore, to avoid slowing down the user interface and causing problems for your users, you should avoid performing complex calculations and making network connections during your user interface event handler functions. For example, if your Klip requires a complex or lengthy operation, it is best to set a global state flag, make a request Klip.requestRefresh(), which causes Klipfolio Dashboard to send an onRefresh() event as soon as the current event handler exits. Before calling onRefresh, Klipfolio Dashboard will update the state of all UI components. In the onRefresh() handler, the function can test the state flag to do the lengthy operation.. Klipfolio Dashboard Threading ModelEach Klip has a single-thread execution model. This makes it easy to program in JavaScript, but it means that incoming events may queue up. (Klipfolio Dashboard itself is multi-threaded and can update a number of Klips simultaneously.) For example, if Klipfolio Dashboard is in the process of executing a user handler function and it's time to send the Klip refresh event, Klipfolio Dashboard will wait until your user event handler is finished before calling your Klip.onRefresh handler function. Specifically, when the thread of execution leaves your handler function, say a Button.onClick handler function, your Klip.onRefresh handler will be called. To ensure the user cannot inadvertently queue up multiple events -- and put your Klip into an unknown state -- Klipfolio Dashboard temporarily disables user input to your Klip's setup components when executing a handler function. To the user, the components don't appear disabled; rather, the user's mouse changes to an hour glass. For example, imagine a Klip has two checkboxes, where checking the first disables the second. If the event handler for the first checkbox was supposed to cause a second checkbox to be removed, and the onClick handler function could not be called because your onRefresh handler function was still busy downloading a file, the second checkbox would not be removed and the user would be able to click on it. If these events piled up, waiting for the onRefresh handler function to return, you would need a lot of code to handle unexpected cases. Klipfolio Dashboard keeps the event model simple so you can keep your code simple. Klip Root Object is OptionalThe root Klip object is implied when making KlipScript API. This means you can write Klip.Items.icon = "http://www.mysite.com/images/myKlipIcon.gif"; Klip.Setup.AddTab( "New Tab" ); or simply write the following: Items.icon = "http://www.mysite.com/images/myKlipIcon.gif"; Setup.AddTab( "New Tab" );
|
|
Klipfolio Dashboard API | |||||||
| PREV NEXT | FRAMES NO FRAMES | |||||||