My favorites | English | Sign in

Google Desktop APIs (Labs)

ContentItem Object

A ContentItem represents an item of information within a contentarea. Here is an example of setting up a content item that displays "Hello World!".

// Create a content item and say hello.
var item = new ContentItem();
item.heading = "Hello World!";          // this string is shown in the item
item.snippet = "Detailed description";   // this string shown in details view
plugin.AddContentItem(item, gddItemDisplayInSidebar); // add the item to the display

Properties

To create an Image object, as required by the image and notifier_image properties, use the graphics.loadImage method to load a file from the gadget's .gg package. For example:

image = graphics.loadImage("anImage.gif");
Name Description Type Read/Write
image Image to show in the item. Image Read/write
notifier_image Image to show in the notifier. Image Read/write
time_created Time in UTC (in JavaScript, the variant time value). Example: item.time_created = system.localTimeToUniversalTime(new Date().getVarDate()); time Read/write
heading Item's displayed title. string Read/write
source Item's displayed website/news source. string Read/write
snippet Item's displayed snippet. string Read/write
open_command URL/file path opened when the user opens/double clicks the item. string Read/write
layout Layout of the item indicating the format in which the item should be displayed. See Content Item Layout Flags. integer Read/write
flags Combination of the content item flags. integer Write only
tooltip Tooltip text, such as full path, full headlines, etc. string Write only

Methods

Name and Arguments Description Returns
SetRect(x, y, width, height) Set the item's display position. Before setting any item's position, enable the plug-in's MANUAL_LAYOUT flag. If this is not done, the items will appear in the default positions given by the plug-in. Nothing

Event Handlers

ContentItem has a different event handling model from most other objects in the Gadget API. To handle a content item event, you must set a handler function for that specific event. Handler functions can only be set inside JavaScript blocks, not in XML definitions. If you don't set a particular handler, its default action happens in response to its associated event.

The function you assign to a particular event handler should match the prototype signature given in this page. For example, the Prototype column of onOpenItem gives the signature OpenItem(item). Knowing that, here's how you might declare and set an onOpenItem event handler for a ContentItem object:

function DoSomething(item) {
  ///...Implementation goes here. 
}
...
aContentItem.onOpenItem = DoSomething;
Name Prototype Description Returns
onDrawItem DrawItem(item, display_target, graphics, x, y, width, height) Called to draw the item. Returns nothing.
onGetHeight GetHeight(item, display_target, graphics, width) Called to get the height in pixels of the item for the given width. Returns integer giving the item's height in pixels.
onOpenItem OpenItem(item) Called when the user opens/double clicks the item. Returns nothing.
onToggleItemPinnedState ToggleItemPinnedState(item) Called when the user clicks the 'pin' button of an item Returns nothing.
onGetIsTooltipRequired GetIsTooltipRequired(item, display_target, graphics, x, y, width, height) Called to check if a tooltip is required for the item displayed at the given position Returns boolean, true to show the tooltip, false to not show it.
onDetailsView OnDetailsView(item) Called before showing the details view for the given item Returns nothing to cancel the details view, or returns an object with the following properties:
  • obj.title - the title to be shown for the details view
  • obj.details_control - an activeX control which should be shown in the details view
  • obj.flags - flags controlling the details view layout/usage

For more info on each of the above params, see the archived doc for OnDetailsView in interface IGoogleDesktopDisplayContentItemHandler.
onProcessDetailsViewFeedback ProcessDetailsViewFeedback(item, details_view_flags) Called to process user action in the details view. Returns nothing.
onRemoveItem RemoveItem(item) Called when user removed an item from the display Returns true to cancel the remove and keep the item, false to continue and remove the item.