Search code examples
javascripthtmlcsspolymerweb-component

JavaScript plugin initialization in Polymer Shadow DOM


I tried to use this plugin with Polymer, but it did't work. I use a Javascript version of this plugin. I have also used domReady: function{}. What is the problem?

Shadow DOM:

    <link rel="import" href="../../bower_components/polymer/polymer.html">
<script src="../../assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js"></script>
<polymer-element name="paper-scrollbar">
    <template>
        <!-- begin element CSS -->
        <link rel="stylesheet" href="../../assets/plugins/perfect-scrollbar/css/perfect-scrollbar.css">
        <style>
            .scrollbar-container {
                width: 100%;
                height: 100%;
                overflow: auto;
                position: relative;
                margin: 0;
            }
        </style>
        <!-- end element CSS-->
        <!-- begin element HTML -->
        <div class="scrollbar-container">
            <content></content>
        </div>
        <!-- end element HTML -->
    </template>
    <!-- begin element JavaScript -->
    <script>
        Polymer('paper-scrollbar', {
            ready: function () {
                var container = document.querySelector('.scrollbar-container');

                Ps.initialize(container);
            }
        });
    </script>
    <!-- end element JavaScript -->
</polymer-element>

Solution

  • The issue is in plugin. It doesn't work with scope of elements under the same class. You should use unique id for each DOM element.