-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactors JS utilities; separates IE concerns #583
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
// Manages the application initialization for most pages. | ||
// This script is called by the homepage, search result | ||
// and search details pages. It is not called by | ||
// the about page, because that page does not have popups to manage. | ||
// the about page. | ||
require([ | ||
'util/translation/google-translate-manager', | ||
'app/popup-manager', | ||
'app/alert-manager' | ||
], | ||
function (pm, alert) { | ||
function (googleTranslate, popups, alert) { | ||
'use strict'; | ||
|
||
// If box-shadow CSS is supported, initialize the popups. | ||
if (Modernizr.boxshadow) | ||
pm.init(); | ||
// If page is not translated, initialize the header popups. | ||
if (!googleTranslate.isTranslated()) | ||
popups.init(); | ||
|
||
alert.init(); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Provides a upgrade notice that can be shown to outdated browsers (e.g. IE8). | ||
define([ | ||
'util/cookie', | ||
'app/alert-manager' | ||
], | ||
function (cookie, alert) { | ||
'use strict'; | ||
|
||
// Show upgrade notice if browser-upgrade-notice cookie isn't set. | ||
function show() { | ||
if (cookie.read('browser-upgrade-notice') === null) { | ||
var notice = "<i class='fa fa-exclamation-triangle'></i> " + | ||
'Your browser is out-of-date and has known security issues.' + | ||
'<br />' + | ||
"<a href='https://browser-update.org/update.html'>" + | ||
'Please visit this page to download an up-to-date browser.' + | ||
'</a>'; | ||
alert.addEventListener('close', _alertClosed); | ||
alert.show(notice, alert.type.INFO); | ||
} | ||
} | ||
|
||
// Create a cookie when the alert is closed that will hide the alert for the next day. | ||
function _alertClosed() { | ||
cookie.create('browser-upgrade-notice', 'true', true, 1); | ||
} | ||
|
||
return { | ||
show:show | ||
}; | ||
}); |
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,52 @@ | ||
// Cookie CRUD functions, from http://www.quirksmode.org/js/cookies.html | ||
// ERB needed to retrieve domain name that the cookie is saved under. | ||
define( | ||
function () { | ||
'use strict'; | ||
|
||
// @param name [String] The cookie's name. | ||
// @param value [String] The cookie's value. | ||
// @param useDomain [Boolean] Whether set under subdomains or not. | ||
// @param days [Number] Number of days till the cookie expires. | ||
// Can be negative. | ||
function create(name, value, useDomain, days) { | ||
if (days) { | ||
var date = new Date(); | ||
date.setTime(date.getTime() + (days*24*60*60*1000)); | ||
var expires = '; expires=' + date.toGMTString(); | ||
} | ||
else var expires = ''; | ||
|
||
var setting = name + '=' + value + expires + '; path=/'; | ||
|
||
// Sets the cookie under domain and subdomains (if useDomain parameter is present). | ||
document.cookie = setting; | ||
if (useDomain) | ||
document.cookie = setting + "; domain=.<%= ENV['DOMAIN_NAME'] %>"; | ||
} | ||
|
||
// @param name [String] The cookie's name to read. | ||
// @return [String] The named cookie's value, or null. | ||
function read(name) { | ||
var nameEQ = name + "="; | ||
var ca = document.cookie.split(';'); | ||
for(var i=0;i < ca.length;i++) { | ||
var c = ca[i]; | ||
while (c.charAt(0)==' ') c = c.substring(1,c.length); | ||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); | ||
} | ||
return null; | ||
} | ||
|
||
// @param name [String] The cookie's name to remove. | ||
// @param usedDomain [Boolean] Whether to clear subdomains also. | ||
function erase(name, useDomain) { | ||
create(name, '', !!useDomain, -1); | ||
} | ||
|
||
return { | ||
create:create, | ||
read:read, | ||
erase:erase | ||
}; | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior for upgrade notice is when alert is closed a cookie is set for a expiration of one day in the future, so it won't show till the next day. It will continually show till the close (x) is clicked on the alert, however.