+

Search Tips | Advanced Search

For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.


Editing WebView (JavaScript) code

Editing the WebView resources is more convenient using an IDE that provides autocompletion for JavaScript.

Xcode, Android Studio, and Visual Studio provide full editing capabilities for editing Objective C, Swift, C#, and Java™, however they may be limited in how they assist the editing of JavaScript. To facilitate JavaScript editing, the MobileFirst Cordova project contains a defintion file for providing autocomplete for MobileFirst API elements.

Each MobileFirst Cordova plug-in provides a d.ts configuration file for each MobileFirst JavaScript files. The d.ts file name matches the corresponding JavaScript file name and is located within the plug-in folder. For example for the main MobileFirst SDK the file is here:

[myapp]\plugins\cordova-plugin-mfp\typings\worklight.d.ts

This definition provides autocomplete for all IDEs with TypeScript support:

TypeScript Playground

Visual Studio Code

WebStorm

WebEssentials

Eclipse

The resources (HTML and JavaScript files) for the WebView are located in the [myapp]\www folder. When the project is built with the cordova build command, or the cordova prepare command is run, these resources are copied to the corresponding www folder in the [myapp]\platforms\ios\www, [myapp]\platforms\android\assets\www, or myapp]\platforms\windows\www folder.

When we open the main app folder with one of the previous IDEs, the context is preserved. The IDE editor will now be linked to the relevant d.ts files and autocomplete the MobileFirst API elements as you type.

Parent topic: Cordova WebView