14.7 ADD_LIBRARY Procedure

This procedure adds the script tag to load a JavaScript library. If a library has been added, it is not added a second time.

Syntax

APEX_JAVASCRIPT.ADD_LIBRARY (
    p_name                    IN VARCHAR2,
    p_directory               IN VARCHAR2,
    p_version                 IN VARCHAR2 DEFAULT NULL,
    p_check_to_add_minified   IN BOOLEAN DEFAULT FALSE,
    p_skip_extension          IN BOOLEAN  DEFAULT FALSE,
    p_ie_condition            IN VARCHAR2 DEFAULT NULL,
    p_requirejs_module        IN VARCHAR2 DEFAULT NULL,
    p_requirejs_js_expression IN VARCHAR2 DEFAULT NULL,
    p_requirejs_required      IN BOOLEAN DEFAULT FALSE,
    p_key                     IN VARCHAR2 DEFAULT NULL);


Parameters

Table 14-7 ADD_LIBRARY Parameters

Parameter Description

p_name

Name of the JavaScript file. Must not use .js when specifying.

p_directory

Directory where JavaScript library is loaded. Must have a trailing slash.

p_version

Version identifier.

p_check_to_add_minified

If TRUE, the procedure tests if it is appropriate to add .min extension and add it if appropriate. This is added if an application is not running in DEBUG mode, and omitted when in DEBUG mode.

p_skip_extension

If TRUE the extension .js is NOT added.

p_ie_condition

Condition which is used as Internet Explorer condition.

p_requirejs_module

Module name which is used to expose the library to RequireJS.

p_requirejs_js_expression

JavaScript expression which is used to expose the library to the RequireJS module.

p_requirejs_required

This has to be true if the library uses RequireJS in its code to loading other JavaScript files.

p_key

Name used to indicate if the library has already been loaded. If not specified, defaults to p_directory||p_name||p_version.

Example

The following example includes the JavaScript library file named hammer-2.0.4.min.js (if the application has not been started from the Builder), or hammer-2.0.4.js (if the application has been started from the Builder or is running in DEBUG mode), from the directory specified by p_plugin.file_prefix. Since p_skip_extension is not specified, this defaults to .js. Also, since p_key is not specified, the key defaults to p_plugin.file_prefix||hammer-2.0.4. Hammer is a JavaScript library which exposes itself to RequireJS using hammerjs as module name.

apex_javascript.add_library (
    p_name                    => 'hammer-2.0.4#MIN#',
    p_directory               => p_plugin.file_prefix,
    p_requirejs_module        => 'hammerjs',
    p_requirejs_js_expression => 'Hammer' );