1"use strict"; 2 3(function ($) { 4 $(document).on('click', 'a', wpil_link_clicked); 5 $(document).on('auxclick', 'a', wpil_link_clicked); 6 7 function wpil_link_clicked(e){ 8// e.preventDefault(); 9 var link = $(this); 10 var linkAnchor = ''; 11 var hasImage = false; 12 var imageTitle = ''; 13 var imageTags = ['img', 'svg']; 14 15 if('1' === wpilFrontend.disableClicks){ 16 return; 17 } 18 19 if(this.href === undefined || link.attr('href') === '#'){ 20 return; 21 } 22 23 function findLinkText(link){ 24 if(link.children().length > 0){ 25 $(link).contents().filter(function(){ 26 var childThis = $(this); 27 28 if(childThis.children().length > 0 && linkAnchor === ''){ 29 findLinkText(childThis); 30 } 31 32 if(this.nodeType === 1 && -1 !== imageTags.indexOf(this.nodeName.toLowerCase()) && imageTitle === ''){ 33 hasImage = true; 34 var title = $(this).attr('title'); 35 36 if(undefined !== title){ 37 imageTitle = title.trim(); 38 } 39 } 40
41 if(this.nodeType === 3 && linkAnchor === ''){ 42 var text = $(this).text().trim(); 43 if(text.length > 0){ 44 linkAnchor = text; 45 } 46 } 47 48 linkAnchor = linkAnchor.trim(); 49 imageTitle = (imageTitle !== undefined) ? imageTitle.trim(): ''; 50 }); 51 52 }else{ 53 linkAnchor = link.text().trim(); 54 } 55 } 56 57 findLinkText(link); 58 59 if(linkAnchor === '' && hasImage){ 60 if(imageTitle !== ''){ 61 linkAnchor = wpilFrontend.clicksI18n.imageText + imageTitle; 62 }else{ 63 linkAnchor = wpilFrontend.clicksI18n.imageNoText; 64 } 65 }else if(linkAnchor === '' && !hasImage){ 66 linkAnchor = wpilFrontend.clicksI18n.noText; 67 } 68 69 // if the click wasn't a primary or middle click, or there's no link, exit 70 if(!(e.which == 1 || e.button == 0 ) && !(e.which == 2 || e.button == 4 ) || link.length < 1){ 71 return; 72 } 73 74 // ignore non-content links 75 if($(link).parents('header, footer, nav, [id~=header], [id~=menu], [id~=footer], [id~=widget], [id~=comment], [class~=header], [class~=menu], [class~=footer], [class~=widget], [class~=comment], #wpadminbar').length){ 76 return; 77 } 78 79 jQuery.ajax({ 80 type: 'POST', 81 url: wpilFrontend.ajaxUrl, 82 data: { 83 action: 'wpil_link_clicked', 84 post_id: wpilFrontend.postId, 85 post_type: wpilFrontend.postType, 86 link_url: link.prop('href'), 87 link_anchor: linkAnchor, 88 }, 89 success: function(response){ 90 91 } 92 }); 93 } 94 $(window).on('load', openLinksInNewTab); 95 96 /** 97 * Sets non nav links on a page to open in a new tab based on the settings. 98 **/ 99 function openLinksInNewTab(){ 100 // exit if non of the links are supposed to open in a new tab via JS 101 if(wpilFrontend.openLinksWithJS = 0 || (wpilFrontend.openExternalInNewTab == 0 && wpilFrontend.openInternalInNewTab == 0) ){ 102 return; 103 } 104 var links = $('body').find('a'); 105 106 $(links).each(function(index, element){ 107 // if the link is not a nav link 108 if($(element).parents('header, footer, nav, [id~=header], [id~=menu], [id~=footer], [id~=widget], [id~=comment], [class~=header], [class~=menu], [class~=footer], [class~=widget], [class~=comment], #wpadminbar').length < 1){ 109 // if there is a url in the link, there isn't a target and the link isn't a jump link 110 if(element.href && !element.target && element.href.indexOf(window.location.href) === -1){ 111 var url = new URL(element.href); 112 var internal = (window.location.hostname === url.hostname) ? true: false; 113 // if the settings allow it 114 if( (internal && parseInt(wpilFrontend.openInternalInNewTab)) || (!internal && parseInt(wpilFrontend.openExternalInNewTab)) ){ 115 // set the link to open in a new page 116 $(element).attr('target', '_blank'); 117 } 118 } 119 } 120 121 }); 122 } 123 124})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.