unprefix/unprefix-scripts

此软件包已被 废弃 且不再维护。没有建议的替代软件包。

一个小型库,用于在WordPress中注册和排队脚本。

安装: 543

依赖项: 0

建议者: 0

安全性: 0

星标: 1

关注者: 1

分支: 0

开放问题: 1

类型:wordpress-plugin

3.0.0 2017-07-31 22:24 UTC

This package is not auto-updated.

Last update: 2020-02-27 17:57:23 UTC


README

Build Status codecov License Mit

Unprefix Scripts

一个小型库,用于在WordPress中注册和排队脚本。

还可以注销脚本和样式,并本地化变量,以便从每个js文件中访问它们。

示例

$lists = [
    'scripts => [
        // Modernizr.
        'modernizr' => [
            'modernizr',
            Plugin::getPluginDirUrl('/assets/js/vendor/modernizr.min.js'),
            array(),
            '3.3.1',
            true,
            function () {
                return true;
            },
            function () {
                return true;
            },
        ],
    ],
    'styles' => [
        // Select2.
        'select2' => [
            'select2',
            Plugin::getPluginDirUrl('/assets/css/vendor/select2.min.css'),
            array(),
            '',
            'screen',
            function () {
                return true;
            },
            function () {
                return true;
            },
        ],
    ],
];

$unRegisterScriptsList = [
    'styles'  => [
        [
            'handle'  => 'script-handle',
            'condition' => function() {
                // ... condition
            }
        ],
    ],
    'scripts => [
        [
            'handle'  => 'script-handle',
            'condition' => function() {
                // ... condition
            }
        ],
    ]
];

$localizedList = [
    'localized' => [
        [
            'handle' => is_admin() ? 'admin' : 'front',
            'name'   => 'handlename',
            [
                'lang'        => get_bloginfo('language'),
                'date_format' => get_option('date_format'),
                'time_format' => get_option('time_format'),
            ],
        ],  
    ]
];

// Create the Instances.
$scripts           = new ScriptsFacade($lists);
$unRegister        = new UnRegister($unRegisterScriptsList);
$localizedScripts  = new LocalizeScripts($localizedList);

// Register the scripts.
add_action('enqueue_scripts', [$unRegister, 'unRegister'], 10);
add_action('enqueue_scripts', [$scripts, 'register'], 20);
add_action('enqueue_scripts', [$scripts, 'enqueuer'], 30);
add_action('enqueue_scripts', [$localizedScripts, 'localizeScripts'], 40);