forked from saurabh/orbit4-5
189 lines
6.9 KiB
JavaScript
189 lines
6.9 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);
|
|
});
|
|
},
|
|
|
|
// Remove table row, list item if it only has sigle title or value not in pair
|
|
removeEmptyRow: function() {
|
|
// Remove index page empty item
|
|
$('.i-member-profile-item .i-member-value').each(function() {
|
|
if ($(this).text().trim() === '' || $(this).text().trim() === ':') {
|
|
$(this).parent().addClass('hide');
|
|
}
|
|
});
|
|
|
|
// Remove empty table cell on show page
|
|
$('.show-member th, .show-member td').each(function() {
|
|
if ($(this).text().trim() === '') {
|
|
$(this).parent('tr').addClass('hide');
|
|
}
|
|
});
|
|
},
|
|
},
|
|
|
|
// 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');
|
|
}
|
|
}
|
|
},
|
|
|
|
// Go back top button
|
|
goBackTop: function(txt, speed) {
|
|
var top = document.createElement('div');
|
|
top.className = 'go-back-top';
|
|
top.textContent = txt;
|
|
doc.body.appendChild(top);
|
|
|
|
$(window).scroll(function() {
|
|
if($(this).scrollTop() != 0) {
|
|
$('.go-back-top').fadeIn();
|
|
} else {
|
|
$('.go-back-top').fadeOut();
|
|
}
|
|
});
|
|
|
|
$('.go-back-top').click(function() {
|
|
$('body, html').animate({scrollTop:0}, speed);
|
|
return false;
|
|
});
|
|
}
|
|
|
|
};
|
|
// Specific functions that will be running on homepage
|
|
if (pageModule === 'home') {
|
|
|
|
|
|
}
|
|
if (pageModule === 'member') {
|
|
orbit.member.removeEmptyRow();
|
|
}
|
|
|
|
// Functions that will be running on every page
|
|
orbit.sitemenuDropdown();
|
|
orbit.goBackTop('top', 800);
|
|
orbit.plugins.bullEye();
|
|
}
|
|
|
|
// Run the init function when DOM is ready
|
|
$(document).ready(function() {
|
|
init();
|
|
});
|
|
|
|
}(jQuery)); |