Skip to content

Commit

Permalink
fix(chore): reuse variables and quicker element access
Browse files Browse the repository at this point in the history
Some slight performance adjustments by using native array access instead of .get(0) and reusage of cached variables
  • Loading branch information
lubber-de committed Aug 21, 2022
1 parent e6828e7 commit 1f24f1d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/definitions/behaviors/visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,15 @@ $.fn.visibility = function(parameters) {
},
verticallyScrollableContext: function() {
var
overflowY = ($context.get(0) !== window)
overflowY = ($context[0] !== window)
? $context.css('overflow-y')
: false
;
return (overflowY == 'auto' || overflowY == 'scroll');
},
horizontallyScrollableContext: function() {
var
overflowX = ($context.get(0) !== window)
overflowX = ($context[0] !== window)
? $context.css('overflow-x')
: false
;
Expand Down
14 changes: 7 additions & 7 deletions src/definitions/modules/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ $.fn.dropdown = function(parameters) {
moduleNamespace = 'module-' + namespace,

$module = $(this),
$context = [window,document].indexOf(settings.context) < 0 ? $(document).find(settings.context) : $(settings.context),
$context = [window,document].indexOf(settings.context) < 0 ? $document.find(settings.context) : $(settings.context),
$text = $module.find(selector.text),
$search = $module.find(selector.search),
$sizer = $module.find(selector.sizer),
Expand Down Expand Up @@ -448,7 +448,7 @@ $.fn.dropdown = function(parameters) {
// replace module reference
$module = $module.parent(selector.dropdown);
instance = $module.data(moduleNamespace);
element = $module.get(0);
element = $module[0];
module.refresh();
module.setup.returnedObject();
},
Expand Down Expand Up @@ -1921,7 +1921,7 @@ $.fn.dropdown = function(parameters) {
},
caretPosition: function(returnEndPos) {
var
input = $search.get(0),
input = $search[0],
range,
rangeLength
;
Expand Down Expand Up @@ -3520,15 +3520,15 @@ $.fn.dropdown = function(parameters) {
},
verticallyScrollableContext: function() {
var
overflowY = ($context.get(0) !== window)
overflowY = ($context[0] !== window)
? $context.css('overflow-y')
: false
;
return (overflowY == 'auto' || overflowY == 'scroll');
},
horizontallyScrollableContext: function() {
var
overflowX = ($context.get(0) !== window)
overflowX = ($context[0] !== window)
? $context.css('overflow-X')
: false
;
Expand Down Expand Up @@ -3561,7 +3561,7 @@ $.fn.dropdown = function(parameters) {
;
calculations = {
context: {
offset : ($context.get(0) === window)
offset : ($context[0] === window)
? { top: 0, left: 0}
: $context.offset(),
scrollTop : $context.scrollTop(),
Expand Down Expand Up @@ -3609,7 +3609,7 @@ $.fn.dropdown = function(parameters) {
;
calculations = {
context: {
offset : ($context.get(0) === window)
offset : ($context[0] === window)
? { top: 0, left: 0}
: $context.offset(),
scrollLeft : $context.scrollLeft(),
Expand Down
16 changes: 8 additions & 8 deletions src/definitions/modules/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ $.fn.popup = function(parameters) {
moduleNamespace = 'module-' + namespace,

$module = $(this),
$context = [window,document].indexOf(settings.context) < 0 ? $(document).find(settings.context) : $(settings.context),
$scrollContext = [window,document].indexOf(settings.scrollContext) < 0 ? $(document).find(settings.scrollContext) : $(settings.scrollContext),
$boundary = [window,document].indexOf(settings.boundary) < 0 ? $(document).find(settings.boundary) : $(settings.boundary),
$context = [window,document].indexOf(settings.context) < 0 ? $document.find(settings.context) : $(settings.context),
$scrollContext = [window,document].indexOf(settings.scrollContext) < 0 ? $document.find(settings.scrollContext) : $(settings.scrollContext),
$boundary = [window,document].indexOf(settings.boundary) < 0 ? $document.find(settings.boundary) : $(settings.boundary),
$target = (settings.target)
? ([window,document].indexOf(settings.target) < 0 ? $(document).find(settings.target) : $(settings.target))
? ([window,document].indexOf(settings.target) < 0 ? $document.find(settings.target) : $(settings.target))
: $module,

$popup,
Expand Down Expand Up @@ -122,7 +122,7 @@ $.fn.popup = function(parameters) {

refresh: function() {
if(settings.popup) {
$popup = $(document).find(settings.popup).eq(0);
$popup = $document.find(settings.popup).eq(0);
}
else {
if(settings.inline) {
Expand Down Expand Up @@ -287,7 +287,7 @@ $.fn.popup = function(parameters) {
settings.onCreate.call($popup, element);
}
else if(settings.popup) {
$(document).find(settings.popup).data(metadata.activator, $module);
$document.find(settings.popup).data(metadata.activator, $module);
module.verbose('Used popup specified in settings');
module.refresh();
if(settings.hoverable) {
Expand Down Expand Up @@ -368,7 +368,7 @@ $.fn.popup = function(parameters) {
},

hideAll: function() {
$(document).find(selector.popup)
$document.find(selector.popup)
.filter('.' + className.popupVisible)
.each(function() {
$(this)
Expand Down Expand Up @@ -557,7 +557,7 @@ $.fn.popup = function(parameters) {
};

// if popup offset context is not same as target, then adjust calculations
if($popupOffsetParent.get(0) !== $offsetParent.get(0)) {
if($popupOffsetParent[0] !== $offsetParent[0]) {
var
popupOffset = $popupOffsetParent.offset()
;
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/modules/sticky.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ $.fn.sticky = function(parameters) {
},
containerSize: function() {
var
tagName = $container.get(0).tagName
tagName = $container[0].tagName
;
if(tagName === 'HTML' || tagName == 'body') {
if(tagName === 'HTML' || tagName === 'body') {
// this can trigger for too many reasons
//module.error(error.container, tagName, $module);
module.determineContainer();
Expand Down

0 comments on commit 1f24f1d

Please sign in to comment.