first commit
This commit is contained in:
1004
public/assets/js/rd-navbar/jquery.rd-navbar.css
Normal file
1004
public/assets/js/rd-navbar/jquery.rd-navbar.css
Normal file
File diff suppressed because it is too large
Load Diff
717
public/assets/js/rd-navbar/jquery.rd-navbar.js
Normal file
717
public/assets/js/rd-navbar/jquery.rd-navbar.js
Normal file
@ -0,0 +1,717 @@
|
||||
/**
|
||||
* @module RD Navbar
|
||||
* @author Evgeniy Gusarov
|
||||
* @version 2.2.5
|
||||
*/
|
||||
(function() {
|
||||
var isTouch;
|
||||
|
||||
isTouch = "ontouchstart" in window;
|
||||
|
||||
(function($, document, window) {
|
||||
|
||||
/**
|
||||
* Creates a RDNavbar.
|
||||
* @class RDNavbar.
|
||||
* @public
|
||||
* @param {HTMLElement} element - The element to create the RDNavbar for.
|
||||
* @param {Object} [options] - The options
|
||||
*/
|
||||
var RDNavbar;
|
||||
RDNavbar = (function() {
|
||||
|
||||
/**
|
||||
* Default options for RDNavbar.
|
||||
* @protected
|
||||
*/
|
||||
RDNavbar.prototype.Defaults = {
|
||||
layout: 'rd-navbar-static',
|
||||
deviceLayout: 'rd-navbar-fixed',
|
||||
focusOnHover: true,
|
||||
focusOnHoverTimeout: 800,
|
||||
linkedElements: ["html"],
|
||||
domAppend: true,
|
||||
stickUp: true,
|
||||
stickUpClone: true,
|
||||
stickUpOffset: '100%',
|
||||
anchorNav: true,
|
||||
anchorNavSpeed: 400,
|
||||
anchorNavOffset: 0,
|
||||
anchorNavEasing: 'swing',
|
||||
autoHeight: true,
|
||||
responsive: {
|
||||
0: {
|
||||
layout: "rd-navbar-fixed",
|
||||
deviceLayout: "rd-navbar-fixed",
|
||||
focusOnHover: false,
|
||||
stickUp: false
|
||||
},
|
||||
1200: {
|
||||
layout: "rd-navbar-static",
|
||||
deviceLayout: "rd-navbar-static",
|
||||
focusOnHover: true,
|
||||
stickUp: true
|
||||
}
|
||||
},
|
||||
callbacks: {
|
||||
onToggleSwitch: false,
|
||||
onToggleClose: false,
|
||||
onDomAppend: false,
|
||||
onDropdownOver: false,
|
||||
onDropdownOut: false,
|
||||
onDropdownToggle: false,
|
||||
onDropdownClose: false,
|
||||
onStuck: false,
|
||||
onUnstuck: false,
|
||||
onAnchorChange: false
|
||||
}
|
||||
};
|
||||
|
||||
function RDNavbar(element, options) {
|
||||
|
||||
/**
|
||||
* Current options set
|
||||
* @public
|
||||
*/
|
||||
this.options = $.extend(true, {}, this.Defaults, options);
|
||||
|
||||
/**
|
||||
* Plugin element
|
||||
* @public
|
||||
*/
|
||||
this.$element = $(element);
|
||||
|
||||
/**
|
||||
* Plugin element clone
|
||||
* @public
|
||||
*/
|
||||
this.$clone = null;
|
||||
|
||||
/**
|
||||
* Additional references
|
||||
* @public
|
||||
*/
|
||||
this.$win = $(window);
|
||||
this.$doc = $(document);
|
||||
this.currentLayout = this.options.layout;
|
||||
this.loaded = false;
|
||||
this.focusOnHover = this.options.focusOnHover;
|
||||
this.focusTimer = false;
|
||||
this.cloneTimer = false;
|
||||
this.isStuck = false;
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the RDNavbar.
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.initialize = function() {
|
||||
var ctx;
|
||||
ctx = this;
|
||||
ctx.$element.addClass("rd-navbar").addClass(ctx.options.layout);
|
||||
if (isTouch) {
|
||||
ctx.$element.addClass("rd-navbar--is-touch");
|
||||
}
|
||||
if (ctx.options.domAppend) {
|
||||
ctx.createNav(ctx);
|
||||
}
|
||||
if (ctx.options.stickUpClone) {
|
||||
ctx.createClone(ctx);
|
||||
}
|
||||
ctx.$element.addClass('rd-navbar-original');
|
||||
ctx.addAdditionalClassToToggles('.rd-navbar-original', 'toggle-original', 'toggle-original-elements');
|
||||
ctx.applyHandlers(ctx);
|
||||
ctx.offset = ctx.$element.offset().top;
|
||||
ctx.height = ctx.$element.outerHeight();
|
||||
ctx.loaded = true;
|
||||
return ctx;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Changes {ctx.$element} layout basing on screen resolution
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.resize = function(ctx, e) {
|
||||
var targetElement, targetLayout;
|
||||
targetLayout = isTouch ? ctx.getOption('deviceLayout') : ctx.getOption('layout');
|
||||
targetElement = ctx.$element.add(ctx.$clone);
|
||||
if (targetLayout !== ctx.currentLayout || !ctx.loaded) {
|
||||
ctx.switchClass(targetElement, ctx.currentLayout, targetLayout);
|
||||
if (ctx.options.linkedElements != null) {
|
||||
$.grep(ctx.options.linkedElements, function(link, index) {
|
||||
return ctx.switchClass(link, ctx.currentLayout + '-linked', targetLayout + '-linked');
|
||||
});
|
||||
}
|
||||
ctx.currentLayout = targetLayout;
|
||||
}
|
||||
ctx.focusOnHover = ctx.getOption('focusOnHover');
|
||||
return ctx;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Toggles bar stickup on scroll
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.stickUp = function(ctx, e) {
|
||||
var scrollTop, stickUp, stickUpOffset, targetElement, threshold;
|
||||
stickUp = ctx.getOption("stickUp");
|
||||
if ($('html').hasClass('ios') || ctx.$element.hasClass('rd-navbar-fixed')) {
|
||||
stickUp = false;
|
||||
}
|
||||
scrollTop = ctx.$doc.scrollTop();
|
||||
targetElement = ctx.$clone != null ? ctx.$clone : ctx.$element;
|
||||
stickUpOffset = ctx.getOption('stickUpOffset');
|
||||
threshold = (typeof stickUpOffset === 'string' ? (stickUpOffset.indexOf('%') > 0 ? parseFloat(stickUpOffset) * ctx.height / 100 : parseFloat(stickUpOffset)) : stickUpOffset);
|
||||
if (stickUp) {
|
||||
if ((scrollTop >= threshold && !ctx.isStuck) || (scrollTop < threshold && ctx.isStuck)) {
|
||||
ctx.$element.add(ctx.$clone).find('[data-rd-navbar-toggle]').each(function() {
|
||||
$.proxy(ctx.closeToggle, this)(ctx, false);
|
||||
}).end().find('.rd-navbar-submenu').removeClass('opened').removeClass('focus');
|
||||
if (scrollTop >= threshold && !ctx.isStuck && !ctx.$element.hasClass('rd-navbar-fixed')) {
|
||||
if (ctx.options.callbacks.onStuck) {
|
||||
ctx.options.callbacks.onStuck.call(ctx);
|
||||
}
|
||||
|
||||
|
||||
setTimeout(function(){
|
||||
if (e.type === 'resize') {
|
||||
ctx.switchClass(targetElement, '', 'rd-navbar--is-stuck');
|
||||
} else {
|
||||
targetElement.addClass('rd-navbar--is-stuck');
|
||||
}
|
||||
ctx.isStuck = true;
|
||||
}, navigator.platform.match(/(Mac)/i) ? 10 : 0);
|
||||
|
||||
} else {
|
||||
if (e.type === 'resize') {
|
||||
ctx.switchClass(targetElement, 'rd-navbar--is-stuck', '');
|
||||
} else {
|
||||
targetElement.removeClass('rd-navbar--is-stuck').one('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', $.proxy(ctx.resizeWrap, ctx, e));
|
||||
}
|
||||
ctx.isStuck = false;
|
||||
if (ctx.options.callbacks.onUnstuck) {
|
||||
ctx.options.callbacks.onUnstuck.call(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ctx.$element.find('.rd-navbar-submenu').removeClass('opened').removeClass('focus');
|
||||
if (ctx.isStuck) {
|
||||
ctx.switchClass(targetElement, 'rd-navbar--is-stuck', '');
|
||||
ctx.isStuck = false;
|
||||
ctx.resizeWrap(e);
|
||||
}
|
||||
}
|
||||
return ctx;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Resizes an external wrap of navbar
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.resizeWrap = function(e) {
|
||||
var $wrap, ctx;
|
||||
ctx = this;
|
||||
if ((ctx.$clone == null) && !ctx.isStuck) {
|
||||
$wrap = ctx.$element.parent();
|
||||
if (!ctx.getOption('autoHeight')) {
|
||||
$wrap.css('height', 'auto');
|
||||
return;
|
||||
}
|
||||
ctx.height = ctx.$element.outerHeight();
|
||||
if (e.type === 'resize') {
|
||||
$wrap.addClass('rd-navbar--no-transition').css('height', ctx.height);
|
||||
$wrap[0].offsetHeight;
|
||||
return $wrap.removeClass('rd-navbar--no-transition');
|
||||
} else {
|
||||
return $wrap.css('height', ctx.height);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates additional DOM for navigation functionality
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.createNav = function(ctx) {
|
||||
ctx.$element.find('.rd-navbar-dropdown, .rd-navbar-megamenu').each(function() {
|
||||
var $this, rect;
|
||||
$this = $(this);
|
||||
rect = this.getBoundingClientRect();
|
||||
if ($this.hasClass('rd-navbar-megamenu')) {
|
||||
return $this.parent().addClass('rd-navbar--has-megamenu');
|
||||
} else {
|
||||
return $this.parent().addClass('rd-navbar--has-dropdown');
|
||||
}
|
||||
}).parents("li").addClass("rd-navbar-submenu");
|
||||
$('<span class="rd-navbar-submenu-toggle"></span>').insertAfter('.rd-navbar-nav li.rd-navbar-submenu > a');
|
||||
if (ctx.options.callbacks.onDomAppend) {
|
||||
ctx.options.callbacks.onDomAppend.call(this);
|
||||
}
|
||||
return ctx;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates navbar clone to stick up
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.createClone = function(ctx) {
|
||||
ctx.$clone = ctx.$element.clone().insertAfter(ctx.$element).addClass('rd-navbar--is-clone');
|
||||
ctx.addAdditionalClassToToggles('.rd-navbar--is-clone', 'toggle-cloned', 'toggle-cloned-elements');
|
||||
return ctx;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Closes all toggles on outside click of each item
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.closeToggle = function(ctx, e) {
|
||||
var $items, $target, additionalToggleElClass, additionalToogleClass, collapse, linkedElements, needClose;
|
||||
$target = $(e.target);
|
||||
collapse = false;
|
||||
linkedElements = this.getAttribute('data-rd-navbar-toggle');
|
||||
if (ctx.options.stickUpClone && ctx.isStuck) {
|
||||
additionalToogleClass = '.toggle-cloned';
|
||||
additionalToggleElClass = '.toggle-cloned-elements';
|
||||
needClose = !$target.hasClass('toggle-cloned');
|
||||
} else {
|
||||
additionalToogleClass = '.toggle-original';
|
||||
additionalToggleElClass = '.toggle-original-elements';
|
||||
needClose = !$target.hasClass('toggle-original');
|
||||
}
|
||||
if (e.target !== this && !$target.parents(additionalToogleClass + '[data-rd-navbar-toggle]').length && !$target.parents(additionalToggleElClass).length && linkedElements && needClose) {
|
||||
$items = $(this).parents('body').find(linkedElements).add($(this).parents('.rd-navbar')[0]);
|
||||
$items.each(function() {
|
||||
if (!collapse) {
|
||||
return collapse = (e.target === this || $.contains(this, e.target)) === true;
|
||||
}
|
||||
});
|
||||
if (!collapse) {
|
||||
$items.add(this).removeClass('active');
|
||||
if (ctx.options.callbacks.onToggleClose) {
|
||||
ctx.options.callbacks.onToggleClose.call(this, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Switches toggle
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.switchToggle = function(ctx, e) {
|
||||
var additionalToggleElClass, linkedElements, navbarClass;
|
||||
e.preventDefault();
|
||||
if ($(this).hasClass('toggle-cloned')) {
|
||||
navbarClass = '.rd-navbar--is-clone';
|
||||
additionalToggleElClass = '.toggle-cloned-elements';
|
||||
} else {
|
||||
navbarClass = '.rd-navbar-original';
|
||||
additionalToggleElClass = '.toggle-original-elements';
|
||||
}
|
||||
if (linkedElements = this.getAttribute('data-rd-navbar-toggle')) {
|
||||
$(navbarClass + ' [data-rd-navbar-toggle]').not(this).each(function() {
|
||||
var deactivateElements;
|
||||
if (deactivateElements = this.getAttribute('data-rd-navbar-toggle')) {
|
||||
return $(this).parents('body').find(navbarClass + ' ' + deactivateElements + additionalToggleElClass).add(this).add($.inArray('.rd-navbar', deactivateElements.split(/\s*,\s*/i)) > -1 ? $(this).parents('body')[0] : false).removeClass('active');
|
||||
}
|
||||
});
|
||||
$(this).parents('body').find(navbarClass + ' ' + linkedElements + additionalToggleElClass).add(this).add($.inArray('.rd-navbar', linkedElements.split(/\s*,\s*/i)) > -1 ? $(this).parents('.rd-navbar')[0] : false).toggleClass('active');
|
||||
}
|
||||
if (ctx.options.callbacks.onToggleSwitch) {
|
||||
ctx.options.callbacks.onToggleSwitch.call(this, ctx);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Triggers submenu popup to be shown on mouseover
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.dropdownOver = function(ctx, timer) {
|
||||
var $this;
|
||||
if (ctx.focusOnHover) {
|
||||
$this = $(this);
|
||||
clearTimeout(timer);
|
||||
if (ctx.options.callbacks.onDropdownOver) {
|
||||
if (!ctx.options.callbacks.onDropdownOver.call(this, ctx)){
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
$this.addClass('focus').siblings().removeClass('opened').each(ctx.dropdownUnfocus);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Triggers submenu popup to be shown on mouseover
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.dropdownTouch = function(ctx, timer) {
|
||||
var $this, hasFocus;
|
||||
$this = $(this);
|
||||
clearTimeout(timer);
|
||||
if (ctx.focusOnHover) {
|
||||
hasFocus = false;
|
||||
if ($this.hasClass('focus')) {
|
||||
hasFocus = true;
|
||||
}
|
||||
if (!hasFocus) {
|
||||
$this.addClass('focus').siblings().removeClass('opened').each(ctx.dropdownUnfocus);
|
||||
return false;
|
||||
}
|
||||
if (ctx.options.callbacks.onDropdownOver) {
|
||||
ctx.options.callbacks.onDropdownOver.call(this, ctx);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Triggers submenu popop to be hidden on mouseout
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.dropdownOut = function(ctx, timer) {
|
||||
var $this;
|
||||
if (ctx.focusOnHover) {
|
||||
$this = $(this);
|
||||
$this.one('mouseenter.navbar', function() {
|
||||
return clearTimeout(timer);
|
||||
});
|
||||
|
||||
if (ctx.options.callbacks.onDropdownOut) {
|
||||
ctx.options.callbacks.onDropdownOut.call(this, ctx);
|
||||
}
|
||||
clearTimeout(timer);
|
||||
|
||||
timer = setTimeout($.proxy(ctx.dropdownUnfocus, this, ctx), ctx.options.focusOnHoverTimeout);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Removes a focus from submenu
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.dropdownUnfocus = function(ctx) {
|
||||
var $this;
|
||||
$this = $(this);
|
||||
$this.find('li.focus').add(this).removeClass('focus');
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Closes submenu
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.dropdownClose = function(ctx, e) {
|
||||
var $this;
|
||||
if (e.target !== this && !$(e.target).parents('.rd-navbar-submenu').length) {
|
||||
$this = $(this);
|
||||
$this.find('li.focus').add(this).removeClass('focus').removeClass('opened');
|
||||
if (ctx.options.callbacks.onDropdownClose) {
|
||||
ctx.options.callbacks.onDropdownClose.call(this, ctx);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Toggles submenu popup to be shown on trigger click
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.dropdownToggle = function(ctx) {
|
||||
$(this).toggleClass('opened').siblings().removeClass('opened');
|
||||
if (ctx.options.callbacks.onDropdownToggle) {
|
||||
ctx.options.callbacks.onDropdownToggle.call(this, ctx);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Scrolls the page to triggered anchor
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.goToAnchor = function(ctx, e) {
|
||||
var $anchor, hash;
|
||||
hash = this.hash;
|
||||
$anchor = $(hash);
|
||||
|
||||
if (!ctx.getOption('anchorNav')){
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($anchor.length) {
|
||||
e.preventDefault();
|
||||
$('html, body').stop().animate({
|
||||
'scrollTop': $anchor.offset().top + ctx.getOption('anchorNavOffset') + 1
|
||||
}, ctx.getOption('anchorNavSpeed'), ctx.getOption('anchorNavEasing'), function() {
|
||||
return ctx.changeAnchor(hash);
|
||||
});
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Highlight an active anchor
|
||||
* @protected
|
||||
*/
|
||||
|
||||
/* RDNavbar.prototype.activateAnchor = function(e) {
|
||||
var $anchor, $item, $link, ctx, docHeight, hash, i, link, links, navOffset, scrollTop, winHeight;
|
||||
ctx = this;
|
||||
scrollTop = ctx.$doc.scrollTop();
|
||||
winHeight = ctx.$win.height();
|
||||
docHeight = ctx.$doc.height();
|
||||
navOffset = ctx.getOption('anchorNavOffset');
|
||||
|
||||
if (!ctx.options.anchorNav){
|
||||
return false;
|
||||
}
|
||||
|
||||
if (scrollTop + winHeight > docHeight - 50) {
|
||||
$anchor = $('[data-type="anchor"]').last();
|
||||
if ($anchor.length) {
|
||||
if ($anchor.offset().top >= scrollTop) {
|
||||
hash = '#' + $anchor.attr("id");
|
||||
$item = $('.rd-navbar-nav a[href^="' + hash + '"]').parent();
|
||||
if (!$item.hasClass('active')) {
|
||||
$item.addClass('active').siblings().removeClass('active');
|
||||
if (ctx.options.callbacks.onAnchorChange) {
|
||||
ctx.options.callbacks.onAnchorChange.call($anchor[0], ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $anchor;
|
||||
} else {
|
||||
links = $('.rd-navbar-nav a[href^="#"]').get();
|
||||
for (i in links) {
|
||||
link = links[i];
|
||||
$link = $(link);
|
||||
hash = $link.attr('href');
|
||||
$anchor = $(hash);
|
||||
if ($anchor.length) {
|
||||
if ($anchor.offset().top + navOffset <= scrollTop && $anchor.offset().top + $anchor.outerHeight() > scrollTop) {
|
||||
$link.parent().addClass('active').siblings().removeClass('active');
|
||||
if (ctx.options.callbacks.onAnchorChange) {
|
||||
ctx.options.callbacks.onAnchorChange.call($anchor[0], ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns current anchor
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.getAnchor = function() {
|
||||
if (history) {
|
||||
if (history.state) {
|
||||
return history.state.id;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Changes current page anchor
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.changeAnchor = function(hash) {
|
||||
if (history) {
|
||||
if (history.state) {
|
||||
if (history.state.id !== hash) {
|
||||
history.replaceState({
|
||||
'anchorId': hash
|
||||
}, null, hash);
|
||||
} else {
|
||||
history.pushState({
|
||||
'anchorId': hash
|
||||
}, null, hash);
|
||||
}
|
||||
} else {
|
||||
history.pushState({
|
||||
'anchorId': hash
|
||||
}, null, hash);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Applies all JS event handlers
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.applyHandlers = function(ctx) {
|
||||
if (ctx.options.responsive != null) {
|
||||
ctx.$win.on('resize.navbar', $.proxy(ctx.resize, ctx.$win[0], ctx)).on('resize.navbar', $.proxy(ctx.resizeWrap, ctx)).on('resize.navbar', $.proxy(ctx.stickUp, (ctx.$clone != null ? ctx.$clone : ctx.$element), ctx)).on('orientationchange.navbar', $.proxy(ctx.resize, ctx.$win[0], ctx)).trigger('resize.navbar');
|
||||
}
|
||||
ctx.$doc.on('scroll.navbar', $.proxy(ctx.stickUp, (ctx.$clone != null ? ctx.$clone : ctx.$element), ctx)).on('scroll.navbar', $.proxy(ctx.activateAnchor, ctx));
|
||||
ctx.$element.add(ctx.$clone).find('[data-rd-navbar-toggle]').each(function() {
|
||||
var $this;
|
||||
$this = $(this);
|
||||
$this.on('click', $.proxy(ctx.switchToggle, this, ctx));
|
||||
return $this.parents('body').on('click', $.proxy(ctx.closeToggle, this, ctx));
|
||||
});
|
||||
ctx.$element.add(ctx.$clone).find('.rd-navbar-submenu').each(function() {
|
||||
var $this, timer;
|
||||
$this = $(this);
|
||||
timer = $this.parents(".rd-navbar--is-clone").length ? ctx.cloneTimer : ctx.focusTimer;
|
||||
$this.on('mouseleave.navbar', $.proxy(ctx.dropdownOut, this, ctx, timer));
|
||||
$this.find('> a').on('mouseenter.navbar', $.proxy(ctx.dropdownOver, this, ctx, timer));
|
||||
$this.find('> a').on('touchstart.navbar', $.proxy(ctx.dropdownTouch, this, ctx, timer));
|
||||
$this.find('> .rd-navbar-submenu-toggle').on('click', $.proxy(ctx.dropdownToggle, this, ctx));
|
||||
return $this.parents('body').on('click', $.proxy(ctx.dropdownClose, this, ctx));
|
||||
});
|
||||
ctx.$element.add(ctx.$clone).find('.rd-navbar-nav a[href^="#"]').each(function() {
|
||||
return $(this).on('click', $.proxy(ctx.goToAnchor, this, ctx));
|
||||
});
|
||||
|
||||
ctx.$element.find('.rd-navbar-dropdown, .rd-navbar-megamenu').each(function() {
|
||||
var $this, rect;
|
||||
$this = $(this);
|
||||
rect = this.getBoundingClientRect();
|
||||
if ((rect.left + $this.outerWidth()) >= window.innerWidth - 10) {
|
||||
this.className += ' rd-navbar-open-left';
|
||||
} else if ((rect.left - $this.outerWidth()) <= 10) {
|
||||
this.className += ' rd-navbar-open-right';
|
||||
}
|
||||
});
|
||||
|
||||
return ctx;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Switches classes of elements without transition
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.switchClass = function(element, before, after) {
|
||||
var obj;
|
||||
obj = element instanceof jQuery ? element : $(element);
|
||||
obj.addClass('rd-navbar--no-transition').removeClass(before).addClass(after);
|
||||
obj[0].offsetHeight;
|
||||
return obj.removeClass('rd-navbar--no-transition');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Gets specific option of plugin
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.getOption = function(key) {
|
||||
var point, targetPoint;
|
||||
for (point in this.options.responsive) {
|
||||
if (point <= window.innerWidth) {
|
||||
targetPoint = point;
|
||||
}
|
||||
}
|
||||
if ((this.options.responsive != null) && (this.options.responsive[targetPoint][key] != null)) {
|
||||
return this.options.responsive[targetPoint][key];
|
||||
} else {
|
||||
return this.options[key];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Add additional class to navbar toggles to identify it when navbar is cloned
|
||||
* @protected
|
||||
*/
|
||||
|
||||
RDNavbar.prototype.addAdditionalClassToToggles = function(navbarClass, toggleAdditionalClass, toggleElAdditionalClass) {
|
||||
return $(navbarClass).find('[data-rd-navbar-toggle]').each(function() {
|
||||
var toggleElement;
|
||||
$(this).addClass(toggleAdditionalClass);
|
||||
toggleElement = this.getAttribute('data-rd-navbar-toggle');
|
||||
return $(this).parents('body').find(navbarClass).find(toggleElement).addClass(toggleElAdditionalClass);
|
||||
});
|
||||
};
|
||||
|
||||
return RDNavbar;
|
||||
|
||||
})();
|
||||
|
||||
/**
|
||||
* The jQuery Plugin for the RD Navbar
|
||||
* @public
|
||||
*/
|
||||
$.fn.extend({
|
||||
RDNavbar: function(options) {
|
||||
var $this;
|
||||
$this = $(this);
|
||||
if (!$this.data('RDNavbar')) {
|
||||
return $this.data('RDNavbar', new RDNavbar(this, options));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* RD Navbar window export
|
||||
* @public
|
||||
*/
|
||||
});
|
||||
return window.RDNavbar = RDNavbar;
|
||||
})(window.jQuery, document, window);
|
||||
|
||||
|
||||
/**
|
||||
* The Plugin AMD export
|
||||
* @public
|
||||
*/
|
||||
|
||||
if (typeof module !== "undefined" && module !== null) {
|
||||
module.exports = window.RDNavbar;
|
||||
} else if (typeof define === 'function' && define.amd) {
|
||||
define(["jquery"], function() {
|
||||
'use strict';
|
||||
return window.RDNavbar;
|
||||
});
|
||||
}
|
||||
|
||||
}).call(this);
|
28
public/assets/js/rd-navbar/jquery.rd-navbar.min.js
vendored
Normal file
28
public/assets/js/rd-navbar/jquery.rd-navbar.min.js
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @module RD Navbar
|
||||
* @author Evgeniy Gusarov
|
||||
* @version 2.2.5
|
||||
*/
|
||||
(function(){var l="ontouchstart"in window;(function(c,n,h){var m=function(){function b(a,e){this.options=c.extend(!0,{},this.Defaults,e);this.$element=c(a);this.$clone=null;this.$win=c(h);this.$doc=c(n);this.currentLayout=this.options.layout;this.loaded=!1;this.focusOnHover=this.options.focusOnHover;this.isStuck=this.cloneTimer=this.focusTimer=!1;this.initialize()}b.prototype.Defaults={layout:"rd-navbar-static",deviceLayout:"rd-navbar-fixed",focusOnHover:!0,focusOnHoverTimeout:800,linkedElements:["html"],
|
||||
domAppend:!0,stickUp:!0,stickUpClone:!0,stickUpOffset:"100%",anchorNav:!0,anchorNavSpeed:400,anchorNavOffset:0,anchorNavEasing:"swing",autoHeight:!0,responsive:{0:{layout:"rd-navbar-fixed",deviceLayout:"rd-navbar-fixed",focusOnHover:!1,stickUp:!1},992:{layout:"rd-navbar-static",deviceLayout:"rd-navbar-static",focusOnHover:!0,stickUp:!0}},callbacks:{onToggleSwitch:!1,onToggleClose:!1,onDomAppend:!1,onDropdownOver:!1,onDropdownOut:!1,onDropdownToggle:!1,onDropdownClose:!1,onStuck:!1,onUnstuck:!1,onAnchorChange:!1}};
|
||||
b.prototype.initialize=function(){this.$element.addClass("rd-navbar").addClass(this.options.layout);l&&this.$element.addClass("rd-navbar--is-touch");this.options.domAppend&&this.createNav(this);this.options.stickUpClone&&this.createClone(this);this.$element.addClass("rd-navbar-original");this.addAdditionalClassToToggles(".rd-navbar-original","toggle-original","toggle-original-elements");this.applyHandlers(this);this.offset=this.$element.offset().top;this.height=this.$element.outerHeight();this.loaded=
|
||||
!0;return this};b.prototype.resize=function(a,e){var d=l?a.getOption("deviceLayout"):a.getOption("layout");var g=a.$element.add(a.$clone);d===a.currentLayout&&a.loaded||(a.switchClass(g,a.currentLayout,d),null!=a.options.linkedElements&&c.grep(a.options.linkedElements,function(e,c){return a.switchClass(e,a.currentLayout+"-linked",d+"-linked")}),a.currentLayout=d);a.focusOnHover=a.getOption("focusOnHover");return a};b.prototype.stickUp=function(a,e){var d=a.getOption("stickUp");if(c("html").hasClass("ios")||
|
||||
a.$element.hasClass("rd-navbar-fixed"))d=!1;var g=a.$doc.scrollTop();var b=null!=a.$clone?a.$clone:a.$element;var f=a.getOption("stickUpOffset");f="string"===typeof f?0<f.indexOf("%")?parseFloat(f)*a.height/100:parseFloat(f):f;if(d){if(g>=f&&!a.isStuck||g<f&&a.isStuck)if(a.$element.add(a.$clone).find("[data-rd-navbar-toggle]").each(function(){c.proxy(a.closeToggle,this)(a,!1)}).end().find(".rd-navbar-submenu").removeClass("opened").removeClass("focus"),g>=f&&!a.isStuck&&!a.$element.hasClass("rd-navbar-fixed"))a.options.callbacks.onStuck&&
|
||||
a.options.callbacks.onStuck.call(a),setTimeout(function(){"resize"===e.type?a.switchClass(b,"","rd-navbar--is-stuck"):b.addClass("rd-navbar--is-stuck");a.isStuck=!0},navigator.platform.match(/(Mac)/i)?10:0);else{if("resize"===e.type)a.switchClass(b,"rd-navbar--is-stuck","");else b.removeClass("rd-navbar--is-stuck").one("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd",c.proxy(a.resizeWrap,a,e));a.isStuck=!1;a.options.callbacks.onUnstuck&&a.options.callbacks.onUnstuck.call(a)}}else a.$element.find(".rd-navbar-submenu").removeClass("opened").removeClass("focus"),
|
||||
a.isStuck&&(a.switchClass(b,"rd-navbar--is-stuck",""),a.isStuck=!1,a.resizeWrap(e));return a};b.prototype.resizeWrap=function(a){if(null==this.$clone&&!this.isStuck){var e=this.$element.parent();if(this.getOption("autoHeight"))return this.height=this.$element.outerHeight(),"resize"===a.type?(e.addClass("rd-navbar--no-transition").css("height",this.height),e[0].offsetHeight,e.removeClass("rd-navbar--no-transition")):e.css("height",this.height);e.css("height","auto")}};b.prototype.createNav=function(a){a.$element.find(".rd-navbar-dropdown, .rd-navbar-megamenu").each(function(){var a=
|
||||
c(this);this.getBoundingClientRect();return a.hasClass("rd-navbar-megamenu")?a.parent().addClass("rd-navbar--has-megamenu"):a.parent().addClass("rd-navbar--has-dropdown")}).parents("li").addClass("rd-navbar-submenu");c('<span class="rd-navbar-submenu-toggle"></span>').insertAfter(".rd-navbar-nav li.rd-navbar-submenu > a");a.options.callbacks.onDomAppend&&a.options.callbacks.onDomAppend.call(this);return a};b.prototype.createClone=function(a){a.$clone=a.$element.clone().insertAfter(a.$element).addClass("rd-navbar--is-clone");
|
||||
a.addAdditionalClassToToggles(".rd-navbar--is-clone","toggle-cloned","toggle-cloned-elements");return a};b.prototype.closeToggle=function(a,e){var d=c(e.target);var g=!1;var b=this.getAttribute("data-rd-navbar-toggle");if(a.options.stickUpClone&&a.isStuck){var f=".toggle-cloned";var k=".toggle-cloned-elements";var h=!d.hasClass("toggle-cloned")}else f=".toggle-original",k=".toggle-original-elements",h=!d.hasClass("toggle-original");e.target!==this&&!d.parents(f+"[data-rd-navbar-toggle]").length&&
|
||||
!d.parents(k).length&&b&&h&&(d=c(this).parents("body").find(b).add(c(this).parents(".rd-navbar")[0]),d.each(function(){if(!g)return g=!0===(e.target===this||c.contains(this,e.target))}),g||(d.add(this).removeClass("active"),a.options.callbacks.onToggleClose&&a.options.callbacks.onToggleClose.call(this,a)));return this};b.prototype.switchToggle=function(a,e){var d;e.preventDefault();if(c(this).hasClass("toggle-cloned")){var g=".rd-navbar--is-clone";var b=".toggle-cloned-elements"}else g=".rd-navbar-original",
|
||||
b=".toggle-original-elements";if(d=this.getAttribute("data-rd-navbar-toggle"))c(g+" [data-rd-navbar-toggle]").not(this).each(function(){var a;if(a=this.getAttribute("data-rd-navbar-toggle"))return c(this).parents("body").find(g+" "+a+b).add(this).add(-1<c.inArray(".rd-navbar",a.split(/\s*,\s*/i))?c(this).parents("body")[0]:!1).removeClass("active")}),c(this).parents("body").find(g+" "+d+b).add(this).add(-1<c.inArray(".rd-navbar",d.split(/\s*,\s*/i))?c(this).parents(".rd-navbar")[0]:!1).toggleClass("active");
|
||||
a.options.callbacks.onToggleSwitch&&a.options.callbacks.onToggleSwitch.call(this,a);return this};b.prototype.dropdownOver=function(a,e){if(a.focusOnHover){var d=c(this);clearTimeout(e);if(a.options.callbacks.onDropdownOver&&!a.options.callbacks.onDropdownOver.call(this,a))return this;d.addClass("focus").siblings().removeClass("opened").each(a.dropdownUnfocus)}return this};b.prototype.dropdownTouch=function(a,e){var d=c(this);clearTimeout(e);if(a.focusOnHover){var b=!1;d.hasClass("focus")&&(b=!0);
|
||||
if(!b)return d.addClass("focus").siblings().removeClass("opened").each(a.dropdownUnfocus),!1;a.options.callbacks.onDropdownOver&&a.options.callbacks.onDropdownOver.call(this,a)}return this};b.prototype.dropdownOut=function(a,e){if(a.focusOnHover){var d=c(this);d.one("mouseenter.navbar",function(){return clearTimeout(e)});a.options.callbacks.onDropdownOut&&a.options.callbacks.onDropdownOut.call(this,a);clearTimeout(e);e=setTimeout(c.proxy(a.dropdownUnfocus,this,a),a.options.focusOnHoverTimeout)}return this};
|
||||
b.prototype.dropdownUnfocus=function(a){c(this).find("li.focus").add(this).removeClass("focus");return this};b.prototype.dropdownClose=function(a,e){if(e.target!==this&&!c(e.target).parents(".rd-navbar-submenu").length){var d=c(this);d.find("li.focus").add(this).removeClass("focus").removeClass("opened");a.options.callbacks.onDropdownClose&&a.options.callbacks.onDropdownClose.call(this,a)}return this};b.prototype.dropdownToggle=function(a){c(this).toggleClass("opened").siblings().removeClass("opened");
|
||||
a.options.callbacks.onDropdownToggle&&a.options.callbacks.onDropdownToggle.call(this,a);return this};b.prototype.goToAnchor=function(a,e){var d=this.hash;var b=c(d);if(!a.getOption("anchorNav"))return!1;b.length&&(e.preventDefault(),c("html, body").stop().animate({scrollTop:b.offset().top+a.getOption("anchorNavOffset")+1},a.getOption("anchorNavSpeed"),a.getOption("anchorNavEasing"),function(){return a.changeAnchor(d)}));return this};b.prototype.activateAnchor=function(a){var e=this.$doc.scrollTop();
|
||||
var d=this.$win.height();var b=this.$doc.height();a=this.getOption("anchorNavOffset");if(!this.options.anchorNav)return!1;if(e+d>b-50){b=c('[data-type="anchor"]').last();if(b.length&&b.offset().top>=e){var h="#"+b.attr("id");var f=c('.rd-navbar-nav a[href^="'+h+'"]').parent();f.hasClass("active")||(f.addClass("active").siblings().removeClass("active"),this.options.callbacks.onAnchorChange&&this.options.callbacks.onAnchorChange.call(b[0],this))}return b}d=c('.rd-navbar-nav a[href^="#"]').get();for(f in d){b=
|
||||
d[f];var k=c(b);h=k.attr("href");b=c(h);b.length&&b.offset().top+a<=e&&b.offset().top+b.outerHeight()>e&&(k.parent().addClass("active").siblings().removeClass("active"),this.options.callbacks.onAnchorChange&&this.options.callbacks.onAnchorChange.call(b[0],this))}return null};b.prototype.getAnchor=function(){return history&&history.state?history.state.id:null};b.prototype.changeAnchor=function(a){history&&(history.state?history.state.id!==a?history.replaceState({anchorId:a},null,a):history.pushState({anchorId:a},
|
||||
null,a):history.pushState({anchorId:a},null,a));return this};b.prototype.applyHandlers=function(a){null!=a.options.responsive&&a.$win.on("resize.navbar",c.proxy(a.resize,a.$win[0],a)).on("resize.navbar",c.proxy(a.resizeWrap,a)).on("resize.navbar",c.proxy(a.stickUp,null!=a.$clone?a.$clone:a.$element,a)).on("orientationchange.navbar",c.proxy(a.resize,a.$win[0],a)).trigger("resize.navbar");a.$doc.on("scroll.navbar",c.proxy(a.stickUp,null!=a.$clone?a.$clone:a.$element,a)).on("scroll.navbar",c.proxy(a.activateAnchor,
|
||||
a));a.$element.add(a.$clone).find("[data-rd-navbar-toggle]").each(function(){var b=c(this);b.on("click",c.proxy(a.switchToggle,this,a));return b.parents("body").on("click",c.proxy(a.closeToggle,this,a))});a.$element.add(a.$clone).find(".rd-navbar-submenu").each(function(){var b=c(this);var d=b.parents(".rd-navbar--is-clone").length?a.cloneTimer:a.focusTimer;b.on("mouseleave.navbar",c.proxy(a.dropdownOut,this,a,d));b.find("> a").on("mouseenter.navbar",c.proxy(a.dropdownOver,this,a,d));b.find("> a").on("touchstart.navbar",
|
||||
c.proxy(a.dropdownTouch,this,a,d));b.find("> .rd-navbar-submenu-toggle").on("click",c.proxy(a.dropdownToggle,this,a));return b.parents("body").on("click",c.proxy(a.dropdownClose,this,a))});a.$element.add(a.$clone).find('.rd-navbar-nav a[href^="#"]').each(function(){return c(this).on("click",c.proxy(a.goToAnchor,this,a))});a.$element.find(".rd-navbar-dropdown, .rd-navbar-megamenu").each(function(){var a=c(this);var b=this.getBoundingClientRect();b.left+a.outerWidth()>=h.innerWidth-10?this.className+=
|
||||
" rd-navbar-open-left":10>=b.left-a.outerWidth()&&(this.className+=" rd-navbar-open-right")});return a};b.prototype.switchClass=function(a,b,d){a=a instanceof jQuery?a:c(a);a.addClass("rd-navbar--no-transition").removeClass(b).addClass(d);a[0].offsetHeight;return a.removeClass("rd-navbar--no-transition")};b.prototype.getOption=function(a){var b,c;for(b in this.options.responsive)b<=h.innerWidth&&(c=b);return null!=this.options.responsive&&null!=this.options.responsive[c][a]?this.options.responsive[c][a]:
|
||||
this.options[a]};b.prototype.addAdditionalClassToToggles=function(a,b,d){return c(a).find("[data-rd-navbar-toggle]").each(function(){c(this).addClass(b);var e=this.getAttribute("data-rd-navbar-toggle");return c(this).parents("body").find(a).find(e).addClass(d)})};return b}();c.fn.extend({RDNavbar:function(b){var a=c(this);if(!a.data("RDNavbar"))return a.data("RDNavbar",new m(this,b))}});return h.RDNavbar=m})(window.jQuery,document,window);"undefined"!==typeof module&&null!==module?module.exports=
|
||||
window.RDNavbar:"function"===typeof define&&define.amd&&define(["jquery"],function(){return window.RDNavbar})}).call(this);
|
176
public/assets/js/rd-navbar/rd-navbar.js
Normal file
176
public/assets/js/rd-navbar/rd-navbar.js
Normal file
@ -0,0 +1,176 @@
|
||||
/**
|
||||
* @module RD Navbar
|
||||
* @author Evgeniy Gusarov
|
||||
* @see https://ua.linkedin.com/pub/evgeniy-gusarov/8a/a40/54a
|
||||
* @version 2.2.5
|
||||
*/
|
||||
(function () {
|
||||
var t;
|
||||
t = "ontouchstart" in window,
|
||||
function (n, o, e) {
|
||||
var a;
|
||||
a = function () {
|
||||
function a(t, a) {
|
||||
this.options = n.extend(!0, {}, this.Defaults, a), this.$element = n(t), this.$clone = null, this.$win = n(e), this.$doc = n(o), this.currentLayout = this.options.layout, this.loaded = !1, this.focusOnHover = this.options.focusOnHover, this.focusTimer = !1, this.cloneTimer = !1, this.isStuck = !1, this.initialize()
|
||||
}
|
||||
return a.prototype.Defaults = {
|
||||
layout: "rd-navbar-static",
|
||||
deviceLayout: "rd-navbar-fixed",
|
||||
focusOnHover: !0,
|
||||
focusOnHoverTimeout: 800,
|
||||
linkedElements: ["html"],
|
||||
domAppend: !0,
|
||||
stickUp: !0,
|
||||
stickUpClone: !0,
|
||||
stickUpOffset: "100%",
|
||||
anchorNav: !0,
|
||||
anchorNavSpeed: 400,
|
||||
anchorNavOffset: 0,
|
||||
anchorNavEasing: "swing",
|
||||
autoHeight: !0,
|
||||
responsive: {
|
||||
0: {
|
||||
layout: "rd-navbar-fixed",
|
||||
deviceLayout: "rd-navbar-fixed",
|
||||
focusOnHover: !1,
|
||||
stickUp: !1
|
||||
},
|
||||
1200: {
|
||||
layout: "rd-navbar-static",
|
||||
deviceLayout: "rd-navbar-static",
|
||||
focusOnHover: !0,
|
||||
stickUp: !0
|
||||
}
|
||||
},
|
||||
callbacks: {
|
||||
onToggleSwitch: !1,
|
||||
onToggleClose: !1,
|
||||
onDomAppend: !1,
|
||||
onDropdownOver: !1,
|
||||
onDropdownOut: !1,
|
||||
onDropdownToggle: !1,
|
||||
onDropdownClose: !1,
|
||||
onStuck: !1,
|
||||
onUnstuck: !1,
|
||||
onAnchorChange: !1
|
||||
}
|
||||
}, a.prototype.initialize = function () {
|
||||
var n;
|
||||
return (n = this).$element.addClass("rd-navbar").addClass(n.options.layout), t && n.$element.addClass("rd-navbar--is-touch"), n.options.domAppend && n.createNav(n), n.options.stickUpClone && n.createClone(n), n.$element.addClass("rd-navbar-original"), n.addAdditionalClassToToggles(".rd-navbar-original", "toggle-original", "toggle-original-elements"), n.applyHandlers(n), n.offset = n.$element.offset().top, n.height = n.$element.outerHeight(), n.loaded = !0, n
|
||||
}, a.prototype.resize = function (o, e) {
|
||||
var a, s;
|
||||
return s = t ? o.getOption("deviceLayout") : o.getOption("layout"), a = o.$element.add(o.$clone), s === o.currentLayout && o.loaded || (o.switchClass(a, o.currentLayout, s), null != o.options.linkedElements && n.grep(o.options.linkedElements, function (t, n) {
|
||||
return o.switchClass(t, o.currentLayout + "-linked", s + "-linked")
|
||||
}), o.currentLayout = s), o.focusOnHover = o.getOption("focusOnHover"), o
|
||||
}, a.prototype.stickUp = function (t, o) {
|
||||
function e() {
|
||||
"resize" === o.type ? t.switchClass(i, "", "rd-navbar--is-stuck") : i.addClass("rd-navbar--is-stuck"), t.isStuck = !0
|
||||
}
|
||||
var a, s, r, i, l;
|
||||
return s = t.getOption("stickUp"), (n("html").hasClass("ios") || t.$element.hasClass("rd-navbar-fixed")) && (s = !1), a = t.$doc.scrollTop(), i = null != t.$clone ? t.$clone : t.$element, r = t.getOption("stickUpOffset"), l = "string" == typeof r ? r.indexOf("%") > 0 ? parseFloat(r) * t.height / 100 : parseFloat(r) : r, s ? (a >= l && !t.isStuck || a < l && t.isStuck) && (t.$element.add(t.$clone).find("[data-rd-navbar-toggle]").each(function () {
|
||||
n.proxy(t.closeToggle, this)(t, !1)
|
||||
}).end().find(".rd-navbar-submenu").removeClass("opened").removeClass("focus"), a >= l && !t.isStuck && !t.$element.hasClass("rd-navbar-fixed") ? (t.options.callbacks.onStuck && t.options.callbacks.onStuck.call(t), navigator.platform.match(/(Mac)/i) ? setTimeout(e, 10) : e()) : ("resize" === o.type ? t.switchClass(i, "rd-navbar--is-stuck", "") : i.removeClass("rd-navbar--is-stuck").one("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", n.proxy(t.resizeWrap, t, o)), t.isStuck = !1, t.options.callbacks.onUnstuck && t.options.callbacks.onUnstuck.call(t))) : (t.$element.find(".rd-navbar-submenu").removeClass("opened").removeClass("focus"), t.isStuck && (t.switchClass(i, "rd-navbar--is-stuck", ""), t.isStuck = !1, t.resizeWrap(o))), t
|
||||
}, a.prototype.resizeWrap = function (t) {
|
||||
var n, o;
|
||||
if (null == (o = this).$clone && !o.isStuck) return n = o.$element.parent(), o.getOption("autoHeight") ? (o.height = o.$element.outerHeight(), "resize" === t.type ? (n.addClass("rd-navbar--no-transition").css("height", o.height), n[0].offsetHeight, n.removeClass("rd-navbar--no-transition")) : n.css("height", o.height)) : void n.css("height", "auto")
|
||||
}, a.prototype.createNav = function (t) {
|
||||
return t.$element.find(".rd-navbar-dropdown, .rd-navbar-megamenu").each(function () {
|
||||
var t;
|
||||
return t = n(this), this.getBoundingClientRect(), t.hasClass("rd-navbar-megamenu") ? t.parent().addClass("rd-navbar--has-megamenu") : t.parent().addClass("rd-navbar--has-dropdown")
|
||||
}).parents("li").addClass("rd-navbar-submenu"), n('<span class="rd-navbar-submenu-toggle"></span>').insertAfter(".rd-navbar-nav li.rd-navbar-submenu > a"), t.options.callbacks.onDomAppend && t.options.callbacks.onDomAppend.call(this), t
|
||||
}, a.prototype.createClone = function (t) {
|
||||
return t.$clone = t.$element.clone().insertAfter(t.$element).addClass("rd-navbar--is-clone"), t.addAdditionalClassToToggles(".rd-navbar--is-clone", "toggle-cloned", "toggle-cloned-elements"), t
|
||||
}, a.prototype.closeToggle = function (t, o) {
|
||||
var e, a, s, r, i, l, c;
|
||||
return a = n(o.target), i = !1, l = this.getAttribute("data-rd-navbar-toggle"), t.options.stickUpClone && t.isStuck ? (r = ".toggle-cloned", s = ".toggle-cloned-elements", c = !a.hasClass("toggle-cloned")) : (r = ".toggle-original", s = ".toggle-original-elements", c = !a.hasClass("toggle-original")), o.target !== this && !a.parents(r + "[data-rd-navbar-toggle]").length && !a.parents(s).length && l && c && ((e = n(this).parents("body").find(l).add(n(this).parents(".rd-navbar")[0])).each(function () {
|
||||
if (!i) return i = !0 === (o.target === this || n.contains(this, o.target))
|
||||
}), i || (e.add(this).removeClass("active"), t.options.callbacks.onToggleClose && t.options.callbacks.onToggleClose.call(this, t))), this
|
||||
}, a.prototype.switchToggle = function (t, o) {
|
||||
var e, a, s;
|
||||
return o.preventDefault(), n(this).hasClass("toggle-cloned") ? (s = ".rd-navbar--is-clone", e = ".toggle-cloned-elements") : (s = ".rd-navbar-original", e = ".toggle-original-elements"), (a = this.getAttribute("data-rd-navbar-toggle")) && (n(s + " [data-rd-navbar-toggle]").not(this).each(function () {
|
||||
var t;
|
||||
if (t = this.getAttribute("data-rd-navbar-toggle")) return n(this).parents("body").find(s + " " + t + e).add(this).add(n.inArray(".rd-navbar", t.split(/\s*,\s*/i)) > -1 && n(this).parents("body")[0]).removeClass("active")
|
||||
}), n(this).parents("body").find(s + " " + a + e).add(this).add(n.inArray(".rd-navbar", a.split(/\s*,\s*/i)) > -1 && n(this).parents(".rd-navbar")[0]).toggleClass("active")), t.options.callbacks.onToggleSwitch && t.options.callbacks.onToggleSwitch.call(this, t), this
|
||||
}, a.prototype.dropdownOver = function (t, o) {
|
||||
var e;
|
||||
if (t.focusOnHover) {
|
||||
if (e = n(this), clearTimeout(o), t.options.callbacks.onDropdownOver && !t.options.callbacks.onDropdownOver.call(this, t)) return this;
|
||||
e.addClass("focus").siblings().removeClass("opened").each(t.dropdownUnfocus)
|
||||
}
|
||||
return this
|
||||
}, a.prototype.dropdownTouch = function (t, o) {
|
||||
var e, a;
|
||||
if (e = n(this), clearTimeout(o), t.focusOnHover) {
|
||||
if (a = !1, e.hasClass("focus") && (a = !0), !a) return e.addClass("focus").siblings().removeClass("opened").each(t.dropdownUnfocus), !1;
|
||||
t.options.callbacks.onDropdownOver && t.options.callbacks.onDropdownOver.call(this, t)
|
||||
}
|
||||
return this
|
||||
}, a.prototype.dropdownOut = function (t, o) {
|
||||
return t.focusOnHover && (n(this).one("mouseenter.navbar", function () {
|
||||
return clearTimeout(o)
|
||||
}), t.options.callbacks.onDropdownOut && t.options.callbacks.onDropdownOut.call(this, t), clearTimeout(o), o = setTimeout(n.proxy(t.dropdownUnfocus, this, t), t.options.focusOnHoverTimeout)), this
|
||||
}, a.prototype.dropdownUnfocus = function (t) {
|
||||
return n(this).find("li.focus").add(this).removeClass("focus"), this
|
||||
}, a.prototype.dropdownClose = function (t, o) {
|
||||
return o.target === this || n(o.target).parents(".rd-navbar-submenu").length || (n(this).find("li.focus").add(this).removeClass("focus").removeClass("opened"), t.options.callbacks.onDropdownClose && t.options.callbacks.onDropdownClose.call(this, t)), this
|
||||
}, a.prototype.dropdownToggle = function (t) {
|
||||
return n(this).toggleClass("opened").siblings().removeClass("opened"), t.options.callbacks.onDropdownToggle && t.options.callbacks.onDropdownToggle.call(this, t), this
|
||||
}, a.prototype.goToAnchor = function (t, o) {
|
||||
var e, a;
|
||||
return a = this.hash, e = n(a), !!t.getOption("anchorNav") && (e.length && (o.preventDefault(), n("html, body").stop().animate({
|
||||
scrollTop: e.offset().top + t.getOption("anchorNavOffset") + 1
|
||||
}, t.getOption("anchorNavSpeed"), t.getOption("anchorNavEasing"), function () {
|
||||
return t.changeAnchor(a)
|
||||
})), this)
|
||||
}, a.prototype.activateAnchor = function (t) {
|
||||
var o, e, a, s, r, i, l, c, d, p, u, h;
|
||||
if (s = this, u = s.$doc.scrollTop(), h = s.$win.height(), r = s.$doc.height(), p = s.getOption("anchorNavOffset"), !s.options.anchorNav) return !1;
|
||||
if (u + h > r - 50) return (o = n('[data-type="anchor"]').last()).length && o.offset().top >= u && (i = "#" + o.attr("id"), (e = n('.rd-navbar-nav a[href^="' + i + '"]').parent()).hasClass("active") || (e.addClass("active").siblings().removeClass("active"), s.options.callbacks.onAnchorChange && s.options.callbacks.onAnchorChange.call(o[0], s))), o;
|
||||
d = n('.rd-navbar-nav a[href^="#"]').get();
|
||||
for (l in d) c = d[l], i = (a = n(c)).attr("href"), (o = n(i)).length && o.offset().top + p <= u && o.offset().top + o.outerHeight() > u && (a.parent().addClass("active").siblings().removeClass("active"), s.options.callbacks.onAnchorChange && s.options.callbacks.onAnchorChange.call(o[0], s));
|
||||
return null
|
||||
}, a.prototype.getAnchor = function () {
|
||||
return history && history.state ? history.state.id : null
|
||||
}, a.prototype.changeAnchor = function (t) {
|
||||
return history && (history.state && history.state.id !== t ? history.replaceState({
|
||||
anchorId: t
|
||||
}, null, t) : history.pushState({
|
||||
anchorId: t
|
||||
}, null, t)), this
|
||||
}, a.prototype.applyHandlers = function (t) {
|
||||
return null != t.options.responsive && t.$win.on("resize.navbar", n.proxy(t.resize, t.$win[0], t)).on("resize.navbar", n.proxy(t.resizeWrap, t)).on("resize.navbar", n.proxy(t.stickUp, null != t.$clone ? t.$clone : t.$element, t)).on("orientationchange.navbar", n.proxy(t.resize, t.$win[0], t)).trigger("resize.navbar"), t.$doc.on("scroll.navbar", n.proxy(t.stickUp, null != t.$clone ? t.$clone : t.$element, t)).on("scroll.navbar", n.proxy(t.activateAnchor, t)), t.$element.add(t.$clone).find("[data-rd-navbar-toggle]").each(function () {
|
||||
var o;
|
||||
return (o = n(this)).on("click", n.proxy(t.switchToggle, this, t)), o.parents("body").on("click", n.proxy(t.closeToggle, this, t))
|
||||
}), t.$element.add(t.$clone).find(".rd-navbar-submenu").each(function () {
|
||||
var o, e;
|
||||
return o = n(this), e = o.parents(".rd-navbar--is-clone").length ? t.cloneTimer : t.focusTimer, o.on("mouseleave.navbar", n.proxy(t.dropdownOut, this, t, e)), o.find("> a").on("mouseenter.navbar", n.proxy(t.dropdownOver, this, t, e)), o.find("> a").on("touchstart.navbar", n.proxy(t.dropdownTouch, this, t, e)), o.find("> .rd-navbar-submenu-toggle").on("click", n.proxy(t.dropdownToggle, this, t)), o.parents("body").on("click", n.proxy(t.dropdownClose, this, t))
|
||||
}), t.$element.add(t.$clone).find('.rd-navbar-nav a[href^="#"]').each(function () {
|
||||
return n(this).on("click", n.proxy(t.goToAnchor, this, t))
|
||||
}), t.$element.find(".rd-navbar-dropdown, .rd-navbar-megamenu").each(function () {
|
||||
var t, o;
|
||||
t = n(this), (o = this.getBoundingClientRect()).left + t.outerWidth() >= e.innerWidth - 10 ? this.className += " rd-navbar-open-left" : o.left - t.outerWidth() <= 10 && (this.className += " rd-navbar-open-right")
|
||||
}), t
|
||||
}, a.prototype.switchClass = function (t, o, e) {
|
||||
var a;
|
||||
return (a = t instanceof jQuery ? t : n(t)).addClass("rd-navbar--no-transition").removeClass(o).addClass(e), a[0].offsetHeight, a.removeClass("rd-navbar--no-transition")
|
||||
}, a.prototype.getOption = function (t) {
|
||||
var n, o;
|
||||
for (n in this.options.responsive) n <= e.innerWidth && (o = n);
|
||||
return null != this.options.responsive && null != this.options.responsive[o][t] ? this.options.responsive[o][t] : this.options[t]
|
||||
}, a.prototype.addAdditionalClassToToggles = function (t, o, e) {
|
||||
return n(t).find("[data-rd-navbar-toggle]").each(function () {
|
||||
var a;
|
||||
return n(this).addClass(o), a = this.getAttribute("data-rd-navbar-toggle"), n(this).parents("body").find(t).find(a).addClass(e)
|
||||
})
|
||||
}, a
|
||||
}(), n.fn.extend({
|
||||
RDNavbar: function (t) {
|
||||
var o;
|
||||
if (!(o = n(this)).data("RDNavbar")) return o.data("RDNavbar", new a(this, t))
|
||||
}
|
||||
}), e.RDNavbar = a
|
||||
}(window.jQuery, document, window), "undefined" != typeof module && null !== module ? module.exports = window.RDNavbar : "function" == typeof define && define.amd && define(["jquery"], function () {
|
||||
"use strict";
|
||||
return window.RDNavbar
|
||||
})
|
||||
}).call(this);
|
Reference in New Issue
Block a user