|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// Wraps some elements in anchor tags referencing to the Symfony documentation |
| 4 | +$(function() { |
| 5 | + var $modal = $('#sourceCodeModal'); |
| 6 | + var $controllerCode = $modal.find('code.php'); |
| 7 | + var $templateCode = $modal.find('code.twig'); |
| 8 | + |
| 9 | + function anchor(url, content) { |
| 10 | + return '<a class="doclink" target="_blank" href="' + url + '">' + content + '</a>'; |
| 11 | + }; |
| 12 | + |
| 13 | + // Wraps links to the Symfony documentation |
| 14 | + $modal.find('.hljs-comment').each(function() { |
| 15 | + $(this).html($(this).html().replace(/https:\/\/symfony.com\/doc\/[\w/.#-]+/g, function(url) { |
| 16 | + return anchor(url, url); |
| 17 | + })); |
| 18 | + }); |
| 19 | + |
| 20 | + // Wraps Symfony's annotations |
| 21 | + var annotations = { |
| 22 | + '@Cache': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/cache.html', |
| 23 | + '@Method': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html#route-method', |
| 24 | + '@ParamConverter': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html', |
| 25 | + '@Route': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html#usage', |
| 26 | + '@Security': 'https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/security.html' |
| 27 | + }; |
| 28 | + |
| 29 | + $controllerCode.find('.hljs-doctag').each(function() { |
| 30 | + var annotation = $(this).text(); |
| 31 | + |
| 32 | + if (annotations[annotation]) { |
| 33 | + $(this).html(anchor(annotations[annotation], annotation)); |
| 34 | + } |
| 35 | + }); |
| 36 | + |
| 37 | + // Wraps Twig's tags |
| 38 | + $templateCode.find('.hljs-template-tag > .hljs-name').each(function() { |
| 39 | + var tag = $(this).text(); |
| 40 | + |
| 41 | + if ('else' === tag || tag.match(/^end/)) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + var url = 'https://twig.symfony.com/doc/2.x/tags/' + tag + '.html#' + tag; |
| 46 | + |
| 47 | + $(this).html(anchor(url, tag)); |
| 48 | + }); |
| 49 | + |
| 50 | + // Wraps Twig's functions |
| 51 | + $templateCode.find('.hljs-template-variable > .hljs-name').each(function() { |
| 52 | + var func = $(this).text(); |
| 53 | + |
| 54 | + var url = 'https://twig.symfony.com/doc/2.x/functions/' + func + '.html#' + func; |
| 55 | + |
| 56 | + $(this).html(anchor(url, func)); |
| 57 | + }); |
| 58 | +}); |
0 commit comments