diff --git a/readthedocs/core/static-src/core/js/doc-embed/search.js b/readthedocs/core/static-src/core/js/doc-embed/search.js index 619d7ee19e1..4e0574ee4d4 100644 --- a/readthedocs/core/static-src/core/js/doc-embed/search.js +++ b/readthedocs/core/static-src/core/js/doc-embed/search.js @@ -7,33 +7,6 @@ var xss = require('xss/lib/index'); var MAX_RESULT_PER_SECTION = 3; var MAX_SUBSTRING_LIMIT = 100; -/** - * Use try...catch block to append html to contents - * - * @param {Object} contents html element on which additional html is be appended - * @param {String} template underscore.js template string - * @param {Object} data template vars and their values - */ -function append_html_to_contents(contents, template, data) { - // underscore.js throws variable not defined error - // because of change of syntax in new versions. - // See: https://stackoverflow.com/a/25881231/8601393 - try { - // this is the pre-1.7 syntax from Underscore.js - contents.append( - $u.template( - template, - data - ) - ); - } - catch (error) { - // this is the new syntax - contents.append( - $u.template(template)(data) - ); - } -} /* * Search query override for hitting our local API instead of the standard @@ -50,7 +23,7 @@ function attach_elastic_search_query_sphinx(data) { var search_url = document.createElement('a'); search_url.href = data.proxied_api_host + '/api/v2/search/'; - search_url.search = '?q=' + $.urlencode(query) + '&project=' + project + + search_url.search = '?q=' + encodeURIComponent(query) + '&project=' + project + '&version=' + version + '&language=' + language; /* @@ -64,6 +37,42 @@ function attach_elastic_search_query_sphinx(data) { } }; + /** + * Build a section with its matching results. + * + * A section has the form: + * + *
+ *").html(v))}i.append(s)}}}}else console.log("Read the Docs search returned 0 result. Falling back to MkDocs search."),b()}).fail(function(e){console.log("Read the Docs search failed. Falling back to MkDocs search."),b()}),$.ajax({url:t.href,crossDomain:!0,xhrFields:{withCredentials:!0},complete:function(e,t){return"success"!==t||void 0===e.responseJSON||0===e.responseJSON.count?n.reject():n.resolve(e.responseJSON)}}).fail(function(e,t,i){return n.reject()})}function e(){var e=document.getElementById("mkdocs-search-query"),t=(e&&e.addEventListener("keyup",n),window.getSearchTermFromLocation());t&&(e.value=t,n())}var w=i.project,r=i.version,o=i.language||"en";$(document).ready(function(){window.doSearchFallback=window.doSearch,window.doSearch=n,(window.initSearch=e)()})}t.exports={init:function(){var e=n.get();e.is_sphinx_builder()?r(e):e.features&&!e.features.docsearch_disabled?o(e):console.log("Server side search is disabled.")}}},{"./../../../../../../bower_components/xss/lib/index":3,"./rtd-data":14}],16:[function(n,e,t){var r=n("./rtd-data");e.exports={init:function(){var e,t,i=r.get();$(document).on("click","[data-toggle='rst-current-version']",function(){var e=$("[data-toggle='rst-versions']").hasClass("shift-up")?"was_open":"was_closed";"undefined"!=typeof READTHEDOCS_DATA&&READTHEDOCS_DATA.global_analytics_code&&("undefined"!=typeof gtag?gtag("event","Click",{event_category:"Flyout",event_label:e,send_to:"rtfd"}):"undefined"!=typeof ga?ga("rtfd.send","event","Flyout","Click",e):"undefined"!=typeof _gaq&&_gaq.push(["rtfd._setAccount","UA-17997319-1"],["rtfd._trackEvent","Flyout","Click",e]))}),void 0===window.SphinxRtdTheme&&(e=n("./../../../../../../bower_components/sphinx-rtd-theme/js/theme.js").ThemeNav,$(document).ready(function(){setTimeout(function(){e.navBar||e.enable()},1e3)}),i.is_rtd_like_theme()&&!$("div.wy-side-scroll:first").length&&(console.log("Applying theme sidebar fix..."),i=$("nav.wy-nav-side:first"),t=$("
").addClass("wy-side-scroll"),i.children().detach().appendTo(t),t.prependTo(i),e.navBar=t))}}},{"./../../../../../../bower_components/sphinx-rtd-theme/js/theme.js":1,"./rtd-data":14}],17:[function(e,t,i){e("./constants");var s,l=e("./rtd-data"),c="[data-ea-publisher]",d="#ethical-ad-placement";function u(){var e=!1;return $("").attr("id","rtd-detection").attr("class","ethical-rtd").html(" ").appendTo("body"),0===$("#rtd-detection").height()&&(e=!0),$("#rtd-detection").remove(),e}function h(){console.log("---------------------------------------------------------------------------------------"),console.log("Read the Docs hosts documentation for tens of thousands of open source projects."),console.log("We fund our development (we are open source) and operations through advertising."),console.log("We promise to:"),console.log(" - never let advertisers run 3rd party JavaScript"),console.log(" - never sell user data to advertisers or other 3rd parties"),console.log(" - only show advertisements of interest to developers"),console.log("Read more about our approach to advertising here: https://docs.readthedocs.io/en/latest/advertising/ethical-advertising.html"),console.log("%cPlease allow our Ethical Ads or go ad-free:","font-size: 2em"),console.log("https://docs.readthedocs.io/en/latest/advertising/ad-blocking.html"),console.log("--------------------------------------------------------------------------------------")}function p(e){e&&(e=e.attr("class","keep-us-sustainable"),$("").text("Support Read the Docs!").appendTo(e),$("").html('Please help keep us sustainable by allowing our Ethical Ads in your ad blocker or go ad-free by subscribing.').appendTo(e),$("").text("Thank you! ❤️").appendTo(e))}t.exports={init:function(){var t,e,i,n,r,o,a;(s=l.get()).show_promo()&&(r=null,o="readthedocs-sidebar",t=0<$(c).length?($(c).attr("data-ea-publisher","readthedocs"),$(c).attr("data-ea-manual","true"),"image"!==$(c).attr("data-ea-type")&&"text"!==$(c).attr("data-ea-type")&&$(c).attr("data-ea-type","readthedocs-sidebar"),$(c)):(0<$(d).length?(r=d,e=s.is_rtd_like_theme()?"ethical-rtd ethical-dark-theme":"ethical-alabaster"):s.is_mkdocs_builder()&&s.is_rtd_like_theme()?(r="nav.wy-nav-side",e="ethical-rtd ethical-dark-theme"):s.is_rtd_like_theme()?(r="nav.wy-nav-side > div.wy-side-scroll",e="ethical-rtd ethical-dark-theme"):s.is_alabaster_like_theme()&&(r="div.sphinxsidebar > div.sphinxsidebarwrapper",e="ethical-alabaster"),r?((!(a=(n=$("").appendTo(r)).offset())||a.top-$(window).scrollTop()+200>$(window).height())&&(s.is_rtd_like_theme()?(r=$("").insertAfter("footer hr"),e="ethical-rtd",Math.random()<=.25&&(i="stickybox",o="image")):s.is_alabaster_like_theme()&&(r="div.bodywrapper .body",e="ethical-alabaster")),n.remove(),$("").attr("id","rtd-sidebar").attr("data-ea-publisher","readthedocs").attr("data-ea-type",o).attr("data-ea-manual","true").attr("data-ea-style",i).addClass(e).appendTo(r)):null),(a=document.createElement("script")).src="https://media.ethicalads.io/media/client/beta/ethicalads.min.js",a.type="text/javascript",a.async=!0,a.id="ethicaladsjs",document.getElementsByTagName("head")[0].appendChild(a),$.ajax({url:s.api_host+"/api/v2/sustainability/data/",crossDomain:!0,xhrFields:{withCredentials:!0},dataType:"jsonp",data:{format:"jsonp",project:s.project},success:function(e){t&&!e.ad_free&&(e.keywords&&t.attr("data-ea-keywords",e.keywords.join("|")),e.campaign_types&&t.attr("data-ea-campaign-types",e.campaign_types.join("|")),e.publisher&&t.attr("data-ea-publisher",e.publisher),"undefined"!=typeof ethicalads?ethicalads.load():!s.ad_free&&u()?(h(),p(t)):$("#ethicaladsjs").on("load",function(){"undefined"!=typeof ethicalads&ðicalads.load()}))},error:function(){console.error("Error loading Read the Docs user and project information"),!s.ad_free&&u()&&(h(),p(t))}}))}}},{"./constants":12,"./rtd-data":14}],18:[function(e,t,i){var a=e("./rtd-data");t.exports={init:function(e){var t=a.get();if(!e.is_highest)for(var t=window.location.pathname.replace(t.version,e.slug),i=$('Note
You are not reading the most recent version of this documentation. is the latest version available.
").html(v))}n.append(s)}}}}else console.log("Read the Docs search returned 0 result. Falling back to MkDocs search."),b()}).fail(function(e){console.log("Read the Docs search failed. Falling back to MkDocs search."),b()}),$.ajax({url:t.href,crossDomain:!0,xhrFields:{withCredentials:!0},complete:function(e,t){return"success"!==t||void 0===e.responseJSON||0===e.responseJSON.count?r.reject():r.resolve(e.responseJSON)}}).fail(function(e,t,n){return r.reject()})}function e(){var e=document.getElementById("mkdocs-search-query"),t=(e&&e.addEventListener("keyup",r),window.getSearchTermFromLocation());t&&(e.value=t,r())}var w=n.project,i=n.version,o=n.language||"en";$(document).ready(function(){window.doSearchFallback=window.doSearch,window.doSearch=r,(window.initSearch=e)()})}t.exports={init:function(){var e=r.get();e.is_sphinx_builder()?i(e):e.features&&!e.features.docsearch_disabled?o(e):console.log("Server side search is disabled.")}}},{"./../../../../../../bower_components/xss/lib/index":3,"./rtd-data":14}],16:[function(r,e,t){var i=r("./rtd-data");e.exports={init:function(){var e,t,n=i.get();$(document).on("click","[data-toggle='rst-current-version']",function(){var e=$("[data-toggle='rst-versions']").hasClass("shift-up")?"was_open":"was_closed";"undefined"!=typeof READTHEDOCS_DATA&&READTHEDOCS_DATA.global_analytics_code&&("undefined"!=typeof gtag?gtag("event","Click",{event_category:"Flyout",event_label:e,send_to:"rtfd"}):"undefined"!=typeof ga?ga("rtfd.send","event","Flyout","Click",e):"undefined"!=typeof _gaq&&_gaq.push(["rtfd._setAccount","UA-17997319-1"],["rtfd._trackEvent","Flyout","Click",e]))}),void 0===window.SphinxRtdTheme&&(e=r("./../../../../../../bower_components/sphinx-rtd-theme/js/theme.js").ThemeNav,$(document).ready(function(){setTimeout(function(){e.navBar||e.enable()},1e3)}),n.is_rtd_like_theme()&&!$("div.wy-side-scroll:first").length&&(console.log("Applying theme sidebar fix..."),n=$("nav.wy-nav-side:first"),t=$("
").addClass("wy-side-scroll"),n.children().detach().appendTo(t),t.prependTo(n),e.navBar=t))}}},{"./../../../../../../bower_components/sphinx-rtd-theme/js/theme.js":1,"./rtd-data":14}],17:[function(e,t,n){e("./constants");var s,l=e("./rtd-data"),c="[data-ea-publisher]",d="#ethical-ad-placement";function u(){var e=!1;return $("").attr("id","rtd-detection").attr("class","ethical-rtd").html(" ").appendTo("body"),0===$("#rtd-detection").height()&&(e=!0),$("#rtd-detection").remove(),e}function h(){console.log("---------------------------------------------------------------------------------------"),console.log("Read the Docs hosts documentation for tens of thousands of open source projects."),console.log("We fund our development (we are open source) and operations through advertising."),console.log("We promise to:"),console.log(" - never let advertisers run 3rd party JavaScript"),console.log(" - never sell user data to advertisers or other 3rd parties"),console.log(" - only show advertisements of interest to developers"),console.log("Read more about our approach to advertising here: https://docs.readthedocs.io/en/latest/advertising/ethical-advertising.html"),console.log("%cPlease allow our Ethical Ads or go ad-free:","font-size: 2em"),console.log("https://docs.readthedocs.io/en/latest/advertising/ad-blocking.html"),console.log("--------------------------------------------------------------------------------------")}function p(e){e&&(e=e.attr("class","keep-us-sustainable"),$("").text("Support Read the Docs!").appendTo(e),$("").html('Please help keep us sustainable by allowing our Ethical Ads in your ad blocker or go ad-free by subscribing.').appendTo(e),$("").text("Thank you! ❤️").appendTo(e))}t.exports={init:function(){var t,e,n,r,i,o,a;(s=l.get()).show_promo()&&(i=null,o="readthedocs-sidebar",t=0<$(c).length?($(c).attr("data-ea-publisher","readthedocs"),$(c).attr("data-ea-manual","true"),"image"!==$(c).attr("data-ea-type")&&"text"!==$(c).attr("data-ea-type")&&$(c).attr("data-ea-type","readthedocs-sidebar"),$(c)):(0<$(d).length?(i=d,e=s.is_rtd_like_theme()?"ethical-rtd ethical-dark-theme":"ethical-alabaster"):s.is_mkdocs_builder()&&s.is_rtd_like_theme()?(i="nav.wy-nav-side",e="ethical-rtd ethical-dark-theme"):s.is_rtd_like_theme()?(i="nav.wy-nav-side > div.wy-side-scroll",e="ethical-rtd ethical-dark-theme"):s.is_alabaster_like_theme()&&(i="div.sphinxsidebar > div.sphinxsidebarwrapper",e="ethical-alabaster"),i?((!(a=(r=$("").appendTo(i)).offset())||a.top-$(window).scrollTop()+200>$(window).height())&&(s.is_rtd_like_theme()?(i=$("").insertAfter("footer hr"),e="ethical-rtd",Math.random()<=.25&&(n="stickybox",o="image")):s.is_alabaster_like_theme()&&(i="div.bodywrapper .body",e="ethical-alabaster")),r.remove(),$("").attr("id","rtd-sidebar").attr("data-ea-publisher","readthedocs").attr("data-ea-type",o).attr("data-ea-manual","true").attr("data-ea-style",n).addClass(e).appendTo(i)):null),(a=document.createElement("script")).src="https://media.ethicalads.io/media/client/beta/ethicalads.min.js",a.type="text/javascript",a.async=!0,a.id="ethicaladsjs",document.getElementsByTagName("head")[0].appendChild(a),$.ajax({url:s.api_host+"/api/v2/sustainability/data/",crossDomain:!0,xhrFields:{withCredentials:!0},dataType:"jsonp",data:{format:"jsonp",project:s.project},success:function(e){t&&!e.ad_free&&(e.keywords&&t.attr("data-ea-keywords",e.keywords.join("|")),e.campaign_types&&t.attr("data-ea-campaign-types",e.campaign_types.join("|")),e.publisher&&t.attr("data-ea-publisher",e.publisher),"undefined"!=typeof ethicalads?ethicalads.load():!s.ad_free&&u()?(h(),p(t)):$("#ethicaladsjs").on("load",function(){"undefined"!=typeof ethicalads&ðicalads.load()}))},error:function(){console.error("Error loading Read the Docs user and project information"),!s.ad_free&&u()&&(h(),p(t))}}))}}},{"./constants":12,"./rtd-data":14}],18:[function(e,t,n){var a=e("./rtd-data");t.exports={init:function(e){var t=a.get();if(!e.is_highest)for(var t=window.location.pathname.replace(t.version,e.slug),n=$('Note
You are not reading the most recent version of this documentation. is the latest version available.