RequireJS

Include require.js

\Phoenix\Script\CoreScript::requireJS();

Now yo can load your script by commonJS API:

var foo = require('./foo');

Or require it from PHP:

\Phoenix\Script\CoreScript::requireJS('./foo');

See RequireJS

Underscore

Phoenix provides underscore.js as a base JS library to help us do more things which native JS cannot do.

\Phoenix\Script\CoreScript::underscore();

Phoenix enabled no conflict mode as default, so you must use underscore instead _:

underscore.isNumber(234);

Template

Phoenix override underscore template syntax to same as Blade and Edge, so we can use double braces to render variables:

underscore.template("hello: {{ name }}").compiled({name: 'World'});

To use template in Blade and Edge, you must add @ before braces to escape the echo tag:

<script>
underscore.template("hello: @{{ name }}").compiled({name: 'World'});
</scrip>

See Underscore.js

Underscore String

Support more string operations.

\Phoenix\Script\CoreScript::underscoreString();

See Underscore.string.js

Sprintf

underscore.string deprecated sprintf() method, so you can use JS sprintf package instead:

\Phoenix\Script\CoreScript::sprintf();

See sprintf.js

Backbone

Phoenix provides backbone.js if you want to build a SPA.

\Phoenix\Script\CoreScript::backbone();

See Backbone.js

Ivia

Ivia.js is a reactivity MVVM framework for jQuery with Vue-like interface, it can easily work with phoenix scripts and won't break existing DOM events.

\Phoenix\Script\CoreScript::ivia();

See Ivia.js

Simple Uri

Simple Uri is a JS URI object to help us easily handle uri operations in browser environment:

\Phoenix\Script\CoreScript::simpleUri();

See SimpleUri.js

Silicone

Silicone is a simple css helper to extend bootstrap and other css frameworks.

\Phoenix\Script\CoreScript::silicone();

See silicone.css

Add CSRF Token

Add CSRF token to <head> as a meta tag

\Phoenix\Script\CoreScript::csrfToken();
<meta name="csrf-token" content="a7d71a2c21743d8865fdfa61b71b29e8" />

If you found a typo or error, please help us improve this document.