1- const bookmarks = {
2- add ( $scope , item ) {
3- // let icon = '';
4- // if (!item.imageSrcUrl) {
5- // buildfire.pluginInstance.get(window.appContext.currentPlugin.instanceId, (err, data) => {
6- // if (err) {
7- // console.error(err);
8- // return
9- // } else {
10- // icon = data.iconUrl;
11- // }
12- // });
13- // } else {
14- // icon = item.imageSrcUrl;
15- // };
16- let options = {
17- id : item . link ,
18- title : item . title ,
19- payload : `#/item/goto/${ item . link } ` ,
20- icon : item . imageSrcUrl
21- } ;
22- let callback = ( err , data ) => {
1+ "use strict" ;
2+
3+ var bookmarks = {
4+ add : function add ( $scope , item ) {
5+ var options = {
6+ id : item . guid ,
7+ title : item . title ,
8+ payload : { link : encodeURIComponent ( item . guid ) } ,
9+ icon : item . imageSrcUrl
10+ } ;
11+ var callback = function callback ( err , data ) {
2312 if ( err ) throw err ;
2413 if ( $scope . WidgetHome ) {
25- $scope . WidgetHome . items . map ( i => {
26- const isBookmarked = i . link === item . link ;
14+ $scope . WidgetHome . items . map ( function ( i ) {
15+ var isBookmarked = i . guid === item . guid ;
2716 if ( isBookmarked ) {
2817 i . bookmarked = true ;
2918 }
3019 } ) ;
3120 } else if ( $scope . WidgetMedia ) {
3221 $scope . WidgetMedia . item . bookmarked = true ;
3322 }
34- if ( ! $scope . $$phase ) {
23+ if ( ! $scope . $$phase ) {
3524 $scope . $apply ( ) ;
36- }
37-
38- } ;
39- buildfire . bookmarks ? buildfire . bookmarks . add ( options , callback ) : null ;
25+ }
26+ } ;
27+ buildfire . bookmarks ? buildfire . bookmarks . add ( options , callback ) : null ;
4028 } ,
41- delete ( $scope , item ) {
42- const callback = ( ) => {
29+ delete : function _delete ( $scope , item ) {
30+ var callback = function callback ( ) {
4331 if ( $scope . WidgetHome ) {
44- $scope . WidgetHome . items . map ( i => {
45- const isBookmarked = i . link === item . link ;
32+ $scope . WidgetHome . items . map ( function ( i ) {
33+ var isBookmarked = i . guid === item . guid ;
4634 if ( isBookmarked ) {
4735 i . bookmarked = false ;
4836 }
4937 } ) ;
5038 } else if ( $scope . WidgetMedia ) {
5139 $scope . WidgetMedia . item . bookmarked = false ;
5240 }
53- if ( ! $scope . $$phase ) {
41+ if ( ! $scope . $$phase ) {
5442 $scope . $apply ( ) ;
55- }
56-
43+ }
5744 } ;
58- buildfire . bookmarks ? buildfire . bookmarks . delete ( item . link , callback ) : null ;
45+ buildfire . bookmarks ? buildfire . bookmarks . delete ( item . guid , callback ) : null ;
5946 } ,
60- _getAll ( callback ) {
61- const cb = ( err , bookmarks ) => {
47+ _getAll : function _getAll ( callback ) {
48+ var cb = function cb ( err , bookmarks ) {
6249 if ( err ) throw err ;
6350 callback ( bookmarks ) ;
6451 } ;
6552 buildfire . bookmarks ? buildfire . bookmarks . getAll ( cb ) : cb ( null , [ ] ) ;
6653 } ,
67- sync ( $scope ) {
68- this . _getAll ( bookmarks => {
54+ sync : function sync ( $scope ) {
55+ this . _getAll ( function ( bookmarks ) {
6956 console . log ( bookmarks ) ;
70-
71- const bookmarkIds = [ ] ;
72- bookmarks . forEach ( bookmark => {
57+
58+ var bookmarkIds = [ ] ;
59+ bookmarks . forEach ( function ( bookmark ) {
7360 bookmarkIds . push ( bookmark . id ) ;
7461 } ) ;
7562
7663 if ( $scope . WidgetHome ) {
77- $scope . WidgetHome . items . map ( item => {
78- const isBookmarked = bookmarkIds . includes ( item . link ) ;
64+ $scope . WidgetHome . items . map ( function ( item ) {
65+ var isBookmarked = bookmarkIds . includes ( item . guid ) ;
7966 if ( isBookmarked ) {
8067 item . bookmarked = true ;
8168 } else {
8269 item . bookmarked = false ;
8370 }
8471 } ) ;
8572 } else if ( $scope . WidgetMedia ) {
86- const isBookmarked = bookmarkIds . includes ( $scope . WidgetMedia . item . link ) ;
73+ var isBookmarked = bookmarkIds . includes ( $scope . WidgetMedia . item . guid ) ;
8774 if ( isBookmarked ) {
8875 $scope . WidgetMedia . item . bookmarked = true ;
8976 } else {
@@ -94,6 +81,5 @@ const bookmarks = {
9481 $scope . $apply ( ) ;
9582 }
9683 } ) ;
97-
9884 }
99- } ;
85+ } ;
0 commit comments