mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 12:09:26 +00:00
Move out of else block
This commit is contained in:
@@ -32,66 +32,66 @@
|
||||
|
||||
if(typeof jQuery === 'undefined' && typeof Zepto === 'undefined') {
|
||||
throw new Error('Shoelace dropdowns require either jQuery or Zepto.');
|
||||
} else {
|
||||
(typeof jQuery === 'function' ? jQuery : Zepto)(function($) {
|
||||
$(document)
|
||||
.on('click', function(event) {
|
||||
var dropdown;
|
||||
var menu;
|
||||
var selectedItem;
|
||||
var trigger;
|
||||
|
||||
// Watch for clicks on dropdown triggers
|
||||
if($(event.target).is('.dropdown-trigger')) {
|
||||
dropdown = $(event.target).closest('.dropdown');
|
||||
trigger = event.target;
|
||||
|
||||
// Close other dropdowns
|
||||
$('.dropdown.active')
|
||||
.not(dropdown)
|
||||
.removeClass('active')
|
||||
.trigger('hide');
|
||||
|
||||
// Ignore dropdowns that have the disabled class
|
||||
if($(trigger).is('.disabled, :disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Toggle this dropdown
|
||||
$(dropdown)
|
||||
.toggleClass('active')
|
||||
.trigger($(dropdown).is('.active') ? 'show' : 'hide');
|
||||
} else {
|
||||
menu = $(event.target).closest('.dropdown-menu');
|
||||
|
||||
// Watch for clicks on menu items
|
||||
if(menu.length) {
|
||||
dropdown = $(event.target).closest('.dropdown');
|
||||
selectedItem = $(event.target).closest('a').get(0);
|
||||
|
||||
// If the user selected a menu item and it's not disabled, fire the select event
|
||||
if(selectedItem && !$(selectedItem).is('.disabled')) {
|
||||
$(dropdown).trigger('select', selectedItem);
|
||||
}
|
||||
|
||||
// Prevent the page from scrolling since menu items are #links
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
// Close dropdowns on all other clicks
|
||||
$('.dropdown.active')
|
||||
.removeClass('active')
|
||||
.trigger('hide');
|
||||
}
|
||||
})
|
||||
.on('keydown', function(event) {
|
||||
// Close dropdowns on escape
|
||||
if(event.keyCode === 27) {
|
||||
$('.dropdown.active')
|
||||
.removeClass('active')
|
||||
.trigger('hide');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
(typeof jQuery === 'function' ? jQuery : Zepto)(function($) {
|
||||
$(document)
|
||||
.on('click', function(event) {
|
||||
var dropdown;
|
||||
var menu;
|
||||
var selectedItem;
|
||||
var trigger;
|
||||
|
||||
// Watch for clicks on dropdown triggers
|
||||
if($(event.target).is('.dropdown-trigger')) {
|
||||
dropdown = $(event.target).closest('.dropdown');
|
||||
trigger = event.target;
|
||||
|
||||
// Close other dropdowns
|
||||
$('.dropdown.active')
|
||||
.not(dropdown)
|
||||
.removeClass('active')
|
||||
.trigger('hide');
|
||||
|
||||
// Ignore dropdowns that have the disabled class
|
||||
if($(trigger).is('.disabled, :disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Toggle this dropdown
|
||||
$(dropdown)
|
||||
.toggleClass('active')
|
||||
.trigger($(dropdown).is('.active') ? 'show' : 'hide');
|
||||
} else {
|
||||
menu = $(event.target).closest('.dropdown-menu');
|
||||
|
||||
// Watch for clicks on menu items
|
||||
if(menu.length) {
|
||||
dropdown = $(event.target).closest('.dropdown');
|
||||
selectedItem = $(event.target).closest('a').get(0);
|
||||
|
||||
// If the user selected a menu item and it's not disabled, fire the select event
|
||||
if(selectedItem && !$(selectedItem).is('.disabled')) {
|
||||
$(dropdown).trigger('select', selectedItem);
|
||||
}
|
||||
|
||||
// Prevent the page from scrolling since menu items are #links
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
// Close dropdowns on all other clicks
|
||||
$('.dropdown.active')
|
||||
.removeClass('active')
|
||||
.trigger('hide');
|
||||
}
|
||||
})
|
||||
.on('keydown', function(event) {
|
||||
// Close dropdowns on escape
|
||||
if(event.keyCode === 27) {
|
||||
$('.dropdown.active')
|
||||
.removeClass('active')
|
||||
.trigger('hide');
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
@@ -32,37 +32,37 @@
|
||||
|
||||
if(typeof jQuery === 'undefined' && typeof Zepto === 'undefined') {
|
||||
throw new Error('Shoelace tabs require either jQuery or Zepto.');
|
||||
} else {
|
||||
(window.jQuery || window.Zepto)(function($) {
|
||||
// Watch for clicks on tabs
|
||||
$(document).on('click', '.tabs-nav a', function(event) {
|
||||
var tabs = $(this).closest('.tabs');
|
||||
var tabNav = this;
|
||||
var selectedPane = $(tabs).find(tabNav.hash).get(0);
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// Ignore tabs without an href or with the "disabled" class
|
||||
if(!tabNav.hash || $(tabNav).is('.disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make the selected tab active
|
||||
$(tabNav).siblings().removeClass('active');
|
||||
$(tabNav).addClass('active');
|
||||
|
||||
// Hide active tab panes that aren't getting selected
|
||||
$(tabs).find('.tabs-pane.active').not(selectedPane).each(function() {
|
||||
$(this).removeClass('active');
|
||||
$(tabs).trigger('hide', this);
|
||||
});
|
||||
|
||||
// Show the selected tab pane
|
||||
if(selectedPane && !$(selectedPane).is('.active')) {
|
||||
$(selectedPane).addClass('active');
|
||||
$(tabs).trigger('show', selectedPane);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
(window.jQuery || window.Zepto)(function($) {
|
||||
// Watch for clicks on tabs
|
||||
$(document).on('click', '.tabs-nav a', function(event) {
|
||||
var tabs = $(this).closest('.tabs');
|
||||
var tabNav = this;
|
||||
var selectedPane = $(tabs).find(tabNav.hash).get(0);
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// Ignore tabs without an href or with the "disabled" class
|
||||
if(!tabNav.hash || $(tabNav).is('.disabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make the selected tab active
|
||||
$(tabNav).siblings().removeClass('active');
|
||||
$(tabNav).addClass('active');
|
||||
|
||||
// Hide active tab panes that aren't getting selected
|
||||
$(tabs).find('.tabs-pane.active').not(selectedPane).each(function() {
|
||||
$(this).removeClass('active');
|
||||
$(tabs).trigger('hide', this);
|
||||
});
|
||||
|
||||
// Show the selected tab pane
|
||||
if(selectedPane && !$(selectedPane).is('.active')) {
|
||||
$(selectedPane).addClass('active');
|
||||
$(tabs).trigger('show', selectedPane);
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user