innoweb/silverstripe-requirements-resolver

Helper module to resolve the path to global requirements like jQuery and the like.

Installs: 1 398

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 4

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

2.0.2 2024-01-04 02:45 UTC

This package is auto-updated.

Last update: 2024-11-04 04:30:07 UTC


README

Overview

Helper module to resolve the path to global requirements like jQuery, and the like.

This was built for Silverstripe 4 because the local jQuery and jQuery validate versions in framework were outdated and we needed a way to override those with a newer/more secure version.

It helps making sure that only one version of a certain library is included for a site.

It also makes sure that when a JS requirement is called twice, once with defer/async and once without, the requirement is included without async/defer to make sure all js code works.

Requirements

SilverStripe CMS 5, see composer.json

Note: this version is compatible with Silverstripe 5. For Silverstripe 4, please see the 1 release line.

Installation

Install the module using composer:

composer require innoweb/silverstripe-requirements-resolver dev-master

Then run dev/build.

Usage

In PHP

Requirements::javascript(
    RequirementsResolver::get('jquery')
);

In template

<% require javascript($ResolveRequirement("jquery")) %>

Configuration

The following requirements are pre-configured in the module's config:

jquery: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js'
'jquery-validate': 'https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.20.0/jquery.validate.min.js'
'jqueryui-js': 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js'

Additional requirements can be added the the module's config:

Innoweb\RequirementsResolver\RequirementsResolver:
  requirements:
    '{key}': '{URL}'

Once configured, the key can be used to load the Requirements path.

License

BSD 3-Clause License, see License