-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
421 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<title></title> | ||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> | ||
<script type="text/javascript" src="../internal.js?04dbe7f0"></script> | ||
<style type="text/css"> | ||
.wrapper { | ||
width: 600px; | ||
padding: 10px; | ||
height: 352px; | ||
overflow: hidden; | ||
position: relative; | ||
border-bottom: 1px solid #d7d7d7; | ||
} | ||
|
||
.wrapper .file-upload { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.wrapper .file-upload .file-tip { | ||
color: #999; | ||
font-size: 12px; | ||
padding-left: 10px; | ||
flex-grow: 1; | ||
} | ||
|
||
.wrapper .file-manual { | ||
background: #EEE; | ||
padding: 10px; | ||
border-radius: 5px; | ||
margin-top: 10px; | ||
line-height: 2; | ||
} | ||
|
||
.wrapper .file-manual .title { | ||
font-weight: bold; | ||
font-size: 120%; | ||
} | ||
|
||
.wrapper .file-manual .body { | ||
} | ||
|
||
.wrapper .file-manual .body li { | ||
list-style: disc; | ||
margin-left: 20px; | ||
} | ||
|
||
.wrapper .upload-button { | ||
width: 100px; | ||
height: 30px; | ||
background-color: #F8F8F8; | ||
border: 1px solid #EEE; | ||
border-radius: 4px; | ||
text-align: center; | ||
line-height: 28px; | ||
cursor: pointer; | ||
position: relative; | ||
flex-shrink: 0; | ||
} | ||
|
||
.wrapper .upload-button .text { | ||
display: inline-block; | ||
vertical-align: middle; | ||
} | ||
|
||
.wrapper .upload-button input { | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
opacity: 0; | ||
cursor: pointer; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
.wrapper .file-result { | ||
border: 1px solid #333; | ||
padding: 10px; | ||
border-radius: 5px; | ||
position: absolute; | ||
left: 10px; | ||
right: 10px; | ||
top: 50px; | ||
background: #FFF; | ||
bottom: 10px; | ||
overflow: auto; | ||
display: none; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="wrapper"> | ||
<div class="file-upload"> | ||
<div class="upload-button"> | ||
<div class="text">选择本地文件</div> | ||
<input type="file" id="contentImport"/> | ||
</div> | ||
<div class="file-tip"></div> | ||
</div> | ||
<div class="file-manual"> | ||
<div class="title"> | ||
支持文档格式 | ||
</div> | ||
<div class="body"> | ||
<ul> | ||
<li><b>Word</b>:docx</li> | ||
<li><b>Markdown</b>:md</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div class="file-result"></div> | ||
</div> | ||
<script src="../../third-party/jquery-1.10.2.js?25f4b625"></script> | ||
<script src="https://cdn.bootcdn.net/ajax/libs/mammoth/1.6.0/mammoth.browser.min.js"></script> | ||
<script src="https://cdn.bootcdn.net/ajax/libs/showdown/2.1.0/showdown.min.js"></script> | ||
<script type="text/javascript" src="contentimport.js?07c12a80"></script> | ||
<script type="text/javascript"> | ||
utils.domReady(function () { | ||
var options = {}; | ||
var callbacks = {}; | ||
contentImport.init(options, callbacks); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<!DOCTYPE html> | ||
<head> | ||
<title></title> | ||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> | ||
<script type="text/javascript" src="../internal.js?aea0c61c"></script> | ||
<style type="text/css"> | ||
.wrapper { | ||
width: 600px; | ||
padding: 10px; | ||
height: 352px; | ||
overflow: hidden; | ||
position: relative; | ||
border-bottom: 1px solid #d7d7d7; | ||
} | ||
|
||
.wrapper .file-upload { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.wrapper .file-upload .file-tip { | ||
color: #999; | ||
font-size: 12px; | ||
padding-left: 10px; | ||
flex-grow: 1; | ||
} | ||
|
||
.wrapper .file-manual { | ||
background: #EEE; | ||
padding: 10px; | ||
border-radius: 5px; | ||
margin-top: 10px; | ||
line-height: 2; | ||
} | ||
|
||
.wrapper .file-manual .title { | ||
font-weight: bold; | ||
font-size: 120%; | ||
} | ||
|
||
.wrapper .file-manual .body { | ||
} | ||
|
||
.wrapper .file-manual .body li { | ||
list-style: disc; | ||
margin-left: 20px; | ||
} | ||
|
||
.wrapper .upload-button { | ||
width: 100px; | ||
height: 30px; | ||
background-color: #F8F8F8; | ||
border: 1px solid #EEE; | ||
border-radius: 4px; | ||
text-align: center; | ||
line-height: 28px; | ||
cursor: pointer; | ||
position: relative; | ||
flex-shrink: 0; | ||
} | ||
|
||
.wrapper .upload-button .text { | ||
display: inline-block; | ||
vertical-align: middle; | ||
} | ||
|
||
.wrapper .upload-button input { | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
opacity: 0; | ||
cursor: pointer; | ||
height: 100%; | ||
width: 100%; | ||
} | ||
|
||
.wrapper .file-result { | ||
border: 1px solid #333; | ||
padding: 10px; | ||
border-radius: 5px; | ||
position: absolute; | ||
left: 10px; | ||
right: 10px; | ||
top: 50px; | ||
background: #FFF; | ||
bottom: 10px; | ||
overflow: auto; | ||
display: none; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="wrapper"> | ||
<div class="file-upload"> | ||
<div class="upload-button"> | ||
<div class="text">选择本地文件</div> | ||
<input type="file" id="contentImport"/> | ||
</div> | ||
<div class="file-tip"></div> | ||
</div> | ||
<div class="file-manual"> | ||
<div class="title"> | ||
支持文档格式 | ||
</div> | ||
<div class="body"> | ||
<ul> | ||
<li><b>Word</b>:docx</li> | ||
<li><b>Markdown</b>:md</li> | ||
</ul> | ||
</div> | ||
</div> | ||
<div class="file-result"></div> | ||
</div> | ||
<script src="../../third-party/jquery-1.10.2.js?628072e7"></script> | ||
<script src="https://cdn.bootcdn.net/ajax/libs/mammoth/1.6.0/mammoth.browser.min.js"></script> | ||
<script src="https://cdn.bootcdn.net/ajax/libs/showdown/2.1.0/showdown.min.js"></script> | ||
<script type="text/javascript" src="contentimport.js?50c896a4"></script> | ||
<script type="text/javascript"> | ||
utils.domReady(function () { | ||
var options = {}; | ||
var callbacks = {}; | ||
contentImport.init(options, callbacks); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
var contentImport = {}; | ||
var g = $G; | ||
|
||
contentImport.data = { | ||
result: null, | ||
}; | ||
contentImport.init = function (opt, callbacks) { | ||
addUploadButtonListener(); | ||
addOkListener(); | ||
}; | ||
|
||
function processWord(file) { | ||
$('.file-tip').html('正在转换Word文件,请稍后...'); | ||
$('.file-result').html('').hide(); | ||
var reader = new FileReader(); | ||
reader.onload = function (loadEvent) { | ||
mammoth.convertToHtml({ | ||
arrayBuffer: loadEvent.target.result | ||
}) | ||
.then(function displayResult(result) { | ||
$('.file-tip').html('转换成功'); | ||
contentImport.data.result = result.value; | ||
$('.file-result').html(result.value).show(); | ||
}, function (error) { | ||
$('.file-tip').html('Word文件转换失败:' + error); | ||
}); | ||
}; | ||
reader.onerror = function (loadEvent) { | ||
$('.file-tip').html('Word文件转换失败:' + loadEvent); | ||
}; | ||
reader.readAsArrayBuffer(file); | ||
} | ||
|
||
function processMarkdown(file) { | ||
$('.file-tip').html('正在转换Markdown文件,请稍后...'); | ||
$('.file-result').html('').hide(); | ||
var reader = new FileReader(); | ||
reader.onload = function (loadEvent) { | ||
var converter = new showdown.Converter(); | ||
var html = converter.makeHtml(loadEvent.target.result); | ||
$('.file-tip').html('转换成功'); | ||
contentImport.data.result = html; | ||
$('.file-result').html(html).show(); | ||
}; | ||
reader.onerror = function (loadEvent) { | ||
$('.file-tip').html('Markdown文件转换失败:' + loadEvent); | ||
}; | ||
reader.readAsText(file, "UTF-8"); | ||
} | ||
|
||
function addUploadButtonListener() { | ||
g('contentImport').addEventListener('change', function () { | ||
const file = this.files[0]; | ||
const fileName = file.name; | ||
const fileExt = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase(); | ||
switch (fileExt) { | ||
case 'docx': | ||
case 'doc': | ||
processWord(file); | ||
break; | ||
case 'md': | ||
processMarkdown(file); | ||
break; | ||
default: | ||
$('.file-tip').html('不支持的文件格式:' + fileExt); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
function addOkListener() { | ||
dialog.onok = function () { | ||
if (!contentImport.data.result) { | ||
alert('请先上传文件识别内容'); | ||
return false; | ||
} | ||
editor.fireEvent('saveScene'); | ||
editor.execCommand("inserthtml", contentImport.data.result); | ||
editor.fireEvent('saveScene'); | ||
}; | ||
dialog.oncancel = function () { | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.