2011-08-16 00:05:07 +04:00
|
|
|
var bookmarks_page = 0;
|
|
|
|
var bookmarks_loading = false;
|
|
|
|
|
2011-08-25 14:55:13 +04:00
|
|
|
var bookmarks_sorting = 'bookmarks_sorting_recent';
|
|
|
|
|
2012-04-15 17:53:30 +04:00
|
|
|
$(document).ready(function() {
|
2011-09-13 15:08:11 +04:00
|
|
|
$('#bookmark_add_submit').click(addOrEditBookmark);
|
2012-03-01 23:46:34 +04:00
|
|
|
$(window).resize(function () {
|
|
|
|
fillWindow($('.bookmarks_list'));
|
|
|
|
});
|
|
|
|
$(window).resize();
|
2012-03-24 22:54:54 +04:00
|
|
|
$('.bookmarks_list').scroll(updateOnBottom).empty().width($('#content').width());
|
2011-08-16 00:05:07 +04:00
|
|
|
getBookmarks();
|
|
|
|
});
|
|
|
|
|
|
|
|
function getBookmarks() {
|
|
|
|
if(bookmarks_loading) {
|
|
|
|
//have patience :)
|
|
|
|
return;
|
|
|
|
}
|
2012-04-15 17:53:30 +04:00
|
|
|
|
2011-08-16 00:05:07 +04:00
|
|
|
$.ajax({
|
2012-04-25 23:20:06 +04:00
|
|
|
url: OC.filePath('bookmarks', 'ajax', 'updateList.php'),
|
2012-04-15 17:53:30 +04:00
|
|
|
data: 'tag=' + encodeURIComponent($('#bookmarkFilterTag').val()) + '&page=' + bookmarks_page + '&sort=' + bookmarks_sorting,
|
2011-08-16 00:05:07 +04:00
|
|
|
success: function(bookmarks){
|
2012-03-01 23:46:34 +04:00
|
|
|
if (bookmarks.data.length) {
|
|
|
|
bookmarks_page += 1;
|
|
|
|
}
|
2011-08-16 00:05:07 +04:00
|
|
|
$('.bookmark_link').unbind('click', recordClick);
|
|
|
|
$('.bookmark_delete').unbind('click', delBookmark);
|
2011-09-13 15:08:11 +04:00
|
|
|
$('.bookmark_edit').unbind('click', showBookmark);
|
2012-04-15 17:53:30 +04:00
|
|
|
|
2011-08-16 00:05:07 +04:00
|
|
|
for(var i in bookmarks.data) {
|
|
|
|
updateBookmarksList(bookmarks.data[i]);
|
2012-02-22 01:31:35 +04:00
|
|
|
$("#firstrun").hide();
|
2011-08-16 00:05:07 +04:00
|
|
|
}
|
2012-02-23 02:58:38 +04:00
|
|
|
if($('.bookmarks_list').is(':empty')) {
|
|
|
|
$("#firstrun").show();
|
|
|
|
}
|
2011-10-08 15:54:45 +04:00
|
|
|
|
2011-08-16 00:05:07 +04:00
|
|
|
$('.bookmark_link').click(recordClick);
|
|
|
|
$('.bookmark_delete').click(delBookmark);
|
2011-09-13 15:08:11 +04:00
|
|
|
$('.bookmark_edit').click(showBookmark);
|
2012-04-15 17:53:30 +04:00
|
|
|
|
2011-08-16 00:05:07 +04:00
|
|
|
bookmarks_loading = false;
|
2012-03-01 23:46:34 +04:00
|
|
|
if (bookmarks.data.length) {
|
|
|
|
updateOnBottom()
|
|
|
|
}
|
2011-08-16 00:05:07 +04:00
|
|
|
}
|
2012-04-15 17:53:30 +04:00
|
|
|
});
|
2011-08-16 00:05:07 +04:00
|
|
|
}
|
|
|
|
|
2011-09-13 15:08:11 +04:00
|
|
|
// function addBookmark() {
|
|
|
|
// Instead of creating editBookmark() function, Converted the one above to
|
|
|
|
// addOrEditBookmark() to make .js file more compact.
|
|
|
|
|
|
|
|
function addOrEditBookmark(event) {
|
|
|
|
var id = $('#bookmark_add_id').val();
|
2011-10-08 15:54:45 +04:00
|
|
|
var url = encodeEntities($('#bookmark_add_url').val());
|
|
|
|
var title = encodeEntities($('#bookmark_add_title').val());
|
|
|
|
var tags = encodeEntities($('#bookmark_add_tags').val());
|
2012-02-22 01:31:35 +04:00
|
|
|
$("#firstrun").hide();
|
2012-04-15 17:53:30 +04:00
|
|
|
|
2011-09-13 15:08:11 +04:00
|
|
|
if (id == 0) {
|
|
|
|
$.ajax({
|
2012-04-25 23:20:06 +04:00
|
|
|
url: OC.filePath('bookmarks', 'ajax', 'addBookmark.php'),
|
2012-04-15 17:53:30 +04:00
|
|
|
data: 'url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title) + '&tags=' + encodeURIComponent(tags),
|
|
|
|
success: function(response){
|
|
|
|
$('.bookmarks_input').val('');
|
2012-02-22 19:04:17 +04:00
|
|
|
$('.bookmarks_list').empty();
|
|
|
|
bookmarks_page = 0;
|
|
|
|
getBookmarks();
|
2011-09-13 15:08:11 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$.ajax({
|
2012-04-25 23:20:06 +04:00
|
|
|
url: OC.filePath('bookmarks', 'ajax', 'editBookmark.php'),
|
2012-04-15 17:53:30 +04:00
|
|
|
data: 'id=' + id + '&url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title) + '&tags=' + encodeURIComponent(tags),
|
|
|
|
success: function(){
|
2012-02-23 02:22:17 +04:00
|
|
|
$('.bookmarks_input').val('');
|
2011-09-13 15:40:52 +04:00
|
|
|
$('#bookmark_add_id').val('0');
|
2012-02-22 19:04:17 +04:00
|
|
|
$('.bookmarks_list').empty();
|
|
|
|
bookmarks_page = 0;
|
|
|
|
getBookmarks();
|
2011-09-13 15:08:11 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-04-15 17:53:30 +04:00
|
|
|
|
2011-08-16 00:05:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function delBookmark(event) {
|
2011-10-08 15:54:45 +04:00
|
|
|
var record = $(this).parent().parent();
|
2011-08-16 00:05:07 +04:00
|
|
|
$.ajax({
|
2012-04-25 23:20:06 +04:00
|
|
|
url: OC.filePath('bookmarks', 'ajax', 'delBookmark.php'),
|
2012-05-03 19:29:08 +04:00
|
|
|
data: 'id=' + record.data('id'),
|
2012-02-23 02:28:36 +04:00
|
|
|
success: function(data){
|
2012-05-03 19:29:08 +04:00
|
|
|
if (data.status == 'success') {
|
|
|
|
record.remove();
|
|
|
|
if($('.bookmarks_list').is(':empty')) {
|
|
|
|
$("#firstrun").show();
|
|
|
|
}
|
2012-02-23 02:28:36 +04:00
|
|
|
}
|
|
|
|
}
|
2011-08-16 00:05:07 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-09-13 15:08:11 +04:00
|
|
|
function showBookmark(event) {
|
|
|
|
var record = $(this).parent().parent();
|
|
|
|
$('#bookmark_add_id').val(record.attr('data-id'));
|
|
|
|
$('#bookmark_add_url').val(record.children('.bookmark_url:first').text());
|
|
|
|
$('#bookmark_add_title').val(record.children('.bookmark_title:first').text());
|
|
|
|
$('#bookmark_add_tags').val(record.children('.bookmark_tags:first').text());
|
2012-04-15 17:53:30 +04:00
|
|
|
|
2011-09-13 15:08:11 +04:00
|
|
|
if ($('.bookmarks_add').css('display') == 'none') {
|
|
|
|
$('.bookmarks_add').slideToggle();
|
|
|
|
}
|
|
|
|
$('html, body').animate({
|
2012-02-04 00:37:09 +04:00
|
|
|
scrollTop: ($('.bookmarks_menu'))?$('.bookmarks_menu').offset().top:0
|
2011-09-13 15:08:11 +04:00
|
|
|
}, 500);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-08-16 00:05:07 +04:00
|
|
|
function updateBookmarksList(bookmark) {
|
2011-08-19 15:48:08 +04:00
|
|
|
var tags = encodeEntities(bookmark.tags).split(' ');
|
|
|
|
var taglist = '';
|
2011-08-16 00:05:07 +04:00
|
|
|
for ( var i=0, len=tags.length; i<len; ++i ){
|
2012-02-02 01:02:06 +04:00
|
|
|
if(tags[i] != '')
|
2012-04-15 17:53:30 +04:00
|
|
|
taglist = taglist + '<a class="bookmark_tag" href="?tag=' + encodeURIComponent(tags[i]) + '">' + tags[i] + '</a> ';
|
2011-08-16 00:05:07 +04:00
|
|
|
}
|
2011-08-25 15:23:52 +04:00
|
|
|
if(!hasProtocol(bookmark.url)) {
|
|
|
|
bookmark.url = 'http://' + bookmark.url;
|
|
|
|
}
|
2012-02-22 19:04:17 +04:00
|
|
|
if(bookmark.title == '') bookmark.title = bookmark.url;
|
2011-08-16 00:05:07 +04:00
|
|
|
$('.bookmarks_list').append(
|
2011-09-13 15:08:11 +04:00
|
|
|
'<div class="bookmark_single" data-id="' + bookmark.id +'" >' +
|
2012-02-17 00:01:13 +04:00
|
|
|
'<p class="bookmark_actions">' +
|
|
|
|
'<span class="bookmark_edit">' +
|
|
|
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/rename')+'" title="Edit">' +
|
|
|
|
'</span>' +
|
2012-02-23 23:35:48 +04:00
|
|
|
'<span class="bookmark_delete">' +
|
|
|
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/delete')+'" title="Delete">' +
|
|
|
|
'</span> ' +
|
2012-02-17 00:01:13 +04:00
|
|
|
'</p>' +
|
|
|
|
'<p class="bookmark_title">'+
|
|
|
|
'<a href="' + encodeEntities(bookmark.url) + '" target="_blank" class="bookmark_link">' + encodeEntities(bookmark.title) + '</a>' +
|
|
|
|
'</p>' +
|
2012-03-23 19:58:48 +04:00
|
|
|
'<p class="bookmark_url"><a href="' + encodeEntities(bookmark.url) + '" target="_blank" class="bookmark_link">' + encodeEntities(bookmark.url) + '</a></p>' +
|
2011-08-19 15:48:08 +04:00
|
|
|
'</div>'
|
2011-08-16 00:05:07 +04:00
|
|
|
);
|
2012-02-02 01:02:06 +04:00
|
|
|
if(taglist != '') {
|
|
|
|
$('div[data-id="'+ bookmark.id +'"]').append('<p class="bookmark_tags">' + taglist + '</p>');
|
|
|
|
}
|
2011-08-16 00:05:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateOnBottom() {
|
|
|
|
//check wether user is on bottom of the page
|
2012-03-01 23:46:34 +04:00
|
|
|
var top = $('.bookmarks_list>:last-child').position().top;
|
|
|
|
var height = $('.bookmarks_list').height();
|
|
|
|
// use a bit of margin to begin loading before we are really at the
|
|
|
|
// bottom
|
|
|
|
if (top < height * 1.2) {
|
2011-08-16 00:05:07 +04:00
|
|
|
getBookmarks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function recordClick(event) {
|
|
|
|
$.ajax({
|
2012-04-25 23:20:06 +04:00
|
|
|
url: OC.filePath('bookmarks', 'ajax', 'recordClick.php'),
|
2012-04-15 17:53:30 +04:00
|
|
|
data: 'url=' + encodeURIComponent($(this).attr('href')),
|
|
|
|
});
|
2011-08-16 00:05:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function encodeEntities(s){
|
|
|
|
try {
|
2011-08-19 15:48:08 +04:00
|
|
|
return $('<div/>').text(s).html();
|
2011-08-16 00:05:07 +04:00
|
|
|
} catch (ex) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2011-08-25 15:23:52 +04:00
|
|
|
|
|
|
|
function hasProtocol(url) {
|
|
|
|
var regexp = /(ftp|http|https|sftp)/;
|
|
|
|
return regexp.test(url);
|
|
|
|
}
|