Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override SVG close button. #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions dist/tingle.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
footer: false,
cssClass: [],
closeLabel: 'Close',
closeMethods: ['overlay', 'button', 'escape']
closeMethods: ['overlay', 'button', 'escape'],
closeIcon: null
}

// extends config
Expand Down Expand Up @@ -330,16 +331,20 @@
this.modalCloseBtn.type = 'button'
this.modalCloseBtn.classList.add('tingle-modal__close')

this.modalCloseBtnIcon = document.createElement('span')
this.modalCloseBtnIcon.classList.add('tingle-modal__closeIcon')
this.modalCloseBtnIcon.innerHTML = closeIcon()
if (!this.opts.closeIcon) {
this.modalCloseBtnIcon = document.createElement('span')
this.modalCloseBtnIcon.classList.add('tingle-modal__closeIcon')
this.modalCloseBtnIcon.innerHTML = closeIcon()

this.modalCloseBtnLabel = document.createElement('span')
this.modalCloseBtnLabel.classList.add('tingle-modal__closeLabel')
this.modalCloseBtnLabel.innerHTML = this.opts.closeLabel
this.modalCloseBtnLabel = document.createElement('span')
this.modalCloseBtnLabel.classList.add('tingle-modal__closeLabel')
this.modalCloseBtnLabel.innerHTML = this.opts.closeLabel

this.modalCloseBtn.appendChild(this.modalCloseBtnIcon)
this.modalCloseBtn.appendChild(this.modalCloseBtnLabel)
this.modalCloseBtn.appendChild(this.modalCloseBtnIcon)
this.modalCloseBtn.appendChild(this.modalCloseBtnLabel)
} else {
this.modalCloseBtn.innerHTML = this.opts.closeIcon
}
}

// modal
Expand Down
2 changes: 1 addition & 1 deletion dist/tingle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h2 data-bullet="1" class="title">Give it a try</h2>
<p>Below you will find some examples for using tingle: </p>

<button class="btn btn--primary btn-demo js-tingle-modal-1">A simple modal</button>
<button class="btn btn--primary btn-demo js-tingle-modal-1-2">A simple modal with custom close button</button>
<button class="btn btn--secondary btn-demo js-tingle-modal-2">Need buttons?</button>
<button class="btn btn--secondary btn-demo js-tingle-modal-3">Big content? No problem!</button>
<button class="btn btn--secondary btn-demo js-tingle-modal-4">Stick to me!</button>
Expand Down Expand Up @@ -184,6 +185,11 @@ <h2 data-bullet="4" class="title">Options</h2>
<td>string</td>
<td>Label which appears on the close button (mobile version)</td>
</tr>
<tr>
<td>closeIcon</td>
<td>string or element</td>
<td>Icon to override the default</td>
</tr>
</table>
<h2 data-bullet="5" class="title">CSS</h2>
<p>
Expand Down Expand Up @@ -359,6 +365,33 @@ <h1>Forcing the user to use the close button</h1>
});
modalTinyNoFooter.setContent(document.querySelector('.tingle-demo-tiny').innerHTML);

/**
* Modal Tiny no footer with custom close button.
*/

var modalTinyCustomCloseIcon = new tingle.modal({
onClose: function () {
console.log('close');
},
onOpen: function () {
console.log('open');
},
beforeOpen: function () {
console.log('before open');
},
beforeClose: function () {
console.log('before close');
return true;
},
cssClass: ['class1', 'class2'],
closeIcon: '❌',
});
var btn = document.querySelector('.js-tingle-modal-1-2');
btn.addEventListener('click', function () {
modalTinyCustomCloseIcon.open();
});
modalTinyCustomCloseIcon.setContent(document.querySelector('.tingle-demo-tiny').innerHTML);

/**
* Modal tiny with btn
*/
Expand Down
Loading