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
2015-10-14 21:46:18 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
7039695b65d45edcfb516482c123f099012faf0f
7039695b
1 parent
1520bde1
Added chrome paste-image-upload. Closes #20.
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
10 deletions
app/Http/Controllers/ImageController.php
public/loading.gif
resources/assets/js/pages/page-form.js
resources/views/pages/create.blade.php
resources/views/pages/edit.blade.php
resources/views/pages/form.blade.php
app/Http/Controllers/ImageController.php
View file @
7039695
...
...
@@ -7,7 +7,6 @@ use Illuminate\Http\Request;
use
Illuminate\Support\Facades\Auth
;
use
Intervention\Image\Facades\Image
as
ImageTool
;
use
Illuminate\Support\Facades\DB
;
use
BookStack\Http\Requests
;
use
BookStack\Image
;
use
BookStack\Repos\PageRepo
;
...
...
@@ -37,13 +36,13 @@ class ImageController extends Controller
public
function
getAll
(
$page
=
0
)
{
$pageSize
=
30
;
$images
=
DB
::
table
(
'images'
)
->
orderBy
(
'created_at'
,
'desc'
)
$images
=
$this
->
image
->
orderBy
(
'created_at'
,
'desc'
)
->
skip
(
$page
*
$pageSize
)
->
take
(
$pageSize
)
->
get
();
foreach
(
$images
as
$image
)
{
$image
->
thumbnail
=
$this
->
getThumbnail
(
$image
,
150
,
150
);
}
$hasMore
=
count
(
DB
::
table
(
'images'
)
->
orderBy
(
'created_at'
,
'desc'
)
->
skip
((
$page
+
1
)
*
$pageSize
)
->
take
(
$pageSize
)
->
get
()
)
>
0
;
$hasMore
=
$this
->
image
->
orderBy
(
'created_at'
,
'desc'
)
->
skip
((
$page
+
1
)
*
$pageSize
)
->
take
(
$pageSize
)
->
count
(
)
>
0
;
return
response
()
->
json
([
'images'
=>
$images
,
'hasMore'
=>
$hasMore
...
...
@@ -105,8 +104,8 @@ class ImageController extends Controller
// Create and save image object
$this
->
image
->
name
=
$name
;
$this
->
image
->
url
=
$imagePath
.
$storageName
;
$this
->
image
->
created_by
=
Auth
::
user
()
->
id
;
$this
->
image
->
updated_by
=
Auth
::
user
()
->
id
;
$this
->
image
->
created_by
=
auth
()
->
user
()
->
id
;
$this
->
image
->
updated_by
=
auth
()
->
user
()
->
id
;
$this
->
image
->
save
();
$this
->
image
->
thumbnail
=
$this
->
getThumbnail
(
$this
->
image
,
150
,
150
);
return
response
()
->
json
(
$this
->
image
);
...
...
public/loading.gif
0 → 100644
View file @
7039695
10.8 KB
resources/assets/js/pages/page-form.js
View file @
7039695
...
...
@@ -9,11 +9,13 @@ module.exports = {
relative_urls
:
false
,
statusbar
:
false
,
menubar
:
false
,
paste_data_images
:
false
,
//height: 700,
extended_valid_elements
:
'pre[*]'
,
automatic_uploads
:
false
,
valid_children
:
"-div[p|pre|h1|h2|h3|h4|h5|h6|blockquote]"
,
plugins
:
"image table textcolor paste link imagetools fullscreen code hr"
,
toolbar
:
"
code undo | styleselect | hr bold italic underline strikethrough superscript subscript | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table image link |
fullscreen"
,
toolbar
:
"
undo redo | styleselect | bold italic underline strikethrough superscript subscript | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table image link hr | code
fullscreen"
,
content_style
:
"body {padding-left: 15px !important; padding-right: 15px !important; margin:0!important; margin-left:auto!important;margin-right:auto!important;}"
,
style_formats
:
[
{
title
:
"Header 1"
,
format
:
"h1"
},
...
...
@@ -22,7 +24,8 @@ module.exports = {
{
title
:
"Header 4"
,
format
:
"h4"
},
{
title
:
"Paragraph"
,
format
:
"p"
},
{
title
:
"Blockquote"
,
format
:
"blockquote"
},
{
title
:
"Code Block"
,
icon
:
"code"
,
format
:
"pre"
}
{
title
:
"Code Block"
,
icon
:
"code"
,
format
:
"pre"
},
{
title
:
"Inline Code"
,
icon
:
"code"
,
inline
:
"code"
}
],
file_browser_callback
:
function
(
field_name
,
url
,
type
,
win
)
{
ImageManager
.
show
(
function
(
image
)
{
...
...
@@ -35,5 +38,60 @@ module.exports = {
win
.
document
.
getElementById
(
field_name
).
fireEvent
(
"onchange"
);
}
});
},
paste_preprocess
:
function
(
plugin
,
args
)
{
var
content
=
args
.
content
;
if
(
content
.
indexOf
(
'<img src="file://'
)
!==
-
1
)
{
args
.
content
=
''
;
}
},
setup
:
function
(
editor
)
{
// Paste image-uploads
editor
.
on
(
'paste'
,
function
(
e
)
{
if
(
e
.
clipboardData
)
{
var
items
=
e
.
clipboardData
.
items
;
if
(
items
){
for
(
var
i
=
0
;
i
<
items
.
length
;
i
++
)
{
if
(
items
[
i
].
type
.
indexOf
(
"image"
)
!==
-
1
)
{
var
file
=
items
[
i
].
getAsFile
();
var
formData
=
new
FormData
();
var
ext
=
'png'
;
var
xhr
=
new
XMLHttpRequest
();
if
(
file
.
name
)
{
var
fileNameMatches
=
file
.
name
.
match
(
/
\.(
.+
)
$/
);
if
(
fileNameMatches
)
{
ext
=
fileNameMatches
[
1
];
}
}
var
id
=
"image-"
+
Math
.
random
().
toString
(
16
).
slice
(
2
);
editor
.
execCommand
(
'mceInsertContent'
,
false
,
'<img src="/loading.gif" id="'
+
id
+
'">'
);
var
remoteFilename
=
"image-"
+
Date
.
now
()
+
"."
+
ext
;
formData
.
append
(
'file'
,
file
,
remoteFilename
);
formData
.
append
(
'_token'
,
document
.
querySelector
(
'meta[name="token"]'
).
getAttribute
(
'content'
));
xhr
.
open
(
'POST'
,
'/upload/image'
);
xhr
.
onload
=
function
()
{
if
(
xhr
.
status
===
200
||
xhr
.
status
===
201
)
{
var
result
=
JSON
.
parse
(
xhr
.
responseText
);
//var newImage = editor.getDoc().getElementById(id);
//newImage.setAttribute('src', result.url);
editor
.
dom
.
setAttrib
(
id
,
'src'
,
result
.
url
);
console
.
log
(
result
);
}
else
{
console
.
log
(
'An error occured uploading the image'
);
console
.
log
(
xhr
.
responseText
);
}
};
xhr
.
send
(
formData
);
}
}
}
}
});
}
};
\ No newline at end of file
...
...
resources/views/pages/create.blade.php
View file @
7039695
...
...
@@ -16,4 +16,5 @@
@endif
</form>
</div>
<image-manager></image-manager>
@stop
\ No newline at end of file
...
...
resources/views/pages/edit.blade.php
View file @
7039695
...
...
@@ -14,5 +14,6 @@
@include('pages/form', ['model' => $page])
</form>
</div>
<image-manager></image-manager>
@stop
\ No newline at end of file
...
...
resources/views/pages/form.blade.php
View file @
7039695
...
...
@@ -35,5 +35,3 @@
@endif
</div>
</div>
<image-manager></image-manager>
\ No newline at end of file
...
...
Please
register
or
sign in
to post a comment