Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cribjs-editor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
cribjs-editor
Commits
9ff7a5c3
Commit
9ff7a5c3
authored
Sep 28, 2020
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EditorPage: Types not supported by editor use a File Input
parent
d3561189
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
24 deletions
+105
-24
gadget/gadget_cribjs_page_editor.html
gadget/gadget_cribjs_page_editor.html
+9
-1
gadget/gadget_cribjs_page_editor.js
gadget/gadget_cribjs_page_editor.js
+96
-23
No files found.
gadget/gadget_cribjs_page_editor.html
View file @
9ff7a5c3
...
...
@@ -49,8 +49,16 @@
</tr>
</table>
</div>
<div
class=
"container-fluid file-upload"
style=
"display:none;"
>
<form
class=
"crib-editor-file-upload form-inline"
>
<div
class=
"form-group"
>
<label>
URL:
<input
name=
"file"
class=
"file form-control"
type=
"file"
></label>
</div>
</form>
</div>
</div>
<div
class=
"container-fluid"
>
<div
class=
"container-fluid
editor-gadget
"
>
<div
data-gadget-url=
"./codemirror.gadget.html"
data-gadget-scope=
"codeeditor"
data-gadget-sandbox=
"public"
></div>
...
...
gadget/gadget_cribjs_page_editor.js
View file @
9ff7a5c3
...
...
@@ -5,6 +5,27 @@
var
CODE_CONTENT_KEY
=
"
text_content
"
;
function
getEditorContent
(
gadget
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
gadget
.
getDeclaredGadget
(
'
codeeditor
'
);
})
.
push
(
function
(
code_editor_gadget
)
{
return
code_editor_gadget
.
getContent
();
});
}
function
getFileContent
(
gadget
)
{
var
file_list
=
gadget
.
props
.
element
.
querySelector
(
"
form.crib-editor-file-upload .file
"
)
.
files
;
if
(
file_list
.
length
===
0
)
{
throw
"
No file Provided, not saving
"
;
}
else
{
return
file_list
[
0
];
}
}
function
saveTextContent
(
gadget
,
event
)
{
var
content
,
url
=
gadget
.
props
.
element
.
querySelector
(
"
form.crib-editor-get .url
"
).
value
,
...
...
@@ -14,13 +35,18 @@
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
gadget
.
getDeclaredGadget
(
'
codeeditor
'
);
})
.
push
(
function
(
code_editor_gadget
)
{
return
code_editor_gadget
.
getContent
();
if
(
gadget
.
props
.
use_editor
)
{
return
getEditorContent
(
gadget
);
}
else
{
return
getFileContent
(
gadget
);
}
})
.
push
(
function
(
data
)
{
if
(
gadget
.
props
.
use_editor
)
{
content
=
data
[
CODE_CONTENT_KEY
]
||
""
;
}
else
{
content
=
data
;
}
return
gadget
.
crib_sw_put
(
url
,
{
content
:
content
,
type
:
mimetype
});
})
.
push
(
function
()
{
...
...
@@ -31,38 +57,84 @@
message
:
"
Saved
"
+
url
+
"
files at
"
+
Date
()
});
}
gadget
.
props
.
element
.
querySelector
(
"
form.crib-editor-file-upload
"
).
reset
();
gadget
.
props
.
element
.
querySelector
(
"
.crib-editor-save-status
"
)
.
textContent
=
"
Saved
"
+
url
+
"
files at
"
+
Date
();
})
.
push
(
undefined
,
function
(
error
)
{
gadget
.
props
.
element
.
querySelector
(
"
.crib-editor-save-status
"
)
.
textContent
=
error
;
});
}
function
displayProperEditor
(
gadget
)
{
if
(
gadget
.
props
.
use_editor
)
{
gadget
.
props
.
element
.
querySelector
(
"
div.file-upload
"
)
.
style
=
"
display:none;
"
;
gadget
.
props
.
element
.
querySelector
(
"
div.editor-gadget
"
)
.
style
=
""
;
}
else
{
gadget
.
props
.
element
.
querySelector
(
"
div.file-upload
"
)
.
style
=
""
;
gadget
.
props
.
element
.
querySelector
(
"
div.editor-gadget
"
)
.
style
=
"
display:none;
"
;
}
}
function
displayDataInCodeEditor
(
gadget
,
code_editor
,
data
,
type
)
{
return
RSVP
.
Queue
()
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsText
(
data
,
type
);
})
.
push
(
function
(
evt
)
{
return
code_editor
.
render
({
key
:
CODE_CONTENT_KEY
,
value
:
evt
.
target
.
result
,
mode
:
type
});
})
.
push
(
function
()
{
gadget
.
props
.
use_editor
=
true
;
displayProperEditor
(
gadget
);
});
}
function
displayFile
(
gadget
,
data
,
type
)
{
gadget
.
props
.
element
.
querySelector
(
"
form.crib-editor-file-upload
"
).
reset
();
gadget
.
props
.
use_editor
=
false
;
displayProperEditor
(
gadget
);
}
function
getUrlTextContent
(
gadget
,
event
,
url
)
{
var
type
;
var
type
,
code_editor
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
gadget
.
crib_sw_get
(
url
);
return
gadget
.
getDeclaredGadget
(
'
codeeditor
'
);
})
.
push
(
function
(
data
)
{
.
push
(
function
(
editor
)
{
code_editor
=
editor
;
return
RSVP
.
all
([
editor
.
getSupportedTypeList
(),
gadget
.
crib_sw_get
(
url
)
]);
})
.
push
(
function
(
result_list
)
{
var
data
=
result_list
[
1
];
type
=
data
.
type
;
if
(
!
type
||
type
===
"
application/octet-stream
"
)
{
type
=
mimeType
.
lookup
(
url
,
false
,
"
application/octet-stream
"
);
}
return
jIO
.
util
.
readBlobAsText
(
data
,
type
);
})
.
push
(
function
(
evt
)
{
return
RSVP
.
all
([
evt
.
target
.
result
,
gadget
.
getDeclaredGadget
(
'
codeeditor
'
)
]);
gadget
.
props
.
element
.
querySelector
(
"
form.crib-editor-save .mimetype
"
)
.
value
=
type
;
if
(
result_list
[
0
].
indexOf
(
type
)
!==
-
1
)
{
return
displayDataInCodeEditor
(
gadget
,
code_editor
,
data
,
type
);
}
else
{
return
displayFile
(
gadget
,
data
,
type
);
}
})
.
push
(
function
(
data_list
)
{
gadget
.
props
.
element
.
querySelector
(
"
form.crib-editor-save .mimetype
"
).
value
=
type
;
return
data_list
[
1
].
render
({
key
:
CODE_CONTENT_KEY
,
value
:
data_list
[
0
],
mode
:
type
});
},
function
(
error
)
{
.
push
(
undefined
,
function
(
error
)
{
gadget
.
props
.
element
.
querySelector
(
"
.crib-editor-save-status
"
)
.
textContent
=
error
;
});
...
...
@@ -74,6 +146,7 @@
return
g
.
getElement
()
.
push
(
function
(
element
)
{
g
.
props
.
element
=
element
;
g
.
props
.
use_editor
=
true
;
g
.
props
.
start_deferred
=
RSVP
.
defer
();
});
})
...
...
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