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
code-highlighter.js
87 lines
| 1 | export default function () { |
| 2 | 'use strict'; |
| 3 | |
| 4 | let editor = null; |
| 5 | |
| 6 | /** |
| 7 | * Check ad code and toggle warnings for shortcode or PHP. |
| 8 | */ |
| 9 | const checkSource = () => { |
| 10 | const text = editor |
| 11 | ? editor.codemirror.getValue() |
| 12 | : jQuery('#advads-ad-content-plain').val(); |
| 13 | const phpWarning = jQuery('#advads-parameters-php-warning'); |
| 14 | const allowPhpWarning = jQuery('#advads-allow-php-warning'); |
| 15 | phpWarning.hide(); |
| 16 | allowPhpWarning.hide(); |
| 17 | |
| 18 | // Allow PHP is enabled |
| 19 | if (jQuery('#advads-parameters-php').prop('checked')) { |
| 20 | // ad content has opening php tag. |
| 21 | if (/<\?(?:php|=)/.test(text)) { |
| 22 | allowPhpWarning.show(); |
| 23 | } else { |
| 24 | phpWarning.show(); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // Shortcode warning. |
| 29 | jQuery('#advads-parameters-shortcodes-warning').toggle( |
| 30 | jQuery('#advads-parameters-shortcodes').prop('checked') && |
| 31 | !/\[[^\]]+\]/.test(text) |
| 32 | ); |
| 33 | }; |
| 34 | |
| 35 | jQuery(document).on('keyup', '#advads-ad-content-plain', checkSource); |
| 36 | |
| 37 | jQuery(document).on( |
| 38 | 'click', |
| 39 | '#advads-parameters-php,#advads-parameters-shortcodes', |
| 40 | checkSource |
| 41 | ); |
| 42 | |
| 43 | jQuery(document).on('paramloaded', '#advanced-ads-ad-parameters', () => { |
| 44 | let settings; |
| 45 | try { |
| 46 | settings = window.advancedAds.admin.codeMirror.settings; |
| 47 | } catch (Ex) { |
| 48 | editor = null; |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | if ( |
| 53 | 'plain' !== jQuery('input[name="advanced_ad[type]"]:checked').val() |
| 54 | ) { |
| 55 | editor = null; |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | const source = jQuery('#advads-ad-content-plain'); |
| 60 | |
| 61 | if (!source.length) { |
| 62 | editor = null; |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | editor = wp.codeEditor.initialize(source, settings); |
| 67 | editor.codemirror.on('keyup', checkSource); |
| 68 | |
| 69 | window.advancedAds.admin.codeMirror = editor.codemirror; |
| 70 | |
| 71 | window.advancedAds = window.advancedAds || {}; |
| 72 | window.advancedAds.admin.getSourceCode = () => { |
| 73 | return editor |
| 74 | ? editor.codemirror.getValue() |
| 75 | : jQuery('#advads-ad-content-plain').val(); |
| 76 | }; |
| 77 | |
| 78 | window.advancedAds.admin.setSourceCode = (text) => { |
| 79 | if (editor) { |
| 80 | editor.codemirror.setValue(text); |
| 81 | } else { |
| 82 | jQuery('#advads-ad-content-plain').val(text); |
| 83 | } |
| 84 | }; |
| 85 | }); |
| 86 | } |
| 87 |