Jump to content

Removing commas from inline graphics output


Recommended Posts

Hello,

 

I am using a script suggested from another thread called "floating images". The script works perfect except for one thing, it adds commas and I want to suppress them. The following is my script:

 

var cellImg = Resource("cell").content;
var voiceImg = Resource("voice").content;
var faxImg = Resource("fax").content;
var emailImg = Resource("email").content;

var numbers = [
   [Field('EMAIL'), emailImg],
   [Field('PHONE'), voiceImg],
   [Field('CELL'), cellImg],
   [Field('FAX'), faxImg]
   ].filter(function(s){return s[1]}).map(
       function(s){
           return '<p br=false superoffset=70 superratio=100>' + s[1] + '<superscript> ' + s[0] + '</superscript>';
   })

return numbers;

 

As I stated above, the script works fine but the output includes commas between each element. I do not want those commas. Just removing the commas between each element after the ']' results in errors. Can someone assist me with how I go about suppressing the commas?

 

Thanks!

-Mike

Link to comment
Share on other sites

I think I resolved the issue. I added the following to the code:

 

].filter(function(s){return s[1]}).map(
       function(s){
           return '<p br=false superoffset=70 superratio=100>' + s[1] + '<superscript> ' + s[0] + '</superscript>';
   })[color="Red"].join('<t>')[/color]

 

Then, edited the size of the tab stops on the text frame to an appropriate size.

 

That worked for me. Having said that, any other suggestions would be great for the benefit of others. Thanks!

Link to comment
Share on other sites

Yes, the original script you posted returns an array – the elements within the array are separated by a comma when output. The join method joins the elements with something other than a comma and converts the returned element to a string.

 

So, in your second snippet, you're joining the element with a tab tag. But you could join them with a break tag (<br>) like in the original script, or a space, or any ole' string you want, really:

var cellImg = Resource("cell").content;
var voiceImg = Resource("voice").content;
var faxImg = Resource("fax").content;
var emailImg = Resource("email").content;

var numbers = [
   [Field('EMAIL'), emailImg],
   [Field('PHONE'), voiceImg],
   [Field('CELL'), cellImg],
   [Field('FAX'), faxImg]
   ].filter(function(s){return s[1]}).map(
       function(s){
           return '<p br=false superoffset=70 superratio=100>' + s[1] + '<superscript> ' + s[0] + '</superscript>';
   })

return numbers[color="Red"].join("any ole' string you want");[/color]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...