Page 1 of 2

Create Custom Link w/ Custom Content Plugin

Posted: Thu Mar 20, 2014 4:22 pm
by jfm
Hi Andrew,

I'm trying to add a link to FlightAware on the Aircraft Detail panel. I'm not sure if this is possible with the Custom Content plugin. Can you tell me if I'm on the right track?

The logic I'm trying to use to create the link is:
  1. Check for a callsign
  2. If it exists and it is a number (e.g. 697) and I know the operator flag code (e.g. WJA), then append the two. Westjet only uses the flight number as the callsign, so this would make the callsign WJA697.
  3. If it exists and it is not a number, then use the callsign
  4. Otherwise use the registration
In enums.js in VRS.LinkSite, I believe I need to add the following before StandingDataMaintenance:

Code: Select all

FlightAwareDotCom:			'flightaware.com',
In linksRenderer.js, I believe I need to add a VRS.LinkRenderHandler as follows:

Code: Select all

new VRS.LinkRenderHandler({
	linkSite:           VRS.LinkSite.FlightAwareDotCom,
	displayOrder:       400,
	canLinkAircraft:    function(/** VRS.Aircraft */ aircraft) { return aircraft && (aircraft.registration.val || aircraft.callsign.val); },
	hasChanged:         function(/** VRS.Aircraft */ aircraft) { return aircraft.registration.chg || aircraft.callsign.chg; },
	title:              'www.flightaware.com',
	buildUrl:           function(/** VRS.Aircraft */ aircraft) { return 'http://flightaware.com/live/flight/' + ( aircraft.callsign.val ? (!isNaN(aircraft.callsign.val) && aircraft.operatorIcao.val ? VRS.stringUtility.htmlEscape(aircraft.formatOperatorIcao() + aircraft.formatCallsign()) : VRS.stringUtility.htmlEscape(aircraft.formatCallsign())) : VRS.stringUtility.htmlEscape(aircraft.formatRegistration(true)) )); },
	target:             'flightaware'
}),
Thanks!!!

Re: linkRender

Posted: Thu Mar 20, 2014 5:08 pm
by jfm
Just doing a bit more reading of the documentation. I think I can replace those two files in their entirety with my own versions using the plugin. But could I instead inject those JS snippets into desktop.html? Maybe at the end of the header?

Thanks again.

Re: linkRender

Posted: Thu Mar 20, 2014 10:47 pm
by jfm
Wait long enough and I'll answer my own questions!

I'm injecting the following code at the end of HEAD and it is working!

Code: Select all

<script type="text/javascript">
VRS.LinkSite["FlightAwareDotCom"] = "flightaware.com";

VRS.linkRenderHandlers.push(
	new VRS.LinkRenderHandler({
		linkSite:           VRS.LinkSite.FlightAwareDotCom,
		displayOrder:       400,
		canLinkAircraft:    function(/** VRS.Aircraft */ aircraft) { return aircraft && (aircraft.registration.val || aircraft.callsign.val); },
		hasChanged:         function(/** VRS.Aircraft */ aircraft) { return aircraft.registration.chg || aircraft.callsign.chg; },
		title:              'www.flightaware.com',
		buildUrl:           function(/** VRS.Aircraft */ aircraft) { return 'http://flightaware.com/live/flight/' + ( aircraft.callsign.val ? (!isNaN(aircraft.callsign.val) && aircraft.operatorIcao.val ? VRS.stringUtility.htmlEscape(aircraft.formatOperatorIcao() + aircraft.formatCallsign()) : VRS.stringUtility.htmlEscape(aircraft.formatCallsign())) : VRS.stringUtility.htmlEscape(aircraft.formatRegistration(true)) ); },
		target:             'flightaware'
	})
);
</script>

Re: linkRender

Posted: Fri Mar 21, 2014 12:33 am
by agw
:D

That is exactly the way to add custom links - the only thing I would suggest is adding some kind of prefix to the name of the VRS.LinkSite index so that there's no possibility of clashing with a future update. Perhaps "jfm_FlightAwareDotCom"?

Re: linkRender

