Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2016-03-29 18:25:54 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
efb49019d484f2455897d2249e16ccd0b2ad5e88
efb49019
1 parent
26965fa0
Integrated the markdown editor with the image manager
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
29 deletions
resources/assets/js/directives.js
resources/assets/sass/_forms.scss
resources/views/pages/form.blade.php
resources/assets/js/directives.js
View file @
efb4901
"use strict"
;
var
DropZone
=
require
(
'dropzone'
);
var
markdown
=
require
(
"marked"
);
var
markdown
=
require
(
'marked'
);
var
toggleSwitchTemplate
=
require
(
'./components/toggle-switch.html'
);
var
imagePickerTemplate
=
require
(
'./components/image-picker.html'
);
...
...
@@ -201,9 +201,9 @@ module.exports = function (ngApp, events) {
tinymce
.
init
(
scope
.
tinymce
);
}
}
}])
}])
;
ngApp
.
directive
(
'markdown
Editor
'
,
[
'$timeout'
,
function
(
$timeout
)
{
ngApp
.
directive
(
'markdown
Input
'
,
[
'$timeout'
,
function
(
$timeout
)
{
return
{
restrict
:
'A'
,
scope
:
{
...
...
@@ -233,6 +233,50 @@ module.exports = function (ngApp, events) {
}
}
}]);
ngApp
.
directive
(
'markdownEditor'
,
[
'$timeout'
,
function
(
$timeout
)
{
return
{
restrict
:
'A'
,
link
:
function
(
scope
,
element
,
attrs
)
{
// Elements
var
input
=
element
.
find
(
'textarea[markdown-input]'
);
var
insertImage
=
element
.
find
(
'button[data-action="insertImage"]'
);
var
currentCaretPos
=
0
;
input
.
blur
((
event
)
=>
{
currentCaretPos
=
input
[
0
].
selectionStart
;
});
// Insert image shortcut
input
.
keydown
((
event
)
=>
{
if
(
event
.
which
===
73
&&
event
.
ctrlKey
&&
event
.
shiftKey
)
{
event
.
preventDefault
();
var
caretPos
=
input
[
0
].
selectionStart
;
var
currentContent
=
input
.
val
();
var
mdImageText
=
""
;
input
.
val
(
currentContent
.
substring
(
0
,
caretPos
)
+
mdImageText
+
currentContent
.
substring
(
caretPos
));
input
.
focus
();
input
[
0
].
selectionStart
=
caretPos
+
(
";
input
[
0
].
selectionEnd
=
caretPos
+
(
';
}
});
// Insert image from image manager
insertImage
.
click
((
event
)
=>
{
window
.
ImageManager
.
showExternal
((
image
)
=>
{
var
caretPos
=
currentCaretPos
;
var
currentContent
=
input
.
val
();
var
mdImageText
=
""
;
input
.
val
(
currentContent
.
substring
(
0
,
caretPos
)
+
mdImageText
+
currentContent
.
substring
(
caretPos
));
input
.
change
();
});
});
}
}
}])
};
\ No newline at end of file
...
...
resources/assets/sass/_forms.scss
View file @
efb4901
...
...
@@ -39,45 +39,43 @@
max-height
:
100%
;
flex
:
1
;
border
:
0
;
width
:
100%
;
&
:focus
{
outline
:
0
;
}
}
.markdown-display
,
.markdown-editor-wrap
{
flex
:
1
;
padding-top
:
28px
;
position
:
relative
;
border
:
1px
solid
#DDD
;
&
:before
{
display
:
block
;
position
:
absolute
;
top
:
0
;
left
:
0
;
width
:
100%
;
padding
:
$-xs
$-m
;
font-family
:
'Roboto Mono'
;
font-size
:
11px
;
line-height
:
1
;
border-bottom
:
1px
solid
#DDD
;
background-color
:
#EEE
;
}
}
.markdown-editor-wrap
{
display
:
flex
;
&
:before
{
content
:
'Editor'
;
}
flex-direction
:
column
;
border
:
1px
solid
#DDD
;
}
.markdown-display
{
padding
:
0
$-m
;
padding-top
:
28px
;
padding
:
0
$-m
0
;
margin-left
:
-1px
;
&
:before
{
content
:
'Preview'
;
}
overflow-y
:
scroll
;
}
}
.editor-toolbar
{
width
:
100%
;
padding
:
$-xs
$-m
;
font-family
:
'Roboto Mono'
;
font-size
:
11px
;
line-height
:
1
.6
;
border-bottom
:
1px
solid
#DDD
;
background-color
:
#EEE
;
flex
:
none
;
&
:after
{
content
:
''
;
display
:
block
;
clear
:
both
;
}
}
label
{
display
:
block
;
line-height
:
1
.4em
;
...
...
resources/views/pages/form.blade.php
View file @
efb4901
...
...
@@ -51,14 +51,26 @@
@endif
@if(config('app.editor') === 'markdown')
<div
id=
"markdown-editor"
class=
"flex-fill flex"
>
<div
id=
"markdown-editor"
markdown-editor
class=
"flex-fill flex"
>
<div
class=
"markdown-editor-wrap"
>
<textarea
markdown-editor
md-change=
"editorChange"
md-model=
"editContent"
name=
"markdown"
rows=
"5"
<div
class=
"editor-toolbar"
>
<span
class=
"float left"
>
Editor
</span>
<div
class=
"float right buttons"
>
<button
class=
"text-button"
type=
"button"
data-action=
"insertImage"
><i
class=
"zmdi zmdi-image"
></i>
Insert Image
</button>
</div>
</div>
<textarea
markdown-input
md-change=
"editorChange"
md-model=
"editContent"
name=
"markdown"
rows=
"5"
@
if
($
errors-
>
has('markdown')) class="neg" @endif>@if(isset($model) || old('markdown')){{htmlspecialchars( old('markdown') ? old('markdown') : ($model->markdown === '' ? $model->html : $model->markdown))}}@endif
</textarea>
</div>
<div
class=
"markdown-display page-content"
ng-bind-html=
"displayContent"
></div>
<div
class=
"markdown-editor-wrap"
>
<div
class=
"editor-toolbar"
>
<div
class=
""
>
Preview
</div>
</div>
<div
class=
"markdown-display page-content"
ng-bind-html=
"displayContent"
></div>
</div>
</div>
<input
type=
"hidden"
name=
"html"
ng-value=
"displayContent"
>
...
...
Please
register
or
sign in
to post a comment