The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

failed to make Script

View previous topic View next topic Go down

Solved failed to make Script

Post by Michael_vx on October 23rd 2015, 4:21 am

hello i have find that Script somewhere on the internet for forumotion to replace any image link by
Code:
[img]the image link[/img]
but its not working i tried to fix it but still not working the Script i find
Code:
$(function() {
  var links = $('.postbody a', document.getElementById('main-content')), reg = /\.(?:png|jpeg|jpg|gif)$/i;
  for(var i = 0, link; (link = links[i++]); ) {
  if(reg.test(link.href)) {
  link.innerHTML = '[img]%27%20+%20link.href%20+%20%27[/img]';
  }
  }
  });
the problem i face is the Script replace the image link by
Code:
[img]%27%20+%20link.href%20+%20%27[/img]
the changes i tried is replace the text
%27%20+%20link.href%20+%20%27
i tried
link.href
but failed i tried *.* failed too so is there a way to fix it
im also thinking about making a Script to replace youtube links to show the vedio insted of vedio link like the image replacer

Michael_vx
Forumember

Male Posts : 659
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: failed to make Script

Post by SLGray on October 23rd 2015, 4:39 am

Are you talking about when you are posting images and videos? If yes, then you can use the WYSIWYG mode in the editor.


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.


SLGray
Administrator
Administrator

Male Posts : 36659
Reputation : 2444
Language : English
Location : United States

http://ztwds.forumotion.com/

Back to top Go down

Solved Re: failed to make Script

Post by Michael_vx on October 23rd 2015, 9:33 am

may be something was missed
after post sent
what i meant by image is when i post dierct image link
like this https://i21.servimg.com/u/f21/16/89/96/68/slgray10.png
it should be replaced with the Script to be
Code:
[img]http://i21.servimg.com/u/f21/16/89/96/68/slgray10.png[/img]
but its replace even the the link itself

Michael_vx
Forumember

Male Posts : 659
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: failed to make Script

Post by Michael_vx on October 24th 2015, 9:39 am

bump
any way to solve the main problem ?
Code:
$(function() {
            var links = $('.postbody a', document.getElementById('main-content')), reg = /\.(?:png|jpeg|jpg|gif)$/i;
            for(var i = 0, link; (link = links[i++]); ) {
                if(reg.test(link.href)) {
                    link.innerHTML = '[img]%27%20+%20link.href%20+%20%27[/img]';
                }
            }
        });

Michael_vx
Forumember

Male Posts : 659
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: failed to make Script

Post by Ange Tuteur on October 24th 2015, 11:06 am

Hi @Michael_vx,

The reference to link.href is in string notation, so the string is only going to print "link.href" and not the href value of link. You need to concat link between the two strings like this :
Code:
$(function() {
  var links = $('.postbody a', document.getElementById('main-content')), reg = /\.(?:png|jpeg|jpg|gif)$/i;
  for(var i = 0, link; (link = links[i++]); ) {
    if(reg.test(link.href)) {
      link.innerHTML = '[img]' + link.href + '[/img]';
    }
  }
});

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: failed to make Script

Post by Michael_vx on October 24th 2015, 8:31 pm

thats a good news thanks for that info i think i have a lot to learn
now the link appear as same link i post but the image wont show
http://miclap.logu2.com/t2-topic
i still not sure what he reson

Michael_vx
Forumember

Male Posts : 659
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: failed to make Script

Post by Ange Tuteur on October 24th 2015, 9:10 pm

Oh right, silly me.. I should've noticed you were using bbcode tags. You need to use the HTML image tag instead, as bbcode is only parsed server-side.
Code:
$(function() {
  var links = $('.postbody a', document.getElementById('main-content')), reg = /\.(?:png|jpeg|jpg|gif)$/i;
  for(var i = 0, link; (link = links[i++]); ) {
    if(reg.test(link.href)) {
      link.innerHTML = '<img src="' + link.href + '"/>';
    }
  }
});

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: failed to make Script

Post by Michael_vx on October 24th 2015, 9:33 pm


i think im the silly one
i stuck in a little small thing i scrow up everything
i dont know how to thank you for this big help
you are the life savior
this topic is now solved
only when you close the the topic wish me luck of my next Script that should do the same thing with youtube
thanks again for giving me the hand in solving this

Michael_vx
Forumember

Male Posts : 659
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: failed to make Script

Post by Ange Tuteur on October 24th 2015, 9:41 pm

No problem. ^^

Topic archived

Have a good weekend.

If you need any additional references these are some good sources for learning :
https://developer.mozilla.org/en-US/docs/Web/JavaScript
http://www.quackit.com/
http://www.w3schools.com/

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


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