@@ -13,13 +13,9 @@ import {
1313 encodeNoteId
1414} from './utils'
1515
16- import {
17- checkIfAuth
18- } from './lib/common/login'
16+ import { checkIfAuth } from './lib/common/login'
1917
20- import {
21- urlpath
22- } from './lib/config'
18+ import { urlpath } from './lib/config'
2319
2420window . migrateHistoryFromTempCallback = null
2521
@@ -30,40 +26,40 @@ function migrateHistoryFromTemp () {
3026 $ . get ( `${ serverurl } /temp` , {
3127 tempid : wurl ( '#tempid' )
3228 } )
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 --
3845 }
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 --
4946 }
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+ } )
5551 }
5652}
5753
5854export function saveHistory ( notehistory ) {
5955 checkIfAuth (
60- ( ) => {
61- saveHistoryToServer ( notehistory )
62- } ,
63- ( ) => {
64- saveHistoryToStorage ( notehistory )
65- }
66- )
56+ ( ) => {
57+ saveHistoryToServer ( notehistory )
58+ } ,
59+ ( ) => {
60+ saveHistoryToStorage ( notehistory )
61+ }
62+ )
6763}
6864
6965function saveHistoryToStorage ( notehistory ) {
@@ -82,9 +78,9 @@ export function saveStorageHistoryToServer (callback) {
8278 $ . post ( `${ serverurl } /history` , {
8379 history : data
8480 } )
85- . done ( data => {
86- callback ( data )
87- } )
81+ . done ( data => {
82+ callback ( data )
83+ } )
8884 }
8985}
9086
@@ -111,7 +107,7 @@ export function clearDuplicatedHistory (notehistory) {
111107}
112108
113109function addHistory ( id , text , time , tags , pinned , notehistory ) {
114- // only add when note id exists
110+ // only add when note id exists
115111 if ( id ) {
116112 notehistory . push ( {
117113 id,
@@ -137,14 +133,14 @@ export function removeHistory (id, notehistory) {
137133// used for inner
138134export function writeHistory ( title , tags ) {
139135 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+ )
148144}
149145
150146function writeHistoryToStorage ( title , tags ) {
@@ -165,7 +161,7 @@ if (!Array.isArray) {
165161}
166162
167163function renderHistory ( title , tags ) {
168- // console.debug(tags);
164+ // console.debug(tags);
169165 const id = urlpath ? location . pathname . slice ( urlpath . length + 1 , location . pathname . length ) . split ( '/' ) [ 1 ] : location . pathname . split ( '/' ) [ 1 ]
170166 return {
171167 id,
@@ -177,7 +173,7 @@ function renderHistory (title, tags) {
177173
178174function generateHistory ( title , tags , notehistory ) {
179175 const info = renderHistory ( title , tags )
180- // keep any pinned data
176+ // keep any pinned data
181177 let pinned = false
182178 for ( let i = 0 ; i < notehistory . length ; i ++ ) {
183179 if ( notehistory [ i ] . id === info . id && notehistory [ i ] . pinned ) {
@@ -194,25 +190,25 @@ function generateHistory (title, tags, notehistory) {
194190// used for outer
195191export function getHistory ( callback ) {
196192 checkIfAuth (
197- ( ) => {
198- getServerHistory ( callback )
199- } ,
200- ( ) => {
201- getStorageHistory ( callback )
202- }
203- )
193+ ( ) => {
194+ getServerHistory ( callback )
195+ } ,
196+ ( ) => {
197+ getStorageHistory ( callback )
198+ }
199+ )
204200}
205201
206202function getServerHistory ( callback ) {
207203 $ . 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+ } )
216212}
217213
218214export function getStorageHistory ( callback ) {
@@ -227,25 +223,25 @@ export function getStorageHistory (callback) {
227223
228224export function parseHistory ( list , callback ) {
229225 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+ )
237233}
238234
239235export function parseServerToHistory ( list , callback ) {
240236 $ . 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+ } )
249245}
250246
251247export function parseStorageToHistory ( list , callback ) {
@@ -271,15 +267,15 @@ function parseToHistory (list, notehistory, callback) {
271267 } catch ( err ) {
272268 console . error ( err )
273269 }
274- // parse time to timestamp and fromNow
270+ // parse time to timestamp and fromNow
275271 const timestamp = ( typeof notehistory [ i ] . time === 'number' ? moment ( notehistory [ i ] . time ) : moment ( notehistory [ i ] . time , 'MMMM Do YYYY, h:mm:ss a' ) )
276272 notehistory [ i ] . timestamp = timestamp . valueOf ( )
277273 notehistory [ i ] . fromNow = timestamp . fromNow ( )
278274 notehistory [ i ] . time = timestamp . format ( 'llll' )
279- // prevent XSS
275+ // prevent XSS
280276 notehistory [ i ] . text = escapeHTML ( notehistory [ i ] . text )
281277 notehistory [ i ] . tags = ( notehistory [ i ] . tags && notehistory [ i ] . tags . length > 0 ) ? escapeHTML ( notehistory [ i ] . tags ) . split ( ',' ) : [ ]
282- // add to list
278+ // add to list
283279 if ( notehistory [ i ] . id && list . get ( 'id' , notehistory [ i ] . id ) . length === 0 ) { list . add ( notehistory [ i ] ) }
284280 }
285281 }
0 commit comments