|
1615 | 1615 | $.isFunction(v.callback) && v.callback.call(this);
|
1616 | 1616 | }
|
1617 | 1617 |
|
| 1618 | + /** |
| 1619 | + * Sets the value for the given attribute from the `data-` attribute with the same suffix |
| 1620 | + * ie: data-srcset ==> srcset | data-src ==> src |
| 1621 | + */ |
| 1622 | + function setSrc(element, attribute){ |
| 1623 | + element |
| 1624 | + .attr(attribute, element.data(attribute)) |
| 1625 | + .removeAttr('data-' + attribute); |
| 1626 | + } |
| 1627 | + |
1618 | 1628 | /**
|
1619 | 1629 | * Lazy loads image, video and audio elements.
|
1620 | 1630 | */
|
|
1625 | 1635 |
|
1626 | 1636 | var panel = getSlideOrSection(destiny);
|
1627 | 1637 | var element;
|
1628 |
| - |
1629 |
| - panel.find('img[data-src], source[data-src], audio[data-src], iframe[data-src]').each(function(){ |
| 1638 | + |
| 1639 | + panel.find('img[data-src], img[data-srcset], source[data-src], audio[data-src], iframe[data-src]').each(function(){ |
1630 | 1640 | element = $(this);
|
1631 |
| - element.attr('src', element.data('src')); |
1632 |
| - element.removeAttr('data-src'); |
| 1641 | + |
| 1642 | + $.each(['src', 'srcset'], function(index, type){ |
| 1643 | + var attribute = element.attr('data-' + type); |
| 1644 | + if(typeof attribute !== 'undefined' && attribute){ |
| 1645 | + setSrc(element, type); |
| 1646 | + } |
| 1647 | + }); |
1633 | 1648 |
|
1634 | 1649 | if(element.is('source')){
|
1635 | 1650 | element.closest('video').get(0).load();
|
|
2757 | 2772 |
|
2758 | 2773 | //loading all the lazy load content
|
2759 | 2774 | container.find('img[data-src], source[data-src], audio[data-src], iframe[data-src]').each(function(){
|
2760 |
| - $(this).attr('src', $(this).data('src')); |
2761 |
| - $(this).removeAttr('data-src'); |
| 2775 | + setSrc($(this), 'src'); |
| 2776 | + }); |
| 2777 | + |
| 2778 | + container.find('img[data-srcset]').each(function(){ |
| 2779 | + setSrc($(this), 'srcset'); |
2762 | 2780 | });
|
2763 | 2781 |
|
2764 | 2782 | $(SECTION_NAV_SEL + ', ' + SLIDES_NAV_SEL + ', ' + SLIDES_ARROW_SEL).remove();
|
|
0 commit comments