1String.prototype.replaceAll = function(search, replacement) { 2 const target = this; 3 return target.replace(new RegExp(search, 'g'), replacement); 4}; 5 6$(function () { 7 const baseUrl = "https://javadoc.io"; 8 9 new Vue({ 10 el: '#getting_started', 11 data: { 12 // attributes 13 groupId: 'org.springframework', 14 artifactId: 'spring-core', 15 versionId: '5.1.8.RELEASE', 16 package: 'org.springframework.util', 17 clazz: 'Base64Utils', 18 // typeaheads 19 groupIds: [], 20 artifactIds: [], 21 versionIds: [] 22 }, 23 computed: { 24 encodedGroupId: function() { 25 return this.encode(this.groupId); 26 }, 27 encodedArtifactId: function() { 28 return this.encode(this.artifactId); 29 }, 30 encodedVersionId: function() { 31 return this.encode(this.versionId); 32 }, 33 latestDocLink: function() { 34 return '/doc/' + this.encodedGroupId + '/' + this.encodedArtifactId; 35 }, 36 latestDocLinkFull: function() { 37 return baseUrl + this.latestDocLink; 38 }, 39 versionedDocLink: function() { 40 return this.latestDocLink + '/' + this.encodedVersionId; 41 }, 42 versionedDocLinkFull: function() { 43 return baseUrl + this.versionedDocLink; 44 }, 45 pagePrefix: function() { 46 return '/doc/' + this.encodedGroupId + '/' + this.encodedArtifactId + '/'; 47 }, 48 pageSuffix: function() { 49 return '/' + this.package.replaceAll(/\./g, '/') + '/' + this.clazz.replace('.', '/') + '.html'; 50 }, 51 latestPageLink: function() { 52 return this.pagePrefix + 'latest' + this.pageSuffix; 53 }, 54 latestPageLinkFull: function() { 55 return baseUrl + this.latestPageLink; 56 }, 57 versionedPageLink: function() { 58 return this.pagePrefix + this.encodedVersionId + this.pageSuffix; 59 }, 60 versionedPageLinkFull: function() { 61 return baseUrl + this.versionedPageLink; 62 }, 63 latestBadgeLink: function() { 64 return '/badge2/' + this.encodedGroupId + '/' + this.encodedArtifactId + '/javadoc.svg'; 65 }, 66 latestBadgeLinkFull: function() { 67 return baseUrl + this.latestBadgeLink; 68 }, 69 latestBadgeLinkMarkDown: function() { 70 return '[](' + this.latestDocLinkFull + ')'; 71 }, 72 versionedBadgeLink: function() { 73 return '/badge2/' + this.encodedGroupId + '/' + this.encodedArtifactId + '/' + this.encodedVersionId + '/javadoc.svg'; 74 }, 75 versionedBadgeLinkFull: function() { 76 return baseUrl + this.versionedBadgeLink; 77 }, 78 versionedBadgeLinkMarkDown: function() { 79 return '[](' + this.versionedDocLinkFull + ')'; 80 } 81 }, 82 methods: { 83 encode: function(s) { 84 return s ? encodeURI(s) : 'undefined' 85 }, 86 // only refresh onblur to prevent excessive traffic to the backend 87 onGroupIdBlur: function() { 88 this.updateLatestPreviewBadge(); 89 this.refreshArtifactIds(); 90 }, 91 onArtifactIdBlur: function() { 92 this.updateLatestPreviewBadge(); 93 this.refreshVersionIds(); 94 }, 95 96 // this is done on blur even instead of direct v-binding. 97 // to reduce the load to keep resolving latest version 98 updateLatestPreviewBadge: function() { 99 $('#latest_badge_preview').attr('src', this.latestBadgeLink); 100 }, 101 102 refreshGroupIds: function() { 103 axios.get('/typeahead/group_ids').then(resp => this.groupIds = resp.data); 104 }, 105 refreshArtifactIds: function() { 106 const params = { params: {groupId: this.groupId} }; 107 axios.get('/typeahead/artifact_ids', params).then(resp => this.artifactIds = resp.data); 108 }, 109 refreshVersionIds: function() { 110 const params = { params: {groupId: this.groupId, artifactId: this.artifactId} }; 111 axios.get('/typeahead/version_ids', params).then(resp => this.versionIds = resp.data); 112 } 113 }, 114 mounted() { 115 if (localStorage.groupId) { 116 this.groupId = localStorage.groupId; 117 } 118 if (localStorage.artifactId) { 119 this.artifactId = localStorage.artifactId; 120 } 121 if (localStorage.versionId) { 122 this.versionId = localStorage.versionId; 123 } 124 if (localStorage.package) { 125 this.package = localStorage.package; 126 } 127 if (localStorage.clazz) { 128 this.clazz = localStorage.clazz; 129 } 130 131 // init latest preview badge on startup 132 this.updateLatestPreviewBadge(); 133 134 // init tooltip after mounted 135 $('[data-toggle="tooltip"]').tooltip(); 136 137 // init advanced_toggle
138 $("#advanced_toggle").click(function () { 139 $(this).hide(500); 140 $("#advanced").slideToggle(500); 141 }); 142 143 // init typeahead 144 this.refreshGroupIds(); 145 this.refreshArtifactIds(); 146 this.refreshVersionIds(); 147 }, 148 watch: { 149 groupId(newValue) { 150 localStorage.groupId = newValue; 151 }, 152 artifactId(newValue) { 153 localStorage.artifactId = newValue; 154 }, 155 versionId(newValue) { 156 localStorage.versionId = newValue; 157 }, 158 package(newValue) { 159 localStorage.package = newValue; 160 }, 161 clazz(newValue) { 162 localStorage.clazz = newValue; 163 } 164 } 165 }); 166});
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.