ntlab / ntjs
PHP Javascript Repository
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^9.5
- dev-master
- v3.21.0
- v3.20.0
- v3.19.0
- v3.18.0
- v3.17.0
- v3.16.0
- v3.15.0
- v3.14.0
- v3.13.0
- v3.12.0
- v3.11.0
- v3.10.0
- v3.9.0
- v3.8.0
- v3.7.0
- v3.6.4
- v3.6.3
- v3.6.2
- v3.6.1
- v3.6.0
- v3.5.0
- v3.4.1
- v3.4.0
- v3.3.1
- v3.3.0
- v3.2.0
- v3.1.0
- v3.0.0
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- 1.x-dev
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
This package is auto-updated.
Last update: 2024-11-17 16:29:12 UTC
README
PHP-NTJS allows to dynamically manage your javascripts, stylesheets, and scripts so you can focus on your code. You can code your javascript using PHP class, or write directly in the PHP code, even on template.
JQuery and Bootstrap
Support for popular javascript like JQuery, Bootstrap, and FontAwesome.
CDN
To speed up your page, CDN can be enabled, PHP-NTJS will automatically do it for you. Just loads needed CDN information and assets will loaded from CDN.
Minified Output
On production, you can enable script output compression either by using JSMin or JShrink. On development, you can add script debug information to easily locate problematic code.
Integrate With Your Code
To integrate PHP-NTJS with your code, you need to enable Composer support in your project.
- Require
ntlab/ntjs
and install dependencies.
php composer.phar require ntlab/ntjs php composer.phar install
- Clone the assets somewhere in your public web folder.
git clone https://github.com/tohenk/ntjs-web-assets /path/to/www/cdn
-
Create your script backend, which is responsible for collecting assets, it must be implements
NTLAB\JS\BackendInterface
or extendsNTLAB\JS\Backend
. An example of backend is available here. -
Create script dependency resolver, which us responsible for resolving namespace when the script referenced. It must be implements
NTLAB\JS\DependencyResolverInterface
. An example of resolver is available here. -
Optionally, create script compressor which implements
NTLAB\JS\CompressorInterface
. An example of compressor is available here. -
Connect it together, see example.
use NTLAB\JS\Manager; use NTLAB\JS\Script; class MyClass { protected $useCDN = true; protected $minifyScript = false; protected $debugScript = true; public function initialize() { $manager = Manager::getInstance(); // create backend instance $backend = new Backend($this->useCDN); // set script backend $manager->setBackend($backend); // register script resolver, the backend also a resolver $manager->addResolver($backend); // register script compressor, the backend also a compressor if ($this->minifyScript) { $manager->setCompressor($backend); } // set script debug information if ($this->debugScript) { Script::setDebug(true); } } }
- Start write your javascript code, see example.
use NTLAB\JS\Script; class MyDemoClass { public function something() { Script::create('JQuery') ->add(<<<EOF alert('Do something'); EOF ); } }
- Add a helper to include stylesheets, javascripts and script to the HTML response, see this example and this example.
Available Scripts
This table below contains collection of scripts and its usage.
Live Demo
Live demo is available here.