Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. /**
  2. * @file
  3. * ODFW Education module dynamic content functionality.
  4. */
  5.  
  6. (($, Drupal) => {
  7. Drupal.behaviors.dynamicContent = {
  8. attach(context, setings) {
  9. $('.segment-navigation a').click(function (e) {
  10. e.preventDefault();
  11. let url = $(this).attr('href');
  12.  
  13. fetch(url)
  14. .then(function(response) {
  15. // When the page is loaded convert it to text
  16. return response.text()
  17. })
  18. .then(function(html) {
  19. // Initialize the DOM parser
  20. let parser = new DOMParser();
  21.  
  22. // Parse the text
  23. let doc = parser.parseFromString(html, "text/html");
  24. let content = doc.querySelector('.collection-segment-wrapper').innerHTML;
  25. console.log(content);
  26. $('.collection-segment-wrapper').html(content);
  27. //console.log(docMain);
  28.  
  29.  
  30. })
  31. .catch(function(err) {
  32. console.log('Failed to fetch page: ', err);
  33. });
  34. });
  35. }
  36. };
  37. })(jQuery, Drupal);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement