-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·95 lines (94 loc) · 2.49 KB
/
script.js
File metadata and controls
executable file
·95 lines (94 loc) · 2.49 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
Vue.filter('date',time => moment(time).format())
var app = new Vue({
el: '#notebook',
data () {
return {
notes: JSON.parse(localStorage.getItem('notes')) || [],
selectedId: localStorage.getItem('selected-id') || null
}
},
computed: {
notePreview() {
return this.selectedNote ? marked(this.selectedNote.content) : ''
},
addButtonTitle () {
return this.notes.length + ' note(s) already'
},
selectedNote () {
return this.notes.find(note => note.id === this.selectedId)
},
sortedNotes() {
return this.notes.slice()
.sort((a,b) => a.created - b.created)
.sort((a,b) => (a.favorite === b.favorite) ? 0 : a.favorite ? -1 : 1)
},
linesCount() {
if(this.selectedNote){
return this.selectedNote.content.split(/\r\n|\r|\n/).length
}
},
wordsCount() {
if(this.selectedNote) {
var s = this.selectedNote.content
s = s.replace(/\n/g,'')
s = s.replace(/(^\s*)|(\s*$)/gi,'')
s = s.replace(/\s\s+/g,' ')
return s.split(' ').length
}
},
charactersCount() {
if(this.selectedNote) {
return this.selectedNote.content.split('').length
}
}
},
watch: {
notes: {
handler: 'saveNotes',
deep: true
},
selectedId(val) {
localStorage.setItem('selected-id',val)
}
},
methods: {
addNote() {
const time = Date.now()
const note = {
id:String(time),
title: 'New note ' + (this.notes.length + 1),
content: '**Hi!** This notebook isusing [markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)for formatting1',
created: time,
favorite: false,
}
this.notes.push(note)
},
reportOperation(opName) {
console.log('The',opName,'operation was completed!')
},
selectNote(note) {
this.selectedId = note.id
},
saveNotes(){
localStorage.setItem('notes', JSON.stringify(this.notes))
// console.log('Notes saved!',new Date())
},
removeNote() {
if(this.selectedNote && confirm('Delete the note?')) {
const index = this.notes.indexOf(this.selectedNote)
if(index !== -1) {
this.notes.splice(index,1)
this.selectedId = this.notes[index-1].id || null
}
}
},
favoriteNote() {
this.selectedNote.favorite ^= true
}
},
created() {
}
})
/*
const html = marked('**Bold** *Italic*[link](http://vuejs.org/)')
console.log(html); */