forked from saurabh/orbit4-5
148 lines
4.6 KiB
JavaScript
148 lines
4.6 KiB
JavaScript
(function( $ ) {
|
|
|
|
"use strict"
|
|
|
|
function init() {
|
|
var doc = document,
|
|
lang = doc.documentElement.lang,
|
|
pageModule = doc.body.getAttribute( "data-module" );
|
|
|
|
var orbit = {
|
|
|
|
helpers : {
|
|
// Cross-browser class manipulation
|
|
addClass: function( el, className ) {
|
|
if ( el.classList ) {
|
|
el.classList.add( className );
|
|
} else {
|
|
el.className += " " + className;
|
|
}
|
|
},
|
|
hasClass: function( el, cls ) {
|
|
return ( " " + el.className + " " ).indexOf( " " + cls + " " ) > -1;
|
|
}
|
|
},
|
|
|
|
plugins : {
|
|
// RWD image resize script
|
|
bullEye: function() {
|
|
$( ".bullseye" ).bullseye({
|
|
fadeEffect: false
|
|
});
|
|
}
|
|
},
|
|
|
|
nav : {
|
|
// Add class name to the menu item when its child items are more than 8 items
|
|
addMegaDropdownClass: function( els, len, className ) {
|
|
var els = doc.querySelectorAll( els ),
|
|
elsLen = els.length,
|
|
i = -1;
|
|
|
|
if( elsLen > 1 ) {
|
|
for ( i = 0; i < elsLen; i++ ) {
|
|
if ( els[ i ].children.length > len ) {
|
|
this.helpers.addClass( els[ i ].parentNode, className || "mega-dropdown" );
|
|
}
|
|
}
|
|
}
|
|
},
|
|
// Append caret to menu item if it has dropdown
|
|
addCaret: function() {
|
|
var els = doc.querySelectorAll( ".page_menu.level_2" ),
|
|
len = els.length,
|
|
i = -1;
|
|
|
|
for ( i = 0; i < len; i++ ) {
|
|
var node = doc.createElement( "span" );
|
|
node.className = "caret";
|
|
els[ i ].parentNode.appendChild( node );
|
|
}
|
|
}
|
|
},
|
|
|
|
announcement: {
|
|
// Announcement text truncation
|
|
truncateAnnouncement: function( els, maxLen ) {
|
|
var els = doc.querySelectorAll( els ),
|
|
newTitle = "";
|
|
i = -1,
|
|
elsLen = els.length;
|
|
|
|
for ( i = 0; i < elsLen; i ++ ) {
|
|
if ( els[ i ].firstChild !== null ) {
|
|
if( els[ i ].firstChild.length > maxLen ) {
|
|
newTitle = els[ i ].firstChild.textContent;
|
|
els[ i ].textContent = newTitle.substring( 0, maxLen ) + "...";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
member: {
|
|
equalHeight: function() {
|
|
var bigbrother = -1;
|
|
|
|
$( ".i-member-item" ).each( function() {
|
|
bigbrother = bigbrother > $( ".i-member-item" ).height() ? bigbrother : $( ".i-member-item" ).height();
|
|
});
|
|
|
|
$( ".i-member-item" ).each( function() {
|
|
$( ".i-member-item" ).height( bigbrother );
|
|
});
|
|
}
|
|
},
|
|
|
|
// Add link and cursor class name on element that has data-link attribute
|
|
addLinkOnADBanner: function( els ) {
|
|
$.each( els, function() {
|
|
if ( $( this ).data( "link" ) !== "" && !$( this ).hasClass( "youtube" ) ) {
|
|
$( this ).on( "click", function() {
|
|
var target = $( this ).data( "target" ),
|
|
link = $( this ).data( "link" );
|
|
if ( target === "_blank" ) {
|
|
window.open( link, target );
|
|
} else {
|
|
window.location.href = link;
|
|
}
|
|
}).addClass( "cursor" );
|
|
}
|
|
});
|
|
},
|
|
|
|
// Sitemenu dropdown
|
|
sitemenuDropdown: function( els ) {
|
|
var els = doc.querySelectorAll(".sitemenu__list.level-2"),
|
|
len = els.length,
|
|
i = -1;
|
|
for ( i = 0; i < len; i++ ) {
|
|
if ( els[ i ].children.length ) {
|
|
var caret = doc.createElement( "span" );
|
|
caret.className = "sitemenu___dropdown-toggle fa fa-caret-down";
|
|
caret.setAttribute( "data-toggle", "dropdown" );
|
|
|
|
els[ i ].parentNode.insertBefore( caret, els[ i ] );
|
|
this.helpers.addClass( els[ i ], "dropdown-menu" );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Specific functions that will be running on homepage
|
|
if ( pageModule === "home" ) {
|
|
|
|
}
|
|
|
|
// Functions that will be running on every page
|
|
orbit.sitemenuDropdown();
|
|
orbit.member.equalHeight();
|
|
orbit.plugins.bullEye();
|
|
}
|
|
|
|
$( document ).ready(function() {
|
|
init();
|
|
});
|
|
|
|
}( jQuery ));
|