如何在 YUI3 中添加自定义实用程序/模块

发布于 2024-12-18 14:32:56 字数 649 浏览 4 评论 0原文

我想在 YUI3 中注册一个自定义实用程序/模块,该实用程序/模块传递一个或多个自定义节点,并且可以像这样调用(无需实例化它):

YUI().use('myCustomModule', function (Y) {
 Y.one('nodeToProcess').myCustomUtility(config);
 Y.all('manyNodes').myCustomUtility(config);
});

jQuery 提供类似的功能。

我知道 YUI3 中的自定义模块是这样定义的:

YUI.add('myCustomModule', function(Y) {
// my Code here
}, '0.1', {
requires : ['node']
});

但我不明白的是如何设置我的自定义模块,以便我可以像所描述的那样调用它。我是否必须扩展插件/小部件类或使用 Y.Namespace() 才能使其正常工作? (参见http://www.slideshare.net/caridy/building-yui -3-自定义模块

I would like to register a custom utility / module within YUI3 that is passed one or more custom node(s) and that can be called like this (without having to instantiate it):

YUI().use('myCustomModule', function (Y) {
 Y.one('nodeToProcess').myCustomUtility(config);
 Y.all('manyNodes').myCustomUtility(config);
});

jQuery offers a similar functionality.

I know that a custom module in YUI3 is defined like this:

YUI.add('myCustomModule', function(Y) {
// my Code here
}, '0.1', {
requires : ['node']
});

But what I don't understand is how to setup my custom module, so that I can call it like described. Do I have to extend Plugin / Widget class or use Y.Namespace() to get this to work? (see http://www.slideshare.net/caridy/building-yui-3-custom-modules )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可可 2024-12-25 14:32:56

您可能想尝试这个:

<!doctype html>
<head>
    <meta charset="utf-8">
    <script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
    <script>
YUI.add('joiz', function(Y) {

    function joizMagic(context, config) {
        alert(config.name + ' says: "' + this.getContent() + '"');
    }

    // define a function that will run in the context of a
    // Node instance:
    Y.Node.addMethod("joizMagic", joizMagic);

    // extend this functionality to NodeLists:
    Y.NodeList.importMethod(Y.Node.prototype, "joizMagic");

}, '0.1.1' /* module version */, {
    requires: ['node']
});
YUI().use('joiz', function (Y)
{
    Y.all('.message').joizMagic({ name: 'Beatrice' });
});
    </script>
</head>
<body>
    <div class="message">Hello World!</div>
    <div class="message">I'm still here!</div>
</body>
</html>

You may want to try this:

<!doctype html>
<head>
    <meta charset="utf-8">
    <script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
    <script>
YUI.add('joiz', function(Y) {

    function joizMagic(context, config) {
        alert(config.name + ' says: "' + this.getContent() + '"');
    }

    // define a function that will run in the context of a
    // Node instance:
    Y.Node.addMethod("joizMagic", joizMagic);

    // extend this functionality to NodeLists:
    Y.NodeList.importMethod(Y.Node.prototype, "joizMagic");

}, '0.1.1' /* module version */, {
    requires: ['node']
});
YUI().use('joiz', function (Y)
{
    Y.all('.message').joizMagic({ name: 'Beatrice' });
});
    </script>
</head>
<body>
    <div class="message">Hello World!</div>
    <div class="message">I'm still here!</div>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文