Skip to content

Commit

Permalink
Merge pull request #176 from f5devcentral/add-medallia
Browse files Browse the repository at this point in the history
Add medallia survey
  • Loading branch information
jswongF5 committed May 23, 2022
2 parents 5822b0c + 11dcc20 commit b683ca1
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 59 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 "medallia_inline_survey"
# 'base_url' = '' \\ DEFAULTS TO '/'
}

Expand Down
2 changes: 1 addition & 1 deletion f5_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from os import path


__version__ = "2.1.1"
__version__ = "2.2.0"


def get_html_theme_path():
Expand Down
15 changes: 11 additions & 4 deletions f5_sphinx_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ <h5>{{ project }} {{ version }} </h5>
</div>
</div>
{% endif %}
{% if surveymonkey_url %}
<div id="survey-sm-div" survey-sm-url="{{ surveymonkey_url }}">
{% if theme_medallia_embed_url %}
<hr>
<div id="{{ theme_medallia_id }}" class="medallia_survey">
</div>
<script type="text/javascript" src="{{ theme_medallia_embed_url }}" async></script>
{% endif %}
{% if theme_surveymonkey_url %}
<hr>
<div id="survey-sm-div" survey-sm-url="{{ theme_surveymonkey_url }}">
<a id="survey-sm" target="_blank" rel="noopener noreferrer">Click here to provide feedback</a>
</div>
{% endif %}
Expand All @@ -158,8 +165,8 @@ <h5>{{ project }} {{ version }} </h5>
{% if (theme_version_selector) %}
<script src="{{ pathto('_static/js/index.js', 1) }}"></script>
{%- endif %}
{% if (surveymonkey_url) %}
<script src="{{ pathto('_static/js/survey-monkey.js', 1) }}"></script>
{% if (theme_surveymonkey_url or theme_medallia_embed_url) %}
<script src="{{ pathto('_static/js/feedback.js', 1) }}"></script>
{%- endif %}
<script src="{{ pathto('_static/js/jquery.appear.js', 1) }}"></script>
<script src="{{ pathto('_static/js/printThis.js', 1) }}"></script>
Expand Down
105 changes: 105 additions & 0 deletions f5_sphinx_theme/static/js/feedback.js
Original file line number Diff line number Diff line change
@@ -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;
}
53 changes: 0 additions & 53 deletions f5_sphinx_theme/static/js/survey-monkey.js

This file was deleted.

4 changes: 3 additions & 1 deletion f5_sphinx_theme/theme.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ next_prev_link = False
version_selector = False
base_url = /
enable_version_warning_banner = False
surveymonkey_url = ""
surveymonkey_url =
medallia_embed_url =
medallia_id = medallia_inline_survey

0 comments on commit b683ca1

Please sign in to comment.