Titanium Dictionary Module

What to use the native iOS5 Dictionary in your Titanium Mobile app?

The new benCoding.Dictionary module that makes it easy to this functionality into any Titanium app that targets iOS5 or greater.

Want to download the module?

You can download the compile module here.  Please take a look at the “Before You Start” section to make sure you have all of the module dependencies.

Interested in the source?

The source is available in the benCoding-Dictionary repo on GitHub.

Before You Start

This module has a few dependencies, make sure you meet the below criteria.

  • You need to be targeting Titanium 1.8.1 or greater.
  • This module requires iOS5

How Does It Work?

The module provides a Titanium wrapper around Apple’s native UIReferenceLibraryViewController.

What Does It Look Like?

Since this is largely a UI component please find below a short video showing the example app running in the simulator.

Documentation & Examples

For the example app shown above and full html documentation please check out the documentation and example folders in the module zip.

Need A Quick Example?

Here is a quick example showing how to use the module.  To learn more please see the documentation link here and the example link here.


var referenceLibrary = require('bencoding.dictionary').createReferenceLibrary();
Ti.API.info("This feature is only supported in iOS5 and above");
Ti.API.info("Check if we have the min OS version needed");
Ti.API.info("Is Supported? => " + referenceLibrary.isSupported());
Ti.API.info("Check if Apple knows the definition for fanboy");
var hasDefinition = referenceLibrary.wordHasDefinition('fanboy');
Ti.API.info("Term has definition =>" + hasDefinition);

if(!hasDefinition){
alert('You can still call showDialog it will just display a message that no definition was found');
}else{
//If you want you can define some callbacks
function termDialogBoxHasBeenClosed(){
Ti.API.info("I'm a callback when the Definition Dialog Box has been closed.");
};
function termDialogHadError(e){
Ti.API.info("I'm a callback when an error happens this error is due to: " + e.error);
};

Ti.API.info("You can add an event to be called if there is an error");
referenceLibrary.addEventListener('errored', termDialogHadError);

Ti.API.info("You can add an event to be called when the definition dialog is closed");
referenceLibrary.addEventListener('closed', termDialogBoxHasBeenClosed);

//Open the definition dialog window
referenceLibrary.showDialog({
//This is the term to search for (REQUIRED)
term:'fanboy',
//Indicate if the dialog should be animated on open (OPTIONAL)
animated:true,
//This is the transition style (OPTIONAL)
modalTransitionStyle:Ti.UI.iPhone.MODAL_TRANSITION_STYLE_FLIP_HORIZONTAL
});
}

Leave a comment