base.js 4.4 KB
Newer Older
1
require([
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
    'domReady',
    'jquery',
    'underscore',
    'gettext',
    'common/js/components/views/feedback_notification',
    'common/js/components/views/feedback_prompt',
    'js/utils/date_utils',
    'js/utils/module',
    'js/utils/handle_iframe_binding',
    'edx-ui-toolkit/js/dropdown-menu/dropdown-menu-view',
    'jquery.ui',
    'jquery.leanModal',
    'jquery.form',
    'jquery.smoothScroll'
],
17 18 19 20 21 22 23 24 25 26 27 28
    function(
        domReady,
        $,
        _,
        gettext,
        NotificationView,
        PromptView,
        DateUtils,
        ModuleUtils,
        IframeUtils,
        DropdownMenuView
    )
29
{
30
        var $body;
31

32 33
        domReady(function() {
            var dropdownMenuView;
34

35
            $body = $('body');
cahrens committed
36

37 38 39
            $body.on('click', '.embeddable-xml-input', function() {
                $(this).select();
            });
40

41
            $body.addClass('js');
42

43 44 45
            // alerts/notifications - manual close
            $('.action-alert-close, .alert.has-actions .nav-actions a').bind('click', hideAlert);
            $('.action-notification-close').bind('click', hideNotification);
46

47 48 49 50 51
            // nav - dropdown related
            $body.click(function(e) {
                $('.nav-dd .nav-item .wrapper-nav-sub').removeClass('is-shown');
                $('.nav-dd .nav-item .title').removeClass('is-selected');
            });
Chris Dodge committed
52

53 54 55
            $('.nav-dd .nav-item, .filterable-column .nav-item').click(function(e) {
                $subnav = $(this).find('.wrapper-nav-sub');
                $title = $(this).find('.title');
56

57 58 59 60 61 62 63 64
                if ($subnav.hasClass('is-shown')) {
                    $subnav.removeClass('is-shown');
                    $title.removeClass('is-selected');
                } else {
                    $('.nav-dd .nav-item .title').removeClass('is-selected');
                    $('.nav-dd .nav-item .wrapper-nav-sub').removeClass('is-shown');
                    $title.addClass('is-selected');
                    $subnav.addClass('is-shown');
65
            // if propagation is not stopped, the event will bubble up to the
66
            // body element, which will close the dropdown.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
                    e.stopPropagation();
                }
            });

            // general link management - new window/tab
            $('a[rel="external"]:not([title])').attr('title', gettext('This link will open in a new browser window/tab'));
            $('a[rel="external"]').attr('target', '_blank');

            // general link management - lean modal window
            $('a[rel="modal"]').attr('title', gettext('This link will open in a modal window')).leanModal({
                overlay: 0.50,
                closeButton: '.action-modal-close'
            });
            $('.action-modal-close').click(function(e) {
                (e).preventDefault();
            });

            // general link management - smooth scrolling page links
            $('a[rel*="view"][href^="#"]').bind('click', smoothScrollLink);

            IframeUtils.iframeBinding();

            // disable ajax caching in IE so that backbone fetches work
            if ($.browser.msie) {
                $.ajaxSetup({cache: false});
            }

            // Initiate the edx tool kit dropdown menu
            if ($('.js-header-user-menu').length) {
                dropdownMenuView = new DropdownMenuView({
                    el: '.js-header-user-menu'
                });
                dropdownMenuView.postRender();
            }
101
        });
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

        function smoothScrollLink(e) {
            (e).preventDefault();

            $.smoothScroll({
                offset: -200,
                easing: 'swing',
                speed: 1000,
                scrollElement: null,
                scrollTarget: $(this).attr('href')
            });
        }

        function smoothScrollTop(e) {
            (e).preventDefault();

            $.smoothScroll({
                offset: -200,
                easing: 'swing',
                speed: 1000,
                scrollElement: null,
                scrollTarget: $('#view-top')
            });
        }

        function hideNotification(e) {
            (e).preventDefault();
            $(this).closest('.wrapper-notification').removeClass('is-shown').addClass('is-hiding').attr('aria-hidden', 'true');
        }

        function hideAlert(e) {
            (e).preventDefault();
            $(this).closest('.wrapper-alert').removeClass('is-shown');
        }
    }); // end require()