forked from LeonardoCardoso/Link-Preview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink-preview-database.js
executable file
·81 lines (60 loc) · 2.34 KB
/
link-preview-database.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Copyright (c) 2015 Leonardo Cardoso (http://leocardz.com)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* Version: 1.0.0
*/
app.controller('MyControllerDatabase', ['$scope', '$http', '$sce', function ($scope, $http, $sce) {
$scope.databasePosts = [];
$scope.retrieveFromDatabase = function () {
// You must insert in your page a div with the posts retrieved from database. Just like the posts div
// on template html files
var url = 'src/link-preview/php/retrieve.php';
$http({
url: url,
method: "GET",
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data, status, headers, config) {
for (var i = 0; i < data.length; i++) {
data[i].video = data[i].videoIframe !== "";
data[i].showIframe = false;
data[i].textHTML = $sce.trustAsHtml(data[i].text);
data[i].descriptionHTML = $sce.trustAsHtml(data[i].description);
data[i].videoIframeHTML = $sce.trustAsHtml(data[i].videoIframe);
}
$scope.databasePosts = data;
});
};
$scope.deletePosted = function (post, $index) {
$scope.databasePosts.splice($index, 1);
var url = 'src/link-preview/php/delete.php';
var jsonData = angular.toJson({
id: post.id
});
$http({
url: url,
method: "POST",
data: "data=" + jsonData,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data, status, headers, config) {
});
};
$scope.imageAction = function (post) {
if (post.video == false) {
window.open(post.pageUrl, '_blank');
} else {
post.showIframe = true;
}
};
$scope.hidePlay = function (post) {
return post.video == false || post.showIframe == true;
};
$scope.layoutWithoutImage = function (post) {
return post.image == '' || post.showIframe == true;
};
$scope.layoutWithImage = function (post) {
return post.image != '' || (post.video == true && post.showIframe == false);
};
$scope.retrieveFromDatabase();
}]);