Shopware jquery Plugin 一些内置方法

2018-01-30  本文已影响0人  _chuuuing_

In general, all jquery plugin will be put in the following direction:
themes/Frontend/Responsive/frontend/_public/src/js/

In this folder, you can find all the JS Plugins from Shopware itself.
You can create a new plugin OR customize those exists(NOT recommend).

How to customize an existing plugin?

1. $.publich:
$.publish('plugin/PluginName/Methode', [ me, event ]);
2. $.subscribe:
$.subscribe("plugin/PluginName/Methode", function(event, me) {
    var $el = me.$el,
        opts = me.opts;
    console.log(opts);
    // ...
});

How can I bind the plugin to my theme?

1. JavaScript Datei (z.B. frontend/_public/src/js/jquery.myFile.js)
(function($){
    $.subscribe("plugin/PluginName/Methode", function(event, me) {
        var $el = me.$el,
            opts = me.opts;
        console.log(opts);
        // ...
    });
})(jQuery);
2. Theme index/index.tpl or index/header.tpl
{block name="frontend_index_header_javascript_jquery_lib" append}
    <script src="{link file='frontend/_public/src/js/jquery.myFile.js'}"></script>
{/block}

Official tutorial for jquery plugin: https://developers.shopware.com/designers-guide/javascript-statemanager-and-pluginbase/

上一篇下一篇

猜你喜欢

热点阅读