| 1 |
jQuery(document).ready(function ($) { |
| 2 |
$('.f12-cf7-details').on('click', function () { |
| 3 |
var hash = $(this).attr('data-hash'); |
| 4 |
|
| 5 |
if (hash) { |
| 6 |
$.ajax({ |
| 7 |
url: doi.ajax_url, |
| 8 |
type: 'post', |
| 9 |
data: { |
| 10 |
action: 'f12_doi_details', |
| 11 |
nonce: doi.nonce, |
| 12 |
hash: hash |
| 13 |
}, |
| 14 |
success(data) { |
| 15 |
var data = JSON.parse(data); |
| 16 |
showPopup(data.content); |
| 17 |
} |
| 18 |
}) |
| 19 |
} |
| 20 |
}); |
| 21 |
|
| 22 |
function removePopup() { |
| 23 |
$(document).find('.forge12-plugin-popup, .forge12-plugin-popup-overlay').remove(); |
| 24 |
} |
| 25 |
|
| 26 |
function showPopup(content) { |
| 27 |
removePopup(); |
| 28 |
$('body').append( |
| 29 |
'<div class="forge12-plugin-popup-overlay"></div>' + |
| 30 |
'<div class="forge12-plugin-popup">' + |
| 31 |
'<button type="button" class="forge12-plugin-popup-close">' + |
| 32 |
'<span class="dashicons dashicons-no-alt"></span>' + |
| 33 |
'</button>' + |
| 34 |
'<div class="forge12-plugin-popup-content">' + content + '</div>' + |
| 35 |
'</div>' |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
$(document).on('click', '.forge12-plugin-popup-close', function () { |
| 40 |
removePopup(); |
| 41 |
}); |
| 42 |
|
| 43 |
$(document).on('click', '.forge12-plugin-popup-overlay', function () { |
| 44 |
removePopup(); |
| 45 |
}); |
| 46 |
|
| 47 |
$(document).on('mouseenter', '.forge12-plugin-popup .doi-tooltip', function () { |
| 48 |
var $tip = $(this).find('.doi-tooltip-text'); |
| 49 |
var rect = this.getBoundingClientRect(); |
| 50 |
var tipW = 260; |
| 51 |
var left = rect.left + rect.width / 2 - tipW / 2; |
| 52 |
if (left < 8) left = 8; |
| 53 |
if (left + tipW > window.innerWidth - 8) left = window.innerWidth - tipW - 8; |
| 54 |
$tip.css({ left: left + 'px', bottom: (window.innerHeight - rect.top + 8) + 'px' }); |
| 55 |
}); |
| 56 |
}); |