base.js 3.53 KB
Newer Older
1
require(["domReady", "jquery", "underscore", "gettext", "js/views/feedback_notification", "js/views/feedback_prompt",
2 3 4
    "js/utils/date_utils", "js/utils/module", "js/utils/handle_iframe_binding",
    "jquery.ui", "jquery.leanModal", "jquery.form", "jquery.smoothScroll"],
    function(domReady, $, _, gettext, NotificationView, PromptView, DateUtils, ModuleUtils, IframeUtils)
5
{
6

7 8
var $body;

9
domReady(function() {
cahrens committed
10 11
    $body = $('body');

12
    $body.on('click', '.embeddable-xml-input', function() {
cahrens committed
13 14
        $(this).select();
    });
15

16
    $body.addClass('js');
17

18
    // lean/simple modal
19 20 21 22 23
    $('a[rel*=modal]').leanModal({
        overlay: 0.80,
        closeButton: '.action-modal-close'
    });
    $('a.action-modal-close').click(function(e) {
24 25
        (e).preventDefault();
    });
26

27 28 29
    // alerts/notifications - manual close
    $('.action-alert-close, .alert.has-actions .nav-actions a').bind('click', hideAlert);
    $('.action-notification-close').bind('click', hideNotification);
30

cahrens committed
31
    // nav - dropdown related
32
    $body.click(function(e) {
33 34
        $('.nav-dd .nav-item .wrapper-nav-sub').removeClass('is-shown');
        $('.nav-dd .nav-item .title').removeClass('is-selected');
cahrens committed
35
    });
Chris Dodge committed
36

37
    $('.nav-dd .nav-item').click(function(e) {
38

39 40
        $subnav = $(this).find('.wrapper-nav-sub');
        $title = $(this).find('.title');
41

cahrens committed
42 43 44
        if ($subnav.hasClass('is-shown')) {
            $subnav.removeClass('is-shown');
            $title.removeClass('is-selected');
45
        } else {
46 47
            $('.nav-dd .nav-item .title').removeClass('is-selected');
            $('.nav-dd .nav-item .wrapper-nav-sub').removeClass('is-shown');
cahrens committed
48 49
            $title.addClass('is-selected');
            $subnav.addClass('is-shown');
50
            // if propagation is not stopped, the event will bubble up to the
51 52
            // body element, which will close the dropdown.
            e.stopPropagation();
cahrens committed
53 54 55 56
        }
    });

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

    // general link management - lean modal window
David Baumgold committed
61
    $('a[rel="modal"]').attr('title', gettext('This link will open in a modal window')).leanModal({
62 63 64 65
        overlay: 0.50,
        closeButton: '.action-modal-close'
    });
    $('.action-modal-close').click(function(e) {
cahrens committed
66 67 68
        (e).preventDefault();
    });

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

72
    // tender feedback window scrolling
73
    $('a.show-tender').bind('click', smoothScrollTop);
74

75
    IframeUtils.iframeBinding();
76 77 78 79 80

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

83
function smoothScrollLink(e) {
84 85
    (e).preventDefault();

Steve Strassmann committed
86 87 88
    $.smoothScroll({
        offset: -200,
        easing: 'swing',
89 90 91 92 93 94
        speed: 1000,
        scrollElement: null,
        scrollTarget: $(this).attr('href')
    });
}

95
function smoothScrollTop(e) {
96 97
    (e).preventDefault();

Steve Strassmann committed
98 99 100
    $.smoothScroll({
        offset: -200,
        easing: 'swing',
101 102 103 104 105 106
        speed: 1000,
        scrollElement: null,
        scrollTarget: $('#view-top')
    });
}

107 108
function hideNotification(e) {
    (e).preventDefault();
109
    $(this).closest('.wrapper-notification').removeClass('is-shown').addClass('is-hiding').attr('aria-hidden', 'true');
110 111 112 113 114 115 116
}

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

117
}); // end require()