@@ -77,9 +77,11 @@ import { preventXSS } from './render'
77
77
import Editor from './lib/editor'
78
78
79
79
import getUIElements from './lib/editor/ui-elements'
80
+ import uiElemsWithoutJquery from './lib/editor/ui-elems-without-jquery'
80
81
import { emojifyImageDir } from './lib/editor/constants'
81
82
import modeType from './lib/modeType'
82
83
import appState from './lib/appState'
84
+ //import { isLogicalNot } from 'vega-lite/build/src/logical'
83
85
84
86
require ( '../vendor/showup/showup' )
85
87
@@ -256,6 +258,7 @@ const statusType = {
256
258
257
259
// global vars
258
260
window . loaded = false
261
+ let isLogin = false
259
262
let needRefresh = false
260
263
let isDirty = false
261
264
let editShown = false
@@ -319,6 +322,8 @@ defaultTextHeight = parseInt($('.CodeMirror').css('line-height'))
319
322
// initalize ui reference
320
323
const ui = getUIElements ( )
321
324
325
+ const uiByNativeJS = uiElemsWithoutJquery ( )
326
+
322
327
// page actions
323
328
var opts = {
324
329
lines : 11 , // The number of lines to draw
@@ -423,7 +428,9 @@ Visibility.change(function (e, state) {
423
428
424
429
// when page ready
425
430
$ ( document ) . ready ( function ( ) {
426
- if ( ui . toolbar . edit . data ( 'blockSource' ) ) { replaceUrl ( window . location . href ) }
431
+ if ( ui . toolbar . edit . data ( 'blockSource' ) && isLogin === false ) { replaceUrl ( window . location . href ) }
432
+
433
+ console . log ( "personal info" , onlineUsers )
427
434
428
435
idle . checkAway ( )
429
436
checkResponsive ( )
@@ -473,14 +480,14 @@ $(document).ready(function () {
473
480
474
481
key . filter = function ( e ) { return true }
475
482
key ( 'ctrl+alt+e' , function ( e ) {
476
- if ( ui . toolbar . edit . data ( 'blockSource' ) ) return
483
+ if ( ui . toolbar . edit . data ( 'blockSource' ) && isLogin === false ) return
477
484
changeMode ( modeType . edit )
478
485
} )
479
486
key ( 'ctrl+alt+v' , function ( e ) {
480
487
changeMode ( modeType . view )
481
488
} )
482
489
key ( 'ctrl+alt+b' , function ( e ) {
483
- if ( ui . toolbar . both . data ( 'blockSource' ) ) return
490
+ if ( ui . toolbar . both . data ( 'blockSource' ) && isLogin === false ) return
484
491
changeMode ( modeType . both )
485
492
} )
486
493
// toggle-dropdown
@@ -505,18 +512,36 @@ $(window).on('error', function () {
505
512
} )
506
513
507
514
// replace url if user have not rights to veiw source code
508
- function replaceUrl ( url ) {
509
- const urlHasEdit = / \? e d i t / ;
510
- const urlHasBoth = / \? b o t h / ;
511
- if ( urlHasEdit . test ( url ) ) {
512
- let newUrl = url . toString ( ) . replace ( urlHasEdit , '?view' ) ;
513
- window . location . replace ( newUrl ) ;
514
- } else if ( urlHasBoth . test ( url ) ) {
515
- let newUrl = url . toString ( ) . replace ( urlHasBoth , '?view' ) ;
515
+ function replaceUrl ( url ) {
516
+ const urlHasEditOrBoth = / \? e d i t | \? b o t h / ;
517
+ if ( urlHasEditOrBoth . test ( url ) ) {
518
+ let newUrl = url . toString ( ) . replace ( urlHasEditOrBoth , '?view' ) ;
516
519
window . location . replace ( newUrl ) ;
517
520
}
518
521
}
519
522
523
+ //
524
+ function disableToolbarButtons ( isLogin , elems ) {
525
+ if ( isLogin === false ) {
526
+ elems . edit . setAttribute ( 'disabled' , null )
527
+ elems . edit . setAttribute ( 'title' , 'You have no rights to edit this note' )
528
+ elems . both . setAttribute ( 'disabled' , null )
529
+ elems . both . setAttribute ( 'title' , 'You have no rights to edit this note' )
530
+ } else {
531
+ elems . edit . removeAttribute ( 'disabled' )
532
+ elems . both . removeAttribute ( 'disabled' )
533
+ }
534
+ }
535
+
536
+ function userIsLogin ( userPersonalInfo ) {
537
+ if ( userPersonalInfo . hasOwnProperty ( 'login' ) ) {
538
+ if ( userPersonalInfo . login === true ) {
539
+ return isLogin = true
540
+ }
541
+ }
542
+ return isLogin = false
543
+ }
544
+
520
545
setupSyncAreas ( ui . area . codemirrorScroll , ui . area . view , ui . area . markdown , editor )
521
546
522
547
function autoSyncscroll ( ) {
@@ -1585,12 +1610,17 @@ function importFromUrl (url) {
1585
1610
1586
1611
// mode
1587
1612
ui . toolbar . mode . click ( function ( ) {
1588
- if ( ui . toolbar . mode . data ( 'blockSource' ) ) return
1613
+ if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
1614
+ toggleMode ( )
1615
+ } else if ( ui . toolbar . mode . data ( 'blockSource' ) ) return
1589
1616
toggleMode ( )
1590
1617
} )
1591
1618
// edit
1592
1619
ui . toolbar . edit . click ( function ( ) {
1593
- if ( ui . toolbar . edit . data ( 'blockSource' ) ) return
1620
+ if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
1621
+ console . dir ( personalInfo )
1622
+ changeMode ( modeType . edit )
1623
+ } else if ( ui . toolbar . edit . data ( 'blockSource' ) ) return
1594
1624
changeMode ( modeType . edit )
1595
1625
} )
1596
1626
// view
@@ -1599,7 +1629,9 @@ ui.toolbar.view.click(function () {
1599
1629
} )
1600
1630
// both
1601
1631
ui . toolbar . both . click ( function ( ) {
1602
- if ( ui . toolbar . both . data ( 'blockSource' ) ) return
1632
+ if ( personalInfo . userid && window . owner && personalInfo . userid === window . owner ) {
1633
+ changeMode ( modeType . edit )
1634
+ } else if ( ui . toolbar . both . data ( 'blockSource' ) ) return
1603
1635
changeMode ( modeType . both )
1604
1636
} )
1605
1637
@@ -2189,6 +2221,9 @@ socket.on('online users', function (data) {
2189
2221
var user = data . users [ i ]
2190
2222
if ( user . id !== socket . id ) { buildCursor ( user ) } else { personalInfo = user }
2191
2223
}
2224
+ if ( ui . toolbar . edit . data ( 'blockSource' ) ) {
2225
+ disableToolbarButtons ( userIsLogin ( personalInfo ) , uiByNativeJS )
2226
+ }
2192
2227
} )
2193
2228
socket . on ( 'user status' , function ( data ) {
2194
2229
if ( debug ) { console . debug ( data ) }
@@ -2238,6 +2273,12 @@ socket.on('cursor blur', function (data) {
2238
2273
}
2239
2274
} )
2240
2275
2276
+ //checked user is login
2277
+ async function userPersonalInfo ( personalInfo ) {
2278
+ let userInfo = await personalInfo
2279
+ return userInfo
2280
+ }
2281
+
2241
2282
var options = {
2242
2283
valueNames : [ 'id' , 'name' ] ,
2243
2284
item : '<li class="ui-user-item">' +
0 commit comments