Spinner spinning

This commit is contained in:
Martin Donnelly 2016-11-11 00:07:42 +00:00
parent f465cb8e17
commit 015d4931d6
2 changed files with 166 additions and 151 deletions

View File

@ -1,170 +1,177 @@
var APP = {
refreshStep: 0,
preUrl: '/',
refreshStep: 0,
preUrl: '/',
_storage: {
lastupdated: null,
feeds: {}
},
_list: null,
_feed: null,
_storage: {
lastupdated: null, feeds: {}
},
_list: null,
_feed: null,
feeds: ['paleo', 'lifestyle', 'tech', 'news'],
lastUpdated: null,
preCache: function() {
this._list = new EJS({url: 'ejs/list.ejs'});
this._feed = new EJS({
url: 'ejs/test.ejs'
});
},
init: function() {
/*$('#refresh').on('click', $.proxy(this.refresh, this));*/
console.log('app starting...');
$.zprogress.start();
this.preCache();
$.zprogress.inc(0.2);
this.doLoad();
$.zprogress.inc(0.2);
this.getLastUpdateDate();
$.zprogress.done(true);
console.log('Last updated: ' + this.lastUpdated);
},
getLastUpdateDate: function() {
var formatted, dt;
// This.lastUpdated = localStorage.getItem('lastUpdated') || null;
feeds: ["paleo", "lifestyle", "tech", "news", "fit"],
lastUpdated: null,
preCache: function() {
this._list = new EJS({url: 'ejs/list.ejs'});
this._feed = new EJS({
url: 'ejs/test.ejs'
});
},
init: function() {
/*$('#refresh').on('click', $.proxy(this.refresh, this));*/
console.log('app starting...');
//$.zprogress.start();
this.showProgress();
this.preCache();
//$.zprogress.inc(0.2);
this.doLoad();
//$.zprogress.inc(0.2);
this.getLastUpdateDate();
//$.zprogress.done(true);
this.hideProgress();
console.log('Last updated: ' + this.lastUpdated);
},
getLastUpdateDate: function() {
var formatted, dt;
// This.lastUpdated = localStorage.getItem('lastUpdated') || null;
if (this.lastUpdated == null) {
$('#lastupdate').empty().append('Never');
} else {
dt = new Date(this.lastUpdated);
formatted = moment(dt).startOf('minute').fromNow();
console.log(formatted);
$('#lastupdate').empty().append(formatted);
}
if (this.lastUpdated == null) {
$('#lastupdate').empty().append('Never');
}
else {
dt = new Date(this.lastUpdated);
formatted = moment(dt).startOf('minute').fromNow();
console.log(formatted);
$('#lastupdate').empty().append(formatted);
}
},
refresh: function() {
this.refreshStep = 0;
console.log('refresh');
console.log(this);
console.log('get ' + this.feeds[this.refreshStep]);
$('#lastupdate').empty().append('Refreshing...');
this.showAndroidToast('Refreshing...');
$.zprogress.start();
this.doRefresh();
},
refresh: function() {
this.refreshStep = 0;
console.log('refresh');
console.log(this);
console.log('get ' + this.feeds[this.refreshStep]);
$('#lastupdate').empty().append('Refreshing...');
this.showAndroidToast('Refreshing...');
//$.zprogress.start();
this.showProgress();
},
doRefresh: function() {
var self = this;
if (this.refreshStep < this.feeds.length) {
var feedUrl = this.preUrl + this.feeds[this.refreshStep] + '.json';
$('#lastupdate').empty().append('Refreshing: ' + this.feeds[this.refreshStep]);
/* $.getJSON(feedUrl, function(data) {
console.log(self);
this.doRefresh();
self.doUpdate(data);
});*/
},
doRefresh: function() {
var self = this;
if (this.refreshStep < this.feeds.length) {
var feedUrl = this.preUrl + this.feeds[this.refreshStep] + '.json';
$('#lastupdate').empty().append('Refreshing: ' + this.feeds[this.refreshStep]);
/* $.getJSON(feedUrl, function(data) {
console.log(self);
var jsonData = Android.getJson(feedUrl);
//Console.log();
if (jsonData !== '') {
self.doUpdate(JSON.parse(jsonData));
}
self.doUpdate(data);
});*/
} else {
console.log('Done');
this.doSave();
this.showList();
$.zprogress.done(true);
var jsonData = Android.getJson(feedUrl);
//Console.log();
if (jsonData !== '') {
self.doUpdate(JSON.parse(jsonData));
}
}
},
doUpdate: function(data) {
// Console.log(this);
// console.log(data);
this._storage.feeds[this.feeds[this.refreshStep]] = data;
}
else {
console.log('Done');
this.doSave();
this.showList();
// $.zprogress.done(true);
this.hideProgress();
console.log(this._storage);
this.refreshStep++;
$.zprogress.inc(0.2);
this.doRefresh();
},
doSave: function() {
console.log('Saving...');
this.lastUpdated = new Date();
this._storage.lastupdated = this.lastUpdated;
localStorage.setItem('lastUpdated', this.lastUpdated);
localStorage.setItem('_storage', JSON.stringify(this._storage));
this.getLastUpdateDate();
},
doLoad: function() {
}
},
doUpdate: function(data) {
// Console.log(this);
// console.log(data);
this._storage.feeds[this.feeds[this.refreshStep]] = data;
var _load = localStorage.getItem('_storage');
$('#lastupdate').empty().append('Loading...');
if (_load != null) {
this._storage = JSON.parse(_load);
} else {
this._storage = {
lastupdated: null,
feeds: {}
};
}
this.lastUpdated = this._storage.lastupdated || null;
this.showList();
},
clearFeed: function() {
$('#feedcontent').empty();
},
showList: function() {
var output, d = {},
list = [];
for (var key in this._storage.feeds) {
console.log(key);
list.push({
name: key
});
}
console.log(this._storage);
this.refreshStep++;
// $.zprogress.inc(0.2);
this.showProgress();
this.doRefresh();
},
doSave: function() {
console.log('Saving...');
this.lastUpdated = new Date();
this._storage.lastupdated = this.lastUpdated;
localStorage.setItem('lastUpdated', this.lastUpdated);
localStorage.setItem('_storage', JSON.stringify(this._storage));
this.getLastUpdateDate();
},
doLoad: function() {
d.list = list;
var _load = localStorage.getItem('_storage');
$('#lastupdate').empty().append('Loading...');
if (_load != null) {
this._storage = JSON.parse(_load);
}
else {
this._storage = {
lastupdated: null, feeds: {}
};
}
this.lastUpdated = this._storage.lastupdated || null;
this.showList();
},
clearFeed: function() {
$('#feedcontent').empty();
},
showList: function() {
var output, d = {}, list = [];
for (var key in this._storage.feeds) {
console.log(key);
list.push({
name: key
});
}
output = this._list.render(d);
$('#list').empty().append(output);
d.list = list;
for (var key in this._storage.feeds) {
$('#' + key).on('click', $.proxy(this.showFeed, this, key));
}
output = this._list.render(d);
$('#list').empty().append(output);
for (var key in this._storage.feeds) {
$('#' + key).on('click', $.proxy(this.showFeed, this, key));
}
},
showFeed: function(opt) {
var output, d;
console.log('show feed ' + opt);
$('#feedcontent').empty();
d = {
d: this._storage.feeds[opt]
};
output = this._feed.render(d);
},
showFeed: function(opt) {
var output, d;
console.log('show feed ' + opt);
$('#feedcontent').empty();
d = {
d: this._storage.feeds[opt]
};
output = this._feed.render(d);
$('#feedcontent').append(output);
$('img').unveil();
},showAndroidToast: function(toastmsg) {
Android.showToast(toastmsg);
}, showProgress: function() {
Android.showProgress();
},
hideProgress: function() {
Android.hideProgress();
}
$('#feedcontent').append(output);
$('img').unveil();
},
showAndroidToast: function(toastmsg) {
Android.showToast(toastmsg);
},
showProgress: function() {
Android.showProgress();
},
hideProgress: function() {
Android.hideProgress();
}
};
};
Zepto(function($) {
console.log('Start app');
if (typeof (Storage) !== 'undefined') {
APP.init();
} else {
// Sorry! No Web Storage support..
alert('No local storage');
}
});
console.log('Start app');
if (typeof (Storage) !== 'undefined') {
APP.init();
}
else {
// Sorry! No Web Storage support..
alert('No local storage');
}
});

