JAVASCRIPT   26

get dataType

Guest on 6th July 2022 01:18:28 AM

  1. $(document).ready(function() {
  2.     var prefix = "/docs/"
  3.     var path = document.location.pathname;
  4.     var version = path.substring(prefix.length, path.indexOf("/", prefix.length));
  5.     $.ajax({type: 'GET', dataType: 'xml', url: '../../versions.xml',
  6.             success: function(xml) {
  7.                 $('#toctitle').before('<select id="vchooser"></select>');
  8.                 $('#vchooser').append('<option>Choose version</option>');
  9.                 $(xml).find('version').each(function() {
  10.                     var name = $(this).attr("name");
  11.                     var selected = name.indexOf(version) == 0 ? "selected" : "";
  12.                     $('#vchooser').append('<option value="' + $(this).attr("path") + '" ' + selected + '>' + name + '</option>');
  13.                 });
  14.                 $('#vchooser').change(function(e) {
  15.                     if (this.value !== '')
  16.                         window.location.href = path.replace(version, this.value);
  17.                 });
  18.             }
  19.     });
  20.  
  21.     $('ul.sectlevel1').wrap('<div id="toctree"></div>');
  22.  
  23.     $('#toctree').jstree({
  24.         "core" : {
  25.         "themes" : {"variant" : "small", "icons" : false}
  26.     },
  27.     "plugins" : [ "search", "state", "wholerow" ] })
  28.           .on("activate_node.jstree", function (e, data) { location.href = data.node.a_attr.href; });
  29.     $('#toctree').before('<input placeholder="&#xf002; Search" id="tocsearch" type="text">');
  30.     var searchTimeout = false;
  31.     $('#tocsearch').keyup(function () {
  32.         if(searchTimeout) { clearTimeout(searchTimeout); }
  33.         searchTimeout = setTimeout(function () {
  34.             var v = $('#tocsearch').val();
  35.             $('#toctree').jstree(true).search(v);
  36.         }, 250);
  37.     });
  38.     $('#tocsearch').after('<a href="#" id="toctreeexpand" title="Expand"><i class="fa fa-plus-square" aria-hidden="true"></i></a><a href="#" id="toctreecollapse" title="Collapse"><i class="fa fa-minus-square" aria-hidden="true"></i></a>');
  39.     $('#toctreeexpand').click(function() { $('#toctree').jstree('open_all'); });
  40.     $('#toctreecollapse').click(function() { $('#toctree').jstree('close_all'); });
  41. });

Raw Paste


Login or Register to edit or fork this paste. It's free.