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

Adds possibility of specifying HTMLElement or jQuery object as target #166

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
7 changes: 1 addition & 6 deletions dist/css/iziToast.min.css

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions dist/js/iziToast.min.js

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/js/iziToast.js
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,19 @@

if(settings.target){

$DOM.wrapper = document.querySelector(settings.target);
if (typeof settings.target === 'string') {
$DOM.wrapper = document.querySelector(settings.target);
} else if (settings.target instanceof HTMLElement) {
$DOM.wrapper = settings.target;
} else if (window.jQuery && settings.target instanceof jQuery) {
if (settings.target.length > 1) {
console.warn('The jQuery object passed as a target contained more than one element - only the first one will be used');
}
$DOM.wrapper = settings.target.get(0);
} else {
console.error('Unknown target type');
}

$DOM.wrapper.classList.add(PLUGIN_NAME + '-target');

if(settings.targetFirst) {
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export interface IziToastSettings {
/**
* Fixed place where you want to show the toasts.
*/
target?: string;
target?: string|HTMLElement|jQuery;
/**
* Add toast to first position.
* Default value: true
Expand Down