orbit4-5/app/templates/orbit_bootstrap/assets/javascripts/app.js

113 lines
3.5 KiB
JavaScript

(function($) {
"use strict"
// Init functions
function init () {
// Announcement modules
var annc = {
truncation : function (el, maxLength) {
for( var i = 0; i < el.length; i ++ ) {
if ( el[i].firstChild !== null ) {
if( el[i].firstChild.length > maxLength ) {
var newTitle = el[i].firstChild.nodeValue;
var newTitle = newTitle.substring(0, maxLength) + '...'
el
.eq(i)
.text(newTitle);
}
}
}
}
}
function anncFix() {
var w$ = $('.w-announcement-4');
if( w$.length ) {
annc.truncation(w$.find('.w-annc__subtitle'), 25);
}
}
// Necessary for Responsive images
function bullEye() {
// $(".bullseye").bullseye({
// fadeEffect: false
// });
}
// Adding class to submenu that has dropdown items
function submenuFix () {
var item$ = $('.submenu__item.level-1');
var itemLen = item$.length;
var list$ = item$.find('.submenu__list.level-2');
for( var i=0; i<itemLen; i++ ) {
if( list$.eq(i).find('li').length ) {
list$
.eq(i)
.addClass('dropdown');
}
}
}
// Main navigation dropdown
function dropdown () {
var navItemLevel1$ = $('.main-nav-item.level-1');
var dropdownMenu$ = $('.dropdown-menu.level-2');
// Adding class if nav item has dropdown
$(navItemLevel1$)
.has('.dropdown-menu')
.children('a')
.addClass('has-dropdown-menu');
// Hide all dropdowns when click on any HTML elements
$(document).on('click', function() {
$('.dropdown-menu.level-2')
.addClass('hide')
.removeClass('show');
})
// Hide all dropdown after page load
dropdownMenu$
.addClass('hide')
.removeClass('show');
$('.has-dropdown-menu').on('click', function () {
if( $(this).hasClass('has-dropdown-menu') ) {
if( $(this).next('.dropdown-menu').hasClass('show') ) {
dropdownMenu$.addClass('hide');
$(this)
.next('.dropdown-menu')
.removeClass('show')
.addClass('hide')
} else if ( $(this).next('.dropdown-menu').hasClass('hide') ) {
dropdownMenu$.addClass('hide');
dropdownMenu$.removeClass('show');
dropdownMenu$.addClass('hide');
$(this)
.next('.dropdown-menu')
.removeClass('hide')
.addClass('show')
}
}
return false;
})
}
// Targeting internal page
if( $('body').attr('class') !== 'page-main' ) {
submenuFix();
}
dropdown();
bullEye();
}
$(document).ready(function($) {
init();
});
}(jQuery));