2014-03-08 07:47:15 -05:00
|
|
|
$.fn.ready(function() {
|
|
|
|
|
|
|
|
var $listmode = $('#listmode'),
|
|
|
|
$listentries = $("#list-entries"),
|
|
|
|
$bagit = $('#bagit'),
|
|
|
|
$bagitForm = $('#bagit-form');
|
2014-03-13 12:37:08 -04:00
|
|
|
$bagitFormForm = $('#bagit-form-form');
|
2014-03-08 07:47:15 -05:00
|
|
|
|
|
|
|
/* ==========================================================================
|
|
|
|
Menu
|
|
|
|
========================================================================== */
|
2014-02-27 09:11:37 -05:00
|
|
|
|
|
|
|
$("#menu").click(function(){
|
|
|
|
$("#links").toggle();
|
|
|
|
});
|
|
|
|
|
2014-03-08 07:47:15 -05:00
|
|
|
/* ==========================================================================
|
|
|
|
List mode or Table Mode
|
|
|
|
========================================================================== */
|
2014-02-27 09:11:37 -05:00
|
|
|
|
2014-03-08 07:47:15 -05:00
|
|
|
$listmode.click(function(){
|
2014-02-27 09:11:37 -05:00
|
|
|
if ( $.cookie("listmode") == 1 ) {
|
2014-03-08 07:47:15 -05:00
|
|
|
// Cookie
|
2014-02-27 09:11:37 -05:00
|
|
|
$.removeCookie("listmode");
|
2014-03-08 07:47:15 -05:00
|
|
|
|
|
|
|
$listentries.removeClass("listmode");
|
|
|
|
$listmode.removeClass("tablemode");
|
|
|
|
$listmode.addClass("listmode");
|
2014-02-12 15:58:40 -05:00
|
|
|
}
|
2014-02-27 09:11:37 -05:00
|
|
|
else {
|
2014-03-08 07:47:15 -05:00
|
|
|
// Cookie
|
2014-02-27 09:11:37 -05:00
|
|
|
$.cookie("listmode", 1, {expires: 365});
|
|
|
|
|
2014-03-08 07:47:15 -05:00
|
|
|
$listentries.addClass("listmode");
|
|
|
|
$listmode.removeClass("listmode");
|
|
|
|
$listmode.addClass("tablemode");
|
2014-02-27 09:11:37 -05:00
|
|
|
}
|
|
|
|
|
2014-02-12 15:58:40 -05:00
|
|
|
});
|
2014-02-27 09:11:37 -05:00
|
|
|
|
2014-03-08 07:47:15 -05:00
|
|
|
/* ==========================================================================
|
|
|
|
Cookie listmode
|
|
|
|
========================================================================== */
|
|
|
|
|
2014-02-27 09:11:37 -05:00
|
|
|
if ( $.cookie("listmode") == 1 ) {
|
2014-03-08 07:47:15 -05:00
|
|
|
$listentries.addClass("listmode");
|
|
|
|
$listmode.removeClass("listmode");
|
|
|
|
$listmode.addClass("tablemode");
|
2014-02-27 09:11:37 -05:00
|
|
|
}
|
|
|
|
|
2014-03-08 07:47:15 -05:00
|
|
|
/* ==========================================================================
|
2014-03-12 11:36:04 -04:00
|
|
|
bag it link and close button
|
|
|
|
========================================================================== */
|
2014-03-08 07:47:15 -05:00
|
|
|
|
2014-03-12 11:36:04 -04:00
|
|
|
function toggleSaveLinkForm(url) {
|
|
|
|
$bagit.toggleClass("active-current");
|
2014-03-08 07:47:15 -05:00
|
|
|
$bagitForm.toggle();
|
2014-03-12 11:36:04 -04:00
|
|
|
$('#content').toggleClass("opacity03");
|
|
|
|
if (url !== 'undefined' && url) {
|
|
|
|
$('#plainurl').val(url);
|
|
|
|
}
|
|
|
|
$('#plainurl').focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
$bagit.click(function(){
|
|
|
|
toggleSaveLinkForm();
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#bagit-form-close").click(function(){
|
|
|
|
toggleSaveLinkForm();
|
|
|
|
});
|
|
|
|
|
2014-03-13 12:37:08 -04:00
|
|
|
|
|
|
|
//send "bag it link" form request via ajax
|
|
|
|
$bagitFormForm.submit( function(event) {
|
|
|
|
$bagitFormForm.css("cursor", "wait");
|
|
|
|
$("#add-link-result").empty();
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: $bagitFormForm.attr('method'),
|
|
|
|
url: $bagitFormForm.attr('action'),
|
|
|
|
data: $bagitFormForm.serialize(),
|
|
|
|
success: function(data) {
|
|
|
|
$('#add-link-result').html("Done!");
|
|
|
|
$('#plainurl').val('');
|
|
|
|
$('#plainurl').blur('');
|
|
|
|
$bagitFormForm.css("cursor", "auto");
|
|
|
|
//setTimeout( function() { toggleSaveLinkForm(); }, 1000); //close form after 1000 delay
|
|
|
|
},
|
|
|
|
error: function(data) {
|
|
|
|
$('#add-link-result').html("Failed!");
|
|
|
|
$bagitFormForm.css("cursor", "auto");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
event.preventDefault();
|
2014-03-08 07:47:15 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
/* ==========================================================================
|
2014-03-12 11:36:04 -04:00
|
|
|
Keyboard gestion
|
|
|
|
========================================================================== */
|
2014-03-08 07:47:15 -05:00
|
|
|
|
|
|
|
$(window).keydown(function(e){
|
2014-03-12 11:36:04 -04:00
|
|
|
if ( ( e.target.tagName.toLowerCase() !== 'input' && e.keyCode == 83 ) || e.keyCode == 27 ) {
|
|
|
|
toggleSaveLinkForm();
|
|
|
|
return false;
|
2014-03-08 07:47:15 -05:00
|
|
|
}
|
2014-03-12 11:36:04 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
/* ==========================================================================
|
|
|
|
Process all links inside an article
|
|
|
|
========================================================================== */
|
|
|
|
|
|
|
|
$("article a[href^='http']").after(function() {
|
|
|
|
return " <a href=\"" + $(this).attr('href') + "\" class=\"add-to-wallabag-link-after\" alt=\"add to wallabag\" title=\"add to wallabag\">w</a> ";
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".add-to-wallabag-link-after").click(function(event){
|
|
|
|
toggleSaveLinkForm($(this).attr('href'));
|
2014-03-13 12:37:08 -04:00
|
|
|
event.preventDefault();
|
2014-03-12 11:36:04 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-03-08 07:47:15 -05:00
|
|
|
|
2014-02-27 09:11:37 -05:00
|
|
|
|
2014-03-12 07:00:37 -04:00
|
|
|
});
|