From 086d0eebc6ba8fede89a8bfb2d47de6840dc13e8 Mon Sep 17 00:00:00 2001 From: John Wong Date: Fri, 20 May 2022 15:53:53 -0700 Subject: [PATCH 1/4] feat: Adding ability to enable Medallia survey, fixed survey theme option bug, and renamed js used for surveys --- f5_sphinx_theme/layout.html | 15 ++- f5_sphinx_theme/static/js/feedback.js | 105 +++++++++++++++++++++ f5_sphinx_theme/static/js/survey-monkey.js | 53 ----------- 3 files changed, 116 insertions(+), 57 deletions(-) create mode 100644 f5_sphinx_theme/static/js/feedback.js delete mode 100644 f5_sphinx_theme/static/js/survey-monkey.js diff --git a/f5_sphinx_theme/layout.html b/f5_sphinx_theme/layout.html index d1682d3..c745682 100644 --- a/f5_sphinx_theme/layout.html +++ b/f5_sphinx_theme/layout.html @@ -135,8 +135,15 @@
{{ project }} {{ version }}
{% endif %} - {% if surveymonkey_url %} -
+ {% if theme_medallia_embed_url %} +
+
+
+ + {% endif %} + {% if theme_surveymonkey_url %} +
+ {% endif %} @@ -158,8 +165,8 @@
{{ project }} {{ version }}
{% if (theme_version_selector) %} {%- endif %} -{% if (surveymonkey_url) %} - +{% if (theme_surveymonkey_url or theme_medallia_embed_url) %} + {%- endif %} diff --git a/f5_sphinx_theme/static/js/feedback.js b/f5_sphinx_theme/static/js/feedback.js new file mode 100644 index 0000000..10bf27b --- /dev/null +++ b/f5_sphinx_theme/static/js/feedback.js @@ -0,0 +1,105 @@ +const data = { + surveyMonkey: { + site: "site", + page: "page", + version: "version" + }, + medallia: { + site: "subsite", + page: "page", + version: "version" + } +} + +const surveyMonkeyDivId = "survey-sm-div"; +const surveyMonkeyAId = "survey-sm"; +const surveyMonkeyUrlAttr = 'survey-sm-url'; + +const htmlString = ".html"; +const htmlDefaultIndex = "index.html"; + +// 'window' is a global variable. Define 'medalliaData' global variable here. +var medalliaData = {}; +const medalliaDivClassName = "medallia_survey"; + +$(document).ready(function () { + const surveyMonkeyDiv = document.getElementById(surveyMonkeyDivId); + const medalliaDivs = document.getElementsByClassName(medalliaDivClassName); + + // SurveyMonkey and Medallia are disabled. + if (surveyMonkeyDiv == null && !medalliaDivs.length) { + return; + } + + if (surveyMonkeyDiv != null) { + renderSM(surveyMonkeyDiv); + } + + if (medalliaDivs.length >= 1) { + renderMedallia(); + } +}) + +function renderSM(smDiv) { + // Get SurveyMonkey URL from div id 'survey-sm-div'. + const surveyMonkeyUrl = smDiv.getAttribute(surveyMonkeyUrlAttr); + const surveyMonkey = new URL(surveyMonkeyUrl); + + // Get the current URL. + const url = new URL(window.location.href); + const urlPathNames = url.pathname.split('/').filter(Boolean); + + // If this is an 'index.html' or isn't even an html page, hide the SurveyMonkey link. + if (url.pathname.trim().endsWith(htmlDefaultIndex) || !url.pathname.endsWith(htmlString)) { + console.debug('This page need to hide SurveyMonkey link') + // Hide the SurveyMonkey Div because this pages doesn't need it. + if (smDiv != null) { + $("#" + surveyMonkeyDivId).hide(); + } + } + // Otherwise determine the custom variables for SurveyMonkey. + else if (urlPathNames[urlPathNames.length - 1].endsWith(htmlString)) { + if (urlPathNames.length == 1) { + surveyMonkey.searchParams.append(data.surveyMonkey.page, urlPathNames[urlPathNames.length - 1]); + } else if (urlPathNames.length == 2) { + surveyMonkey.searchParams.append(data.surveyMonkey.site, urlPathNames[urlPathNames.length - 2]); + surveyMonkey.searchParams.append(data.surveyMonkey.page, urlPathNames[urlPathNames.length - 1]); + } else if (urlPathNames.length >= 3) { + surveyMonkey.searchParams.append(data.surveyMonkey.site, urlPathNames[urlPathNames.length - 3]); + surveyMonkey.searchParams.append(data.surveyMonkey.version, urlPathNames[urlPathNames.length - 2]); + surveyMonkey.searchParams.append(data.surveyMonkey.page, urlPathNames[urlPathNames.length - 1]); + } + // Modify SurveyMonkey href. + var surveyMonkeyLink = document.getElementById(surveyMonkeyAId); + if (surveyMonkeyLink != null) { + console.debug('Modifying SurveyMonkey link'); + surveyMonkeyLink.href = surveyMonkey.toString(); + } + } +} + +function renderMedallia() { + // Initialize data Medallia variables. + var medalliaDataSite, medalliaDataVersion, medalliaDataPage; + // Get the current URL. + const url = new URL(window.location.href); + // Create array with each element split by '/' character in url pathname. Then, remove and empty array entries. + const urlPathNames = url.pathname.split('/').filter(Boolean); + + // Assign subsite, page, and version information. + if (urlPathNames.length == 1) { + medalliaDataPage = urlPathNames[urlPathNames.length - 1]; + } else if (urlPathNames.length == 2) { + medalliaDataSite = urlPathNames[urlPathNames.length - 2]; + medalliaDataPage = urlPathNames[urlPathNames.length - 1]; + } else if (urlPathNames.length >= 3) { + medalliaDataSite = urlPathNames[urlPathNames.length - 3]; + medalliaDataVersion = urlPathNames[urlPathNames.length - 2]; + medalliaDataPage = urlPathNames[urlPathNames.length - 1]; + } + + // Set HTML global variable medalliaData. + window.medalliaData[data.medallia.site] = medalliaDataSite; + window.medalliaData[data.medallia.version] = medalliaDataVersion; + window.medalliaData[data.medallia.page] = medalliaDataPage; +} diff --git a/f5_sphinx_theme/static/js/survey-monkey.js b/f5_sphinx_theme/static/js/survey-monkey.js deleted file mode 100644 index 1bab2d2..0000000 --- a/f5_sphinx_theme/static/js/survey-monkey.js +++ /dev/null @@ -1,53 +0,0 @@ -const surveyMonkeyVariablePage = "page"; -const surveyMonkeyVariableSite = "site"; -const surveyMonkeyVariableVersion = "version"; - -const surveyMonkeyDivId = "survey-sm-div"; -const surveyMonkeyAId = "survey-sm"; -const surveyMonkeyUrlAttr = 'survey-sm-url'; - -const htmlString = ".html"; - -$(document).ready(function () { - var surveyMonkeyDiv = document.getElementById(surveyMonkeyDivId); - // SurveyMonkey is disabled. - if (surveyMonkeyDiv == null) { - return; - } - - // Get SurveyMonkey URL from div id 'survey-sm-div'. - const surveyMonkeyUrl = surveyMonkeyDiv.getAttribute(surveyMonkeyUrlAttr); - const surveyMonkey = new URL(surveyMonkeyUrl); - - // Get the current URL. - const url = new URL(window.location.href); - const urlPathNames = url.pathname.split('/').filter(Boolean); - - // If this is an 'index.html' or isn't even an html page, hide the SurveyMonkey link. - if (url.pathname.trim().endsWith("index.html") || !url.pathname.endsWith(htmlString)) { - console.debug('This page need to hide SurveyMonkey link') - // Hide the SurveyMonkey Div because this pages doesn't need it. - if (surveyMonkeyDiv != null) { - $("#" + surveyMonkeyDivId).hide(); - } - } - // Otherwise determine the custom variables for SurveyMonkey. - else if (urlPathNames[urlPathNames.length - 1].endsWith(htmlString)) { - if (urlPathNames.length == 1) { - surveyMonkey.searchParams.append(surveyMonkeyVariablePage, urlPathNames[urlPathNames.length - 1]); - } else if (urlPathNames.length == 2) { - surveyMonkey.searchParams.append(surveyMonkeyVariableSite, urlPathNames[urlPathNames.length - 2]); - surveyMonkey.searchParams.append(surveyMonkeyVariablePage, urlPathNames[urlPathNames.length - 1]); - } else if (urlPathNames.length >= 3) { - surveyMonkey.searchParams.append(surveyMonkeyVariableSite, urlPathNames[urlPathNames.length - 3]); - surveyMonkey.searchParams.append(surveyMonkeyVariableVersion, urlPathNames[urlPathNames.length - 2]); - surveyMonkey.searchParams.append(surveyMonkeyVariablePage, urlPathNames[urlPathNames.length - 1]); - } - // Modify SurveyMonkey href. - var surveyMonkeyLink = document.getElementById(surveyMonkeyAId); - if (surveyMonkeyLink != null) { - console.debug('Modifying SurveyMonkey link'); - surveyMonkeyLink.href = surveyMonkey.toString(); - } - } -}) From a313b0ac2bdccbd7f612f081e2fc575bc958dd59 Mon Sep 17 00:00:00 2001 From: John Wong Date: Fri, 20 May 2022 15:57:09 -0700 Subject: [PATCH 2/4] docs: Adding Medallia default values. --- README.rst | 2 ++ f5_sphinx_theme/theme.conf | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.rst b/README.rst index fc57083..1924c7b 100644 --- a/README.rst +++ b/README.rst @@ -23,6 +23,8 @@ Setup and Configuration 'next_prev_link': True or False, \\ DEFAULTS TO FALSE 'html_last_updated_fmt': '%Y-%m-%d %H:%M:%S', \\ REQUIRED FOR FEDERATED SEARCH, DO NOT CHANGE # 'surveymonkey_url' = '', \\ DEFAULTS TO "" + # 'medallia_embed_url' = '', \\ DEFAULTS TO "" + # 'medallia_id' = '', \\ DEFAULTS TO "" # 'base_url' = '' \\ DEFAULTS TO '/' } diff --git a/f5_sphinx_theme/theme.conf b/f5_sphinx_theme/theme.conf index 6074601..367c33f 100644 --- a/f5_sphinx_theme/theme.conf +++ b/f5_sphinx_theme/theme.conf @@ -9,3 +9,5 @@ version_selector = False base_url = / enable_version_warning_banner = False surveymonkey_url = "" +medallia_embed_url = "" +medallia_id = medallia_inline_survey From 372282e76b3706be98ec513e2a318cfa9849c90e Mon Sep 17 00:00:00 2001 From: John Wong Date: Fri, 20 May 2022 15:58:21 -0700 Subject: [PATCH 3/4] feat: Updating minor version since Medallia is a new feature. --- f5_sphinx_theme/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/f5_sphinx_theme/__init__.py b/f5_sphinx_theme/__init__.py index 7da61b7..3ab6200 100644 --- a/f5_sphinx_theme/__init__.py +++ b/f5_sphinx_theme/__init__.py @@ -16,7 +16,7 @@ from os import path -__version__ = "2.1.1" +__version__ = "2.2.0" def get_html_theme_path(): From 11dcc200dcb9be24459e9cc154a556368f8a77af Mon Sep 17 00:00:00 2001 From: John Wong Date: Fri, 20 May 2022 16:46:15 -0700 Subject: [PATCH 4/4] fix: Resolve blank default values in survey theme variables --- README.rst | 4 ++-- f5_sphinx_theme/theme.conf | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 1924c7b..4cca6e0 100644 --- a/README.rst +++ b/README.rst @@ -23,8 +23,8 @@ Setup and Configuration 'next_prev_link': True or False, \\ DEFAULTS TO FALSE 'html_last_updated_fmt': '%Y-%m-%d %H:%M:%S', \\ REQUIRED FOR FEDERATED SEARCH, DO NOT CHANGE # 'surveymonkey_url' = '', \\ DEFAULTS TO "" - # 'medallia_embed_url' = '', \\ DEFAULTS TO "" - # 'medallia_id' = '', \\ DEFAULTS TO "" + # 'medallia_embed_url' = '', \\ DEFAULTS TO "" + # 'medallia_id' = '', \\ DEFAULTS TO "medallia_inline_survey" # 'base_url' = '' \\ DEFAULTS TO '/' } diff --git a/f5_sphinx_theme/theme.conf b/f5_sphinx_theme/theme.conf index 367c33f..f389d1a 100644 --- a/f5_sphinx_theme/theme.conf +++ b/f5_sphinx_theme/theme.conf @@ -8,6 +8,6 @@ next_prev_link = False version_selector = False base_url = / enable_version_warning_banner = False -surveymonkey_url = "" -medallia_embed_url = "" +surveymonkey_url = +medallia_embed_url = medallia_id = medallia_inline_survey