Commit 24fed02d authored by yPhil's avatar yPhil

Lib: JS files cleanup: npm standard: globals

parent 214f4af0
{
"globals": {
"Dialog": false,
"Feed": false,
"Prefs": false,
"Tab": false,
"Utilities": false
},
"env": {
"browser": true,
"browser": true,
"commonjs": true,
"es6": true,
"jquery": true
},
"extends": "eslint:recommended",
"rules": {
"one-var": ["error", "initializations"],
"indent": [2, 2, {"MemberExpression": 1}],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "never"]
}
}
var express = require('express');
var path = require('path');
var express = require('express')
var path = require('path')
var index = require('./routes/index');
var index = require('./routes/index')
var app = express();
var app = express()
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.set('views', path.join(__dirname, 'views'))
app.engine('html', require('ejs').renderFile)
app.set('view engine', 'html')
app.use('/static', express.static(__dirname + '/public'));
app.use('/tmp', express.static(__dirname + '/tmp'));
app.use('/static', express.static(path.join(__dirname, 'public')))
app.use('/tmp', express.static(path.join(__dirname, 'tmp')))
app.use('/bower', express.static(__dirname + '/bower_components'));
app.use('/', index);
app.use('/bower', express.static(path.join(__dirname, 'bower_components')))
app.use('/', index)
module.exports = app;
module.exports = app
......@@ -31,10 +31,18 @@
"standard": "*"
},
"standard": {
"ignore": [
"public/lib/js/jquery.localize.js",
"test.js",
"public/css"
]
}
"globals": [
"$",
"Dialog",
"Feed",
"Prefs",
"Tab",
"Utilities"
],
"ignore": [
"public/lib/js/jquery.localize.js",
"test.js",
"public/css"
]
}
}
......@@ -2,7 +2,7 @@ var Dialog = (function () {
return {
kill: function ($dialog) {
$dialog.dialog('destroy')
jQuery('#mobDialogs').empty()
$('#mobDialogs').empty()
},
question: function (qn) {
var questions = [
......
var Prefs = (function() {
var tabList =
[{"name":"Actu",
"feeds":[
{"url":"http://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml","type":"photo","limit":16},
{"url":"http://feeds.bbci.co.uk/news/rss.xml?edition=int","type":"photo","limit":16},
{"url":"http://feeds.reuters.com/reuters/environment","type":"text","limit":16}
]},
{"name":"News",
"feeds": [
{"url":"http://feeds.reuters.com/news/artsculture","type":"text","limit": 12},
{"url":"http://feeds.reuters.com/reuters/businessNews","type":"mixed","limit": 8}
]},
{"name":"plup",
"feeds": [
{"url":"https://www.sciencedaily.com/rss/matter_energy/engineering.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 Prefs = (function () {
var tabList =
[{'name': 'Actu',
'feeds': [
{'url': 'http://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml', 'type': 'photo', 'limit': 16},
{'url': 'http://feeds.bbci.co.uk/news/rss.xml?edition=int', 'type': 'photo', 'limit': 16},
{'url': 'http://feeds.reuters.com/reuters/environment', 'type': 'text', 'limit': 16}
]},
{'name': 'News',
'feeds': [
{'url': 'http://feeds.reuters.com/news/artsculture', 'type': 'text', 'limit': 12},
{'url': 'http://feeds.reuters.com/reuters/businessNews', 'type': 'mixed', 'limit': 8}
]},
{'name': 'plup',
'feeds': [
{'url': 'https://www.sciencedaily.com/rss/matter_energy/engineering.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 newTabList = jQuery.extend(true, {}, tabList);
var defaults = {'gallerySlideTransition': 'fade', 'gallerySlideshowSpeed': 3000, 'tabDropActivate': true, 'theme': 'base', 'tabs': JSON.stringify(tabList)};
return {
readConfig:function(key) {
if(typeof localStorage.getItem(key) === 'undefined' || !localStorage.getItem(key)) {
return defaults[key];
} else {
return localStorage.getItem(key);
}
var defaults = {'gallerySlideTransition': 'fade', 'gallerySlideshowSpeed': 3000, 'tabDropActivate': true, 'theme': 'base', 'tabs': JSON.stringify(tabList)}
},
writeConfig:function(key, val) {
$('#progressBar').fadeToggle('fast');
return {
readConfig: function (key) {
if (typeof localStorage.getItem(key) === 'undefined' || !localStorage.getItem(key)) {
return defaults[key]
} else {
return localStorage.getItem(key)
}
},
writeConfig: function (key, val) {
$('#progressBar').fadeToggle('fast')
// $('#savingIcon').fadeToggle('fast');
localStorage.setItem(key, val);
localStorage.setItem(key, val)
// $('#savingIcon').fadeToggle('slow');
$('#progressBar').fadeToggle('slow');
},
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);
}
};
}());
$('#progressBar').fadeToggle('slow')
},
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)
}
}
}())
This diff is collapsed.
var Utilities = (function() {
var Utilities = (function () {
return {
buildProgress: function ($container, eltClass) {
var progress = { step: 0 }
return {
buildProgress : function( $container, eltClass ) {
progress.init = function (steps) {
this.progressContainer = $('<div id="progressBar">')
this.progressElt = $('<div id="cursor">')
var progress = { step: 0 };
this.progressContainer.append(this.progressElt)
$('body').prepend(this.progressContainer)
this.steps = steps
this.go()
}
progress.increment = function () {
var randomColor = '#' + (0x1000000 + (Math.random()) * 0xffffff).toString(16).substr(1, 6)
progress.init = function( steps ) {
this.progressContainer = $('<div id="progressBar">' );
this.progressElt = $('<div id="cursor">' );
this.progressContainer.append( this.progressElt );
$('body').prepend(this.progressContainer);
this.steps = steps;
this.go();
};
progress.increment = function() {
var randomColor = '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
this.progressElt.animate({
width: Math.ceil(100 * (this.step + 1) / this.steps) + '%'
this.progressElt.animate({
width: Math.ceil(100 * (this.step + 1) / this.steps) + '%'
// ,'background-color': randomColor
});
this.step++;
if (this.step + 1 >= this.steps) this.finish()
};
progress.finish = function() {
var self = this;
self.progressContainer.hide('fast');
};
progress.stop = function() {
this.progressElt.removeClass( 'progress-bar-striped active' );
};
progress.go = function() {
this.progressElt.addClass( 'progress-bar-striped active' );
};
})
this.step++
if (this.step + 1 >= this.steps) this.finish()
}
progress.finish = function () {
var self = this
self.progressContainer.hide('fast')
}
progress.stop = function () {
this.progressElt.removeClass('progress-bar-striped active')
}
progress.go = function () {
this.progressElt.addClass('progress-bar-striped active')
}
return progress;
},
notify : function(type, message) {
var $p = $('#menu').find('#mobNotify > p')
return progress
},
notify: function (type, message) {
var $p = $('#menu').find('#mobNotify > p')
$p.parent().fadeIn('fast')
$p.parent().fadeIn('fast')
$p.html('<strong class="' + type + '">' + type + '</strong> ' + message);
$p.fadeIn( 1000, function() {
$p.animate({
opacity: 0.1
}, 6500, function() {
$p.slideUp(500, function() {
$p.animate({opacity: 1}, 1)
$p.parent().fadeOut('slow')
});
});
});
},
milliToSecs : function(s) {
var ms = s % 1000;
s = (s - ms) / 1000;
var secs = s % 60;
s = (s - secs) / 60;
var mins = s % 60;
var hrs = (s - mins) / 60;
$p.html('<strong class="' + type + '">' + type + '</strong> ' + message)
$p.fadeIn(1000, function () {
$p.animate({
opacity: 0.1
}, 6500, function () {
$p.slideUp(500, function () {
$p.animate({opacity: 1}, 1)
$p.parent().fadeOut('slow')
})
})
})
},
milliToSecs: function (s) {
var ms = s % 1000
s = (s - ms) / 1000
var secs = s % 60
s = (s - secs) / 60
var mins = s % 60
var hrs = (s - mins) / 60
return secs + '.' + ms;
}
};
}());
return secs + '.' + ms
}
}
}())
var express = require('express');
var router = express.Router();
var favicon = require('favicon');
var FeedParser = require('feedparser');
var request = require('request'); // for fetching the feed
var express = require('express')
var router = express.Router()
var favicon = require('favicon')
var FeedParser = require('feedparser')
var request = require('request') // for fetching the feed
var feedrat = require('feedrat');
var feedrat = require('feedrat')
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.get('/', function (req, res, next) {
res.render('index', { title: 'Express' })
})
function getFeed (urlfeed, callback) {
var req = request (urlfeed);
var feedparser = new FeedParser ();
var feedItems = new Array ();
req.on ("response", function (res) {
var stream = this;
if (res.statusCode == 200) {
stream.pipe (feedparser);
var req = request(urlfeed)
var feedparser = new FeedParser()
var feedItems = new Array()
req.on('response', function (res) {
var stream = this
if (res.statusCode == 200) {
stream.pipe(feedparser)
// console.log ("OK: (code %s) reading (%s)", res.statusCode, urlfeed);
} else {
} else {
// console.log ("Error (code %s) reading (%s)", res.statusCode, urlfeed);
}
});
req.on ("error", function (res) {
console.log ("getFeed: Error reading %s (%s) .", urlfeed, res);
});
feedparser.on ("readable", function () {
try {
var item = this.read (), flnew;
if (item !== null) { //2/9/17 by DW
feedItems.push (item);
}
}
catch (err) {
console.log ("getFeed: err.message == " + err.message);
}
}).on ("end", function () {
var meta = this.meta;
callback (undefined, feedItems, meta.title);
}).on ("error", function (err) {
console.log ("getFeed: Error reading (%s) feed.", urlfeed);
callback (err);
});
}
})
req.on('error', function (res) {
console.log('getFeed: Error reading %s (%s) .', urlfeed, res)
})
feedparser.on('readable', function () {
try {
var item = this.read(), flnew
if (item !== null) { // 2/9/17 by DW
feedItems.push(item)
}
} catch (err) {
console.log('getFeed: err.message == ' + err.message)
}
}).on('end', function () {
var meta = this.meta
callback(undefined, feedItems, meta.title)
}).on('error', function (err) {
console.log('getFeed: Error reading (%s) feed.', urlfeed)
callback(err)
})
}
router.get('/feed', function(req, res, next) {
getFeed(req.query.feedurl, function (err, feedItems, feedTitle) {
if (!err) {
function pad (num) {
var s = num.toString (), ctplaces = 3;
while (s.length < ctplaces) {
s = "0" + s;
}
return (s);
}
res.status(200).json({"feedItems": feedItems,"feedTitle": feedTitle});
router.get('/feed', function (req, res, next) {
getFeed(req.query.feedurl, function (err, feedItems, feedTitle) {
if (!err) {
function pad (num) {
var s = num.toString(), ctplaces = 3
while (s.length < ctplaces) {
s = '0' + s
}
});
});
function getDomain(url) {
var m = url.match(/^http:\/\/[^/]+/);
return m ? m[0] : null;
return (s)
}
res.status(200).json({'feedItems': feedItems, 'feedTitle': feedTitle})
}
})
})
function getDomain (url) {
var m = url.match(/^http:\/\/[^/]+/)
return m ? m[0] : null
}
router.get('/feedicon', function(req, res, next) {
favicon(req.query.url, function(err, u) {
router.get('/feedicon', function (req, res, next) {
favicon(req.query.url, function (err, u) {
// if (typeof u === 'undefined' || !u) {
// // console.log('Url: ' + req.query.feedhost + '\nFavicon: ' + favicon_url)
......@@ -83,46 +78,36 @@ router.get('/feedicon', function(req, res, next) {
// // console.log('Err: ' + JSON.stringify(err))
// }
if (u) {
res.send(u)
} else {
res.status(500).send('No icon found')
}
});
});
router.get('/discover', function(req, res, next) {
feedrat(req.query.url, function(err, feed) {
if (feed && typeof feed !== 'undefined' ) {
res.send(feed)
} else {
res.status(500).send('No feed found')
}
});
});
router.post('/upload', function(req, res) {
if (!req.files)
return res.status(400).send('No files were uploaded.');
if (u) {
res.send(u)
} else {
res.status(500).send('No icon found')
}
})
})
router.get('/discover', function (req, res, next) {
feedrat(req.query.url, function (err, feed) {
if (feed && typeof feed !== 'undefined') {
res.send(feed)
} else {
res.status(500).send('No feed found')
}
})
})
router.post('/upload', function (req, res) {
if (!req.files) { return res.status(400).send('No files were uploaded.') }
// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
let sampleFile = req.files.sampleFile;
let sampleFile = req.files.sampleFile
// Use the mv() method to place the file somewhere on your server
sampleFile.mv('/tmp/plop.json', function(err) {
if (err)
return res.status(500).send(err);
sampleFile.mv('/tmp/plop.json', function (err) {
if (err) { return res.status(500).send(err) }
res.send('File uploaded!');
});
});
res.send('File uploaded!')
})
})
module.exports = router;
module.exports = router
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment