/* eslint-disable no-multi-str */
(function ($) {
'use strict';
/**
* The recommended way for producing HTML markup through JavaScript is to write
* theming functions. These are similiar to the theming functions that you might
* know from 'phptemplate' (the default PHP templating engine used by most
* Drupal themes including Omega). JavaScript theme functions accept arguments
* and can be overriden by sub-themes.
*
* In most cases, there is no good reason to NOT wrap your markup producing
* JavaScript in a theme function.
*
* @param {string} path
* The link URL.
* @param {string} title
* The link title.
*
* @return {jQuery}
* The anchor element.
*/
Drupal.theme.prototype.badgerExampleButton = function (path, title) {
// Create an anchor element with jQuery.
return $('' + title + '');
};
// Anchor above the header, not at the FAQ item
function raiseAnchors() {
if (window.location.hash) {
window.scrollTo(window.scrollX, window.scrollY - 95);
}
}
$(window).on('hashchange', function () {
raiseAnchors();
});
/**
* Behaviors are Drupal's way of applying JavaScript to a page. In short, the
* advantage of Behaviors over a simple 'document.ready()' lies in how it
* interacts with content loaded through Ajax. Opposed to the
* 'document.ready()' event which is only fired once when the page is
* initially loaded, behaviors get re-executed whenever something is added to
* the page through Ajax.
*
* You can attach as many behaviors as you wish. In fact, instead of overloading
* a single behavior with multiple, completely unrelated tasks you should create
* a separate behavior for every separate task.
*
* In most cases, there is no good reason to NOT wrap your JavaScript code in a
* behavior.
*
* @param context
* The context for which the behavior is being executed. This is either the
* full page or a piece of HTML that was just added through Ajax.
* @param settings
* An array of settings (added through drupal_add_js()). Instead of accessing
* Drupal.settings directly you should use this because of potential
* modifications made by the Ajax callback that also produced 'context'.
*/
Drupal.behaviors.badgerDownload = {
attach: function (context, settings) {
// By using the 'context' variable we make sure that our code only runs on
// the relevant HTML. Furthermore, by using jQuery.once() we make sure that
// we don't run the same piece of code for an HTML snippet that we already
// processed previously. By using .once('foo') all processed elements will
// get tagged with a 'foo-processed' class, causing all future invocations
// of this behavior to ignore them.
$('#badger-download', context).once('badger-download', function () {
var firefox_url = $('#badger-firefox').attr('href');
var chrome_url = $('#badger-chrome').attr('href');
var opera_url = $('#badger-opera').attr('href');
// detect browser
var browser = 'other';
if (navigator && navigator.userAgent) {
if (navigator.userAgent.match(/Android/i)) {
browser = 'android';
}
else if (navigator.userAgent.match(/firefox/i)) {
browser = 'firefox';
}
else if (navigator.userAgent.match(/OPR|opera/i)) {
browser = 'opera';
}
else if (navigator.userAgent.match(/edge/i)) {
browser = 'edge';
}
else if (navigator.userAgent.match(/chrome/i)) {
browser = 'chrome';
}
else if (navigator.userAgent.match(/iPhone/i)) {
browser = 'iphone';
}
else {
browser = 'other';
}
}
// [Install Privacy Badger and enable do not track]
// build the links
function install_link(browser, url) {
var $install = $('')
.attr('href', url)
.html(Drupal.t('Install Privacy Badger') + '
' + Drupal.t('and Enable Do Not Track') + '
');
return $install;
}
function other_link(browser, url) {
var $other = $('')
.attr('href', url)
.html(Drupal.t('Install for !browser', {'!browser': browser}));
return $('').append($other);
}
function changelog_link() {
var url = Drupal.settings.privacyBadger.changelog;
var version = Drupal.settings.privacyBadger.version;
var $link = $('')
.attr('href', url)
.html(Drupal.t('v' + version));
return $('').append($link);
}
$('#badger-download').empty();
// firefox
if (browser === 'firefox') {
$('#badger-download')
.click(function () { window.location = firefox_url; })
.append(install_link('Firefox', firefox_url))
.after(other_link('Firefox on Android', firefox_url))
.after(other_link('Chrome', chrome_url))
.after(other_link('Opera', opera_url))
.after(changelog_link());
}
// chrome
else if (browser === 'chrome') {
$('#badger-download')
.click(function() { window.location = chrome_url; })
.append(install_link('Chrome', chrome_url))
.after(other_link('Firefox on Android', firefox_url))
.after(other_link('Firefox', firefox_url))
.after(other_link('Opera', opera_url))
.after(changelog_link());
}
// opera
else if (browser === 'opera') {
$('#badger-download')
.click(function () { window.location = opera_url; })
.append(install_link('Opera', opera_url))
.after(other_link('Firefox on Android', firefox_url))
.after(other_link('Chrome', chrome_url))
.after(other_link('Firefox', firefox_url))
.after(changelog_link());
}
// android
else if (browser === 'android') {
$('#badger-download')
.click(function () { window.location = firefox_url; })
.append(install_link('Firefox', firefox_url))
.after(Drupal.t('Privacy Badger for Firefox on Android is in BETA.
'));
}
// iPhone
else if (browser === 'iphone') {
$('#badger-download')
.append('Browser Not Supported').addClass("not-supported")
.after(Drupal.t(''));
}
// unsupported browser
else {
$('#badger-download')
.append('Browser Not Supported').addClass("not-supported")
.after(Drupal.t('Privacy Badger is not supported in this browser.
(More info) '));
}
});
}
};
Drupal.behaviors.badgerFaqRedirects = {
attach: function (context, settings) {
if (window.location.hash != "") {
var path = window.location.pathname + encodeURIComponent(window.location.hash);
switch(path) {
case '/privacybadger%23faq-What-is-Privacy-Badger%3F':
window.location.replace('/privacybadger/faq#What-is-Privacy-Badger');
break;
case "/privacybadger%23faq-How-is-Privacy-Badger-different-from-Disconnect%2C-Adblock-Plus%2C-Ghostery%2C-and-other-blocking-extensions%3F":
window.location.replace("/privacybadger/faq#How-is-Privacy-Badger-different-from-Disconnect,-Adblock-Plus,-Ghostery,-and-other-blocking-extensions");
break;
case "/privacybadger%23faq-How-does-Privacy-Badger-work%3F":
window.location.replace("/privacybadger/faq#How-does-Privacy-Badger-work");
break;
case "/privacybadger%23faq-What-is-a-third-party-tracker%3F":
window.location.replace("/privacybadger/faq#What-is-a-third-party-tracker");
break;
case "/privacybadger%23faq-What-do-the-red%2C-yellow-and-green-sliders-in-the-Privacy-Badger-menu-mean%3F":
window.location.replace("/privacybadger/faq#What-do-the-red,-yellow-and-green-sliders-in-the-Privacy-Badger-menu-mean");
break;
case "/privacybadger%23faq-Why-does-Privacy-Badger-block-ads%3F":
window.location.replace("/privacybadger/faq#Why-does-Privacy-Badger-block-ads");
break;
case "/privacybadger%23faq-Why-doesn't-Privacy-Badger-block-all-ads%3F":
window.location.replace("/privacybadger/faq#Why-doesn't-Privacy-Badger-block-all-ads");
break;
case "/privacybadger%23faq-What-about-tracking-by-the-sites-I-actively-visit%2C-like-NYTimes.com-or-Facebook.com%3F":
window.location.replace("/privacybadger/faq#What-about-tracking-by-the-sites-I-actively-visit,-like-NYTimes.com-or-Facebook.com");
break;
case "/privacybadger%23faq-Does-Privacy-Badger-contain-a-%2522black-list%2522-of-blocked-sites%3F":
window.location.replace('/privacybadger/faq#Does-Privacy-Badger-contain-a-"black-list"-of-blocked-sites');
break;
case "/privacybadger%23faq-How-was-the-cookie-blocking-yellowlist-created%3F":
window.location.replace("/privacybadger/faq#How-was-the-cookie-blocking-yellowlist-created");
break;
case "/privacybadger%23faq-Does-Privacy-Badger-prevent-fingerprinting%3F":
window.location.replace("/privacybadger/faq#Does-Privacy-Badger-prevent-fingerprinting");
break;
case "/privacybadger%23faq-Does-Privacy-Badger-consider-every-cookie-to-be-a-tracking-cookie%3F":
window.location.replace("/privacybadger/faq#Does-Privacy-Badger-consider-every-cookie-to-be-a-tracking-cookie");
break;
case "/privacybadger%23faq-Does-Privacy-Badger-account-for-a-cookie-that-was-used-to-track-me-even-if-I-deleted-it%3F":
window.location.replace("/privacybadger/faq#Does-Privacy-Badger-account-for-a-cookie-that-was-used-to-track-me-even-if-I-deleted-it");
break;
case "/privacybadger%23faq-Does-Privacy-Badger-still-work-when-blocking-third-party-cookies-in-the-browser%3F":
window.location.replace("/privacybadger/faq#Does-Privacy-Badger-still-work-when-blocking-third-party-cookies-in-the-browser");
break;
case "/privacybadger%23faq-Will-you-be-supporting-any-other-browsers-besides-Chrome-%2F-Firefox-%2F-Opera%3F":
window.location.replace("/privacybadger/faq#Will-you-be-supporting-any-other-browsers-besides-Chrome-/-Firefox-/-Opera");
break;
case "/privacybadger%23faq-Can-I-download-Privacy-Badger-outside-of-the-Chrome-Web-Store%3F":
window.location.replace("/privacybadger/faq#Can-I-download-Privacy-Badger-outside-of-the-Chrome-Web-Store");
break;
case "/privacybadger%23faq--I-am-an-online-advertising-%2F-tracking-company.--How-do-I-stop-Privacy-Badger-from-blocking-me%3F":
window.location.replace("/privacybadger/faq#-I-am-an-online-advertising-/-tracking-company.--How-do-I-stop-Privacy-Badger-from-blocking-me");
break;
case "/privacybadger%23faq-What-is-the-Privacy-Badger-license%3F--Where-is-the-Privacy-Badger-source-code%3F":
window.location.replace("/privacybadger/faq#What-is-the-Privacy-Badger-license--Where-is-the-Privacy-Badger-source-code");
break;
case "/privacybadger%23faq-I-found-a-bug!-What-do-I-do-now%3F":
window.location.replace("/privacybadger/faq#I-found-a-bug!-What-do-I-do-now");
break;
case "/privacybadger%23faq-How-can-I-support-Privacy-Badger%3F":
window.location.replace("/privacybadger/faq#How-can-I-support-Privacy-Badger");
break;
case "/privacybadger%23faq-How-does-Privacy-Badger-handle-social-media-widgets%3F":
window.location.replace("/privacybadger/faq#How-does-Privacy-Badger-handle-social-media-widgets");
break;
case "/privacybadger%23faq-How-do-I-uninstall%2Fremove-Privacy-Badger%3F":
window.location.replace("/privacybadger/faq#How-do-I-uninstall/remove-Privacy-Badger");
break;
case "/privacybadger%23faq-Is-Privacy-Badger-compatible-with-other-extensions%2C-including-other-adblockers%3F":
window.location.replace("/privacybadger/faq#Is-Privacy-Badger-compatible-with-other-extensions,-including-other-adblockers");
break;
case "/privacybadger%23faq-Why-does-my-browser-connect-to-fastly.com-IP-addresses-on-startup-after-installing-Privacy-Badger%3F":
window.location.replace("/privacybadger/faq#Why-does-my-browser-connect-to-fastly.com-IP-addresses-on-startup-after-installing-Privacy-Badger");
break;
case "/privacybadger%23faq-Why-am-I-getting-a-%2522This-extension-failed-to-redirect-a-network-request-to-...%2522-warning-in-Chrome%3F":
window.location.replace('/privacybadger/faq#Why-am-I-getting-a-"This-extension-failed-to-redirect-a-network-request-to-..."-warning-in-Chrome');
break;
case "/privacybadger%23faq-Why-isn't-my-Badger-learning-to-block-anything%3F":
window.location.replace("/privacybadger/faq#Why-isn't-my-Badger-learning-to-block-anything");
break;
}
}
}
};
})(jQuery);