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';
|
|
|
|
|
2011-08-16 00:05:07 +04:00
|
|
|
$(document).ready(function() {
|
|
|
|
$('.bookmarks_addBtn').click(function(event){
|
|
|
|
$('.bookmarks_add').slideToggle();
|
|
|
|
});
|
|
|
|
|
2011-09-13 15:08:11 +04:00
|
|
|
$('#bookmark_add_submit').click(addOrEditBookmark);
|
2011-08-16 00:05:07 +04:00
|
|
|
$(window).scroll(updateOnBottom);
|
|
|
|
|
2011-08-23 18:30:29 +04:00
|
|
|
$('#bookmark_add_url').focusout(getMetadata);
|
|
|
|
|
2011-08-16 00:05:07 +04:00
|
|
|
$('.bookmarks_list').empty();
|
|
|
|
getBookmarks();
|
2011-09-06 16:43:03 +04:00
|
|
|
|
2011-08-16 00:05:07 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
function getBookmarks() {
|
|
|
|
if(bookmarks_loading) {
|
|
|
|
//have patience :)
|
|
|
|
return;
|
|
|
|
}
|
2011-08-25 14:55:13 +04:00
|
|
|
|
2011-08-16 00:05:07 +04:00
|
|
|
$.ajax({
|
|
|
|
url: 'ajax/updateList.php',
|
2011-08-25 14:55:13 +04:00
|
|
|
data: 'tag=' + encodeURI($('#bookmarkFilterTag').val()) + '&page=' + bookmarks_page + '&sort=' + bookmarks_sorting,
|
2011-08-16 00:05:07 +04:00
|
|
|
success: function(bookmarks){
|
|
|
|
bookmarks_page += 1;
|
|
|
|
$('.bookmark_link').unbind('click', recordClick);
|
|
|
|
$('.bookmark_delete').unbind('click', delBookmark);
|
2011-09-13 15:08:11 +04:00
|
|
|
$('.bookmark_edit').unbind('click', showBookmark);
|
2011-08-16 00:05:07 +04:00
|
|
|
|
|
|
|
for(var i in bookmarks.data) {
|
|
|
|
updateBookmarksList(bookmarks.data[i]);
|
|
|
|
}
|
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);
|
|
|
|
|
2011-08-16 00:05:07 +04:00
|
|
|
bookmarks_loading = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-08-23 18:30:29 +04:00
|
|
|
function getMetadata() {
|
2011-09-06 16:43:03 +04:00
|
|
|
var url = encodeEntities($('#bookmark_add_url').val());
|
|
|
|
$('.loading_meta').css('display','inline');
|
2011-08-23 18:30:29 +04:00
|
|
|
$.ajax({
|
|
|
|
url: 'ajax/getMeta.php',
|
2011-08-25 15:51:48 +04:00
|
|
|
data: 'url=' + encodeURIComponent(url),
|
2011-08-25 15:23:52 +04:00
|
|
|
success: function(pageinfo){
|
|
|
|
$('#bookmark_add_url').val(pageinfo.data.url);
|
2011-08-23 18:30:29 +04:00
|
|
|
$('#bookmark_add_title').val(pageinfo.data.title);
|
2011-09-06 16:43:03 +04:00
|
|
|
$('.loading_meta').css('display','none');
|
2011-08-23 18:30:29 +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());
|
|
|
|
var taglist = tags.split(' ');
|
2011-08-19 15:48:08 +04:00
|
|
|
var tagshtml = '';
|
|
|
|
for ( var i=0, len=taglist.length; i<len; ++i ){
|
2011-09-13 15:08:11 +04:00
|
|
|
tagshtml += '<a class="bookmark_tag" href="?tag=' + encodeURI(taglist[i]) + '">' + taglist[i] + '</a> ';
|
2011-08-19 15:48:08 +04:00
|
|
|
}
|
2011-09-13 15:08:11 +04:00
|
|
|
|
|
|
|
if (id == 0) {
|
|
|
|
$.ajax({
|
|
|
|
url: 'ajax/addBookmark.php',
|
2011-10-08 15:54:45 +04:00
|
|
|
data: 'url=' + encodeURI(url) + '&title=' + encodeURI(title) + '&tags=' + encodeURI(tags),
|
2011-09-13 15:40:52 +04:00
|
|
|
success: function(response){
|
|
|
|
var bookmark_id = response.data;
|
2011-09-13 15:08:11 +04:00
|
|
|
$('.bookmarks_add').slideToggle();
|
|
|
|
$('.bookmarks_add').children('p').children('.bookmarks_input').val('');
|
|
|
|
$('.bookmarks_list').prepend(
|
2011-09-13 15:40:52 +04:00
|
|
|
'<div class="bookmark_single" data-id="' + bookmark_id + '" >' +
|
2011-10-08 15:54:45 +04:00
|
|
|
'<p class="bookmark_title"><a href="' + url + '" target="_blank" class="bookmark_link">' + title + '</a></p>' +
|
2011-09-13 15:08:11 +04:00
|
|
|
'<p class="bookmark_url">' + url + '</p>' +
|
|
|
|
'<p class="bookmark_tags">' + tagshtml + '</p>' +
|
2011-09-13 15:40:52 +04:00
|
|
|
'<p class="bookmark_actions"><span class="bookmark_delete">Delete</span> <span class="bookmark_edit">Edit</span></p>' +
|
2011-09-13 15:08:11 +04:00
|
|
|
'</div>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$.ajax({
|
|
|
|
url: 'ajax/editBookmark.php',
|
2011-10-08 15:54:45 +04:00
|
|
|
data: 'id=' + id + '&url=' + encodeURI(url) + '&title=' + encodeURI(title) + '&tags=' + encodeURI(tags),
|
2011-09-13 15:08:11 +04:00
|
|
|
success: function(){
|
|
|
|
$('.bookmarks_add').slideToggle();
|
|
|
|
$('.bookmarks_add').children('p').children('.bookmarks_input').val('');
|
2011-09-13 15:40:52 +04:00
|
|
|
$('#bookmark_add_id').val('0');
|
|
|
|
|
2011-09-13 15:08:11 +04:00
|
|
|
var record = $('.bookmark_single[data-id = "' + id + '"]');
|
|
|
|
record.children('.bookmark_url:first').text(url);
|
|
|
|
|
|
|
|
var record_title = record.children('.bookmark_title:first').children('a:first');
|
|
|
|
record_title.attr('href', url);
|
|
|
|
record_title.text(title);
|
|
|
|
|
|
|
|
record.children('.bookmark_tags:first').html(tagshtml);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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({
|
|
|
|
url: 'ajax/delBookmark.php',
|
2011-08-19 15:48:08 +04:00
|
|
|
data: 'url=' + encodeURI($(this).parent().parent().children('.bookmark_url:first').text()),
|
|
|
|
success: function(data){ record.animate({ opacity: 'hide' }, 'fast'); }
|
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());
|
|
|
|
|
|
|
|
if ($('.bookmarks_add').css('display') == 'none') {
|
|
|
|
$('.bookmarks_add').slideToggle();
|
|
|
|
}
|
|
|
|
$('html, body').animate({
|
|
|
|
scrollTop: $('.bookmarks_menu').offset().top
|
|
|
|
}, 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 ){
|
2011-09-13 15:08:11 +04:00
|
|
|
taglist = taglist + '<a class="bookmark_tag" href="?tag=' + encodeURI(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;
|
|
|
|
}
|
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 +'" >' +
|
2011-10-08 15:54:45 +04:00
|
|
|
'<p class="bookmark_title"><a href="' + encodeEntities(bookmark.url) + '" target="_blank" class="bookmark_link">' + encodeEntities(bookmark.title) + '</a></p>' +
|
2011-08-19 15:48:08 +04:00
|
|
|
'<p class="bookmark_url">' + encodeEntities(bookmark.url) + '</p>' +
|
2011-09-13 15:08:11 +04:00
|
|
|
'<p class="bookmark_tags">' + taglist + '</p>' +
|
|
|
|
'<p class="bookmark_actions"><span class="bookmark_delete">Delete</span> <span class="bookmark_edit">Edit</span></p>' +
|
2011-08-19 15:48:08 +04:00
|
|
|
'</div>'
|
2011-08-16 00:05:07 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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',
|
2011-08-19 15:48:08 +04:00
|
|
|
data: 'url=' + encodeURI($(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);
|
|
|
|
}
|