R
R
Roman Ogarkov2015-12-10 11:21:56
JavaScript
Roman Ogarkov, 2015-12-10 11:21:56

Am I using require.js correctly?

requirejs.config({
    paths: {
    jquery: 'jquery/dist/jquery.min',
        formstyler: 'jquery.formstyler.min',
        ymaps: '//api-maps.yandex.ru/2.0/?load=package.full&lang=ru-RU'
    },
    shim: {
        'formstyler': {
            deps: ['jquery']
        },
        'ymaps': {
            exports: 'ymaps'
        }
    }
});

require(['jquery', 'formstyler'],function() {
    $(document).ready(function() {
        
        $('.arrow-down-btn').on('click', function(e) {
            e.preventDefault();
            $( this ).closest('.control-row').next().toggleClass('dn');
            $( this ).toggleClass('arrow-up-btn');
        });

        $('input:checkbox').styler();
    });

    (function(cont) {
        if (!cont.length) return;

        require(['ymaps'], function(ymaps) {
            ymaps.ready(initMap);

            function initMap() {
                var myMap = new ymaps.Map(cont.attr('id'), {
                    center: [60.153151, 30.286574],
                    zoom: 13
                });
            }
        });
    })($('#map'));
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question