From 133e3d5b556fc3ec1cc7fd68e44f3687ba782e5f Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 9 Nov 2017 22:38:09 -0500 Subject: [PATCH] remove jquery usage from bar --- src/notification/bar.js | 118 +++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 56 deletions(-) diff --git a/src/notification/bar.js b/src/notification/bar.js index 9841ad2bb7..52f0bd69da 100644 --- a/src/notification/bar.js +++ b/src/notification/bar.js @@ -1,65 +1,71 @@ -require('./bar.less'); +require('./bar.less'); -$(function () { - var content = document.getElementById('content'), - closeButton = $('#close-button'); +document.addEventListener('DOMContentLoaded', function () { + // delay 50ms so that we get proper body dimensions + setTimeout(load, 50); - // i18n - $('body').addClass('lang-' + chrome.i18n.getUILanguage()); + function load() { + var content = document.getElementById('content'), + closeButton = document.getElementById('close-button'), + body = document.querySelector('body'), + bodyRect = body.getBoundingClientRect(); - $('#logo-link').attr('title', chrome.i18n.getMessage('appName')); - closeButton.attr('title', chrome.i18n.getMessage('close')); + // i18n + body.classList.add('lang-' + chrome.i18n.getUILanguage()); - if (window.innerWidth < 768) { - $('#template-add .add-save').text(chrome.i18n.getMessage('yes')); - $('#template-add .never-save').text(chrome.i18n.getMessage('never')); - } - else { - $('#template-add .add-save').text(chrome.i18n.getMessage('notificationAddSave')); - $('#template-add .never-save').text(chrome.i18n.getMessage('notificationNeverSave')); - } + document.getElementById('logo-link').title = chrome.i18n.getMessage('appName'); + closeButton.title = chrome.i18n.getMessage('close'); - $('#template-add .add-text').text(chrome.i18n.getMessage('notificationAddDesc')); - - if (getQueryVariable('add')) { - setContent(document.getElementById('template-add')); - - var add = $('#template-add-clone'), - addButton = $('#template-add-clone .add-save'), - neverButton = $('#template-add-clone .never-save'); - - $(addButton).click(function (e) { - e.preventDefault(); - chrome.runtime.sendMessage({ - command: 'bgAddSave' - }); - }); - - $(neverButton).click(function (e) { - e.preventDefault(); - chrome.runtime.sendMessage({ - command: 'bgNeverSave' - }); - }); - } - else if (getQueryVariable('info')) { - setContent(document.getElementById('template-alert')); - $('#template-alert-clone').text(getQueryVariable('info')); - } - - closeButton.click(function (e) { - e.preventDefault(); - chrome.runtime.sendMessage({ - command: 'bgCloseNotificationBar' - }); - }); - - chrome.runtime.sendMessage({ - command: 'bgAdjustNotificationBar', - data: { - height: document.body.scrollHeight + if (bodyRect.width < 768) { + document.querySelector('#template-add .add-save').textContent = chrome.i18n.getMessage('yes'); + document.querySelector('#template-add .never-save').textContent = chrome.i18n.getMessage('never'); } - }); + else { + document.querySelector('#template-add .add-save').textContent = chrome.i18n.getMessage('notificationAddSave'); + document.querySelector('#template-add .never-save').textContent = chrome.i18n.getMessage('notificationNeverSave'); + } + + document.querySelector('#template-add .add-text').textContent = chrome.i18n.getMessage('notificationAddDesc'); + + if (getQueryVariable('add')) { + setContent(document.getElementById('template-add')); + + var addButton = document.querySelector('#template-add-clone .add-save'), + neverButton = document.querySelector('#template-add-clone .never-save'); + + addButton.addEventListener('click', function (e) { + e.preventDefault(); + chrome.runtime.sendMessage({ + command: 'bgAddSave' + }); + }); + + neverButton.addEventListener('click', function (e) { + e.preventDefault(); + chrome.runtime.sendMessage({ + command: 'bgNeverSave' + }); + }); + } + else if (getQueryVariable('info')) { + setContent(document.getElementById('template-alert')); + document.getElementById('template-alert-clone').textContent = getQueryVariable('info'); + } + + closeButton.addEventListener('click', function (e) { + e.preventDefault(); + chrome.runtime.sendMessage({ + command: 'bgCloseNotificationBar' + }); + }); + + chrome.runtime.sendMessage({ + command: 'bgAdjustNotificationBar', + data: { + height: body.scrollHeight + } + }); + } function getQueryVariable(variable) { var query = window.location.search.substring(1);