Created
January 4, 2016 20:09
-
-
Save bignimbus/9a2661b147ce89ad34a0 to your computer and use it in GitHub Desktop.
Parsing img tags in markup for jquery lazyload at runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function replaceSrc (html) { | |
// matches img tags, captures src | |
var imgSrcRegex = /\<img(.*)src\s?=\s?"(.*)"(.*)\>/gi; | |
// replaces src with data-original to ensure compatibility | |
// with jquery lazyload api | |
return html.replace(imgSrcRegex, '<img$1data-original="$2"$3>'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment