From be7f608c9784cf6c5541090fbc8d6ec5a6c8c560 Mon Sep 17 00:00:00 2001 From: Asa Schachar Date: Tue, 17 Sep 2019 13:33:35 -0700 Subject: [PATCH 1/2] Add the editor template --- .../Editor Extensions/Template/config.json | 61 +++++++++++++++++++ .../Editor Extensions/Template/extension.css | 0 .../Editor Extensions/Template/extension.html | 2 + .../Template/extension_apply.js | 11 ++++ .../Template/extension_properties.json | 55 +++++++++++++++++ .../Template/extension_undo.js | 1 + 6 files changed, 130 insertions(+) create mode 100644 Extensions/Editor Extensions/Template/config.json create mode 100644 Extensions/Editor Extensions/Template/extension.css create mode 100644 Extensions/Editor Extensions/Template/extension.html create mode 100644 Extensions/Editor Extensions/Template/extension_apply.js create mode 100644 Extensions/Editor Extensions/Template/extension_properties.json create mode 100644 Extensions/Editor Extensions/Template/extension_undo.js diff --git a/Extensions/Editor Extensions/Template/config.json b/Extensions/Editor Extensions/Template/config.json new file mode 100644 index 0000000..a602717 --- /dev/null +++ b/Extensions/Editor Extensions/Template/config.json @@ -0,0 +1,61 @@ +{ + "plugin_type": "widget", + "name": "Extension Template", + "edit_page_url": "www.optimizely.com", + "form_schema": [ + { + "default_value": "append", + "field_type": "dropdown", + "name": "position", + "label": "Position", + "options": { + "choices": [ + { + "value": "before", + "label": "Before" + }, + { + "value": "after", + "label": "After" + }, + { + "value": "prepend", + "label": "At Beginning" + }, + { + "value": "append", + "label": "At End Of" + } + ] + } + }, + { + "default_value": "", + "field_type": "selector", + "name": "selector", + "label": "Selector", + "options": null + }, + { + "default_value": "Title Text", + "field_type": "text", + "name": "title", + "label": "title", + "options": null + }, + { + "default_value": "Text", + "field_type": "text", + "name": "text", + "label": "text", + "options": null + } + ], + "description": "", + "options": { + "html": "
\n
", + "css": "", + "apply_js": "\n \nif(extension.position == \"before\"){ \n \tdocument.querySelector(extension.selector).insertAdjacentHTML('beforebegin', extension.$html); \n} else if(extension.position == \"prepend\") { \n document.querySelector(extension.selector).insertAdjacentHTML('afterbegin', extension.$html); \n} else if(extension.position == \"after\") { \n document.querySelector(extension.selector).insertAdjacentHTML('afterend', extension.$html); \n} else if(extension.position == \"append\") { \n document.querySelector(extension.selector).insertAdjacentHTML('beforeend', extension.$html); \n}\n", + "undo_js": "document.getElementById(\"optimizely-extension-\" + extension.$instance).remove();" + } +} diff --git a/Extensions/Editor Extensions/Template/extension.css b/Extensions/Editor Extensions/Template/extension.css new file mode 100644 index 0000000..e69de29 diff --git a/Extensions/Editor Extensions/Template/extension.html b/Extensions/Editor Extensions/Template/extension.html new file mode 100644 index 0000000..c7db4ec --- /dev/null +++ b/Extensions/Editor Extensions/Template/extension.html @@ -0,0 +1,2 @@ +
+
\ No newline at end of file diff --git a/Extensions/Editor Extensions/Template/extension_apply.js b/Extensions/Editor Extensions/Template/extension_apply.js new file mode 100644 index 0000000..0438a13 --- /dev/null +++ b/Extensions/Editor Extensions/Template/extension_apply.js @@ -0,0 +1,11 @@ + + +if(extension.position == "before"){ + document.querySelector(extension.selector).insertAdjacentHTML('beforebegin', extension.$html); +} else if(extension.position == "prepend") { + document.querySelector(extension.selector).insertAdjacentHTML('afterbegin', extension.$html); +} else if(extension.position == "after") { + document.querySelector(extension.selector).insertAdjacentHTML('afterend', extension.$html); +} else if(extension.position == "append") { + document.querySelector(extension.selector).insertAdjacentHTML('beforeend', extension.$html); +} diff --git a/Extensions/Editor Extensions/Template/extension_properties.json b/Extensions/Editor Extensions/Template/extension_properties.json new file mode 100644 index 0000000..33d1c9d --- /dev/null +++ b/Extensions/Editor Extensions/Template/extension_properties.json @@ -0,0 +1,55 @@ +{ + "plugin_type": "widget", + "name": "Extension Template", + "edit_page_url": "www.optimizely.com", + "form_schema": [ + { + "default_value": "append", + "field_type": "dropdown", + "name": "position", + "label": "Position", + "options": { + "choices": [ + { + "value": "before", + "label": "Before" + }, + { + "value": "after", + "label": "After" + }, + { + "value": "prepend", + "label": "At Beginning" + }, + { + "value": "append", + "label": "At End Of" + } + ] + } + }, + { + "default_value": "", + "field_type": "selector", + "name": "selector", + "label": "Selector", + "options": null + }, + { + "default_value": "Title Text", + "field_type": "text", + "name": "title", + "label": "title", + "options": null + }, + { + "default_value": "Text", + "field_type": "text", + "name": "text", + "label": "text", + "options": null + } + ], + "description": "" +} \ No newline at end of file diff --git a/Extensions/Editor Extensions/Template/extension_undo.js b/Extensions/Editor Extensions/Template/extension_undo.js new file mode 100644 index 0000000..7e43cae --- /dev/null +++ b/Extensions/Editor Extensions/Template/extension_undo.js @@ -0,0 +1 @@ +document.getElementById("optimizely-extension-" + extension.$instance).remove(); \ No newline at end of file From c0338530ce136a295bb4c2e116155176bcaef877 Mon Sep 17 00:00:00 2001 From: Asa Schachar Date: Tue, 17 Sep 2019 13:40:05 -0700 Subject: [PATCH 2/2] Simplify the extension --- .../Editor Extensions/Template/config.json | 38 +++++++++---------- .../Editor Extensions/Template/extension.html | 3 +- .../Template/extension_apply.js | 12 +----- .../Template/extension_properties.json | 10 ++--- 4 files changed, 26 insertions(+), 37 deletions(-) diff --git a/Extensions/Editor Extensions/Template/config.json b/Extensions/Editor Extensions/Template/config.json index a602717..40f9caa 100644 --- a/Extensions/Editor Extensions/Template/config.json +++ b/Extensions/Editor Extensions/Template/config.json @@ -10,22 +10,22 @@ "label": "Position", "options": { "choices": [ - { - "value": "before", - "label": "Before" - }, - { - "value": "after", - "label": "After" - }, - { - "value": "prepend", - "label": "At Beginning" - }, - { - "value": "append", - "label": "At End Of" - } + { + "value": "beforebegin", + "label": "Before" + }, + { + "value": "afterend", + "label": "After" + }, + { + "value": "afterbegin", + "label": "At Beginning" + }, + { + "value": "beforeend", + "label": "At End Of" + } ] } }, @@ -53,9 +53,9 @@ ], "description": "", "options": { - "html": "
\n
", + "html": "
\n", "css": "", - "apply_js": "\n \nif(extension.position == \"before\"){ \n \tdocument.querySelector(extension.selector).insertAdjacentHTML('beforebegin', extension.$html); \n} else if(extension.position == \"prepend\") { \n document.querySelector(extension.selector).insertAdjacentHTML('afterbegin', extension.$html); \n} else if(extension.position == \"after\") { \n document.querySelector(extension.selector).insertAdjacentHTML('afterend', extension.$html); \n} else if(extension.position == \"append\") { \n document.querySelector(extension.selector).insertAdjacentHTML('beforeend', extension.$html); \n}\n", + "apply_js": "document.querySelector(extension.selector).insertAdjacentHTML(extension.position, extension.$html);\n", "undo_js": "document.getElementById(\"optimizely-extension-\" + extension.$instance).remove();" } -} +} \ No newline at end of file diff --git a/Extensions/Editor Extensions/Template/extension.html b/Extensions/Editor Extensions/Template/extension.html index c7db4ec..9df1f35 100644 --- a/Extensions/Editor Extensions/Template/extension.html +++ b/Extensions/Editor Extensions/Template/extension.html @@ -1,2 +1 @@ -
-
\ No newline at end of file +
diff --git a/Extensions/Editor Extensions/Template/extension_apply.js b/Extensions/Editor Extensions/Template/extension_apply.js index 0438a13..dc484c1 100644 --- a/Extensions/Editor Extensions/Template/extension_apply.js +++ b/Extensions/Editor Extensions/Template/extension_apply.js @@ -1,11 +1 @@ - - -if(extension.position == "before"){ - document.querySelector(extension.selector).insertAdjacentHTML('beforebegin', extension.$html); -} else if(extension.position == "prepend") { - document.querySelector(extension.selector).insertAdjacentHTML('afterbegin', extension.$html); -} else if(extension.position == "after") { - document.querySelector(extension.selector).insertAdjacentHTML('afterend', extension.$html); -} else if(extension.position == "append") { - document.querySelector(extension.selector).insertAdjacentHTML('beforeend', extension.$html); -} +document.querySelector(extension.selector).insertAdjacentHTML(extension.position, extension.$html); diff --git a/Extensions/Editor Extensions/Template/extension_properties.json b/Extensions/Editor Extensions/Template/extension_properties.json index 33d1c9d..f0b02b8 100644 --- a/Extensions/Editor Extensions/Template/extension_properties.json +++ b/Extensions/Editor Extensions/Template/extension_properties.json @@ -11,19 +11,19 @@ "options": { "choices": [ { - "value": "before", + "value": "beforebegin", "label": "Before" }, { - "value": "after", + "value": "afterend", "label": "After" }, { - "value": "prepend", + "value": "afterbegin", "label": "At Beginning" }, { - "value": "append", + "value": "beforeend", "label": "At End Of" } ] @@ -52,4 +52,4 @@ } ], "description": "" -} \ No newline at end of file +}