Skip to content

Commit

Permalink
Fixed bug in defaultPadding & defaultMargin parameter 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
actuallyakash committed Jun 15, 2021
1 parent 00e8038 commit fb525aa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
16 changes: 8 additions & 8 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ <h2 class="docs-title">defaultPadding</h2>
spacers({
element: '.defaultPadding-prop',
defaultPadding: {
'top': '20px',
'bottom': '20px',
'left': '20px',
'right': '20px'
'top': '20',
'bottom': '20',
'left': '20',
'right': '20'
}
});
</code>
Expand Down Expand Up @@ -363,10 +363,10 @@ <h2 class="docs-title">defaultMargin</h2>
padding: false,
margin: true,
defaultMargin: {
'top': '20px',
'bottom': '20px',
'left': '20px',
'right': '20px'
'top': '20',
'bottom': '20',
'left': '20',
'right': '20'
}
});
</code>
Expand Down
16 changes: 8 additions & 8 deletions docs/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ spacers({
spacers({
element: '.defaultPadding-prop',
defaultPadding: {
'top': '20px',
'bottom': '20px',
'left': '20px',
'right': '20px'
'top': '20',
'bottom': '20',
'left': '20',
'right': '20'
}
});

Expand All @@ -34,10 +34,10 @@ spacers({
padding: false,
margin: true,
defaultMargin: {
'top': '20px',
'bottom': '20px',
'left': '20px',
'right': '20px'
'top': '20',
'bottom': '20',
'left': '20',
'right': '20'
}
});

Expand Down
10 changes: 4 additions & 6 deletions spacers/spacers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function spacers( options ) {

let document = options.containedArea ? options.containedArea : window.document;
let elements = document.querySelectorAll( options.element );
let defaultSpacing = options.defaultSpacing ? options.defaultSpacing : '8px';
let defaultSpacing = options.defaultSpacing ? options.defaultSpacing : '8';
let spacingUnit = options.spacingUnit ? options.spacingUnit : "px";
let enablePadding = options.padding == undefined || options.padding == true ? true : false;
let showOnHover = options.showOnHover ? ' on-hover' : '';
Expand Down Expand Up @@ -58,7 +58,7 @@ function spacers( options ) {
case 'padding':
spacingDimensions.forEach( dim => {

spacerSize = ( padding[dim] == "0" ? defaultSpacing : padding[dim] );
spacerSize = ( padding[dim] == "" ? defaultSpacing : padding[dim] );

spacerDivs += '<div data-size="'+ spacerSize +'" data-type="'+ property +'" data-id="'+ spacerId +'" class="spacer spacer-' + spacerId + ' spacer-'+ dim +'" data-dragging="'+ getOppositeDimension(dim) +'" data-position="'+ dim +'"> <span class="spacer-indicator"> <span class="'+ ( showSpacingValue ? '' : 'display-none ' ) +'spacer-size">'+ (spacerSize == '' ? '0' : spacerSize) +'</span>'+ showLabel + spacerLock + '</span> </div>';

Expand Down Expand Up @@ -89,17 +89,15 @@ function spacers( options ) {
spacers.forEach(spacer => {

// Adding default spacing
if( !options.defaultPadding || !options.defaultMargin ) {
document.documentElement.style.setProperty( '--spacer-size', defaultSpacing + spacingUnit );
}
document.documentElement.style.setProperty( '--spacer-size', defaultSpacing + spacingUnit );

// Addding custom-defined classes
if ( options.spacerClass ) {
spacer.classList.add( ...options.spacerClass.split(' ') );
}

// Adding default spacing
spacerValue = spacer.getAttribute('data-size') ? spacer.getAttribute('data-size') : defaultSpacing;
spacerValue = ( spacer.getAttribute('data-size') ? spacer.getAttribute('data-size') : defaultSpacing ) + spacingUnit;
spacerPosition = spacer.getAttribute('data-position');

if( spacerPosition == "top" || spacerPosition == "bottom" ) {
Expand Down

0 comments on commit fb525aa

Please sign in to comment.