Saturday, 15 June 2013

append - Appending filenames in jQuery -



append - Appending filenames in jQuery -

i have image on site want alter filename / source of @ specific sizes. have kind of working buggy - see code below.

this works if original filename example.jpg - falls on if original filename example@2x.jpg - using retinajs on site - when wide mobile device loads page renders example.jpg file example@2x.jpg - when switched portrait - issue happens code have doesnt rename example@2x.jpg become example_mobile@2x.jpg...

i think need 2nd statement in first section rename files end in @2x.jpg become example_mobile@2x.jpg - beingness renamed example@2x_mobile@2x.jpg wrong...

any ideas? stumped!

function endswith(str, suffix) { homecoming str.indexof(suffix, str.length - suffix.length) !== -1; } var clientslicontrol = function() { var windowsizeclients = $(window).width(); //if (windowsizeclients <= 480) { if (windowsizeclients <= 568) { $("div.nivoslider img").each(function() { if (!endswith($(this).attr('src'), '_mobile@2x.jpg')) { $(this).attr('src', $(this).attr('src').replace(/\.jpg/, '') + '_mobile@2x.jpg'); } //call div resizer resizediv(); }); $("div.heroelementwrapper img").each(function() { if (!endswith($(this).attr('src'), '_mobile@2x.jpg')) { $(this).attr('src', $(this).attr('src').replace(/\.jpg/, '') + '_mobile@2x.jpg'); } //call div resizer resizediv(); }); } //else if (windowsizeclients >= 481) { else if (windowsizeclients >= 569) { $("div.nivoslider img").each(function() { if (endswith($(this).attr('src'), '_mobile@2x.jpg')) { $(this).attr('src', $(this).attr('src').replace(/\_mobile@2x.jpg/, '') + '.jpg'); } //call div resizer resizediv(); }); $("div.heroelementwrapper img").each(function() { if (endswith($(this).attr('src'), '_mobile@2x.jpg')) { $(this).attr('src', $(this).attr('src').replace(/\_mobile@2x.jpg/, '') + '.jpg'); } //call div resizer resizediv(); }); } }; clientslicontrol(); $(window).resize(function() { clientslicontrol(); }); $(window).load(function() { clientslicontrol(); }); $(document).ready(function() { clientslicontrol(); });

the html is

<img id="heroelementbgimage" title="example" alt="example" src="assets/images/heros/example.jpg">

which if served on retina device gets changed to

<img id="heroelementbgimage" title="example" alt="example" src="assets/images/heros/example@2x.jpg">

jquery append

No comments:

Post a Comment