Download the PHP package kinglozzer/yepnopesilverstripe without Composer
On this page you can find all versions of the php package kinglozzer/yepnopesilverstripe. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kinglozzer/yepnopesilverstripe
More information about kinglozzer/yepnopesilverstripe
Files in kinglozzer/yepnopesilverstripe
Package yepnopesilverstripe
Short Description A simple way of adding files to yepnope.js in SilverStripe
License BSD-3-Clause
Homepage https://github.com/kinglozzer/YepnopeSilverStripe
Informations about the package yepnopesilverstripe
YepnopeSilverStripe
A module to allow loading of Javascript & CSS using the conditional loader yepnopejs.
By: Loz Calver & Colin Richardson - Bigfork Ltd.
About yepnope:
"yepnope is an asynchronous conditional resource loader that's super-fast, and allows you to load only the scripts that your users need."
Installation:
Composer:
Download:
Simply clone or download this repository and put it in a folder called 'yepnopesilverstripe' in your SilverStripe installation folder, then run dev/build
.
Examples:
Add files:
The simplest way to add a file, or multiple files, whether they're Javascript or CSS, is to use the add_files()
function in your Page_Controller
:
The above example would output the following:
Callbacks:
You can specify a callback function (called for each file that's loaded) and/or a complete function (called after all files have been loaded) by passing second and third arguments to the add_files()
function:
The above example would output the following:
Tests:
You can make use of yepnope's test functionality with the add_test()
function. Arguments must be passed in the following order:
$test
- The test to be evaluated$yep
- The file (or array of files) to be loaded if the test returns true$nope
- The file (or array of files) to be loaded if the test returns false$load
- The file (or array of files) to be loaded regardless of whether the test reuturns true or false$callback
- The function to be called after each resource is loaded$complete
- The function to be called once after all resources are loaded$id
- The unique identifier for the test - see below
Example test:
The above example would output the following:
The lists of files passed to the function can be either strings, arrays or null
(for example, if no extra files are needed for the 'yep' argument).
Clear files & tests:
Both the add_files()
and add_test()
methods take an optional, last argument (4th and 7th arguments respectively) for a unique identifier. This identifier can then be used to remove a test on certain pages. In the example below, let's assume you have files you want to load on every page except pages with the 'ContactPage' page type:
Override test parameters:
If you specify indentifiers for your tests, you can override individual parameters on an already existing test. The following example would use the 'complete' function pageInit()
on pages with the 'Page' pagetype, and contactPageInit()
on pages with the 'ContactPage' pagetype.
The list of methods that can be used when overriding test properties is as follows:
[get/set]ID()
[get/set]Test()
[get/set]Yep()
[get/set]Nope()
[get/set]Load()
[get/set]Callback()
[get/set]Complete()
Resource callback labels:
Since version 1.5 of yepnope.js, keys to be used in callbacks are automatically generated from the basename of the file. If you require keys to be used in your callback functions, please use these generated keys as per the example below:
Customise:
If you're already using yepnope or modernizr and don't need to include yepnope.js, you can remove the requirement (or set it to use a different script) with the following:
If you wish to specify a custom error timeout length (yepnope's default is 10 seconds) you can use the set_timeout()
method. Note that the time is set in milliseconds:
YepnopeSilverStripe automatically evaluates tests after Controller::init()
, using the Controller->onAfterInit()
extension hook. This behaviour can be disabled by calling Yepnope::set_automatically_evaluate(false);
. You can then manually evaluate your Yepnope tests by calling Yepnope::eval_yepnope()
with one, optional parameter for a 'customScriptID' (YepnopeSilverStripe uses Requirements::customScript()
).
Tips:
If your tests, callback functions or complete functions are quite long, then putting them in a PHP file is ugly and hard to maintain. One alternative is to store the raw javascript in a template (be sure to do a ?flush=1 after creating any templates) and load it using the following method:
MyCallback.ss would then contain your raw Javascript (not wrapped in any HTML tags or anything).
Todo:
- Easier "final complete" function support - see https://github.com/SlexAxton/yepnope.js/issues/29