Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
b524cd9f
Commit
b524cd9f
authored
Sep 11, 2016
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Insert Code Block feature completed
parent
3212b624
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
51 deletions
+91
-51
app.js
assets/js/app.js
+0
-0
editor-codeblock.js
client/js/components/editor-codeblock.js
+62
-0
editor.js
client/js/components/editor.js
+26
-49
editor-codeblock.pug
views/modals/editor-codeblock.pug
+3
-2
No files found.
assets/js/app.js
View file @
b524cd9f
This diff is collapsed.
Click to expand it.
client/js/components/editor-codeblock.js
0 → 100644
View file @
b524cd9f
let
codeEditor
=
ace
.
edit
(
"codeblock-editor"
);
codeEditor
.
setTheme
(
"ace/theme/tomorrow_night"
);
codeEditor
.
getSession
().
setMode
(
"ace/mode/markdown"
);
codeEditor
.
setOption
(
'fontSize'
,
'14px'
);
codeEditor
.
setOption
(
'hScrollBarAlwaysVisible'
,
false
);
codeEditor
.
setOption
(
'wrap'
,
true
);
let
modelist
=
ace
.
require
(
"ace/ext/modelist"
);
let
vueCodeBlock
=
new
Vue
({
el
:
'#modal-editor-codeblock'
,
data
:
{
modes
:
modelist
.
modesByName
,
modeSelected
:
'text'
},
watch
:
{
modeSelected
:
(
val
,
oldVal
)
=>
{
loadAceMode
(
val
).
done
(()
=>
{
ace
.
require
(
"ace/mode/"
+
val
);
codeEditor
.
getSession
().
setMode
(
"ace/mode/"
+
val
);
});
}
},
methods
:
{
cancel
:
(
ev
)
=>
{
mdeModalOpenState
=
false
;
$
(
'#modal-editor-codeblock'
).
slideUp
();
},
insertCode
:
(
ev
)
=>
{
if
(
mde
.
codemirror
.
doc
.
somethingSelected
())
{
mde
.
codemirror
.
execCommand
(
'singleSelection'
);
}
let
codeBlockText
=
'```'
+
vueCodeBlock
.
modeSelected
+
'
\
n'
+
codeEditor
.
getValue
()
+
'
\
n```'
;
mde
.
codemirror
.
doc
.
replaceSelection
(
codeBlockText
);
vueCodeBlock
.
cancel
();
}
}
});
// ACE - Mode Loader
let
modelistLoaded
=
[];
let
loadAceMode
=
(
m
)
=>
{
return
$
.
ajax
({
url
:
'/js/ace/mode-'
+
m
+
'.js'
,
dataType
:
"script"
,
cache
:
true
,
beforeSend
:
()
=>
{
if
(
_
.
includes
(
modelistLoaded
,
m
))
{
return
false
;
}
},
success
:
()
=>
{
modelistLoaded
.
push
(
m
);
}
});
}
\ No newline at end of file
client/js/components/editor.js
View file @
b524cd9f
...
...
@@ -5,30 +5,10 @@
if
(
$
(
'#mk-editor'
).
length
===
1
)
{
let
codeEditor
=
ace
.
edit
(
"codeblock-editor"
);
codeEditor
.
setTheme
(
"ace/theme/tomorrow_night"
);
codeEditor
.
getSession
().
setMode
(
"ace/mode/markdown"
);
codeEditor
.
setOption
(
'fontSize'
,
'14px'
);
codeEditor
.
setOption
(
'hScrollBarAlwaysVisible'
,
false
);
codeEditor
.
setOption
(
'wrap'
,
true
);
let
mdeModalOpenState
=
false
;
let
mdeCurrentEditor
=
null
;
let
modelist
=
ace
.
require
(
"ace/ext/modelist"
);
let
vueCodeBlock
=
new
Vue
({
el
:
'#modal-editor-codeblock'
,
data
:
{
modes
:
modelist
.
modesByName
,
modeSelected
:
'text'
},
watch
:
{
modeSelected
:
(
val
,
oldVal
)
=>
{
loadAceMode
(
val
).
done
(()
=>
{
ace
.
require
(
"ace/mode/"
+
val
);
codeEditor
.
getSession
().
setMode
(
"ace/mode/"
+
val
);
});
}
}
});
//=include editor-codeblock.js
var
mde
=
new
SimpleMDE
({
autofocus
:
true
,
...
...
@@ -97,7 +77,10 @@ if($('#mk-editor').length === 1) {
{
name
:
"link"
,
action
:
(
editor
)
=>
{
$
(
'#modal-editor-link'
).
slideToggle
();
if
(
!
mdeModalOpenState
)
{
mdeModalOpenState
=
true
;
$
(
'#modal-editor-link'
).
slideToggle
();
}
},
className
:
"fa fa-link"
,
title
:
"Insert Link"
,
...
...
@@ -114,6 +97,7 @@ if($('#mk-editor').length === 1) {
{
name
:
"inline-code"
,
action
:
(
editor
)
=>
{
if
(
!
editor
.
codemirror
.
doc
.
somethingSelected
())
{
return
alerts
.
pushError
(
'Invalid selection'
,
'You must select at least 1 character first.'
);
}
...
...
@@ -122,6 +106,7 @@ if($('#mk-editor').length === 1) {
return
'`'
+
s
+
'`'
;
});
editor
.
codemirror
.
doc
.
replaceSelections
(
curSel
);
},
className
:
"fa fa-terminal"
,
title
:
"Inline Code"
,
...
...
@@ -129,10 +114,21 @@ if($('#mk-editor').length === 1) {
{
name
:
"code-block"
,
action
:
(
editor
)
=>
{
$
(
'#modal-editor-codeblock'
).
slideDown
(
400
,
()
=>
{
codeEditor
.
resize
();
codeEditor
.
focus
();
});
if
(
!
mdeModalOpenState
)
{
mdeModalOpenState
=
true
;
if
(
mde
.
codemirror
.
doc
.
somethingSelected
())
{
codeEditor
.
setValue
(
mde
.
codemirror
.
doc
.
getSelection
());
}
else
{
codeEditor
.
setValue
(
''
);
}
$
(
'#modal-editor-codeblock'
).
slideDown
(
400
,
()
=>
{
codeEditor
.
resize
();
codeEditor
.
focus
();
});
}
},
className
:
"fa fa-code"
,
title
:
"Code Block"
,
...
...
@@ -181,23 +177,4 @@ $('.btn-edit-save').on('click', (ev) => {
alerts
.
pushError
(
'Something went wrong'
,
'Save operation failed.'
);
});
});
// ACE - Mode Loader
let
modelistLoaded
=
[];
let
loadAceMode
=
(
m
)
=>
{
return
$
.
ajax
({
url
:
'/js/ace/mode-'
+
m
+
'.js'
,
dataType
:
"script"
,
cache
:
true
,
beforeSend
:
()
=>
{
if
(
_
.
includes
(
modelistLoaded
,
m
))
{
return
false
;
}
},
success
:
()
=>
{
modelistLoaded
.
push
(
m
);
}
});
}
\ No newline at end of file
});
\ No newline at end of file
views/modals/editor-codeblock.pug
View file @
b524cd9f
...
...
@@ -11,9 +11,9 @@
select(style={width: '300px'}, v-model='modeSelected')
option(v-for="mode in modes" v-bind:value='mode.name') {{ mode.caption }}
.column.is-narrow
a.button.is-warning.is-outlined Cancel
a.button.is-warning.is-outlined
(v-on:click="cancel")
Cancel
.column.is-narrow
a.button.is-primary.is-outlined Insert Code Block
a.button.is-primary.is-outlined
(v-on:click="insertCode")
Insert Code Block
.ace-container(style={'border-radius':'5px'})
#codeblock-editor
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment