Titanium.UI.Clipboard

Submodule of Titanium.UI.
Platform Since
Android 1.5
iPhone 1.5
iPad 1.5
Mobile Web 1.5

Summary

A module used for accessing clipboard data.

Code Examples

Copying text to the clipboard

copyButton.addEventListener('click', function() {
    Ti.UI.Clipboard.setText(data.url);
});

Pasting text from the clipboard

if (Ti.UI.Clipboard.hasText()) {
    doSomethingWith(Ti.UI.Clipboard.getText());
} else {
    alert('Hey there was no text.');
}

Clipboard data types

The Text() functions are equivalent to calling Data() with 'text' or 'text/plain' types, and work with plain Unicode strings.

On Android, only plain text is supported; other MIME types will be ignored.

On iOS, images will be returned as a Titanium.Blob; the special type 'image' or an explicit MIME type may be specified. URLs can be fetched with the special 'URL' or 'text/uri-list' types, and will return strings. Other data types may or may not be correctly mapped to clipboard types by the system, and will be retrieved as binary data in a Titanium.Blob.

Methods

Name Summary
addEventListener

Adds the specified callback as an event listener for the named event.

clearData

Clear data of the given mime-type from the clipboard. If no mime-type is given, clear all data from the clipboard.

clearText

Clear the text portion of the clipboard.

fireEvent

Fires a synthesized event to any registered listeners.

getData

Get the data on the clipboard from the portion which contains data of the given mime-type.

getText

Get the current text on the clipboard.

hasData

Return true if there is any content of the given mime-type on the clipboard.

hasText

Return true if there is any content in the text portion of the clipboard.

removeEventListener

Removes the specified callback as an event listener for the named event.

setData

Set the data on the clipboard given a mime-type and the new data. This method will set data on the appropriate portion of the clipboard for the given mime-type.

setText

Set the text on the clipboard. This will overwrite the current contents of the clipboard.

Properties

This type has no properties.

Events

This type has no events.