Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @file
- * ODFW Education module dynamic content functionality.
- */
- (($, Drupal) => {
- Drupal.behaviors.dynamicContent = {
- attach(context, setings) {
- $('.segment-navigation a').click(function (e) {
- e.preventDefault();
- let url = $(this).attr('href');
- fetch(url)
- .then(function(response) {
- // When the page is loaded convert it to text
- return response.text()
- })
- .then(function(html) {
- // Initialize the DOM parser
- let parser = new DOMParser();
- // Parse the text
- let doc = parser.parseFromString(html, "text/html");
- let content = doc.querySelector('.collection-segment-wrapper').innerHTML;
- console.log(content);
- $('.collection-segment-wrapper').html(content);
- //console.log(docMain);
- })
- .catch(function(err) {
- console.log('Failed to fetch page: ', err);
- });
- });
- }
- };
- })(jQuery, Drupal);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement