function cnb_show_condition_placeholder_action() { const optionSelected = jQuery('#cnb_condition_match_type').val() let placeholderText if(optionSelected === 'SIMPLE') { placeholderText = '/blog/' } else if(optionSelected === 'EXACT') { placeholderText = 'https://www.example.com/sample-page/' } else if(optionSelected === 'SUBSTRING') { placeholderText = 'category/' } else if(optionSelected === 'REGEX') { placeholderText = '/(index|about)(\?id=[0-9]+)?$' } else if(optionSelected === 'COUNTRY_CODE') { placeholderText = '2 letter country code (e.g. NL)' } jQuery('#cnb_condition_match_value').attr('placeholder', placeholderText) } /** * Show an example condition in the form field for each of the match types */ function cnb_show_condition_placeholder() { cnb_show_condition_placeholder_action() jQuery('#cnb_condition_match_type').on('change', function () { cnb_show_condition_placeholder_action() }) } /** * * @param {HTMLElement} element */ function cnb_condition_type_change_action(element) { // Get the select item const selected = jQuery(element).find(":selected") // Get the new option const value = selected.val() // Hide all "conditionType" jQuery('.conditionType').attr('hidden', 'hidden') // Show all "conditionType_TYPE" jQuery('.conditionType_' + value).removeAttr('hidden') // Ensure the selected item is NOT a hidden item // If it is, select the first non-hidden version const matchTypeEle = jQuery('#cnb_condition_match_type') const selectedMatchType = matchTypeEle.find(":selected") if (selectedMatchType.is('[hidden="hidden"]')) { const firstNotHidden = matchTypeEle.find('option[hidden!="hidden"]') if (firstNotHidden.length) { firstNotHidden.first().attr('selected', 'selected') // Also clear the Match value, since it's no longer valid jQuery('#cnb_condition_match_value').val('') cnb_show_condition_placeholder_action() } } } function cnb_condition_type_change_listener() { const ele = jQuery('#cnb_condition_condition_type') if (!ele.length) { return } ele.on('change', function (element) { cnb_condition_type_change_action(element.target) }) cnb_condition_type_change_action(ele[0]) } /** * This calls the admin-ajax action called 'cnb_delete_condition' */ function cnb_delete_condition() { jQuery('tbody[data-wp-lists="list:cnb_list_condition"]#the-list span.delete a[data-ajax="true"]') .on('click', function(){ // Prep data const id = jQuery(this).data('id') const bid = jQuery(this).data('bid') const data = { 'action': 'cnb_delete_condition', 'id': id, 'bid': bid, '_ajax_nonce': jQuery(this).data('wpnonce'), } // Send remove request jQuery.post(ajaxurl, data) .done(() => { // Remove container const action_row = jQuery(this).closest('tr') jQuery(action_row).css("background-color", "#ff726f") jQuery(action_row).fadeOut(function() { jQuery(action_row).css("background-color", "") jQuery(action_row).remove() // Special case: if this is the last item, show a "no items" row const remaining_items = jQuery('table.cnb_list_conditions #the-list tr').length if (!remaining_items) { // Add row jQuery('table.cnb_list_conditions #the-list').html('You have no display rules set up. This means that your button will show on all pages.

' + '

Click the Add display rule button above to limit the appearance. You can freely mix and match rules to meet your requirements.

') } }) }) // Remove ID from Button array jQuery('input[name^="conditions['+id+']"').remove() return false }) } jQuery( function() { cnb_delete_condition() cnb_show_condition_placeholder() cnb_condition_type_change_listener() }) {"id":119,"date":"2023-02-01T15:27:25","date_gmt":"2023-02-01T18:27:25","guid":{"rendered":"https:\/\/incentiveacademy.com.br\/?page_id=119"},"modified":"2023-02-01T15:27:25","modified_gmt":"2023-02-01T18:27:25","slug":"blog","status":"publish","type":"page","link":"https:\/\/incentiveacademy.com.br\/blog\/","title":{"rendered":"Blog"},"content":{"rendered":"","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-119","page","type-page","status-publish","hentry"],"yoast_head":"\nBlog - Incentive Academy<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/incentiveacademy.com.br\/blog\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Blog\" \/>\n<meta property=\"og:url\" content=\"https:\/\/incentiveacademy.com.br\/blog\/\" \/>\n<meta property=\"og:site_name\" content=\"Incentive Academy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/incentiveacademy.com.br\/blog\/\",\"url\":\"https:\/\/incentiveacademy.com.br\/blog\/\",\"name\":\"Blog - Incentive Academy\",\"isPartOf\":{\"@id\":\"https:\/\/incentiveacademy.com.br\/#website\"},\"datePublished\":\"2023-02-01T18:27:25+00:00\",\"dateModified\":\"2023-02-01T18:27:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/incentiveacademy.com.br\/blog\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/incentiveacademy.com.br\/blog\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/incentiveacademy.com.br\/blog\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/incentiveacademy.com.br\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Blog\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/incentiveacademy.com.br\/#website\",\"url\":\"https:\/\/incentiveacademy.com.br\/\",\"name\":\"Incentive Academy\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/incentiveacademy.com.br\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/incentiveacademy.com.br\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/incentiveacademy.com.br\/#organization\",\"name\":\"Incentive Academy\",\"url\":\"https:\/\/incentiveacademy.com.br\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/incentiveacademy.com.br\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/incentiveacademy.com.br\/wp-content\/uploads\/2023\/01\/Incentive-Academy-Logo-Cabecalho.png\",\"contentUrl\":\"https:\/\/incentiveacademy.com.br\/wp-content\/uploads\/2023\/01\/Incentive-Academy-Logo-Cabecalho.png\",\"width\":200,\"height\":67,\"caption\":\"Incentive Academy\"},\"image\":{\"@id\":\"https:\/\/incentiveacademy.com.br\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Blog - Incentive Academy","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/incentiveacademy.com.br\/blog\/","og_locale":"en_US","og_type":"article","og_title":"Blog","og_url":"https:\/\/incentiveacademy.com.br\/blog\/","og_site_name":"Incentive Academy","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/incentiveacademy.com.br\/blog\/","url":"https:\/\/incentiveacademy.com.br\/blog\/","name":"Blog - Incentive Academy","isPartOf":{"@id":"https:\/\/incentiveacademy.com.br\/#website"},"datePublished":"2023-02-01T18:27:25+00:00","dateModified":"2023-02-01T18:27:25+00:00","breadcrumb":{"@id":"https:\/\/incentiveacademy.com.br\/blog\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/incentiveacademy.com.br\/blog\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/incentiveacademy.com.br\/blog\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/incentiveacademy.com.br\/"},{"@type":"ListItem","position":2,"name":"Blog"}]},{"@type":"WebSite","@id":"https:\/\/incentiveacademy.com.br\/#website","url":"https:\/\/incentiveacademy.com.br\/","name":"Incentive Academy","description":"","publisher":{"@id":"https:\/\/incentiveacademy.com.br\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/incentiveacademy.com.br\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/incentiveacademy.com.br\/#organization","name":"Incentive Academy","url":"https:\/\/incentiveacademy.com.br\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/incentiveacademy.com.br\/#\/schema\/logo\/image\/","url":"https:\/\/incentiveacademy.com.br\/wp-content\/uploads\/2023\/01\/Incentive-Academy-Logo-Cabecalho.png","contentUrl":"https:\/\/incentiveacademy.com.br\/wp-content\/uploads\/2023\/01\/Incentive-Academy-Logo-Cabecalho.png","width":200,"height":67,"caption":"Incentive Academy"},"image":{"@id":"https:\/\/incentiveacademy.com.br\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/incentiveacademy.com.br\/wp-json\/wp\/v2\/pages\/119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/incentiveacademy.com.br\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/incentiveacademy.com.br\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/incentiveacademy.com.br\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/incentiveacademy.com.br\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":0,"href":"https:\/\/incentiveacademy.com.br\/wp-json\/wp\/v2\/pages\/119\/revisions"}],"wp:attachment":[{"href":"https:\/\/incentiveacademy.com.br\/wp-json\/wp\/v2\/media?parent=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}