Skip to content

Commit 8466e5f

Browse files
authored
Merge pull request #77 from lyonx/master
switch bookmark navigation to deeplink
2 parents 6dde058 + d9adc14 commit 8466e5f

File tree

2 files changed

+48
-71
lines changed

2 files changed

+48
-71
lines changed

widget/bookmarkHandler.js

Lines changed: 35 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,76 @@
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+
};

widget/controllers/widget.home.controller.js

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,20 @@
99
$rootScope.deviceHeight = window.innerHeight;
1010
$rootScope.deviceWidth = window.innerWidth || 320;
1111

12-
const _path = $location.path();
13-
14-
const handleBookmarkNav = () => {
15-
const reg = /^\/item\/goto/;
16-
17-
if (reg.test(_path)) {
18-
let targetLink = _path.slice([_path.lastIndexOf('/goto/') + 6]);
19-
let itemLinks = _items.map(item => item.link);
20-
let index = itemLinks.indexOf(targetLink);
21-
if (index < 0) {
22-
// buildfire.notifications.alert({
23-
// title: "Item not found"
24-
// , message: "The bookmarked item no longer exists."
25-
// , okButton: { text: 'Ok' }
26-
// }, function () {
27-
// buildfire.bookmarks.delete(targetLink, () => console.log('bookmark deleted'));
28-
// });
29-
console.warn('bookmarked item not found.');
30-
} else {
31-
WidgetHome.goToItem(index, _items[index]);
12+
var handleBookmarkNav = function handleBookmarkNav() {
13+
buildfire.deeplink.getData(function(data){
14+
if(data && data.link){
15+
var targetGuid = data.link;
16+
var itemLinks = _items.map(item => item.guid);
17+
var index = itemLinks.indexOf(targetGuid);
18+
if (index < 0) {
19+
console.warn('bookmarked item not found.');
20+
} else {
21+
WidgetHome.goToItem(index, _items[index]);
22+
}
3223
}
33-
}
34-
}
24+
});
25+
};
3526

3627
/**
3728
* Private variables

0 commit comments

Comments
 (0)