diff --git a/acf-fields/split-test-post.json b/acf-fields/split-test-post.json index 8f1965c..2f812b4 100644 --- a/acf-fields/split-test-post.json +++ b/acf-fields/split-test-post.json @@ -20,7 +20,7 @@ "title": "Post Title Test", "dom": "DOM Test" }, - "default_value": false, + "default_value": "dom", "return_format": "value", "multiple": 0, "allow_null": 0, @@ -168,15 +168,7 @@ "type": "repeater", "instructions": "", "required": 0, - "conditional_logic": [ - [ - { - "field": "field_668fec3b09224", - "operator": "==", - "value": "dom" - } - ] - ], + "conditional_logic": 0, "wrapper": { "width": "", "class": "", @@ -254,6 +246,102 @@ } ], "parent_repeater": "field_66982f55bb940" + }, + { + "key": "field_6740b0595dbdb", + "label": "Change classes", + "name": "classes", + "aria-label": "", + "type": "repeater", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "layout": "block", + "pagination": 0, + "min": 0, + "max": 0, + "collapsed": "", + "button_label": "Add Change", + "rows_per_page": 20, + "sub_fields": [ + { + "key": "field_6740b0795dbdc", + "label": "Selector", + "name": "selector", + "aria-label": "", + "type": "text", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "default_value": "", + "maxlength": "", + "allow_in_bindings": 0, + "placeholder": "", + "prepend": "", + "append": "", + "parent_repeater": "field_6740b0595dbdb" + }, + { + "key": "field_6740b0995dbdd", + "label": "Change", + "name": "change", + "aria-label": "", + "type": "radio", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "choices": { + "add": "Add a class", + "remove": "Remove a class" + }, + "default_value": "add", + "return_format": "value", + "allow_null": 0, + "other_choice": 0, + "allow_in_bindings": 0, + "layout": "vertical", + "save_other_choice": 0, + "parent_repeater": "field_6740b0595dbdb" + }, + { + "key": "field_6740b0c55dbde", + "label": "Class", + "name": "class", + "aria-label": "", + "type": "text", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "default_value": "", + "maxlength": "", + "allow_in_bindings": 0, + "placeholder": "", + "prepend": "", + "append": "", + "parent_repeater": "field_6740b0595dbdb" + } + ], + "parent_repeater": "field_66982f55bb940" } ] }, diff --git a/bin/build b/bin/build index b18e1fc..ac50001 100755 --- a/bin/build +++ b/bin/build @@ -17,8 +17,6 @@ if [ ! -f .env ] ; then echo "What is your ACF Pro key?" read -p "> " ACF_PRO_KEY echo >> .env - echo "# This is for the ACF Pro installer plugin" >> .env - echo "# See: https://github.com/dphiffer/acf-pro-installer" >> .env echo "ACF_PRO_KEY=$ACF_PRO_KEY" >> .env echo echo "Thank you!" diff --git a/src/DomTests.php b/src/DomTests.php index 5d75dcc..39d5bfa 100644 --- a/src/DomTests.php +++ b/src/DomTests.php @@ -107,7 +107,16 @@ function show_results($post) { } foreach ($_variants as $index => $variant) { - $_variants[$index]['description'] = count($variant['content']) . ' content changes'; + // Describe content changes + $plural = (! empty($variant['content']) && count($variant['content']) > 1) ? 's' : ''; + $description = empty($variant['content']) ? '' : count($variant['content']) . ' content change' . $plural; + + // Describe class changes + $separator = empty($description) ? '' : ', '; + $plural = (! empty($variant['classes']) && count($variant['classes']) > 1) ? 's' : ''; + $description .= empty($variant['classes']) ? '' : $separator . count($variant['classes']) . ' class change' . $plural; + + $_variants[$index]['description'] = $description; } $variants = [ diff --git a/src/split-tests.js b/src/split-tests.js index 0569dc4..ca07edc 100644 --- a/src/split-tests.js +++ b/src/split-tests.js @@ -58,7 +58,7 @@ export default function split_tests_init() { for (let replacement of variant.content) { let targets = document.querySelectorAll(replacement.selector); for (let target of targets) { - if (replacement.search && target.innerText.trim() != replacement.search.trim()) { + if (replacement.search != '' && target.innerText.trim() != replacement.search.trim()) { continue; } target.innerText = replacement.replace; @@ -66,6 +66,19 @@ export default function split_tests_init() { } } + if (variant.classes) { + for (let change of variant.classes) { + let targets = document.querySelectorAll(change.selector); + for (let target of targets) { + if (change.change == 'add') { + target.classList.add(change.class); + } else if (change.change == 'remove') { + target.classList.remove(change.class); + } + } + } + } + if (variant.conversion == 'click') { const selector = variant.click_selector; const content = variant.click_content;