Skip to content

Commit

Permalink
Move data fetching to an event page (Rel #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Feb 23, 2013
1 parent 68ec220 commit a2406e7
Show file tree
Hide file tree
Showing 12 changed files with 3,010 additions and 2,857 deletions.
24 changes: 24 additions & 0 deletions extension/app/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function fetch() {
window.ENV = "Events";
require(['config'], function( conf ) {

// Fetch Chrome bookmarks
require([ "modules/bookmarks.chrome" ], function( chromeBookmarks ) {
chromeBookmarks.fetch();
});

// Fetch Delicious bookmarks
require([ "modules/bookmarks.delicious" ], function( deliciousBookmarks ) {
deliciousBookmarks.fetch();
});

});
}

if( chrome.alarms ) {
chrome.alarms.create('fetch', { periodInMinutes : 30 });
chrome.alarms.onAlarm.addListener(fetch);
} else {
setInterval( fetch, 1800000 );
}
chrome.runtime.onInstalled.addListener(fetch);
9 changes: 2 additions & 7 deletions extension/app/config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
/*global require:true, define:true, window:true, document:true */

/**
* AMD loader Configuration
*/

require.config({

// Initialize the application with the main application file
deps: [
"main"
],

deps: window.ENV === 'events' ? [] : ["main"],

paths: {
// Libraries.
Expand Down
27 changes: 3 additions & 24 deletions extension/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,9 @@ function( app, $, _, Backbone, settings, bookmarksCollection, AllBookmarksView,


// ---
// Get Bookmarks
// Get Bookmarks (LocalStorage is Synchronous)

bookmarksCollection.fetch({
success: fetchSources
});


// ---
// Check bookmarks sources updates
// @info: triggered after bookmarksCollection fetch is done
// TODO: Transfer to an event/background page

function fetchSources() {

// Fetch Chrome bookmarks
require([ "modules/bookmarks.chrome" ], function( chromeBookmarks ) {
chromeBookmarks.fetch();
});

// Fetch Delicious bookmarks
require([ "modules/bookmarks.delicious" ], function( deliciousBookmarks ) {
deliciousBookmarks.fetch();
});

}
bookmarksCollection.fetch();


// ---
Expand All @@ -62,6 +40,7 @@ function( app, $, _, Backbone, settings, bookmarksCollection, AllBookmarksView,
"#stage" : new AllBookmarksView()
}).render();



// ---
// Listen click on a tags and open link in current Tab
Expand Down
14 changes: 7 additions & 7 deletions extension/app/models/single-bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ function( app, $, _, Backbone, utils, BookmarkView ) {

var Bookmark = Backbone.Model.extend({

// Identify model via their URL as this is their canonical/unique reference
idAttribute: "url",

defaults: {
url : "",
title : "",
Expand All @@ -35,13 +32,17 @@ function( app, $, _, Backbone, utils, BookmarkView ) {
localStorage: new Backbone.LocalStorage('whatever2'),

initialize: function() {
if( this.isNew() ) {
this.parseNew();
}
},

parseNew: function() {

// Set domain
var url = this.get('url');
if ( utils.isURL(url) ) {
this.set( 'domain', utils.getDomain(url) );
} else {
//this can be a bookmarklet, a FTP, or special page bookmark...
this.set( 'domain', false );
}

//set the main set_content_type
Expand All @@ -54,7 +55,6 @@ function( app, $, _, Backbone, utils, BookmarkView ) {

this.set( 'thumbnail_url', this.get_thumb_url() );
this.save();

},

save: function(attrs, options) {
Expand Down
1 change: 0 additions & 1 deletion extension/app/modules/bookmarks.chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function( $, _, allBookmarks ) {
importChromeBookmarks: function() {
var def = new $.Deferred(),
self = this;

chrome.bookmarks.getTree(function( tree, folder ) {
self.parseChromeBookmarkTree( tree, folder, def );
});
Expand Down
7 changes: 6 additions & 1 deletion extension/app/views/all-bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@ function( app, $, _, Backbone, allBookmarks, BookmarkView, searchCriterias ) {

$(document).on('keydown', _.bind(this.keyAction, this));
this.on('change:focus', this.setScroll);
this.listenTo(this.collection, 'add', _.throttle(this.render, 500));
},

beforeRender: function() {
this.collection.each(function( model ) {
this.insertView( ".app-bookmarks", new BookmarkView({ model: model }) );
this.add( model );
}, this);
},

afterRender: function() {
this.$el.nanoScroller({ scroll: 'top' });
},

add: function( model ) {
return this.insertView( ".app-bookmarks", new BookmarkView({ model: model }) );
},


// ---
Expand Down
4 changes: 4 additions & 0 deletions extension/app/views/single-bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ function( app, $, _, Backbone ) {

template: "single-bookmark",
el: false,

initialize: function() {
this.listenTo( this.model, 'change', this.render );
},

serialize: function() {
return this.model.toJSON();
Expand Down
Loading

0 comments on commit a2406e7

Please sign in to comment.