Skip to content

Commit

Permalink
Fix Safari bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
t4t5 committed Sep 7, 2017
1 parent 6f6225f commit 01a2e22
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/assets/sweetalert/sweetalert.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sweetalert",
"version": "2.0.0",
"version": "2.0.1",
"description": "A beautiful replacement for JavaScript's \"alert\"",
"main": "dist/sweetalert.min.js",
"scripts": {
Expand Down
6 changes: 4 additions & 2 deletions src/css/text.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
line-height: normal;
vertical-align: top;
text-align: left;
padding: 0;
display: inline-block;
margin: 0;
padding: 0 28px;
padding: 0 10px;
font-weight: 400;
color: rgba(0, 0, 0, 0.64);
max-width: calc(100% - 20px);
overflow-wrap: break-word;
box-sizing: border-box;
&:first-child {
margin-top: 45px;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/init/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { initTitle, initText } from './text';
import initButtons from './buttons';
import initContent from './content';

export const injectElIntoModal = (markup: string): Element => {
export const injectElIntoModal = (markup: string): HTMLElement => {
const modal: Element = getNode(MODAL);
const el: Element = stringToNode(markup);
const el: HTMLElement = stringToNode(markup);

modal.appendChild(el);

Expand Down
21 changes: 19 additions & 2 deletions src/modules/init/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,34 @@ import {

import { injectElIntoModal } from './modal';

/*
* Fixes a weird bug that doesn't wrap long text in modal
* This is visible in the Safari browser for example.
* https://stackoverflow.com/a/3485654/2679245
*/
const webkitRerender = (el: HTMLElement) => {
if (navigator.userAgent.includes('AppleWebKit')){
el.style.display = 'none';
el.offsetHeight;
el.style.display = '';
}
}

export const initTitle = (title: string): void => {
if (title) {
const titleEl: Node = injectElIntoModal(titleMarkup);
const titleEl: HTMLElement = injectElIntoModal(titleMarkup);
titleEl.textContent = title;

webkitRerender(titleEl);
}
};

export const initText = (text: string): void => {
if (text) {
const textEl: Node = injectElIntoModal(textMarkup);
const textEl: HTMLElement = injectElIntoModal(textMarkup);
textEl.textContent = text;

webkitRerender(textEl);
}
};

6 changes: 3 additions & 3 deletions src/modules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export const getNode = (className: string): HTMLElement => {
return <HTMLElement>document.querySelector(selector);
};

export const stringToNode = (html: string): Element => {
let wrapper: Element = document.createElement('div');
export const stringToNode = (html: string): HTMLElement => {
let wrapper: HTMLElement = document.createElement('div');
wrapper.innerHTML = html.trim();

return <Element>wrapper.firstChild;
return <HTMLElement>wrapper.firstChild;
};

export const insertAfter = (newNode: Node, referenceNode: Node) => {
Expand Down
10 changes: 7 additions & 3 deletions src/sweetalert.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
& .swal-modal {
opacity: 1;
pointer-events: auto;
transform: scale(1);
box-sizing: border-box;
animation: showSweetAlert 0.3s;
will-change: transform;
}
}
}
Expand All @@ -56,7 +57,7 @@
display: inline-block;
vertical-align: middle;

transform: scale(0.5);
transform: scale(1);
transform-origin: 50% 50%;
z-index: 10001;
transition: transform 0.3s, opacity 0.2s;
Expand All @@ -68,7 +69,10 @@

@keyframes showSweetAlert {
0% {
transform: scale(0.7);
transform: scale(1);
}
1% {
transform: scale(0.5);
}

45% {
Expand Down

0 comments on commit 01a2e22

Please sign in to comment.