The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

What should I add to this code assignments change the caption of the photo.

2 posters

Go down

Solved What should I add to this code assignments change the caption of the photo.

Post by smurfavr July 10th 2014, 12:35 am

What should I add to this code assignments change the caption of the photo. 

What should I add to this code assignments change the caption of the photo.  7459021l

Code:
$(function() {
    var replace1 = 'Трябва да си регистриран за да виждаш линковете..';
    var replace2 = 'Вие нямате права за сваляне !';
    var replace3 = '$1Свален $2 пъти.';
 
    var post = $('.postbody div');
    var atbox = $('.attachbox');
    var reg1 = /\[You must be.*?to see this [A-Z]+.\]/ig;
    var reg2 = /You don't have permission to download attachments./ig;
    var reg3 = /(\(\d+ [A-Z]+\)) Downloaded (\d+) times/ig;
   
    for (i=0;i<post.length;i++)if(reg1.test(post[i].innerHTML))post[i].innerHTML=post[i].innerHTML.replace(reg1,replace1);
    for (i=0;i<atbox.length;i++)if(reg2.test(atbox[i].innerHTML) || reg3.test(atbox[i].innerHTML))atbox[i].innerHTML=atbox[i].innerHTML.replace(reg2,replace2).replace(reg3,replace3);
});
smurfavr
smurfavr
Active Poster

Male Posts : 1881
Reputation : 22
Language : Bulgarian

http://smurfa.bulgarianforum.net/

Back to top Go down

Solved Re: What should I add to this code assignments change the caption of the photo.

Post by Ange Tuteur July 10th 2014, 1:14 am

Hello smurfavr,

I simplified the code for you, replace your script by :
Code:
$(function() {
  replaceText('.postbody div', /\[You must be.*?to see this [A-Z]+.\]/ig, 'Трябва да си регистриран за да виждаш линковете..');
  replaceText('.attachbox', /You don't have permission to download attachments./ig, 'Вие нямате права за сваляне !');
  replaceText('.attachbox', /(\(\d+ [A-Z]+\)) Downloaded (\d+) times/ig, '$1 Свален $2 пъти.');
  replaceText('.attachbox', /Attachments/g, 'Attachments text');
    
  function replaceText(element, reg, rep){var el=$('.post '+element);for(i=0;i<el.length;i++)if(reg.test(el[i].innerHTML))el[i].innerHTML=el[i].innerHTML.replace(reg,rep)}
});

In the script you'll see :
Code:
replaceText('.attachbox', /Attachments/g, 'Attachments text');

Replace Attachments text by the texts you want to display.


Explanation :

To replace texts simply write replaceText();, between the parenthesis you'll fill out the following information in order :
Element : The element the texts are inside
Reg : The regular expression to search for the texts
Rep : The replacement for the searched texts

When done your result should be :
Code:
replaceText('.attachbox', /Attachments/g, 'Attachments text');
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: What should I add to this code assignments change the caption of the photo.

Post by smurfavr July 10th 2014, 1:25 am

Thank you Ange Tuteur.Everything works.
smurfavr
smurfavr
Active Poster

Male Posts : 1881
Reputation : 22
Language : Bulgarian

http://smurfa.bulgarianforum.net/

Back to top Go down

Solved Re: What should I add to this code assignments change the caption of the photo.

Post by Ange Tuteur July 10th 2014, 1:28 am

You're welcome :rose:

Topic archived

Have a good day ! ^^
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13207
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum