\CGExtensions\jsloaderjsloader

A utility class to manage loading and combining javascript libraries and associated stylesheets.

Summary

Methods
Properties
Constants
__construct()
register()
unregister_by_module()
require_lib()
add_jsext()
add_jsfile()
add_js()
add_cssfile()
add_css()
render()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

__construct()

__construct(string  $key, \cms_config  $config) 

Constructor

Parameters

string $key

A static key that is used in the unique naming of generated files.

\cms_config $config

The cms config instance to use.

register()

register(\CGExtensions\jsloader\libdefn  $rec, boolean  $force = FALSE) 

Register a library definition

Parameters

\CGExtensions\jsloader\libdefn $rec

The library definition to register.

boolean $force

Force the libdefn to be registered even if it already has been.

unregister_by_module()

unregister_by_module(string  $module_name) 

Unregister all javascript libraries associated with a module.

Parameters

string $module_name

require_lib()

require_lib(string  $name, boolean  $nominify = false) 

For this request, indicate that a javascript library is required.

Parameters

string $name
boolean $nominify

If true, the library code will not be minified.

add_jsext()

add_jsext(string  $url, boolean  $nominify = false) 

Add an external javascript library.

[experimental]

Parameters

string $url
boolean $nominify

If true, the library code will not be minified.

add_jsfile()

add_jsfile(string  $file, null|array<mixed,string>  $depends = null, boolean  $nominify = false) 

For this request, add a specified javascript file.

Parameters

string $file

The complete pathname to the javascript file.

null|array<mixed,string> $depends

array of library names (must already be registered) that this file depends upon.

boolean $nominify

If true, the library code will not be minified.

add_js()

add_js(string  $code, null|array<mixed,string>  $depends = null, boolean  $nominify = true, boolean  $append = false) 

Add javascript code to the output for this request.

Parameters

string $code

The javascript code (script tags are not required)

null|array<mixed,string> $depends

Array of required javascript libraries.

boolean $nominify

If true, the library code will not be minified.

boolean $append

If true, this code will be appended after all other scripts.. otherwise included in order

add_cssfile()

add_cssfile(string  $file, null|array<mixed,string>  $depends = null, boolean  $nominify = true) 

Add a css file to the output.

Parameters

string $file

The filename. If not an absolute path, then search for the file within the current module directory (if any), the uploads path, and then the root path.

null|array<mixed,string> $depends

Array of libraries that this css file depends upon.

boolean $nominify

If true, the library code will not be minified.

add_css()

add_css(string  $styles, array  $depends = null, boolean  $nominify = true, boolean  $append = false) 

Add static css text to the output.

Parameters

string $styles

The static CSS text (style tags are not needed).

array $depends

A list of libraries that this css depends upon.

boolean $nominify

If true, the library code will not be minified.

boolean $append

If true, this code will be appended after all other scripts.. otherwise included in order

render()

render(array  $opts = null) : string

Render the output javascript and stylesheets into cachable files and output the appropriate HTML tags.

This function actually adds appropriate hook handlers to process the rendering of css and js tags during the final process of HTML rendering this removes all problems with smarty processing orders.

Parameters

array $opts

Options for this method (for further reference, see the {cgjs_render} smarty tag.

Returns

string —

HTML output code.