View File

@ -21,7 +21,7 @@ var options = {};
gulp.task('partials', function() {
gulp.src(['app/assets/fm.png']).pipe(gulp.dest('dist/assets'));
gulp.src(['app/assets/*.ejs']).pipe(gulp.dest('dist/ejs'));
gulp.src(['app/ejs/*.ejs']).pipe(gulp.dest('dist/ejs'));
//gulp.src(['app/js/output.min.js']).pipe(gulp.dest('dist/js'));
});
@ -87,7 +87,7 @@ gulp.task('index', function() {
return gulp.src(['app/feeds.html'])
.pipe(htmlreplace({
css: 'css/app.css',
js: 'js/app.js',
js: 'js/app.prod.js',
vendor: 'js/vendor.js',
fonts: 'fonts/fonts.css'
}))
@ -99,6 +99,8 @@ gulp.task('index', function() {
.pipe(gulp.dest('dist/'));
});
gulp.task('clean', function() {
return del(['dist']);
});
@ -106,3 +108,9 @@ gulp.task('clean', function() {
gulp.task('default', ['clean'], function() {
gulp.start('styles', 'scripts', 'vendor', 'fonts', 'partials', 'index');
});
gulp.task('migrate', function() {
return gulp.src(['dist/**/*'])
// .pipe(debug({title: 'migrate:'}))
.pipe(gulp.dest('/Users/martin/newdev/Feedmaster/app/src/main/assets'));
});