Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
8 lines
No EOL
1.8 KiB
JavaScript
8 lines
No EOL
1.8 KiB
JavaScript
;'use strict';(function(exports){var eventTypesToListenFor=['added','updated','removed'];function BookmarkSource(store){this.store=store;this.entries=[];eventTypesToListenFor.forEach(function iterateTypes(type){BookmarksDatabase.addEventListener(type,this);},this);}
|
|
BookmarkSource.prototype={synchronize:function(){var allAppBookmarks={};var toAdd=[];var icons=app.grid.getIcons();for(var i in icons){var icon=icons[i];if(icon.detail.type!=='bookmark'){continue;}
|
|
allAppBookmarks[icon.detail.url]=icon;}
|
|
for(var j=0,jLen=this.entries.length;j<jLen;j++){var entry=this.entries[j];if(!allAppBookmarks[entry.detail.url]){toAdd.push(entry);}else{delete allAppBookmarks[entry.detail.url];}}
|
|
for(i in allAppBookmarks){this.removeIconFromGrid(allAppBookmarks[i].detail.url);}
|
|
for(i=0;i<toAdd.length;i++){this.addIconToGrid(toAdd[i].detail);}
|
|
app.itemStore.deferredSave(app.grid.getItems());},populate:function(success){var self=this;BookmarksDatabase.getAll().then(function(systemBookmarks){Object.keys(systemBookmarks).forEach(function(id){self.entries.push(new GaiaGrid.Bookmark(systemBookmarks[id]));});success(self.entries);},success);},handleEvent:function(e){switch(e.type){case'added':case'updated':this.addIconToGrid(e.target);app.itemStore.deferredSave(app.grid.getItems());break;case'removed':var id=e.target.id;this.removeIconFromGrid(id);break;}},addIconToGrid:function(detail){var icons=app.grid.getIcons();var existing=icons[detail.id];if(existing){existing.update(detail);app.grid.render();return;}
|
|
var bookmark=new GaiaGrid.Bookmark(detail);bookmark.setPosition(this.store.getNextPosition());this.entries.push(bookmark);app.grid.appendItemToExpandedGroup(bookmark);app.grid.render();},removeIconFromGrid:function(url){var icons=app.grid.getIcons();var appObject=icons[url];if(appObject){appObject.removeFromGrid();}}};exports.BookmarkSource=BookmarkSource;}(window)); |