Commit 1d13160d authored by yPhil's avatar yPhil

Sys: Huge refactoring, everything is now in the PLT Module namespace

parent a0ffed73
......@@ -115,9 +115,11 @@ h1 {
margin-top: 0
}
p,
.ui-dialog,
div.dialog {
line-height: 1.5em;
/* color: red; */
color: var(--color-pri);
}
ul {
......@@ -138,11 +140,11 @@ a:visited {
li.error a:hover,
a:hover,
a:active,
i.media:hover {
i.feedItemSmallIcon:hover {
color: var(--ui-color-sec);
}
i.media {
i.feedItemSmallIcon {
float: right;
margin: .2em;
}
......@@ -151,6 +153,7 @@ i.feedControl:hover {
color: var(--ui-color-sec);
}
i.danger,
i.dangerous:hover {
color: var(--ui-color-danger);
}
......@@ -736,7 +739,7 @@ img.warning {
}
i.huge {
font-size: 10em;
font-size: 8em;
}
p.dialog-warning {
......@@ -974,13 +977,13 @@ li.feedItem {
word-wrap: break-word;
}
div.feedItem img {
div.itemDiv img {
max-width:30%;
float:left;
margin: 0 .2rem .2rem 0; /* Some gutter */
}
div.feedItem img.full {
div.itemDiv img.full {
min-width:100%;
}
......@@ -1024,7 +1027,7 @@ li.feed {
li.feed a:active,
li.feed a:hover,
.feedControl:hover,
.media:hover {
.feedItemSmallIcon:hover {
color: none !important;
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// var $menu = $('#menu');
// var $menuButton = $('#menuButton'),
// $newSourceButton = $('#newSourceButton');
// $menuButton
// .data('title', MOB.tr('Options'))
// .attr('title', MOB.tr('Options'));
// $newSourceButton
// .data('title', MOB.tr('Add a source'))
// .attr('title', MOB.tr('Add a source'));
var $tabs = $('#tabs').tabs({
heightStyle: 'content',
activate: function() {
var $activeTab = $tabs.find('.ui-tabs-active');
$(document).prop('title', $activeTab.text() + ' | Petrolette');
$('.tabCloser').hide();
$activeTab.find('.tabCloser').show();
}
});
$tabs.find('.ui-tabs-nav').sortable({
axis: 'x',
items: '> li:not(#newTabButton)',
stop: function() {
$tabs.tabs('refresh');
MOB.tab.saveTabs();
}
});
$tabs.on('mouseup', '.ui-tabs-active a', function(e){
e.preventDefault();
if (e.which === 1) {
MOB.dialog.editGroup($(this));
}
});
$tabs.on("click", "i.tabCloser", function() {
MOB.dialog.killTab($(this));
});
MOB.utilities.noSourcesButton();
// INIT
if (MOB.utilities.isMobile()) {
$tabs.find('.feedControls > div').removeClass('collapsible');
}
$tabs.find('.collapsible').show('fast');
MOB.tab.makeNewTabButton($tabs);
MOB.sync.readSync();
// if ($.parseJSON(MOB.sync.readSync()).length > 0) {
// MOB.tab.populate(JSON.parse(MOB.sync.readSync()));
// } else if ($.parseJSON(MOB.prefs.readConfig('tabs')).length > 0) {
// MOB.tab.populate(JSON.parse(MOB.prefs.readConfig('tabs')));
// } else {
// $('#noSourcesButton').fadeIn('slow');
// }
setTimeout(function() {
$('#tabs').fadeIn(350);
$('#menu').fadeIn(600);
}, 1000);
// ===== Scroll to Top ====
$(window).scroll(function() {
if ($(this).scrollTop() >= 50) { // If page is scrolled more than 50px
$('#scrollToTop').fadeIn(200); // Fade in the arrow
} else {
$('#scrollToTop').fadeOut(200); // Else fade out the arrow
}
});
$('#scrollToTop').click(function() { // When arrow is clicked
$('body,html').animate({
scrollTop : 0 // Scroll to top of body
}, 500);
});
var MOB = (function() {
return {
// language: Prefs.readConfig('lang'),
language: 'en',
start : function() {
var self = this;
},
tr : function( string ) {
var _trAux,
stringVarRegExp = /(%.)/,
matchData,
translatedString,
translations,
currentReplacement,
i = 1; // pour pointer sur le premier argument optionnel, arguments[1]
// Retourne la traduction de la chaine de caractère passée en argument.
_trAux = function( string ) {
if( !string ) {
return "";
}
if ( MOB.language === "en" ) {
// Le discriminant sert à distinguer masculin/féminin ou singulier pluriel, ex <plural>Open
// En "en" la clé sert aussi à la traduction, donc on retire simplement le discriminant
var discriminantRegExp = /(<.*>)(.*)/;
var match = string.match( discriminantRegExp );
var stringWithoutDiscriminant = match ? match[ 2 ] : null;
return stringWithoutDiscriminant || string;
} else {
translations = MOB.i18n.translations[ string ];
translatedString = translations ? translations[ MOB.language ] : string;
return translatedString || string;
}
};
translatedString = _trAux( string );
while ( ( matchData = stringVarRegExp.exec( translatedString ) ) !== null ) {
currentReplacement = translatedString.replace( matchData[0], arguments[ i ] );
translatedString = currentReplacement;
i++;
}
return translatedString;
}
};
})();
$('<div id="menu">').appendTo($('body')).load('/static/templates/menu.html', function() {
var $menu = $(this),
$overlay = $('#overlay'),
$menuButton = $('#menuButton'),
$helpButton = $('.helpButton'),
$newSourceButton = $('#newSourceButton'),
$sourceCodeButton = $('button#sourceCode'),
$importButton = $("button#fileImport"),
$fileImportInput = $("input#fileImport"),
$saveButton = $('#saveTabs'),
$langMenu = $('select#language'),
$donateButton = $('button#donate'),
$slider = $('div#gallerySpeedSlider'),
$spinner = $('#gallerySpeedSpinner');
$('button').button();
MOB.sync.attachWidget();
$menuButton.click(function() {
$overlay.toggleClass('visible');
$menu.toggleClass('expanded');
});
$sourceCodeButton.click(function(event) {
event.preventDefault();
window.open('https://framagit.org/yphil/petrolette');
});
$overlay.click(function() {
$(this).removeClass('visible');
$menu.removeClass('expanded');
});
$newSourceButton.click(function() {
var $openGroupPanel = $($('.ui-tabs-active').find('a').attr('href')).find('.tabSort');
$overlay.removeClass('visible');
$menu.removeClass('expanded');
MOB.feed.make($openGroupPanel, 'New Feed', 'mixed', 8, true);
});
$(document).keydown(function(event) {
if (event.keyCode === $.ui.keyCode.ESCAPE) {
$('.tabSort' ).sortable('cancel');
}
});
var $widget = $('#remotestorage-widget');
var $readMore = $('<a>')
.attr('class', 'rs-help')
.attr('href', 'https:remotestorage.io/')
.text(MOB.tr('Read more.'));
$widget.find('.rs-short-desc').text(MOB.tr('Pétrolette allows you to sync data with a storage of your choice ; '))
.append($readMore);
var $fuckingButton = $widget.find('.rs-choose-rs');
$fuckingButton.css('border-color', '#f00');
$fuckingButton.click(function (event) {
event.preventDefault();
});
MOB.utilities.translate();
$langMenu.val(MOB.prefs.readConfig('lang')).prop('selected', true);
$langMenu.change(function() {
var selectedLang = $(this).val();
MOB.language = selectedLang;
MOB.prefs.writeConfig('lang', selectedLang);
MOB.utilities.translate();
});
$helpButton.click(function (event) {
event.preventDefault();
$('#tabs').tabs('option', 'active', 0);
// MOB.utilities.help('ui');
MOB.dialog.help();
});
$donateButton.click(function (event) {
event.preventDefault();
window.open('https://liberapay.com/yPhil/donate', '_blank');
});
$importButton.click(function () {
$("input#fileImport").click();
return false;
});
$saveButton.click(function () {
MOB.prefs.exportConfig(MOB.tab.list(), 'petrolette.conf');
return false;
});
$(".checkboxradio").checkboxradio({
icon: false
});
$(this).find('input#' + MOB.prefs.readConfig('theme')).prop("checked", true)
.checkboxradio('refresh');
$('.themeSwitcher').change(function() {
console.log('Theme: ' + '/static/css/themes/' + $(this).attr('value') + '.css');
$("#mobStyle").attr({href : '/static/css/themes/' + $(this).attr('value') + '.css'});
MOB.prefs.writeConfig('theme', $(this).attr('value'));
});
var gallerySlideshowSpeed = MOB.prefs.readConfig('gallerySlideshowSpeed');
var gallerySlideTransition = MOB.prefs.readConfig('gallerySlideTransition');
// $.fancybox.defaults.thumbs.autoStart = true;
$.fancybox.defaults.transitionEffect = gallerySlideTransition;
$.fancybox.defaults.slideShow.speed = gallerySlideshowSpeed;
$menu.find('select#gallerySlideTransition').change(function() {
console.log('New FX: %s', $(this).val());
$.fancybox.defaults.transitionEffect = $(this).val();
MOB.prefs.writeConfig('gallerySlideTransition', $(this).val());
});
$menu.find('select#gallerySlideTransition').val(gallerySlideTransition);
if (MOB.prefs.readConfig('tabDropActivate') === 'true')
$('input#tabDropActivate').prop('checked', true).checkboxradio('refresh');
else
$('input#tabDropActivate').prop('checked', false).checkboxradio('refresh');
$('input#tabDropActivate').change(function() {
MOB.prefs.writeConfig('tabDropActivate', $(this).prop('checked'));
});
$spinner.spinner({
min: 0.5,
max: 10000,
step: 0.5,
classes: {
"ui-spinner": "shrink ui-corner-all",
"ui-spinner-down": "ui-corner-br",
"ui-spinner-up": "ui-corner-tr"
}
});
$spinner.spinner('value', MOB.utilities.milliToSecs(gallerySlideshowSpeed));
$spinner.on( 'spinstop', function() {
$slider.slider( 'option', 'value', $(this).val() * 1000);
$('.ui-slider-handle').text(MOB.utilities.milliToSecs($(this).val() * 1000) + 's');
});
$slider.slider({
classes: {
"ui-slider": "grow ui-corner-all",
"ui-slider-handle": "ui-corner-all",
"ui-slider-range": "ui-corner-all ui-widget-header"
},
value: gallerySlideshowSpeed,
min: 500,
max: 10000,
step: 500,
create: function() {
$(this).find('.ui-slider-handle').text(MOB.utilities.milliToSecs(gallerySlideshowSpeed) + 's');
},
slide: function(event, ui) {
// $('#gallerySlideshowSpeedValue').text(ui.value + 'ms');
$spinner.val(MOB.utilities.milliToSecs(ui.value));
$(this).find('.ui-slider-handle').text(MOB.utilities.milliToSecs(ui.value) + 's');
},
change: function(event, ui) {
MOB.prefs.writeConfig('gallerySlideshowSpeed', ui.value);
$('#tabs').find("[data-fancybox]").fancybox({
slideShow: {
speed: ui.value
}
});
}
});
// File reader
$fileImportInput.change(function(evt){
var f = evt.target.files[0],
reader = new FileReader();
reader.onload = (function() {
return function(e) {
function isOk(o) {
var isValid = false;
if (Object.prototype.toString.call(o) === '[object Array]') {
isValid = o.some(obj => Array.isArray(obj.feeds) && obj.feeds.some(feed => Object.prototype.hasOwnProperty.call(feed, 'url')));
} else {
isValid = false;
}
return isValid;
}
var y = e.target.result;
function isJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
var p = false;
if (isJsonString(y)) {
p = JSON.parse(y);
} else {
console.error('Pétrolette | ' + MOB.tr('This file is bad'));
}
if (p && isOk(p) === true){
console.info('Pétrolette | ' + MOB.tr('Loading of [%s] OK', f.name));
MOB.tab.populate(p, true);
} else {
console.error('Pétrolette | ' + MOB.tr('This file is bad'));
}
};
})(f);
reader.readAsText(f);
});
});
MOB.prefs = (function() {
var emptyTabList = [
{"name":"Group 1",
"feeds": [
{"url":"http://www.androidpolice.com/feed","type":"mixed","limit": 8},
{"url":"http://feeds.nature.com/nature/rss/current","type":"text","limit": 16},
{"url":"https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss","type":"photo","limit": 4}
]
}
];
var newsTabList = [
{"name":"World",
"feeds": [
{"url":"http://feeds.bbci.co.uk/news/world/rss.xml","type":"mixed","limit":8},
{"url":"http://www.nytimes.com/services/xml/rss/nyt/World.xml","type":"mixed","limit": 4},
{"url":"http://feeds.reuters.com/Reuters/worldNews","type":"text","limit": 16},
{"url":"http://feeds.reuters.com/reuters/USVideoWorldNews","type":"photo","limit": 16},
{"url":"http://www.economist.com/sections/international/rss.xml","type":"text","limit": 8},
{"url":"https://www.reddit.com/.rss","type":"text","limit": 8}
]
},
{"name":"Europe",
"feeds": [
{"url":"http://www.economist.com/sections/europe/rss.xml", "type":"text", "limit": 12},
{"url":"https://feeds.feedburner.com/TechCrunch/","type":"mixed","limit": 8},
{"url":"http://xkcd.com/rss.xml","type":"photo","limit": 4},
{"url":"https://www.reddit.com/.rss","type":"text","limit": 8}
]
}
];
var miscTabList = [
{"name":"Tech",
"feeds": [
{"url":"https://feeds.feedburner.com/TechCrunch/","type":"mixed","limit": 8},
{"url":"http://feeds.reuters.com/reuters/technologyNews", "type":"text", "limit": 16},
{"url":"https://www.sciencedaily.com/rss/matter_energy/engineering.xml", "type":"mixed", "limit": 12},
{"url":"https://www.theengineer.co.uk/feed", "type":"mixed", "limit": 14},
{"url":"http://feed.cnet.com/feed/topics/tech-industry", "type":"mixed", "limit": 14},
{"url":"https://spectrum.ieee.org/rss/videos", "type":"mixed", "limit": 16}
]
},
{"name":"Computing",
"feeds": [
{"url":"http://feeds.reuters.com/reuters/technologyNews", "type":"text", "limit": 16},
{"url":"https://spectrum.ieee.org/rss/computing/fulltext", "type":"mixed", "limit": 12},
{"url":"https://www.technologyreview.com/c/computing/rss/", "type":"photo", "limit": 4},
{"url":"http://www.economist.com/blogs/gametheory/index.xml","type":"mixed","limit": 8},
{"url":"http://rss.slashdot.org/Slashdot/slashdot", "type":"mixed", "limit": 4},
{"url":"http://rss.slashdot.org/Slashdot/slashdot", "type":"mixed", "limit": 4},
{"url":"http://rss.slashdot.org/Slashdot/slashdot", "type":"mixed", "limit": 4},
{"url":"http://www.economist.com/topics/computer-technology/index.xml", "type":"text", "limit": 16}
]
},
{"name":"Science",
"feeds": [
{"url":"http://feeds.bbci.co.uk/news/science_and_environment/rss.xml", "type":"mixed", "limit": 6},
{"url":"https://feeds.feedburner.com/TechCrunch/","type":"mixed","limit": 8},
{"url":"https://spectrum.ieee.org/rss/biomedical/fulltext","type":"mixed","limit": 4},
{"url":"https://www.technologyreview.com/topnews.rss","type":"mixed","limit": 4},
{"url":"https://www.technologyreview.com/c/biomedicine/rss/","type":"mixed","limit": 4},
{"url":"https://www.technologyreview.com/c/energy/rss/","type":"mixed","limit": 4},
{"url":"https://spectrum.ieee.org/rss/blog/energywise/fulltext","type":"mixed","limit": 4},
{"url":"https://spectrum.ieee.org/rss/blog/automaton/fulltext","type":"mixed","limit": 4},
{"url":"https://www.reddit.com/.rss","type":"text","limit": 8}
]
},
{"name":"Comics",
"feeds": [
{"url":"http://xkcd.com/rss.xml","type":"photo","limit": 8},
{"url":"http://thisisindexed.com/feed","type":"photo","limit": 8},
{"url":"http://what-if.xkcd.com/feed.atom","type":"photo","limit": 8},
{"url":"http://phdcomics.com/gradfeed.php","type":"photo","limit": 8},
{"url":"http://comicfeeds.chrisbenard.net/view/pennyarcade/default","type":"photo","limit": 8},
{"url":"http://comicfeeds.chrisbenard.net/view/dilbert/default","type":"photo","limit": 8}
]
}
];
var defaults = {
'gallerySlideTransition': 'fade',
'gallerySlideshowSpeed': 3000,
'tabDropActivate': true,
'theme': 'day',
'columns': 3,
'lang': 'en',
'explicitLang': false,
'tabs': JSON.stringify(emptyTabList)
};
var collections = {
'news': JSON.stringify(newsTabList),
'misc': JSON.stringify(miscTabList)
};
return {
collection:function(key) {
return collections[key];
},
isValidSourcesFile:function(sources) {
var isValid = false;
if (Object.prototype.toString.call(sources) === '[object Array]') {
isValid = sources.some(obj => Array.isArray(obj.feeds) && obj.feeds.some(feed => Object.prototype.hasOwnProperty.call(feed, 'url')));
} else {
isValid = false;
}
return isValid;
},
readConfig:function(key) {
if(typeof localStorage.getItem(key) === 'undefined' || !localStorage.getItem(key)) {
return defaults[key];
} else {
return localStorage.getItem(key);
}
},
writeConfig:function(key, val) {
var $loader = $('#indicatorContainer');
$loader.fadeToggle(50);
localStorage.setItem(key, val);
$loader.fadeToggle('fast');
},
exportConfig:function(data, fileName) {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
var json = JSON.stringify(data, null, 2),
blob = new Blob([json], {type: "application/json"}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
}
};
}());
MOB.sync = (function() {
var synchronized = false;
var syncDirectory = 'petrolette';
var Sources = {
name: syncDirectory, builder: function(privateClient, publicClient) {
return {
exports: {
read: function () {
return privateClient.getFile('petrolette.conf', 9999999999)
.then(function (file) {
return file.data;
});
},
write: function (sources) {
return privateClient.storeFile('text/plain', 'petrolette.conf', sources);
}
}
};
}
};
const remoteStorage = new RemoteStorage({
// logging: true,
// cordovaRedirectUri: 'http://petrolette.space',
modules: [ Sources ]
});
// remoteStorage.setApiKeys({
// dropbox: 'jyss37l88l4ural',
// googledrive: '228755392285-87kkpdod9op50nmnrvnvo6eofr5d3ehl.apps.googleusercontent.com'
// });
remoteStorage.on('connected', function() {
synchronized = true;
console.info('Pétrolette | Connected to remote storage');
});
remoteStorage.on('disconnected', function() {
synchronized = false;
console.info('Pétrolette | Disconnected from remote storage');
});
return {
attachWidget:function() {
const widget = new Widget(remoteStorage, {
leaveOpen: true
// logging: true
});
remoteStorage.access.claim('petrolette', 'rw');
return widget.attach('syncBox');
},
readSync:function() {
remoteStorage.petrolette.read()
.then((data) => {
if (MOB.prefs.isValidSourcesFile(JSON.parse(data))) {
console.info('Pétrolette | Remote file validation OK');
return MOB.tab.populate(JSON.parse(data));
} else {
console.error('Pétrolette | Remote file validation NOT OK(%s) Tryin browser cache', data);
if (MOB.prefs.isValidSourcesFile(JSON.parse(MOB.prefs.readConfig('tabs')))) {
console.log('plop');
MOB.tab.populate(JSON.parse(MOB.prefs.readConfig('tabs')));
} else {
localStorage.setItem("tabs", "");
}
}
})
.catch((err) => {
if (MOB.prefs.isValidSourcesFile(JSON.parse(MOB.prefs.readConfig('tabs')))) {
MOB.tab.populate(JSON.parse(MOB.prefs.readConfig('tabs')));
} else {
localStorage.setItem("tabs", "");
}
});
},
writeSync:function(sources) {
var $loader = $('#indicatorContainer');
$loader.fadeToggle(50);
remoteStorage.petrolette.write(sources)
.then(() => {
console.info('Pétrolette | Writing to remote storage OK');
})
.catch((err) => {
console.error('Pétrolette | Remote file validation error:', err);
});
// localStorage.setItem(key, val);
$loader.fadeToggle('fast');
}
};