Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors JS utilities; separates IE concerns
- Removes unused util/util methods. - Moves cookie code to its own CRUD module. - Fixes #565 - Removes server-side handling of Google Translate cookie and consolidates cookie handling in google-translate-manager. - Moves isTranslated method to google-translate-manager. - Updates “close” button method to “clear” to go with new naming. - Pads header popup title text so (x) button doesn’t risk overlapping. - Gives alert close button min height/width so that size doesn’t change as (x) icon is loading. - Implements addEventListener on alert so events can be attached to it being dismissed. - Fixes #573 - Creates IE8-specific override stylesheet and pulls :before and :after selectors out of main stylesheet into this one. Also provides overrides to elements that have box-shadows but no border by providing a border instead (alert and popup). - Updates modernizr custom build to include html5-shiv and include all core features used on the site. - Removes gsub from requirejs include tag.
- Loading branch information
1 parent
db1d2c6
commit d6e361f
Showing
24 changed files
with
306 additions
and
652 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
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 ie-upgrade-notice cookie isn't set. | ||
function show() { | ||
if (cookie.read('ie-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('ie-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.