Skip to content

Commit

Permalink
Fix position of close button on small screens
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Weiß committed Jun 5, 2014
1 parent f0360e3 commit cdcea70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## HEAD

* Fix position of close button on small screens
* Fix max-width plugin to work on all sizes and listen to resize

## 1.1.3 - 05.06.2014
Expand Down
9 changes: 8 additions & 1 deletion plugins/modal-maxwidth.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
// can be overwritten with `data-cssmodal-margin` attribute
var _margin = 20;

var MODAL_SMALL_BREAKPOINT = 480;

/**
* Include styles into the DOM
* @param {string} rule Styles to inject into the DOM
Expand Down Expand Up @@ -64,12 +66,17 @@
var _scaleLower = function () {
var innerWidth = global.innerWidth || document.documentElement.clientWidth;
var element = CSSModal.activeElement;
var closeButtonMarginRight = '-' + Math.floor(_currentMaxWidth / 2);

// Skip if there is no max width or the window is wider
if (!_currentMaxWidth || innerWidth > _currentMaxWidth) {
return;
}

if (innerWidth < MODAL_SMALL_BREAKPOINT) {
closeButtonMarginRight = 10;
}

// Window width minus margin left and right
_margin = parseInt(element.getAttribute('data-cssmodal-margin'), 10) || _margin;
_currentMaxWidth = innerWidth - (_margin * 2);
Expand All @@ -80,7 +87,7 @@
'}' +

'[data-cssmodal-maxwidth] .modal-close:after {' +
'margin-right: -' + (_currentMaxWidth / 2) + 'px !important;' +
'margin-right: ' + closeButtonMarginRight + 'px !important;' +
'}', element.id);
};

Expand Down

0 comments on commit cdcea70

Please sign in to comment.