initial commit

This commit is contained in:
s2
2019-03-05 09:39:57 +01:00
commit 17097243b2
8 changed files with 1741 additions and 0 deletions

14
.editorconfig Normal file
View File

@@ -0,0 +1,14 @@
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = tab
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
[*.md]
max_line_length = off
trim_trailing_whitespace = false

32
.eslintrc.json Normal file
View File

@@ -0,0 +1,32 @@
{"parserOptions":
{"ecmaVersion": 6},
"rules": {
"quotes": [2, "single", {"allowTemplateLiterals": true}],
"curly": [2, "all"],
"keyword-spacing": [2, {"overrides": {"else": {"before": true}, "catch": {"before": true, "after": false}}}],
"space-before-blocks": [2, "always"],
"wrap-iife": [2, "inside"],
"space-before-function-paren": [2, "never"],
"one-var": [2, "never"],
"vars-on-top": 0, "no-empty": [2, {"allowEmptyCatch": true}],
"array-bracket-spacing": [2, "never"],
"space-in-parens": [2, "never"],
"no-underscore-dangle": 0,
"comma-style": [2, "last"],
"comma-spacing": [2, {"before": false, "after": true}],
"space-unary-ops": [2, {"words": false, "nonwords": false}],
"no-multi-spaces": 2,
"space-infix-ops": 2,
"no-with": 2,
"indent": [2, "tab", {"SwitchCase": 1, "FunctionExpression": {"body": 1, "parameters": 1}, "MemberExpression": 0}],
"no-mixed-spaces-and-tabs": 2,
"no-trailing-spaces": 2,
"comma-dangle": [2, "never"],
"semi": [2, "always"],
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
"eol-last": 2,
"dot-notation": 0,
"no-multi-str": 2,
"key-spacing": [2, {"afterColon": true}]
}
}

23
index.html Normal file
View File

@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://unpkg.com/papercss@1.6.1/dist/paper.min.css">
<title>it.comp.console today</title>
</head>
<body>
<div class="paper container">
<h1>icc today</h1>
<p>I post più importanti della giornata:</p>
<div class="js-articles"></div>
</div>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.js"></script>
<script src="js/ejs.js"></script>
<script src="js/ejs-utils.js"></script>
<script src="js/utils.js"></script>
<script src="js/index.js"></script>
</body>
</html>

3
js/ejs-utils.js Normal file
View File

@@ -0,0 +1,3 @@
ejs.rtfe = function(templateElement, data) {
return ejs.render($('#template-' + templateElement).html(), data);
};

1533
js/ejs.js Normal file

File diff suppressed because it is too large Load Diff

18
js/index.js Normal file
View File

@@ -0,0 +1,18 @@
(function($) {
if (typeof(n3wz) == 'undefined') {
var n3wz = {};
n3wz.apiPrefix = '/api/';
}
$.when(
$.get('templates.ejs'),
$.getJSON(n3wz.apiPrefix + 'newsgroup/it.comp.console/threads')
)
.then(function(templates, threads) {
$('body').append(templates[0]);
$('.js-articles').html(ejs.rtfe('articles', {
threads: threads[0].threads
}));
});
})(jQuery);

91
js/utils.js Normal file
View File

@@ -0,0 +1,91 @@
//utils
(function() {
window.Utils = {};
Utils.uuidv4 = function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0;
var v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
Utils.ellipsis = function(text, maxLength) {
if (typeof maxLength === 'undefined') {
maxLength = 9000; //a large number
}
if (typeof text === 'undefined') {
return '';
}
if (text.length <= maxLength) {
return text;
}
var xMaxFit = maxLength - 1;
var xTruncateAt = text.lastIndexOf(' ', xMaxFit);
if (xTruncateAt == -1 || xTruncateAt < maxLength / 2) {
xTruncateAt = xMaxFit;
}
return text.substr(0, xTruncateAt) + '…';
};
Utils.getSelectionText = function() {
var text = '';
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != 'Control') {
text = document.selection.createRange().text;
}
return text;
};
Utils.getParameterByName = function(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results == null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
Utils.isElementInViewport = function(el) {
//special bonus for those using jQuery
if (typeof jQuery === 'function' && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
);
};
Utils.getUserColor = function(userstring) {
var hashCode = function(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
return hash;
};
var intToRGB = function(i) {
var c = (i & 0x00FFFFFF)
.toString(16)
.toUpperCase();
return '#00000'.substring(0, 6 - c.length) + c;
};
var intToHSL = function(i) {
var shortened = Math.abs(i) % 360;
var l = 40 - (Math.abs(i) % 20);
return 'hsl(' + shortened + ',100%,' + l + '%)';
};
return (userstring ? intToHSL(hashCode(userstring)) : '3a87ad');
};
})();

27
templates.ejs Normal file
View File

@@ -0,0 +1,27 @@
<script id="template-articles" type="text/html">
<%
for (var i=0; i < threads.length - 1; i += 2) {
%>
<div class="row">
<div class="sm-12 md-6 col"><%- ejs.rtfe('article', threads[i]) %></div>
<div class="sm-12 md-6 col"><%- ejs.rtfe('article', threads[i + 1]) %></div>
</div>
<% } %>
</script>
<script id="template-article" type="text/html">
<div class="card">
<div class="card-body">
<h4 class="card-title"><%= Utils.ellipsis(subject, 80) %></h4>
<h5 class="card-subtitle"><%= Utils.ellipsis(from ? from : from_email, 500) %></h5>
<p class="card-text"><%= Utils.ellipsis(body, 500) %></p>
<a class="card-link" href="https://fcku.it/it.comp.console/thread/<%= id %>">leggi tutto...</a>
</div>
</div>
</script>