1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

frontend: use gulp, eslint, code refactor

Apologies in advance for the insanely huge commit. This commit is
primarily based on Anton Linevych's amazing work found here [1]. While
he had gone through the pains of making small, atomic changes to each
file, I had put off reviewing the PR for a long time. By the time I
finally got around to it, the project had changed so much that it didn't
make sense to keep the commits the same way. So I've cherry-picked most
of his commits, with some changes here and there, and I've squashed them
into one commit.

[1] https://gitlab.com/linevych/commento-ce/tree/feature/frontend_building_improvements
This commit is contained in:
Anton Linevych
2018-06-24 04:01:21 +02:00
committed by Adhityaa Chandrasekar
parent e4f71fe402
commit 9e3935b3b2
30 changed files with 5059 additions and 395 deletions

View File

@ -1,14 +1,16 @@
(function (global, document) {
"use strict";
// Gets a GET parameter in the current URL.
global.paramGet = function(param) {
var pageURL = decodeURIComponent(window.location.search.substring(1));
var urlVariables = pageURL.split('&');
var urlVariables = pageURL.split("&");
for (var i = 0; i < urlVariables.length; i++) {
var paramURL = urlVariables[i].split('=');
if (paramURL[0] === param)
var paramURL = urlVariables[i].split("=");
if (paramURL[0] === param) {
return paramURL[1] === undefined ? true : paramURL[1];
}
}
return null;
@ -42,16 +44,16 @@
// Given an array of input IDs, this function calls a callback function with
// the first unfilled ID.
global.unfilledMark = function(fields, callback) {
var all_ok = true;
var allOk = true;
for (var i = 0; i < fields.length; i++) {
var el = $(fields[i]);
if (el.val() == "") {
if (el.val() === "") {
callback(el);
}
}
return all_ok;
return allOk;
}
@ -59,8 +61,9 @@
global.cookieGet = function(name) {
var c = "; " + document.cookie;
var x = c.split("; " + name + "=");
if (x.length == 2)
if (x.length === 2) {
return x.pop().split(";").shift();
}
};
@ -72,8 +75,9 @@
expires = "; expires=" + date.toUTCString();
var cookieString = name + "=" + value + expires + "; path=/";
if (/^https:\/\//i.test(origin))
if (/^https:\/\//i.test(origin)) {
cookieString += "; secure";
}
document.cookie = cookieString;
}
@ -81,7 +85,7 @@
// Deletes a cookie.
global.cookieDelete = function(name) {
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:01 GMT;";
}
@ -90,29 +94,35 @@
var seconds = Math.floor((new Date() - date) / 1000);
var interval = Math.floor(seconds / 31536000);
if (interval > 1)
if (interval > 1) {
return interval + " years ago";
}
interval = Math.floor(seconds / 2592000);
if (interval > 1)
if (interval > 1) {
return interval + " months ago";
}
interval = Math.floor(seconds / 86400);
if (interval > 1)
if (interval > 1) {
return interval + " days ago";
}
interval = Math.floor(seconds / 3600);
if (interval > 1)
if (interval > 1) {
return interval + " hours ago";
}
interval = Math.floor(seconds / 60);
if (interval > 1)
if (interval > 1) {
return interval + " minutes ago";
}
if (seconds > 5)
if (seconds > 5) {
return Math.floor(seconds) + " seconds ago";
else
} else {
return "just now";
}
}
} (window.commento, document));