ad-types.js
3 months ago
code-highlighter.js
3 months ago
editing.css
3 months ago
editing.js
3 months ago
listing.css
1 week ago
listing.js
3 months ago
placement-box.js
3 months ago
quick-bulk-edit.js
1 week ago
placement-box.js
73 lines
| 1 | import jQuery from 'jquery'; |
| 2 | |
| 3 | function setOptions(placementType, options) { |
| 4 | if ('post_content' === placementType) { |
| 5 | const paragraph = prompt(advadstxt.after_paragraph_promt, 1); |
| 6 | if (paragraph !== null) { |
| 7 | return { ...options, index: parseInt(paragraph, 10) }; |
| 8 | } |
| 9 | } |
| 10 | return options; |
| 11 | } |
| 12 | |
| 13 | function sendAjaxRequest(placementType, placementId, postId, options) { |
| 14 | const advadsBox = jQuery('#advads-ad-injection-box'); |
| 15 | |
| 16 | jQuery.ajax({ |
| 17 | type: 'POST', |
| 18 | url: ajaxurl, |
| 19 | data: { |
| 20 | action: 'advads-ad-injection-content', |
| 21 | placement_type: placementType, |
| 22 | placement_id: placementId, |
| 23 | ad_id: postId, |
| 24 | options, |
| 25 | nonce: advadsglobal.ajax_nonce, |
| 26 | }, |
| 27 | success(r) { |
| 28 | if (!r) { |
| 29 | advadsBox.html('an error occured'); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | jQuery('#advads-ad-injection-box *').hide(); |
| 34 | jQuery( |
| 35 | '#advads-ad-injection-message-placement-created, #advads-ad-injection-message-placement-created *' |
| 36 | ).show(); |
| 37 | |
| 38 | if ('server' === placementType) { |
| 39 | jQuery('.hide-server-placement').hide(); |
| 40 | } |
| 41 | }, |
| 42 | error(MLHttpRequest, textStatus, errorThrown) { |
| 43 | advadsBox.html(errorThrown); |
| 44 | }, |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | export default function () { |
| 49 | const advadsBox = jQuery('#advads-ad-injection-box'); |
| 50 | const postId = jQuery('#post_ID').val(); |
| 51 | |
| 52 | jQuery(document).on('click', '.advads-ad-injection-button', function () { |
| 53 | const placementType = jQuery(this).data('placement-type'); |
| 54 | const placementId = jQuery(this).data('placement-id'); |
| 55 | let options = {}; |
| 56 | |
| 57 | if (!placementType && !placementId) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | options = setOptions(placementType, options); |
| 62 | sendAjaxRequest(placementType, placementId, postId, options); |
| 63 | |
| 64 | advadsBox.find('.advads-loader').show(); |
| 65 | advadsBox.find('.advads-ad-injection-box-placements').hide(); |
| 66 | jQuery('body').animate( |
| 67 | { scrollTop: advadsBox.offset().top - 40 }, |
| 68 | 1, |
| 69 | 'linear' |
| 70 | ); |
| 71 | }); |
| 72 | } |
| 73 |