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

Fix jQuery's 3.0 deprecated method #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 21 additions & 9 deletions lib/assets/javascripts/sweet-alert-confirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var sweetAlertConfirmConfig = sweetAlertConfirmConfig || {}; // Add default conf

(function( $ ) {
var sweetAlertConfirm = function(event) {

swalDefaultOptions = {
title: sweetAlertConfirmConfig.title || 'Are you sure?',
type: sweetAlertConfirmConfig.type || 'warning',
Expand Down Expand Up @@ -36,7 +36,7 @@ var sweetAlertConfirmConfig = sweetAlertConfirmConfig || {}; // Add default conf
'method',
'function'
];

function afterAlertCallback(r){
if (nameFunction) {
window[nameFunction]();
Expand Down Expand Up @@ -68,13 +68,13 @@ var sweetAlertConfirmConfig = sweetAlertConfirmConfig || {}; // Add default conf
else {
window.location.href = $linkToVerify.attr('href');
}

}
}
}

var beforeFunction = null;

$.each($linkToVerify.data(), function(key, val){
if ($.inArray(key, optionKeys) >= 0) {
swalOptions[key] = val
Expand All @@ -87,27 +87,39 @@ var sweetAlertConfirmConfig = sweetAlertConfirmConfig || {}; // Add default conf
beforeFunction = val;
}
});

// Skip alert if false
if(beforeFunction != null) {
var beforeRes = window[beforeFunction]($linkToVerify);
if(beforeRes === true) {
return afterAlertCallback(true); // Skip alert
}
}

var nameFunction = swalOptions['function'];
message = $linkToVerify.attr('data-sweet-alert-confirm')
swalOptions['title'] = message
swal(swalOptions, afterAlertCallback);

return false;
}
$(document).on('ready turbolinks:load page:update ajaxComplete', function() {

$(function() {
$('[data-sweet-alert-confirm]').on('click', sweetAlertConfirm)
})

$(document).on('turbolinks:load page:update ajaxComplete', function() {
$('[data-sweet-alert-confirm]').on('click', sweetAlertConfirm)
});

$(function() {
//To avoid "Uncaught TypeError: Cannot read property 'querySelector' of null" on turbolinks
if (typeof window.sweetAlertInitialize === 'function') {
window.sweetAlertInitialize();
}
});

$(document).on('ready turbolinks:load page:load', function() {
$(document).on('turbolinks:load page:load', function() {
//To avoid "Uncaught TypeError: Cannot read property 'querySelector' of null" on turbolinks
if (typeof window.sweetAlertInitialize === 'function') {
window.sweetAlertInitialize();
Expand Down