-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscripts.js
More file actions
64 lines (56 loc) · 1.83 KB
/
scripts.js
File metadata and controls
64 lines (56 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var deleteButton = $('.delete-button');
var bookmarkCard = $('.card');
var rightSide = $('.right-side');
rightSide.on('click', '.delete-button', deleteBookmark);
$('body').on('click', '.clear-bookmarks-button', deleteAllBookmarks);
rightSide.on('click', '.read-button', markAsRead);
$('.enter-button').on('click', function(){
var titleInput = $('.title-input');
var websiteInput = $('.website-input');
if (titleInput.val() === '' || validURL() == false) {
alert('Please enter a title and valid URL');
$('.enter-button').attr('disabled')
$('.title-input').focus()
} else {
rightSide.append('<article class=\"card\"> <h2 class=\"card-title\">' + titleInput.val() + '</h2><a href=\"' + websiteInput.val() + '\" class=\"card-url\">' + websiteInput.val() + '</a><button class=\"card-button read-button\">Read</button><button class=\"card-button delete-button\">Delete</button></article>');
websiteInput.val('');
titleInput.val('');
readCounter();
linkCounter();
$('.title-input').focus()
}
});
function deleteBookmark() {
$(this).closest('article').remove();
linkCounter();
readCounter();
}
function deleteAllBookmarks() {
$('.read-card').remove();
linkCounter();
readCounter();
}
function markAsRead() {
$(this).toggleClass('read');
$(this).closest('article').toggleClass('read-card');
$(this).siblings('a').toggleClass('change-underline');
readCounter();
}
function readCounter() {
var testR = $('.test-read');
testR.text($('.read').length);
}
function linkCounter() {
var links = $('.card').length;
$('.count').text(links);
}
function validURL (){
var validateUrl = /^(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-_])+(.[a-z])?/;
var regex = new RegExp(validateUrl);
var websiteAddress = $('.website-input').val();
if (websiteAddress.match(regex)) {
return true
}else {
return false;
}
};