定制 souldigital/silverstripe-headjs 二次开发

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

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

souldigital/silverstripe-headjs

最新稳定版本:1.0.2

Composer 安装命令:

composer require souldigital/silverstripe-headjs

包简介

Use headjs to load requirements in Silverstripe

README 文档

README

Use HeadJS for assets loading.

##Compatibility

Tested with Silverstripe 3.1

##Features

  • Async loading of requirements using the native Requirements engine
  • Specific targeting of requirement locations in DOM via SectionedHeadJsBackend
  • Critical js/css files to be required in the head while all other requirements are loaded above the closing body
  • Add JS callbacks to requirements
  • Add dependencies to JS / CSS files

##How do I use this thing?

###Setup If you just want to use the HeadJS integration for your Requirements backend, add the following to your mysite/_config.php

Requirements::set_backend(Injector::inst()->get("HeadJsBackend"));

If you'd like to use the Sectioned Head JS, add the following to your mysite/_config.php

Requirements::set_backend(Injector::inst()->get("SectionedHeadJsBackend"));

###Adding a callback An example of adding a callback to a CSS or JS requirement is below:

$custom_js = <<<JS
    (function ($) {
        $(document).ready(function () {
            alert("Loaded!");
        });
    })($);
JS;

Requirements::javascript("framework/thirdparty/jquery/jquery.js");
if(method_exists(Requirements::backend(), "add_callback")){
    Requirements::backend()->add_callback("framework/thirdparty/jquery/jquery.js", $custom_js);
}else{
    Requirements::customScript($custom_js, "loadedalert");
}

###Adding a dependency An example of adding a dependency to a CSS or JS requirement is below:

Requirements::javascript("framework/thirdparty/jquery/jquery-ui.js");
if(method_exists(Requirements::backend(), "add_dependency")){
    Requirements::backend()->add_dependency("framework/thirdparty/jquery-ui/jquery-ui.js", "framework/thirdparty/jquery/jquery.js");
} 

In the example above, we require jQuery UI, but make sure that it is only loaded after jQuery has loaded. Note that we can add multiple dependent files to the jQuery JS file if we want, but there is a limitation around chaining dependencies; i.e. we can only have a single level of dependency - in the example above, we can not add a new file that is dependent on jQuery UI.

###Specifying a section An example of specifying a section for a CSS or JS requirement is below:

if(method_exists(Requirements::backend(), "add_to_section")){
    Requirements::backend()->add_to_section("framework/thirdparty/jquery/jquery.js", SectionedHeadJsBackend::SECTION_AFTER_BODY_OPEN);
}

###Super-specific bugs and their associated fixes

####UserForms module validation won't work (it says it can't find jQuery) There are lots of different ways we can solve this issue, but the simplest one I've found is if you add an extension to the UserDefinedForm_Controller - or even just edit Page_Controller - and add the following to the init() function:

class UserDefinedFormHeadJSExtension extends Extension {
    public function afterGenerateConditionalJavascript(){
        if(method_exists(Requirements::backend(), "add_dependency")){
            Requirements::backend()->add_dependency("UserFormsConditional", USERFORMS_DIR . '/javascript/UserForm.js');
        }
    }
}   

##Maintainer Tim - tim@souldigital.com.au

##Original Repo silverstripe-headjs by the awesome lekoala

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 5
  • Forks: 2
  • 开发语言: JavaScript

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-04-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固