2011-08-15 22:05:07 +02:00
|
|
|
var bookmarks_page = 0;
|
|
|
|
var bookmarks_loading = false;
|
|
|
|
|
2011-08-25 12:55:13 +02:00
|
|
|
var bookmarks_sorting = 'bookmarks_sorting_recent';
|
|
|
|
|
2012-07-02 00:12:59 +02:00
|
|
|
var bookmark_view = 'image';
|
|
|
|
|
2012-04-15 15:53:30 +02:00
|
|
|
$(document).ready(function() {
|
2012-07-03 14:14:30 +02:00
|
|
|
$('.centercontent').click(clickSideBar);
|
|
|
|
$('#view_type input').click(clickSwitchView);
|
2012-06-29 14:12:29 +02:00
|
|
|
$('#bookmark_add_submit').click(addBookmark);
|
2012-03-01 20:46:34 +01:00
|
|
|
$(window).resize(function () {
|
|
|
|
fillWindow($('.bookmarks_list'));
|
|
|
|
});
|
|
|
|
$(window).resize();
|
2012-06-27 16:32:04 +02:00
|
|
|
$('.bookmarks_list').scroll(updateOnBottom).empty().width($('#rightcontent').width());
|
2012-06-28 11:40:42 +02:00
|
|
|
$('#tag_filter input').tagit({
|
|
|
|
allowSpaces: true,
|
|
|
|
availableTags: fullTags,
|
|
|
|
onTagRemoved: filterTagsChanged
|
|
|
|
}).tagit('option', 'onTagAdded', filterTagsChanged);
|
2011-08-15 22:05:07 +02:00
|
|
|
getBookmarks();
|
2012-07-03 14:14:30 +02:00
|
|
|
|
|
|
|
if(init_sidebar == 'true')
|
|
|
|
toggleSideBar();
|
|
|
|
bookmark_view = init_view;
|
|
|
|
switchView();
|
2011-08-15 22:05:07 +02:00
|
|
|
});
|
2012-07-03 14:14:30 +02:00
|
|
|
|
|
|
|
function clickSideBar() {
|
|
|
|
$.post(OC.filePath('bookmarks', 'ajax', 'changescreen.php'), {sidebar: $('#leftcontent').is(':visible')});
|
|
|
|
toggleSideBar();
|
|
|
|
}
|
|
|
|
|
2012-07-03 13:47:09 +02:00
|
|
|
function toggleSideBar(){
|
|
|
|
if($('#leftcontent:visible')) {
|
|
|
|
$('#rightcontent').css('left','32.5em');
|
|
|
|
$('.right_img').hide();
|
|
|
|
$('.left_img').show();
|
|
|
|
|
|
|
|
}
|
|
|
|
$('#leftcontent').animate({width: 'toggle' },'normal', function() {
|
|
|
|
if(! $('#leftcontent').is(':visible')) {
|
|
|
|
$('#rightcontent').css('left','auto');
|
|
|
|
$('.left_img').hide();
|
|
|
|
$('.right_img').show();
|
|
|
|
}
|
|
|
|
$(window).trigger('resize');
|
|
|
|
});
|
2012-07-03 14:14:30 +02:00
|
|
|
}
|
2012-06-28 11:40:42 +02:00
|
|
|
|
2012-07-03 14:14:30 +02:00
|
|
|
function clickSwitchView(){
|
|
|
|
$.post(OC.filePath('bookmarks', 'ajax', 'changescreen.php'), {view:bookmark_view});
|
|
|
|
switchView();
|
2012-07-03 13:47:09 +02:00
|
|
|
}
|
2012-07-03 14:14:30 +02:00
|
|
|
|
2012-07-02 00:12:59 +02:00
|
|
|
function switchView(){
|
2012-07-02 09:41:48 +02:00
|
|
|
if(bookmark_view == 'list') { //Then switch to img
|
2012-07-02 00:12:59 +02:00
|
|
|
$('.bookmarks_list').addClass('bm_view_img');
|
|
|
|
$('.bookmarks_list').removeClass('bm_view_list');
|
2012-07-02 09:41:48 +02:00
|
|
|
$('#view_type input.image').hide();
|
|
|
|
$('#view_type input.list').show();
|
2012-07-02 00:12:59 +02:00
|
|
|
bookmark_view = 'image';
|
2012-07-02 09:41:48 +02:00
|
|
|
} else { // Then Image
|
|
|
|
$('.bookmarks_list').addClass('bm_view_list');
|
|
|
|
$('.bookmarks_list').removeClass('bm_view_img');
|
|
|
|
$('#view_type input.list').hide();
|
|
|
|
$('#view_type input.image').show();
|
|
|
|
bookmark_view = 'list';
|
2012-07-02 00:12:59 +02:00
|
|
|
}
|
|
|
|
filterTagsChanged(); //Refresh the view
|
|
|
|
}
|
2012-06-29 14:12:29 +02:00
|
|
|
function addFilterTag(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
$('#tag_filter input').tagit('createTag', $(this).text());
|
2012-06-28 11:40:42 +02:00
|
|
|
}
|
|
|
|
|
2012-06-28 00:43:11 +02:00
|
|
|
function updateTagsList(tag) {
|
|
|
|
$('.tag_list').append('<li><a href="" class="tag">'+tag['tag']+'</a>'+
|
|
|
|
'<p class="tags_actions">'+
|
2012-06-29 15:50:19 +02:00
|
|
|
'<span class="tag_edit">'+
|
2012-06-28 00:43:11 +02:00
|
|
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/rename')+'" title="Edit">'+
|
|
|
|
'</span>'+
|
2012-06-29 15:50:19 +02:00
|
|
|
'<span class="tag_delete">'+
|
2012-06-28 00:43:11 +02:00
|
|
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/delete')+'" title="Delete">'+
|
|
|
|
'</span>'+
|
|
|
|
'</p>'+
|
|
|
|
'<em>'+tag['nbr']+'</em>'+
|
|
|
|
'</li>');
|
2012-06-29 15:50:19 +02:00
|
|
|
|
2012-06-28 00:43:11 +02:00
|
|
|
}
|
2012-06-28 11:40:42 +02:00
|
|
|
|
|
|
|
function filterTagsChanged()
|
|
|
|
{
|
|
|
|
$('#bookmarkFilterTag').val($('#tag_filter input:hidden').val());
|
|
|
|
$('.bookmarks_list').empty();
|
2012-07-02 15:24:26 +02:00
|
|
|
bookmarks_page = 0;
|
2012-06-28 11:40:42 +02:00
|
|
|
getBookmarks();
|
|
|
|
}
|
2011-08-15 22:05:07 +02:00
|
|
|
function getBookmarks() {
|
|
|
|
if(bookmarks_loading) {
|
|
|
|
//have patience :)
|
|
|
|
return;
|
2012-07-02 15:24:26 +02:00
|
|
|
}
|
|
|
|
bookmarks_loading = true;
|
2012-07-02 15:49:20 +02:00
|
|
|
//Update Rel Tags if first page
|
|
|
|
if(bookmarks_page == 0) {
|
2012-06-29 15:50:19 +02:00
|
|
|
|
2012-07-02 15:49:20 +02:00
|
|
|
$.ajax({
|
|
|
|
type: 'GET',
|
|
|
|
url: OC.filePath('bookmarks', 'ajax', 'updateList.php') + '&type=rel_tags',
|
|
|
|
data: {tag: $('#bookmarkFilterTag').val(), page:bookmarks_page, sort:bookmarks_sorting },
|
|
|
|
success: function(tags){
|
|
|
|
$('.tag_list').empty();
|
|
|
|
for(var i in tags.data) {
|
|
|
|
updateTagsList(tags.data[i]);
|
|
|
|
}
|
|
|
|
$('.tag_list .tag_edit').click(renameTag);
|
|
|
|
$('.tag_list .tag_delete').click(deleteTag);
|
|
|
|
$('.tag_list a.tag').click(addFilterTag);
|
2012-06-29 15:50:19 +02:00
|
|
|
|
2012-07-02 15:49:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2011-08-15 22:05:07 +02:00
|
|
|
$.ajax({
|
2012-07-02 15:24:26 +02:00
|
|
|
type: 'GET',
|
2012-06-28 00:43:11 +02:00
|
|
|
url: OC.filePath('bookmarks', 'ajax', 'updateList.php') + '&type=bookmark',
|
|
|
|
data: {tag: $('#bookmarkFilterTag').val(), page:bookmarks_page, sort:bookmarks_sorting },
|
2011-08-15 22:05:07 +02:00
|
|
|
success: function(bookmarks){
|
2012-03-01 20:46:34 +01:00
|
|
|
if (bookmarks.data.length) {
|
|
|
|
bookmarks_page += 1;
|
|
|
|
}
|
2011-08-15 22:05:07 +02:00
|
|
|
$('.bookmark_link').unbind('click', recordClick);
|
|
|
|
$('.bookmark_delete').unbind('click', delBookmark);
|
2012-06-29 14:12:29 +02:00
|
|
|
$('.bookmark_edit').unbind('click', editBookmark);
|
2012-04-15 15:53:30 +02:00
|
|
|
|
2011-08-15 22:05:07 +02:00
|
|
|
for(var i in bookmarks.data) {
|
|
|
|
updateBookmarksList(bookmarks.data[i]);
|
2012-02-21 22:31:35 +01:00
|
|
|
$("#firstrun").hide();
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
2012-02-22 23:58:38 +01:00
|
|
|
if($('.bookmarks_list').is(':empty')) {
|
|
|
|
$("#firstrun").show();
|
|
|
|
}
|
2011-10-08 13:54:45 +02:00
|
|
|
|
2011-08-15 22:05:07 +02:00
|
|
|
$('.bookmark_link').click(recordClick);
|
|
|
|
$('.bookmark_delete').click(delBookmark);
|
2012-06-29 14:12:29 +02:00
|
|
|
$('.bookmark_edit').click(editBookmark);
|
2012-04-15 15:53:30 +02:00
|
|
|
|
2011-08-15 22:05:07 +02:00
|
|
|
bookmarks_loading = false;
|
2012-03-01 20:46:34 +01:00
|
|
|
if (bookmarks.data.length) {
|
|
|
|
updateOnBottom()
|
|
|
|
}
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
2012-04-15 15:53:30 +02:00
|
|
|
});
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
|
|
|
|
2011-09-13 13:08:11 +02:00
|
|
|
|
2012-06-29 14:12:29 +02:00
|
|
|
function createEditDialog(record){
|
2012-06-29 11:33:13 +02:00
|
|
|
dialog_html = $('#edit_dialog').html();
|
|
|
|
var dialog = $(dialog_html).dialog({
|
|
|
|
width : 620,
|
|
|
|
height: 450,
|
|
|
|
title: t('bookmark', 'Edit bookmark'),
|
|
|
|
modal: true,
|
|
|
|
close : function(event, ui) {
|
|
|
|
$(this).dialog('destroy').remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.ui-dialog').bookmark_dialog({
|
2012-06-29 14:12:29 +02:00
|
|
|
on_success: function(){
|
2012-06-29 11:33:13 +02:00
|
|
|
dialog.dialog('destroy').remove();
|
|
|
|
filterTagsChanged();
|
2012-06-29 14:12:29 +02:00
|
|
|
},
|
|
|
|
record: record
|
2012-06-29 11:33:13 +02:00
|
|
|
});
|
2012-06-29 14:12:29 +02:00
|
|
|
}
|
2012-06-29 11:33:13 +02:00
|
|
|
|
2012-06-29 14:12:29 +02:00
|
|
|
function addBookmark(event) {
|
|
|
|
createEditDialog();
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function delBookmark(event) {
|
2011-10-08 13:54:45 +02:00
|
|
|
var record = $(this).parent().parent();
|
2011-08-15 22:05:07 +02:00
|
|
|
$.ajax({
|
2012-06-10 23:38:26 +02:00
|
|
|
type: 'POST',
|
2012-04-25 21:20:06 +02:00
|
|
|
url: OC.filePath('bookmarks', 'ajax', 'delBookmark.php'),
|
2012-05-03 17:29:08 +02:00
|
|
|
data: 'id=' + record.data('id'),
|
2012-02-22 23:28:36 +01:00
|
|
|
success: function(data){
|
2012-05-03 17:29:08 +02:00
|
|
|
if (data.status == 'success') {
|
|
|
|
record.remove();
|
|
|
|
if($('.bookmarks_list').is(':empty')) {
|
|
|
|
$("#firstrun").show();
|
|
|
|
}
|
2012-02-22 23:28:36 +01:00
|
|
|
}
|
|
|
|
}
|
2011-08-15 22:05:07 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-06-29 14:12:29 +02:00
|
|
|
function editBookmark(event) {
|
2011-09-13 13:08:11 +02:00
|
|
|
var record = $(this).parent().parent();
|
2012-06-29 14:12:29 +02:00
|
|
|
bookmark = record.data('record');
|
|
|
|
createEditDialog(bookmark);
|
2011-09-13 13:08:11 +02:00
|
|
|
}
|
2012-05-14 03:10:07 +02:00
|
|
|
|
2011-08-15 22:05:07 +02:00
|
|
|
function updateBookmarksList(bookmark) {
|
2012-06-27 14:14:45 +02:00
|
|
|
var tags = bookmark.tags;
|
2011-08-19 13:48:08 +02:00
|
|
|
var taglist = '';
|
2011-08-15 22:05:07 +02:00
|
|
|
for ( var i=0, len=tags.length; i<len; ++i ){
|
2012-02-01 22:02:06 +01:00
|
|
|
if(tags[i] != '')
|
2012-06-29 14:36:37 +02:00
|
|
|
taglist = taglist + '<a class="bookmark_tag" href="#">' + encodeEntities(tags[i]) + '</a> ';
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
2011-08-25 13:23:52 +02:00
|
|
|
if(!hasProtocol(bookmark.url)) {
|
|
|
|
bookmark.url = 'http://' + bookmark.url;
|
|
|
|
}
|
2012-02-22 16:04:17 +01:00
|
|
|
if(bookmark.title == '') bookmark.title = bookmark.url;
|
2012-07-02 00:12:59 +02:00
|
|
|
|
|
|
|
if(bookmark_view == 'image') { //View in images
|
|
|
|
$('.bookmarks_list').append(
|
|
|
|
'<div class="bookmark_single" data-id="' + bookmark.id +'" >' +
|
|
|
|
'<p class="shot"><img src="'+ "http://screenshots.bookmarkly.com/thumb?url="+encodeEntities(bookmark.url) +'"></p>'+
|
|
|
|
'<p class="bookmark_actions">' +
|
|
|
|
'<span class="bookmark_edit">' +
|
|
|
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/rename')+'" title="Edit">' +
|
|
|
|
'</span>' +
|
|
|
|
'<span class="bookmark_delete">' +
|
|
|
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/delete')+'" title="Delete">' +
|
|
|
|
'</span> ' +
|
|
|
|
'</p>' +
|
|
|
|
'<p class="bookmark_title">'+
|
|
|
|
'<a href="' + encodeEntities(bookmark.url) + '" target="_blank" class="bookmark_link">' + encodeEntities(bookmark.title) + '</a>' +
|
|
|
|
'</p>' +
|
2012-07-02 15:24:26 +02:00
|
|
|
'<p class="bookmark_desc">'+ encodeEntities(bookmark.description) + '</p>' +
|
2012-07-02 00:12:59 +02:00
|
|
|
'<p class="bookmark_url"><a href="' + encodeEntities(bookmark.url) + '" target="_blank" class="bookmark_link">' + encodeEntities(bookmark.url) + '</a></p>' +
|
|
|
|
'</div>'
|
|
|
|
);
|
|
|
|
$('div[data-id="'+ bookmark.id +'"]').data('record', bookmark);
|
|
|
|
if(taglist != '') {
|
|
|
|
$('div[data-id="'+ bookmark.id +'"]').append('<p class="bookmark_tags">' + taglist + '</p>');
|
|
|
|
}
|
|
|
|
$('div[data-id="'+ bookmark.id +'"] a.bookmark_tag').bind('click', addFilterTag);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('.bookmarks_list').append(
|
|
|
|
'<div class="bookmark_single" data-id="' + bookmark.id +'" >' +
|
|
|
|
'<p class="bookmark_actions">' +
|
|
|
|
'<span class="bookmark_edit">' +
|
|
|
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/rename')+'" title="Edit">' +
|
|
|
|
'</span>' +
|
|
|
|
'<span class="bookmark_delete">' +
|
|
|
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/delete')+'" title="Delete">' +
|
|
|
|
'</span> ' +
|
|
|
|
'</p>' +
|
|
|
|
'<p class="bookmark_title">'+
|
|
|
|
'<a href="' + encodeEntities(bookmark.url) + '" target="_blank" class="bookmark_link">' + encodeEntities(bookmark.title) + '</a>' +
|
|
|
|
'</p>' +
|
|
|
|
'<p class="bookmark_url"><a href="' + encodeEntities(bookmark.url) + '" target="_blank" class="bookmark_link">' + encodeEntities(bookmark.url) + '</a></p>' +
|
2012-07-02 15:24:26 +02:00
|
|
|
'<p class="bookmark_desc">'+ encodeEntities(bookmark.description) + '</p>' +
|
2012-07-02 00:12:59 +02:00
|
|
|
'</div>'
|
|
|
|
);
|
|
|
|
$('div[data-id="'+ bookmark.id +'"]').data('record', bookmark);
|
|
|
|
if(taglist != '') {
|
|
|
|
$('div[data-id="'+ bookmark.id +'"]').append('<p class="bookmark_tags">' + taglist + '</p>');
|
|
|
|
}
|
|
|
|
$('div[data-id="'+ bookmark.id +'"] a.bookmark_tag').bind('click', addFilterTag);
|
2012-02-01 22:02:06 +01:00
|
|
|
}
|
2012-06-29 14:36:37 +02:00
|
|
|
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateOnBottom() {
|
|
|
|
//check wether user is on bottom of the page
|
2012-03-01 20:46:34 +01: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) {
|
2012-07-01 23:08:41 +02:00
|
|
|
getBookmarks();
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function recordClick(event) {
|
|
|
|
$.ajax({
|
2012-06-10 23:38:26 +02:00
|
|
|
type: 'POST',
|
2012-04-25 21:20:06 +02:00
|
|
|
url: OC.filePath('bookmarks', 'ajax', 'recordClick.php'),
|
2012-04-15 15:53:30 +02:00
|
|
|
data: 'url=' + encodeURIComponent($(this).attr('href')),
|
|
|
|
});
|
2011-08-15 22:05:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function encodeEntities(s){
|
|
|
|
try {
|
2011-08-19 13:48:08 +02:00
|
|
|
return $('<div/>').text(s).html();
|
2011-08-15 22:05:07 +02:00
|
|
|
} catch (ex) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2011-08-25 13:23:52 +02:00
|
|
|
|
|
|
|
function hasProtocol(url) {
|
|
|
|
var regexp = /(ftp|http|https|sftp)/;
|
|
|
|
return regexp.test(url);
|
|
|
|
}
|
2012-06-29 15:50:19 +02:00
|
|
|
|
|
|
|
function renameTag(event) {
|
|
|
|
tag_el = $(this).closest('li');
|
|
|
|
tag_el.append('<input name="tag_new_name" type="text">');
|
|
|
|
|
|
|
|
tag_name = tag_el.find('.tag').hide().text();
|
|
|
|
tag_el.find('input').val(tag_name).bind('blur',submitTagName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function submitTagName(event) {
|
|
|
|
tag_el = $(this).closest('li')
|
|
|
|
new_tag_name = tag_el.find('input').val();
|
|
|
|
old_tag_name = tag_el.find('.tag').show().text();
|
|
|
|
tag_el.find('input').remove();
|
|
|
|
|
|
|
|
//submit
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: OC.filePath('bookmarks', 'ajax', 'renameTag.php'),
|
|
|
|
data: { old_name: old_tag_name, new_name: new_tag_name},
|
|
|
|
success: function(bookmarks){
|
|
|
|
if (bookmarks.status =='success') {
|
|
|
|
filterTagsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteTag(event){
|
|
|
|
tag_el = $(this).closest('li');
|
|
|
|
var old_tag_name = tag_el.find('.tag').show().text();
|
|
|
|
OC.dialogs.confirm(t('bookmarks', 'Are you sure you want to remove this tag fro every entry?'),
|
|
|
|
t('bookmarks', 'Warning'), function(answer) {
|
|
|
|
if(answer) {
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: OC.filePath('bookmarks', 'ajax', 'delTag.php'),
|
|
|
|
data: { old_name: old_tag_name},
|
|
|
|
success: function(bookmarks){
|
|
|
|
if (bookmarks.status =='success') {
|
|
|
|
filterTagsChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|