Skip to content

Commit

Permalink
fix(chore): variable declaration and usage fixes and optimization
Browse files Browse the repository at this point in the history
Many variable usages were wrong/unused/buggy which this PR fixes or optimizes
  • Loading branch information
lubber-de committed Sep 8, 2022
1 parent 8fd82d5 commit 6dec24a
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 135 deletions.
2 changes: 1 addition & 1 deletion src/definitions/behaviors/api.js
Expand Up @@ -1015,7 +1015,7 @@ $.api = $.fn.api = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
19 changes: 7 additions & 12 deletions src/definitions/behaviors/form.js
Expand Up @@ -465,7 +465,7 @@ $.fn.form = function(parameters) {
},
beforeUnload: function(event) {
if (module.is.dirty() && !submitting) {
var event = event || window.event;
event = event || window.event;

// For modern browsers
if (event) {
Expand Down Expand Up @@ -801,16 +801,11 @@ $.fn.form = function(parameters) {
if(typeof identifier !== 'string') {
module.error(error.identifier, identifier);
}
if($field.filter('#' + identifier).length > 0 ) {
return true;
}
else if( $field.filter('[name="' + identifier +'"]').length > 0 ) {
return true;
}
else if( $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').length > 0 ) {
return true;
}
return false;
return (
$field.filter('#' + identifier).length > 0 ||
$field.filter('[name="' + identifier +'"]').length > 0 ||
$field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').length > 0
);
}

},
Expand Down Expand Up @@ -1457,7 +1452,7 @@ $.fn.form = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/behaviors/state.js
Expand Up @@ -527,7 +527,7 @@ $.fn.state = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/behaviors/visibility.js
Expand Up @@ -1139,7 +1139,7 @@ $.fn.visibility = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/globals/site.js
Expand Up @@ -359,7 +359,7 @@ $.site = $.fn.site = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/modules/accordion.js
Expand Up @@ -496,7 +496,7 @@ $.fn.accordion = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
5 changes: 2 additions & 3 deletions src/definitions/modules/calendar.js
Expand Up @@ -599,9 +599,9 @@ $.fn.calendar = function(parameters) {
}

if (module.popup('is visible')) {
var mode = module.get.mode();
if (keyCode === 37 || keyCode === 38 || keyCode === 39 || keyCode === 40) {
//arrow keys
var mode = module.get.mode();
var bigIncrement = mode === 'day' ? 7 : mode === 'hour' ? 4 : mode === 'minute' ? timeGap['column'] : 3;
var increment = keyCode === 37 ? -1 : keyCode === 38 ? -bigIncrement : keyCode == 39 ? 1 : bigIncrement;
increment *= mode === 'minute' ? settings.minTimeGap : 1;
Expand All @@ -620,7 +620,6 @@ $.fn.calendar = function(parameters) {
}
} else if (keyCode === 13) {
//enter
var mode = module.get.mode();
var date = module.get.focusDate();
if (date && !settings.isDisabled(date, mode) && !module.helper.isDisabled(date, mode) && module.helper.isEnabled(date, mode)) {
if (settings.onSelect.call(element, date, module.get.mode()) !== false) {
Expand Down Expand Up @@ -1413,7 +1412,7 @@ $.fn.calendar = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if (typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/modules/checkbox.js
Expand Up @@ -754,7 +754,7 @@ $.fn.checkbox = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
7 changes: 2 additions & 5 deletions src/definitions/modules/dimmer.js
Expand Up @@ -380,10 +380,7 @@ $.fn.dimmer = function(parameters) {
},
closable: function() {
if(settings.closable == 'auto') {
if(settings.on == 'hover') {
return false;
}
return true;
return settings.on != 'hover';
}
return settings.closable;
},
Expand Down Expand Up @@ -602,7 +599,7 @@ $.fn.dimmer = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
68 changes: 21 additions & 47 deletions src/definitions/modules/dropdown.js
Expand Up @@ -228,7 +228,6 @@ $.fn.dropdown = function(parameters) {
var
$userChoices,
$userChoice,
isUserValue,
html
;
values = values || module.get.userValues();
Expand Down Expand Up @@ -914,30 +913,18 @@ $.fn.dropdown = function(parameters) {
}
if(settings.match === 'both' || settings.match === 'text') {
text = module.remove.diacritics(String(module.get.choiceText($choice, false)));
if(text.search(beginsWithRegExp) !== -1) {
results.push(this);
return true;
}
else if (settings.fullTextSearch === 'exact' && module.exactSearch(searchTerm, text)) {
results.push(this);
return true;
}
else if (settings.fullTextSearch === true && module.fuzzySearch(searchTerm, text)) {
if(text.search(beginsWithRegExp) !== -1 ||
(settings.fullTextSearch === 'exact' && module.exactSearch(searchTerm, text)) ||
(settings.fullTextSearch === true && module.fuzzySearch(searchTerm, text))) {
results.push(this);
return true;
}
}
if(settings.match === 'both' || settings.match === 'value') {
value = module.remove.diacritics(String(module.get.choiceValue($choice, text)));
if(value.search(beginsWithRegExp) !== -1) {
results.push(this);
return true;
}
else if (settings.fullTextSearch === 'exact' && module.exactSearch(searchTerm, value)) {
results.push(this);
return true;
}
else if (settings.fullTextSearch === true && module.fuzzySearch(searchTerm, value)) {
if(value.search(beginsWithRegExp) !== -1 ||
(settings.fullTextSearch === 'exact' && module.exactSearch(searchTerm, value)) ||
(settings.fullTextSearch === true && module.fuzzySearch(searchTerm, value))) {
results.push(this);
return true;
}
Expand Down Expand Up @@ -1438,8 +1425,7 @@ $.fn.dropdown = function(parameters) {
isFocusedOnSearch = module.is.focusedOnSearch(),
isFocused = module.is.focused(),
caretAtStart = (isFocusedOnSearch && module.get.caretPosition(false) === 0),
isSelectedSearch = (caretAtStart && module.get.caretPosition(true) !== 0),
$nextLabel
isSelectedSearch = (caretAtStart && module.get.caretPosition(true) !== 0)
;
if(isSearch && !hasActiveLabel && !isFocusedOnSearch) {
return;
Expand Down Expand Up @@ -1556,8 +1542,7 @@ $.fn.dropdown = function(parameters) {
delimiterPressed = (event.key === settings.delimiter && module.is.multiple()),
isAdditionWithoutMenu = (settings.allowAdditions && settings.hideAdditions && (pressedKey == keys.enter || delimiterPressed) && selectedIsSelectable),
$nextItem,
isSubMenuItem,
newIndex
isSubMenuItem
;
// allow selection with menu closed
if(isAdditionWithoutMenu) {
Expand Down Expand Up @@ -1661,7 +1646,7 @@ $.fn.dropdown = function(parameters) {
// down arrow (traverse menu down)
if(pressedKey == keys.downArrow) {
$nextItem = (hasSelectedItem && inVisibleMenu)
? $nextItem = $selectedItem.nextAll(selector.item + ':not(' + selector.unselectable + ')').eq(0)
? $selectedItem.nextAll(selector.item + ':not(' + selector.unselectable + ')').eq(0)
: $item.eq(0)
;
if($nextItem.length === 0) {
Expand Down Expand Up @@ -2416,7 +2401,6 @@ $.fn.dropdown = function(parameters) {
currentScroll = $menu.scrollTop(),
itemHeight = $item.eq(0).outerHeight(),
itemsPerPage = Math.floor(menuHeight / itemHeight),
maxScroll = $menu.prop('scrollHeight'),
newScroll = (direction == 'up')
? currentScroll - (itemHeight * itemsPerPage)
: currentScroll + (itemHeight * itemsPerPage),
Expand Down Expand Up @@ -2541,7 +2525,6 @@ $.fn.dropdown = function(parameters) {
$menu,
hasActive,
offset,
itemHeight,
itemOffset,
menuOffset,
menuScroll,
Expand Down Expand Up @@ -2704,8 +2687,7 @@ $.fn.dropdown = function(parameters) {
currentValue = module.get.values(),
stringValue = (value !== undefined)
? String(value)
: value,
newValue
: value
;
if(hasInput) {
if(!settings.allowReselection && stringValue == currentValue) {
Expand Down Expand Up @@ -2914,7 +2896,7 @@ $.fn.dropdown = function(parameters) {
;
}
else {
$message = $('<div/>')
$('<div/>')
.html(html)
.addClass(className.message)
.appendTo($menu)
Expand Down Expand Up @@ -2997,16 +2979,13 @@ $.fn.dropdown = function(parameters) {
hasCount = (message.search('{count}') !== -1),
hasMaxCount = (message.search('{maxCount}') !== -1),
hasTerm = (message.search('{term}') !== -1),
count,
query
;
module.verbose('Adding templated variables to message', message);
if(hasCount) {
count = module.get.selectionCount();
message = message.replace('{count}', count);
message = message.replace('{count}', module.get.selectionCount());
}
if(hasMaxCount) {
count = module.get.selectionCount();
message = message.replace('{maxCount}', settings.maxSelections);
}
if(hasTerm) {
Expand Down Expand Up @@ -3453,7 +3432,7 @@ $.fn.dropdown = function(parameters) {
return (document.activeElement === $search[0]);
},
allFiltered: function() {
return( (module.is.multiple() || module.has.search()) && !(settings.hideAdditions == false && module.has.userSuggestion()) && !module.has.message() && module.has.allResultsFiltered() );
return( (module.is.multiple() || module.has.search()) && !(!settings.hideAdditions && module.has.userSuggestion()) && !module.has.message() && module.has.allResultsFiltered() );
},
hidden: function($subMenu) {
return !module.is.visible($subMenu);
Expand Down Expand Up @@ -3539,22 +3518,17 @@ $.fn.dropdown = function(parameters) {

can: {
activate: function($item) {
if(settings.useLabels) {
return true;
}
if(!module.has.maxSelections()) {
return true;
}
if(module.has.maxSelections() && $item.hasClass(className.active)) {
return true;
}
return false;
return (
settings.useLabels ||
!module.has.maxSelections() ||
(module.has.maxSelections() && $item.hasClass(className.active))
);
},
openDownward: function($subMenu) {
var
$currentMenu = $subMenu || $menu,
canOpenDownward = true,
onScreen = {},
canOpenDownward,
onScreen,
calculations
;
$currentMenu
Expand Down Expand Up @@ -3936,7 +3910,7 @@ $.fn.dropdown = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
6 changes: 2 additions & 4 deletions src/definitions/modules/embed.js
Expand Up @@ -128,9 +128,7 @@ $.fn.embed = function(parameters) {

createPlaceholder: function(placeholder) {
var
icon = module.get.icon(),
url = module.get.url(),
embed = module.generate.embed(url)
icon = module.get.icon()
;
placeholder = placeholder || module.get.placeholder();
$module.html( templates.placeholder(placeholder, icon) );
Expand Down Expand Up @@ -509,7 +507,7 @@ $.fn.embed = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
3 changes: 1 addition & 2 deletions src/definitions/modules/modal.js
Expand Up @@ -671,7 +671,6 @@ $.modal = $.fn.modal = function(parameters) {
}
else {
module.debug('Dimmer is not visible cannot hide');
return;
}
},

Expand Down Expand Up @@ -1224,7 +1223,7 @@ $.modal = $.fn.modal = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/modules/nag.js
Expand Up @@ -403,7 +403,7 @@ $.fn.nag = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down
14 changes: 3 additions & 11 deletions src/definitions/modules/popup.js
Expand Up @@ -1087,10 +1087,7 @@ $.fn.popup = function(parameters) {
is: {
closable: function() {
if(settings.closable == 'auto') {
if(settings.on == 'hover') {
return false;
}
return true;
return settings.on != 'hover';
}
return settings.closable;
},
Expand All @@ -1105,12 +1102,7 @@ $.fn.popup = function(parameters) {
offstage.push(direction);
}
});
if(offstage.length > 0) {
return true;
}
else {
return false;
}
return offstage.length > 0;
},
svg: function(element) {
return module.supports.svg() && (element instanceof SVGGraphicsElement);
Expand Down Expand Up @@ -1264,7 +1256,7 @@ $.fn.popup = function(parameters) {
response
;
passedArguments = passedArguments || queryArguments;
context = element || context;
context = context || element;
if(typeof query == 'string' && object !== undefined) {
query = query.split(/[\. ]/);
maxDepth = query.length - 1;
Expand Down

0 comments on commit 6dec24a

Please sign in to comment.