summaryrefslogtreecommitdiffstats
path: root/apps/bookmarks/js
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2011-08-15 22:05:07 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2011-08-15 22:05:07 +0200
commit5608aaee8a8bbf913f4abb665f18fbe510da7214 (patch)
treef704a1657117af202001ddcc71a9d3ad0df338ad /apps/bookmarks/js
parent523b0966d22d0fc149ca64afb32995a0eb29a6d3 (diff)
downloadnextcloud-server-5608aaee8a8bbf913f4abb665f18fbe510da7214.tar.gz
nextcloud-server-5608aaee8a8bbf913f4abb665f18fbe510da7214.zip
initial commit of Bookmarks App
Diffstat (limited to 'apps/bookmarks/js')
-rw-r--r--apps/bookmarks/js/bookmarks.js94
1 files changed, 94 insertions, 0 deletions
diff --git a/apps/bookmarks/js/bookmarks.js b/apps/bookmarks/js/bookmarks.js
new file mode 100644
index 00000000000..7624ff5d394
--- /dev/null
+++ b/apps/bookmarks/js/bookmarks.js
@@ -0,0 +1,94 @@
+var bookmarks_page = 0;
+var bookmarks_loading = false;
+
+$(document).ready(function() {
+ $('.bookmarks_addBtn').click(function(event){
+ $('.bookmarks_add').slideToggle();
+ });
+
+ $('#bookmark_add_submit').click(addBookmark);
+ $(window).scroll(updateOnBottom);
+
+ $('.bookmarks_list').empty();
+ getBookmarks();
+});
+
+function getBookmarks() {
+ if(bookmarks_loading) {
+ //have patience :)
+ return;
+ }
+ $.ajax({
+ url: 'ajax/updateList.php',
+ data: "tag=" + encodeURI($('#bookmarkFilterTag').val()) + "&page=" + bookmarks_page,
+ success: function(bookmarks){
+ bookmarks_page += 1;
+ $('.bookmark_link').unbind('click', recordClick);
+ $('.bookmark_delete').unbind('click', delBookmark);
+
+ for(var i in bookmarks.data) {
+ updateBookmarksList(bookmarks.data[i]);
+ }
+ $('.bookmark_link').click(recordClick);
+ $('.bookmark_delete').click(delBookmark);
+ bookmarks_loading = false;
+ }
+ });
+}
+
+function addBookmark(event) {
+ $.ajax({
+ url: 'ajax/addBookmark.php',
+ data: "url=" + encodeURI($('#bookmark_add_url').val()) + "&title=" + encodeURI($('#bookmark_add_title').val()) + "&description=" + encodeURI($('#bookmark_add_description').val()) + "&tags=" + encodeURI($('#bookmark_add_tags').val()),
+ success: function(data){ $('.bookmarks_add').slideToggle(); $('.bookmarks_add').children('p').children('.bookmarks_input').val(''); }
+ });
+}
+
+function delBookmark(event) {
+ $.ajax({
+ url: 'ajax/delBookmark.php',
+ data: "url=" + encodeURI($(this).parent().parent().children('.bookmark_url:first').text()),
+ success: function(data){ alert('deleted!'); }
+ });
+}
+
+function updateBookmarksList(bookmark) {
+ var tags = encodeEntities(bookmark.tags).split(" ");
+ var taglist = "";
+ for ( var i=0, len=tags.length; i<len; ++i ){
+ taglist = taglist + "<a class=\"bookmark_tags\" href=\"?tag=" + encodeURI(tags[i]) + "\">" + tags[i] + "</a> ";
+ }
+ $('.bookmarks_list').append(
+ "<div class=\"bookmark_single\">" +
+ "<p class=\"bookmark_title\"><a href=\"" + encodeEntities(bookmark.url) + "\" target=\"_new\" class=\"bookmark_link\">" + encodeEntities(bookmark.title) + "</a></p>" +
+ "<p class=\"bookmark_url\">" + encodeEntities(bookmark.url) + "</p>" +
+ "<p class=\"bookmark_description\">" + encodeEntities(bookmark.description) + "</p>" +
+ "<p>" + taglist + "</p>" +
+ "<p class=\"bookmark_actions\"><span class=\"bookmark_delete\">Delete</span></p>" +
+ "</div>"
+ );
+}
+
+function updateOnBottom() {
+ //check wether user is on bottom of the page
+ if ($('body').height() <= ($(window).height() + $(window).scrollTop())) {
+ getBookmarks();
+ }
+}
+
+function recordClick(event) {
+ $.ajax({
+ url: 'ajax/recordClick.php',
+ data: "url=" + encodeURI($(this).attr('href')),
+ });
+ return false;
+}
+
+function encodeEntities(s){
+ try {
+ return $("<div/>").text(s).html();
+
+ } catch (ex) {
+ return "";
+ }
+}