PHP code example of ntlab / ntjs

1. Go to this page and download the library: Download ntlab/ntjs library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ntlab / ntjs example snippets


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);
        }
    }
}

use NTLAB\JS\Script;

class MyDemoClass
{
    public function something()
    {
        Script::create('JQuery')
            ->add(<<<EOF
alert('Do something');
EOF
            );
    }
}
shell
php composer.phar all