定制 ntlab/ntjs 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ntlab/ntjs

Composer 安装命令:

composer require ntlab/ntjs

包简介

PHP-NTJS Javascript Repository

README 文档

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 can be achieved using ntlab/ntjs-repo.

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 extends NTLAB\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.

Live Demo

Live demo is available here.

统计信息

  • 总下载量: 1.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固