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

147 lines
4.6 KiB
JavaScript
Raw Normal View History

2015-03-23 09:39:58 +00:00
(function( $ ) {
"use strict";
2015-01-06 07:22:41 +00:00
2015-03-06 09:20:26 +00:00
function init() {
2015-03-23 09:39:58 +00:00
var doc = document,
2015-04-14 07:31:41 +00:00
lang = doc.documentElement.lang,
pageModule = doc.body.getAttribute( "data-module" );
2015-01-06 07:22:41 +00:00
2015-03-06 09:20:26 +00:00
var orbit = {
2015-03-23 09:39:58 +00:00
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;
2015-03-06 09:20:26 +00:00
}
2015-03-23 09:39:58 +00:00
},
plugins : {
// RWD image resize script
bullEye: function() {
$( ".bullseye" ).bullseye({
fadeEffect: false
});
2015-03-06 09:20:26 +00:00
}
2015-03-23 09:39:58 +00:00
},
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 );
2014-12-08 06:54:40 +00:00
}
2015-03-06 09:20:26 +00:00
}
2015-03-23 09:39:58 +00:00
},
announcement: {
// Announcement text truncation
truncateAnnouncement: function( els, maxLen ) {
var els = doc.querySelectorAll( els ),
newTitle = "";
i = -1,
elsLen = els.length;
2015-04-14 07:31:41 +00:00
for ( i = 0; i < elsLen; i ++ ) {
2015-03-23 09:39:58 +00:00
if ( els[ i ].firstChild !== null ) {
if( els[ i ].firstChild.length > maxLen ) {
newTitle = els[ i ].firstChild.textContent;
els[ i ].textContent = newTitle.substring( 0, maxLen ) + "...";
}
}
}
2015-03-06 09:20:26 +00:00
}
2015-03-23 09:39:58 +00:00
},
2014-11-12 11:00:18 +00:00
2015-04-14 07:31:41 +00:00
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 );
});
}
},
2015-03-23 09:39:58 +00:00
// 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" );
}
}
}
};
2014-11-12 11:00:18 +00:00
2015-03-06 09:20:26 +00:00
// Specific functions that will be running on homepage
2015-04-14 07:31:41 +00:00
if ( pageModule === "home" ) {
2014-11-12 11:00:18 +00:00
}
2014-11-12 11:00:18 +00:00
2015-03-06 09:20:26 +00:00
// Functions that will be running on every page
orbit.sitemenuDropdown();
2015-03-23 09:39:58 +00:00
orbit.plugins.bullEye();
2015-03-06 09:20:26 +00:00
}
2015-03-23 09:39:58 +00:00
$( document ).ready(function() {
2015-03-06 09:20:26 +00:00
init();
});
2014-11-12 11:00:18 +00:00
2015-03-23 09:39:58 +00:00
}( jQuery ));