-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from 18F/private-eye
Added private eye
- Loading branch information
Showing
10 changed files
with
204 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
document.addEventListener('DOMContentLoaded', function() { | ||
PrivateEye({ | ||
defaultMessage: "This link is private to TTS.", | ||
ignoreUrls: [ | ||
'18f.slack.com', | ||
'anywhere.gsa.gov', | ||
'bookit.gsa.gov', | ||
'calendar.gsa.gov', | ||
'connect.gsa.gov', | ||
'docs.google.com', | ||
'drive.google.com', | ||
'ea.gsa.gov', | ||
'email.gsa.gov', | ||
'eopf.opm.gov', | ||
'gcims.gsa.gov', | ||
'github.com/18F/Accessibility_Reviews', | ||
'github.com/18F/blog-drafts', | ||
'github.com/18F/codereviews', | ||
'github.com/18F/DevOps', | ||
'github.com/18F/Infrastructure', | ||
'github.com/18F/security-incidents', | ||
'github.com/18F/staffing', | ||
'github.com/18F/team-api.18f.gov', | ||
'github.com/18F/writing-lab', | ||
'gkey.gsa.gov', | ||
'gsa-tts.slack.com', | ||
'gsa.my.salesforce.com', | ||
'gsaolu.gsa.gov', | ||
'hrlinks.gsa.gov', | ||
'hrprod.hr.gsa.gov', | ||
'insite.gsa.gov', | ||
'mail.gsa.gov', | ||
'meet.gsa.gov', | ||
'sign.gsa.gov', | ||
'tock.18f.gov' | ||
] | ||
}); | ||
}, false ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// https://github.com/18F/private-eye | ||
(function() { | ||
'use strict'; | ||
|
||
// The line below differs from private eye v2.0. We need to update the source file. | ||
var STYLES = 'a.private-link::after { content: "\\1F512"; font-size: 0.75em; text-decoration: none }'; | ||
var STYLES_ID = '_privateEye-styles'; | ||
|
||
var DEFAULT_OPTIONS = { | ||
defaultMessage: 'This is a link to a private site, which may or may not be accessible to you.', | ||
wrapper: '' | ||
}; | ||
|
||
var isString = function(str) { return !!str && typeof str === 'string'; }; | ||
var isArray = function(arr) { return !!arr && arr.length; }; | ||
|
||
var optionValidators = { | ||
defaultMessage: isString, | ||
wrapper: isString, | ||
ignoreUrls: isArray, | ||
}; | ||
|
||
function setStyles() { | ||
var styles = document.createElement('style'); | ||
styles.innerHTML = STYLES; | ||
styles.id = STYLES_ID; | ||
document.body.appendChild(styles); | ||
} | ||
|
||
function getOptions(opts) { | ||
var newObj = {}; | ||
|
||
for (var prop in DEFAULT_OPTIONS) { | ||
newObj[prop] = DEFAULT_OPTIONS[prop]; | ||
} | ||
|
||
for (var prop in opts) { | ||
var val = opts[prop]; | ||
|
||
if (optionValidators[prop](val)) { | ||
newObj[prop] = val; | ||
} | ||
} | ||
|
||
return newObj; | ||
} | ||
|
||
var PrivateEye = function(opts) { | ||
// The old docs recommend calling this as a function. This is here to detect | ||
// those cases and make sure backward compatibility stays intact now that the | ||
// new syntax is preferred. | ||
if (!(this instanceof PrivateEye)) { | ||
return new PrivateEye(opts); | ||
} | ||
|
||
// Don't add the styles to the page more than once. | ||
if (!document.getElementById(STYLES_ID)) { | ||
setStyles(); | ||
} | ||
|
||
this.opts = getOptions(opts); | ||
|
||
this.checkLinks(); | ||
}; | ||
|
||
PrivateEye.prototype.checkLinks = function() { | ||
var self = this; | ||
|
||
this.opts.ignoreUrls.forEach(function(url) { | ||
var hrefValue; | ||
var titleValue; | ||
|
||
// If the `url` is an Object, then parse the properties `message` & `url` | ||
if (url === Object(url)) { | ||
titleValue = url.message; | ||
hrefValue = url.url; | ||
} else { | ||
hrefValue = url; | ||
titleValue = self.opts.defaultMessage; | ||
} | ||
|
||
var wrapper = self.opts.wrapper.length ? self.opts.wrapper + ' ' : ''; | ||
var selector = wrapper + 'a'; | ||
var anchors = document.querySelectorAll(selector); | ||
|
||
Array.prototype.forEach.call(anchors, function(anchor) { | ||
var anchorHref = anchor.href.toLowerCase().trim(); | ||
|
||
if (anchorHref.indexOf(hrefValue.toLowerCase()) !== -1) { | ||
anchor.className += ' private-link'; | ||
|
||
// Only replace the anchor's title if it is empty | ||
if (!anchor.title) { | ||
anchor.title = titleValue; | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
if (typeof module === 'object' && typeof module.exports === 'object') { | ||
module.exports = PrivateEye; | ||
} else { | ||
window.PrivateEye = PrivateEye; | ||
} | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
Gem::Specification.new do |s| | ||
s.name = 'uswds-jekyll' | ||
s.version = '5.2.0' | ||
s.version = '5.3.0' | ||
s.authors = ['Shawn Allen', 'Tom Black', 'Brian Hurst', 'Scott Weber', 'Dan O. Williams'] | ||
s.email = ['[email protected]'] | ||
|
||
|