jQuery(document).ready(function () {
const fbv_cross = `
Your WordPress media library is messy?
Start using FileBird to organize your files into folders by drag and drop.
`
const install_failed = `Oops! Installation failed.
`
jQuery.fn.exists = function (callback) {
var args = [].slice.call(arguments, 1)
if (this.length) {
callback.call(this, args)
}
return this
}
jQuery('body.upload-php #wpfooter').exists(function () {
njtCross.show_popup && this.append(fbv_cross)
})
jQuery('.fbv-cross-popup').click(function () {
jQuery(this).parent().toggleClass('fbv-cross-popup-open')
})
jQuery('.fbv-cross-link.fbv-cross-hide-popup').click(function () {
const a = jQuery('#filebird_cross')
jQuery.ajax({
url: ajaxurl,
method: 'POST',
data: {
action: 'njt_filebird_cross_hide',
nonce: njtCross.nonce,
type: 'popup'
},
beforeSend: function(){
a.removeClass('fbv-cross-popup-open').addClass('fbv_permanent_hide')
},
success: function(){
// a.removeClass('fbv-cross-popup-open').addClass('fbv_permanent_hide')
setTimeout(function () {
a.remove()
}, 2000)
}
})
// const a = jQuery('#filebird_cross')
// a.removeClass('fbv-cross-popup-open').addClass('fbv_permanent_hide')
// setTimeout(function () {
// a.remove()
// }, 2000)
})
jQuery('.fbv-cross-link.fbv-cross-hide-notification').click(function(){
jQuery.ajax({
url: ajaxurl,
type: 'POST',
dataType: 'json',
data: {
action: 'njt_filebird_cross_hide',
nonce: njtCross.nonce,
type: 'notification'
}
}).done(function(result) {
if (result.success) {
jQuery('#njt-ads-wrapper button.notice-dismiss').click()
} else {
console.log("Error", result.data.status)
}
});
})
jQuery('.fbv-cross-install:not(.fbv_installing)').click(function (e) {
e.preventDefault()
const normal = 'Install for free'
const loading = 'Installing.'
const done = 'Installed! Organize files now'
const error = 'Install failed. Retry'
const a = jQuery(this)
jQuery.ajax({
url: ajaxurl,
method: 'POST',
data: {
action: 'njt_filebird_cross_install',
nonce: njtCross.nonce
},
beforeSend: function(){
a.focusout()
a.addClass('fbv_installing')
a.html(loading)
},
success: function(response){
if (response.success) {
a.removeClass('fbv_installing').addClass('fbv_done')
a.html(done)
a.off('click')
a.click(()=> { window.location.href = njtCross.media_url })
} else {
a.removeClass('fbv_installing').addClass('fbv_error')
a.parent().after(install_failed)
a.html(error)
}
},
error: function(response){
a.removeClass('fbv_installing').addClass('fbv_error')
a.parent().after(install_failed)
a.html(error)
}
})
// setTimeout(function () {
// a.removeClass('fbv_installing').addClass('fbv_done')
// a.html(done)
// }, 3000)
})
})