This function loops through all images on the page, and serves the appropriately sized image file from a list in a data attribute.
example link: http://total.maloweb.com/responsive
example html:
<img src="default.png" data-widths="400,600,800,1023" data-srcsuffix="-foo.png">
example javascript:
onload=onresize=function(){
respImg("data-widths","data-srcsuffix")
}
example filenames:
400-foo.png
600-foo.png
800-foo.png
1023-foo.png
OK, will have to look into this later. This will probably require to revert the resolution numbers to the former order. Do I get it right in that case that it should always be the resolution 1 notch above (and not below, like it is now) the current one?
Update: made a mix of both of our codes (168bytes):
Another update: rethought my regex version (161bytes):
Last update (depending on the former one): sneaky abuse of string value comparison (159bytes):