# All files / src Navbar.vue

0% Statements 0/30
0% Branches 0/21
0% Functions 0/19
0% Lines 0/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    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
    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

     <template>
      <nav ref="navbar" :class="['navbar', 'navbar-expand-md', themeOptions, addClass, fixedOptions]">
        <div class="container-fluid">
          <div class="navbar-brand">
            <slot name="brand"/>
          </div>
          <button v-if="!slots.collapse" class="navbar-toggler" type="button" aria-expanded="false" aria-label="Toggle navigation" @click="toggleCollapse">
            <span class="navbar-toggler-icon"/>
            <slot name="collapse"/>
          </button>

          <div :class="['navbar-collapse',{collapse:collapsed}]">
            <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
              <slot/>
            </ul>
            <ul v-if="slots.right" class="navbar-nav navbar-right">
              <slot name="right"/>
            </ul>
          </div>
        </div>
      </nav>
    </template>

    <script>
      import $ from './utils/NodeList.js'
      import { toBoolean } from './utils/utils';
      export default {
        props: {
          type: {
            type: String,
            default: 'primary'
          },
          addClass: {
            type: String,
            default: ''
          },
          fixed: {
            type: Boolean,
            default: false
          }
        },
        data () {
          return {
            id: 'bs-example-navbar-collapse-1',
            collapsed: true,
            styles: {}
          }
        },
        computed: {
          fixedBool() {
            return toBoolean(this.fixed);
          },
          fixedOptions() {
            if (this.fixedBool) {
              return 'navbar-fixed';
            }
            return '';
          },
          slots () {
            return this.$slots
          },
          themeOptions () {
            switch (this.type) {
            case 'none':
              return ''
            case 'light':
              return 'navbar-light bg-light'
            case 'dark':
              return 'navbar-dark bg-dark'
            case 'primary':
            default:
              return 'navbar-dark bg-primary'
            }
          }
        },
        methods: {
          toggleCollapse (e) {
            e && e.preventDefault()
            this.collapsed = !this.collapsed
          }
        },
        created () {
          this._navbar = true
        },
        mounted () {
          let $dropdown = $('.dropdown>[data-toggle="dropdown"]',this.$el).parent()
          $dropdown.on('click', '.dropdown-toggle', (e) => {
            e.preventDefault()
            $dropdown.each((content) => {
              if (content.contains(e.target)) content.classList.toggle('open')
            })
          }).on('click', '.dropdown-menu>li>a', (e) => {
            $dropdown.each((content) => {
              if (content.contains(e.target)) content.classList.remove('open')
            })
          }).onBlur((e) => {
            $dropdown.each((content) => {
              if (!content.contains(e.target)) content.classList.remove('open')
            })
          })
          $(this.$el).on('click','li:not(.dropdown)>a', e => {
            setTimeout(() => { this.collapsed = true }, 200)
          }).onBlur(e => {
            if (!this.$el.contains(e.target)) { this.collapsed = true }
          })
          if (this.slots.collapse) $('[data-toggle="collapse"]',this.$el).on('click', (e) => this.toggleCollapse(e))
        },
        beforeDestroy () {
          $('.dropdown',this.$el).off('click').offBlur()
          if (this.slots.collapse) $('[data-toggle="collapse"]',this.$el).off('click')
        }
      }
    </script>

    <style scoped>
      @media (max-width: 767px) {
        .navbar-collapse {
          max-height: 80vh !important;
          overflow-x: hidden !important;
          overflow-y: scroll !important;
        }
      }

      .navbar-fixed {
        position: fixed;
        width: 100%;
        z-index: 1000;
      }
    </style>