Skip to content
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

update some javascript file with modern javascript #1571

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/common_functionality.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Preselect a tab when it's referenced in url
$(document).ready(function () {
var hash = window.location.hash;
let hash = window.location.hash;
hash && $('ul.nav a[href="' + hash + '"]').tab('show');
});
34 changes: 17 additions & 17 deletions app/assets/javascripts/js-cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Released under the MIT license
*/
(function(factory) {
var registeredInModuleLoader = false;
let registeredInModuleLoader = false;
if (typeof define === "function" && define.amd) {
define(factory);
registeredInModuleLoader = true;
Expand All @@ -16,20 +16,20 @@
registeredInModuleLoader = true;
}
if (!registeredInModuleLoader) {
var OldCookies = window.Cookies;
var api = (window.Cookies = factory());
let OldCookies = window.Cookies;
let api = (window.Cookies = factory());
api.noConflict = function() {
window.Cookies = OldCookies;
return api;
};
}
})(function() {
function extend() {
var i = 0;
var result = {};
let i = 0;
let result = {};
for (; i < arguments.length; i++) {
var attributes = arguments[i];
for (var key in attributes) {
let attributes = arguments[i];
for (let key in attributes) {
result[key] = attributes[key];
}
}
Expand All @@ -38,7 +38,7 @@

function init(converter) {
function api(key, value, attributes) {
var result;
let result;
if (typeof document === "undefined") {
return;
}
Expand All @@ -55,7 +55,7 @@
);

if (typeof attributes.expires === "number") {
var expires = new Date();
let expires = new Date();
expires.setMilliseconds(
expires.getMilliseconds() + attributes.expires * 864e5
);
Expand Down Expand Up @@ -87,9 +87,9 @@
key = key.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent);
key = key.replace(/[\(\)]/g, escape);

var stringifiedAttributes = "";
let stringifiedAttributes = "";

for (var attributeName in attributes) {
for (let attributeName in attributes) {
if (!attributes[attributeName]) {
continue;
}
Expand All @@ -111,20 +111,20 @@
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all. Also prevents odd result when
// calling "get()"
var cookies = document.cookie ? document.cookie.split("; ") : [];
var rdecode = /(%[0-9A-Z]{2})+/g;
var i = 0;
let cookies = document.cookie ? document.cookie.split("; ") : [];
let rdecode = /(%[0-9A-Z]{2})+/g;
let i = 0;

for (; i < cookies.length; i++) {
var parts = cookies[i].split("=");
var cookie = parts.slice(1).join("=");
let parts = cookies[i].split("=");
let cookie = parts.slice(1).join("=");

if (!this.json && cookie.charAt(0) === '"') {
cookie = cookie.slice(1, -1);
}

try {
var name = parts[0].replace(rdecode, decodeURIComponent);
let name = parts[0].replace(rdecode, decodeURIComponent);
cookie = converter.read
? converter.read(cookie, name)
: converter(cookie, name) ||
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/piwik.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var _paq = _paq || [];
let _paq = _paq || [];
(function(){
var u="https://beans.opensuse.org/piwik/";
let u="https://beans.opensuse.org/piwik/";
_paq.push(['setSiteId', 7]);
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['trackPageView']);
_paq.push([ 'setDomains', ["*.opensuse.org"]]);
var d=document,
let d=document,
g=d.createElement('script'),
s=d.getElementsByTagName('script')[0];
g.type='text/javascript';
Expand Down
18 changes: 9 additions & 9 deletions app/assets/javascripts/search-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* - Clicking Cancel or x button do nothing.
*/
$(function() {
var $settings_modal = $("#search-settings");
var $project_dropdown = $("#baseproject");
var $ok = $settings_modal.find(".ok-button");
var $cancel = $settings_modal.find(".cancel-button");
let $settings_modal = $("#search-settings");
let $project_dropdown = $("#baseproject");
let $ok = $settings_modal.find(".ok-button");
let $cancel = $settings_modal.find(".cancel-button");

function set_cookie(name, value) {
console.log("Setting cookie: " + name + " = " + value);
Expand All @@ -19,8 +19,8 @@ $(function() {
/*
* See https://stackoverflow.com/a/41542008 for editing query string
*/
var value = $project_dropdown.val();
var query_params = new URLSearchParams(window.location.search);
let value = $project_dropdown.val();
let query_params = new URLSearchParams(window.location.search);

set_cookie("baseproject", value);
if (query_params.has("baseproject")) query_params.set("baseproject", value);
Expand All @@ -30,10 +30,10 @@ $(function() {
});

$ok.click(function() {
var settings = [ "search_devel", "search_lang", "search_debug" ];
for (var i = 0; i < Object.keys(settings).length; i++) {
let settings = [ "search_devel", "search_lang", "search_debug" ];
for (let i = 0; i < Object.keys(settings).length; i++) {
setting = settings[i];
var value = $settings_modal.find('[name="'+ setting +'"]').prop("checked");
let value = $settings_modal.find('[name="'+ setting +'"]').prop("checked");
set_cookie(setting, value);
}
location.reload();
Expand Down