Posted: Fri Mar 21, 2014 2:45 pm
by jfm
Thanks, I'll make that change.

Maybe you can change the topic title to something more descriptive, if anyone else is looking to do the same thing?

Re: linkRender

Posted: Sat Mar 22, 2014 4:03 pm
by agw
I can change the topic title but it's probably better if you do it :) Just click on the Edit button on your first post, you should be able to change the topic title from there.

Re: Create Custom Link w/ Custom Content Plugin

Posted: Sat Apr 19, 2014 1:34 pm
by Lector
I did replicate this behaviour for the planespotters.net, since it provides (on one page) another links to different kinds of information (plane photos, airframe infos, aircompany fleet info etc).
Thanks to jfm for posting this thread, so I could walk the same way :)
Here below the script itself:

Code: Select all

<script type="text/javascript">
VRS.LinkSite["Lector_PlaneSpottersDotNet"] = "planespotters.net";

VRS.linkRenderHandlers.push(
   new VRS.LinkRenderHandler({
      linkSite:           VRS.LinkSite.Lector_PlaneSpottersDotNet,
      displayOrder:       400,
            canLinkAircraft:    function(/** VRS.Aircraft */ aircraft) { return aircraft && aircraft.registration.val; },
            hasChanged:         function(/** VRS.Aircraft */ aircraft) { return aircraft.registration.chg; },
            title:              'www.planespotters.net',
            buildUrl:           function(/** VRS.Aircraft */ aircraft) { return 'http://www.planespotters.net/Aviation_Photos/search.php?tag=' + VRS.stringUtility.htmlEscape(aircraft.formatRegistration()); },
            target:             'planespotters'
   })
);
</script>

Re: Create Custom Link w/ Custom Content Plugin

Posted: Sun Apr 20, 2014 8:39 pm
by jfm
You can also remove the default links. For example, I remove Airframes.Org with:

VRS.linkRenderHandlers.splice(0,1);

The 0 tells it to start at the first item in the array of links (0 is the first) and the 1 tells it to remove 1 item.

http://www.w3schools.com/jsref/jsref_splice.asp

Re: Create Custom Link w/ Custom Content Plugin

Posted: Wed Oct 15, 2014 2:20 am
by TammaraBa30
I agree. Adding custom links is a bit tricky. You may add some sort of prefix to VRS.LinkSite index so that there's little possibility of clashing when you do the updates. Thanks.

Re: Create Custom Link w/ Custom Content Plugin

Posted: Wed Nov 22, 2017 4:59 am
by louisd13
Would anyone be able to help me in creating a custom link to flightradar24 as well? I have successfully created a custom link to flightaware.com using jfm's instruction above with the custom content plugin, but I am not able to create a link to Flightradar24. This is the script I am running with the custom content plugin:

Code: Select all

<script type="text/javascript">
VRS.LinkSite["FlightRadar24DotCom"] = "flightradar24.com";

VRS.linkRenderHandlers.push(
   new VRS.LinkRenderHandler({
      linkSite:           VRS.LinkSite.FlightRadar24DotCom,
      displayOrder:       400,
      canLinkAircraft:    function(/** VRS.Aircraft */ aircraft) { return aircraft && (aircraft.registration.val || aircraft.callsign.val); },
      hasChanged:         function(/** VRS.Aircraft */ aircraft) { return aircraft.registration.chg || aircraft.callsign.chg; },
      title:              'www.flightradar24.com',
      buildUrl:           function(/** VRS.Aircraft */ aircraft) { return 'http://fr24.com/'+selected.flight' + ( aircraft.callsign.val ? (!isNaN(aircraft.callsign.val) && aircraft.operatorIcao.val ? VRS.stringUtility.htmlEscape(aircraft.formatOperatorIcao() + aircraft.formatCallsign()) : VRS.stringUtility.htmlEscape(aircraft.formatCallsign())) : VRS.stringUtility.htmlEscape(aircraft.formatRegistration(true)) ); },
      target:             'flightradar24'
   })
);
</script>
any assistance would be greatly appreciated. thanks!