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-09-02 18:54:26 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
23e014cb25263aa20f21edd343704c88a3131fc6
23e014cb
1 parent
5b64358e
Added link selector to markdown editor
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
17 deletions
resources/assets/js/directives.js
resources/assets/js/global.js
resources/views/pages/edit.blade.php
resources/views/pages/form.blade.php
resources/views/partials/entity-selector-popup.blade.php
resources/assets/js/directives.js
View file @
23e014c
...
...
@@ -271,8 +271,6 @@ module.exports = function (ngApp, events) {
scope
.
mdModel
=
content
;
scope
.
mdChange
(
markdown
(
content
));
console
.
log
(
'test'
);
element
.
on
(
'change input'
,
(
event
)
=>
{
content
=
element
.
val
();
$timeout
(()
=>
{
...
...
@@ -304,6 +302,7 @@ module.exports = function (ngApp, events) {
const
input
=
element
.
find
(
'[markdown-input] textarea'
).
first
();
const
display
=
element
.
find
(
'.markdown-display'
).
first
();
const
insertImage
=
element
.
find
(
'button[data-action="insertImage"]'
);
const
insertEntityLink
=
element
.
find
(
'button[data-action="insertEntityLink"]'
)
let
currentCaretPos
=
0
;
...
...
@@ -355,6 +354,13 @@ module.exports = function (ngApp, events) {
input
[
0
].
selectionEnd
=
caretPos
+
(
';
return
;
}
// Insert entity link shortcut
if
(
event
.
which
===
75
&&
event
.
ctrlKey
&&
event
.
shiftKey
)
{
showLinkSelector
();
return
;
}
// Pass key presses to controller via event
scope
.
$emit
(
'editor-keydown'
,
event
);
});
...
...
@@ -370,6 +376,26 @@ module.exports = function (ngApp, events) {
});
});
function
showLinkSelector
()
{
window
.
showEntityLinkSelector
((
entity
)
=>
{
let
selectionStart
=
currentCaretPos
;
let
selectionEnd
=
input
[
0
].
selectionEnd
;
let
textSelected
=
(
selectionEnd
!==
selectionStart
);
let
currentContent
=
input
.
val
();
if
(
textSelected
)
{
let
selectedText
=
currentContent
.
substring
(
selectionStart
,
selectionEnd
);
let
linkText
=
`[
${
selectedText
}
](
${
entity
.
link
}
)`
;
input
.
val
(
currentContent
.
substring
(
0
,
selectionStart
)
+
linkText
+
currentContent
.
substring
(
selectionEnd
));
}
else
{
let
linkText
=
` [
${
entity
.
name
}
](
${
entity
.
link
}
) `
;
input
.
val
(
currentContent
.
substring
(
0
,
selectionStart
)
+
linkText
+
currentContent
.
substring
(
selectionStart
))
}
input
.
change
();
});
}
insertEntityLink
.
click
(
showLinkSelector
);
}
}
}]);
...
...
resources/assets/js/global.js
View file @
23e014c
...
...
@@ -140,6 +140,11 @@ $(function () {
$
(
this
).
fadeOut
(
240
);
});
$
(
'.markdown-display'
).
on
(
'click'
,
'a'
,
function
(
event
)
{
event
.
preventDefault
();
window
.
open
(
$
(
this
).
attr
(
'href'
));
});
});
// Page specific items
...
...
resources/views/pages/edit.blade.php
View file @
23e014c
...
...
@@ -19,22 +19,9 @@
</div>
@include('partials/image-manager', ['imageType' => 'gallery', 'uploaded_to' => $page->id])
<div
id=
"entity-selector-wrap"
>
<div
class=
"overlay"
entity-link-selector
>
<div
class=
"popup-body small flex-child"
>
<div
class=
"popup-header primary-background"
>
<div
class=
"popup-title"
>
Entity Select
</div>
<button
type=
"button"
class=
"corner-button neg button"
>
x
</button>
</div>
@include('partials/entity-selector', ['name' => 'entity-selector'])
<div
class=
"popup-footer"
>
<button
type=
"button"
disabled=
"true"
class=
"button entity-link-selector-confirm pos corner-button"
>
Select
</button>
</div>
</div>
</div>
</div>
@include('partials/entity-selector-popup')
<script>
(
function
()
{
...
...
resources/views/pages/form.blade.php
View file @
23e014c
...
...
@@ -73,6 +73,8 @@
<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>
|
<button
class=
"text-button"
type=
"button"
data-action=
"insertEntityLink"
><i
class=
"zmdi zmdi-link"
></i>
Insert Entity Link
</button>
</div>
</div>
...
...
resources/views/partials/entity-selector-popup.blade.php
0 → 100644
View file @
23e014c
<div
id=
"entity-selector-wrap"
>
<div
class=
"overlay"
entity-link-selector
>
<div
class=
"popup-body small flex-child"
>
<div
class=
"popup-header primary-background"
>
<div
class=
"popup-title"
>
Entity Select
</div>
<button
type=
"button"
class=
"corner-button neg button popup-close"
>
x
</button>
</div>
@include('partials/entity-selector', ['name' => 'entity-selector'])
<div
class=
"popup-footer"
>
<button
type=
"button"
disabled=
"true"
class=
"button entity-link-selector-confirm pos corner-button"
>
Select
</button>
</div>
</div>
</div>
</div>
\ No newline at end of file
Please
register
or
sign in
to post a comment