@@ -13,13 +13,9 @@ import {
13
13
encodeNoteId
14
14
} from './utils'
15
15
16
- import {
17
- checkIfAuth
18
- } from './lib/common/login'
16
+ import { checkIfAuth } from './lib/common/login'
19
17
20
- import {
21
- urlpath
22
- } from './lib/config'
18
+ import { urlpath } from './lib/config'
23
19
24
20
window . migrateHistoryFromTempCallback = null
25
21
@@ -30,40 +26,40 @@ function migrateHistoryFromTemp () {
30
26
$ . get ( `${ serverurl } /temp` , {
31
27
tempid : wurl ( '#tempid' )
32
28
} )
33
- . done ( data => {
34
- if ( data && data . temp ) {
35
- getStorageHistory ( olddata => {
36
- if ( ! olddata || olddata . length === 0 ) {
37
- saveHistoryToStorage ( JSON . parse ( data . temp ) )
29
+ . done ( data => {
30
+ if ( data && data . temp ) {
31
+ getStorageHistory ( olddata => {
32
+ if ( ! olddata || olddata . length === 0 ) {
33
+ saveHistoryToStorage ( JSON . parse ( data . temp ) )
34
+ }
35
+ } )
36
+ }
37
+ } )
38
+ . always ( ( ) => {
39
+ let hash = location . hash . split ( '#' ) [ 1 ]
40
+ hash = hash . split ( '&' )
41
+ for ( let i = 0 ; i < hash . length ; i ++ ) {
42
+ if ( hash [ i ] . indexOf ( 'tempid' ) === 0 ) {
43
+ hash . splice ( i , 1 )
44
+ i --
38
45
}
39
- } )
40
- }
41
- } )
42
- . always ( ( ) => {
43
- let hash = location . hash . split ( '#' ) [ 1 ]
44
- hash = hash . split ( '&' )
45
- for ( let i = 0 ; i < hash . length ; i ++ ) {
46
- if ( hash [ i ] . indexOf ( 'tempid' ) === 0 ) {
47
- hash . splice ( i , 1 )
48
- i --
49
46
}
50
- }
51
- hash = hash . join ( '&' )
52
- location . hash = hash
53
- if ( window . migrateHistoryFromTempCallback ) { window . migrateHistoryFromTempCallback ( ) }
54
- } )
47
+ hash = hash . join ( '&' )
48
+ location . hash = hash
49
+ if ( window . migrateHistoryFromTempCallback ) { window . migrateHistoryFromTempCallback ( ) }
50
+ } )
55
51
}
56
52
}
57
53
58
54
export function saveHistory ( notehistory ) {
59
55
checkIfAuth (
60
- ( ) => {
61
- saveHistoryToServer ( notehistory )
62
- } ,
63
- ( ) => {
64
- saveHistoryToStorage ( notehistory )
65
- }
66
- )
56
+ ( ) => {
57
+ saveHistoryToServer ( notehistory )
58
+ } ,
59
+ ( ) => {
60
+ saveHistoryToStorage ( notehistory )
61
+ }
62
+ )
67
63
}
68
64
69
65
function saveHistoryToStorage ( notehistory ) {
@@ -82,9 +78,9 @@ export function saveStorageHistoryToServer (callback) {
82
78
$ . post ( `${ serverurl } /history` , {
83
79
history : data
84
80
} )
85
- . done ( data => {
86
- callback ( data )
87
- } )
81
+ . done ( data => {
82
+ callback ( data )
83
+ } )
88
84
}
89
85
}
90
86
@@ -111,7 +107,7 @@ export function clearDuplicatedHistory (notehistory) {
111
107
}
112
108
113
109
function addHistory ( id , text , time , tags , pinned , notehistory ) {
114
- // only add when note id exists
110
+ // only add when note id exists
115
111
if ( id ) {
116
112
notehistory . push ( {
117
113
id,
@@ -137,14 +133,14 @@ export function removeHistory (id, notehistory) {
137
133
// used for inner
138
134
export function writeHistory ( title , tags ) {
139
135
checkIfAuth (
140
- ( ) => {
141
- // no need to do this anymore, this will count from server-side
142
- // writeHistoryToServer(title, tags);
143
- } ,
144
- ( ) => {
145
- writeHistoryToStorage ( title , tags )
146
- }
147
- )
136
+ ( ) => {
137
+ // no need to do this anymore, this will count from server-side
138
+ // writeHistoryToServer(title, tags);
139
+ } ,
140
+ ( ) => {
141
+ writeHistoryToStorage ( title , tags )
142
+ }
143
+ )
148
144
}
149
145
150
146
function writeHistoryToStorage ( title , tags ) {
@@ -165,7 +161,7 @@ if (!Array.isArray) {
165
161
}
166
162
167
163
function renderHistory ( title , tags ) {
168
- // console.debug(tags);
164
+ // console.debug(tags);
169
165
const id = urlpath ? location . pathname . slice ( urlpath . length + 1 , location . pathname . length ) . split ( '/' ) [ 1 ] : location . pathname . split ( '/' ) [ 1 ]
170
166
return {
171
167
id,
@@ -177,7 +173,7 @@ function renderHistory (title, tags) {
177
173
178
174
function generateHistory ( title , tags , notehistory ) {
179
175
const info = renderHistory ( title , tags )
180
- // keep any pinned data
176
+ // keep any pinned data
181
177
let pinned = false
182
178
for ( let i = 0 ; i < notehistory . length ; i ++ ) {
183
179
if ( notehistory [ i ] . id === info . id && notehistory [ i ] . pinned ) {
@@ -194,25 +190,25 @@ function generateHistory (title, tags, notehistory) {
194
190
// used for outer
195
191
export function getHistory ( callback ) {
196
192
checkIfAuth (
197
- ( ) => {
198
- getServerHistory ( callback )
199
- } ,
200
- ( ) => {
201
- getStorageHistory ( callback )
202
- }
203
- )
193
+ ( ) => {
194
+ getServerHistory ( callback )
195
+ } ,
196
+ ( ) => {
197
+ getStorageHistory ( callback )
198
+ }
199
+ )
204
200
}
205
201
206
202
function getServerHistory ( callback ) {
207
203
$ . get ( `${ serverurl } /history` )
208
- . done ( data => {
209
- if ( data . history ) {
210
- callback ( data . history )
211
- }
212
- } )
213
- . fail ( ( xhr , status , error ) => {
214
- console . error ( xhr . responseText )
215
- } )
204
+ . done ( data => {
205
+ if ( data . history ) {
206
+ callback ( data . history )
207
+ }
208
+ } )
209
+ . fail ( ( xhr , status , error ) => {
210
+ console . error ( xhr . responseText )
211
+ } )
216
212
}
217
213
218
214
export function getStorageHistory ( callback ) {
@@ -227,25 +223,25 @@ export function getStorageHistory (callback) {
227
223
228
224
export function parseHistory ( list , callback ) {
229
225
checkIfAuth (
230
- ( ) => {
231
- parseServerToHistory ( list , callback )
232
- } ,
233
- ( ) => {
234
- parseStorageToHistory ( list , callback )
235
- }
236
- )
226
+ ( ) => {
227
+ parseServerToHistory ( list , callback )
228
+ } ,
229
+ ( ) => {
230
+ parseStorageToHistory ( list , callback )
231
+ }
232
+ )
237
233
}
238
234
239
235
export function parseServerToHistory ( list , callback ) {
240
236
$ . get ( `${ serverurl } /history` )
241
- . done ( data => {
242
- if ( data . history ) {
243
- parseToHistory ( list , data . history , callback )
244
- }
245
- } )
246
- . fail ( ( xhr , status , error ) => {
247
- console . error ( xhr . responseText )
248
- } )
237
+ . done ( data => {
238
+ if ( data . history ) {
239
+ parseToHistory ( list , data . history , callback )
240
+ }
241
+ } )
242
+ . fail ( ( xhr , status , error ) => {
243
+ console . error ( xhr . responseText )
244
+ } )
249
245
}
250
246
251
247
export function parseStorageToHistory ( list , callback ) {
@@ -271,15 +267,15 @@ function parseToHistory (list, notehistory, callback) {
271
267
} catch ( err ) {
272
268
console . error ( err )
273
269
}
274
- // parse time to timestamp and fromNow
270
+ // parse time to timestamp and fromNow
275
271
const timestamp = ( typeof notehistory [ i ] . time === 'number' ? moment ( notehistory [ i ] . time ) : moment ( notehistory [ i ] . time , 'MMMM Do YYYY, h:mm:ss a' ) )
276
272
notehistory [ i ] . timestamp = timestamp . valueOf ( )
277
273
notehistory [ i ] . fromNow = timestamp . fromNow ( )
278
274
notehistory [ i ] . time = timestamp . format ( 'llll' )
279
- // prevent XSS
275
+ // prevent XSS
280
276
notehistory [ i ] . text = escapeHTML ( notehistory [ i ] . text )
281
277
notehistory [ i ] . tags = ( notehistory [ i ] . tags && notehistory [ i ] . tags . length > 0 ) ? escapeHTML ( notehistory [ i ] . tags ) . split ( ',' ) : [ ]
282
- // add to list
278
+ // add to list
283
279
if ( notehistory [ i ] . id && list . get ( 'id' , notehistory [ i ] . id ) . length === 0 ) { list . add ( notehistory [ i ] ) }
284
280
}
285
281
}
0 commit comments