image manager optimization, i18n
This commit is contained in:
@ -14,6 +14,12 @@ type Album struct {
|
||||
BaseController
|
||||
}
|
||||
|
||||
// 图片管理, iframe
|
||||
func (c Album) Index() revel.Result {
|
||||
c.SetLocale();
|
||||
return c.RenderTemplate("album/index.html")
|
||||
}
|
||||
|
||||
// all albums by userId
|
||||
func (c Album) GetAlbums() revel.Result {
|
||||
re := albumService.GetAlbums(c.GetUserId())
|
||||
|
@ -146,9 +146,10 @@ func init() {
|
||||
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Note{})
|
||||
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Share{})
|
||||
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &User{})
|
||||
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Album{})
|
||||
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &File{})
|
||||
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Attach{})
|
||||
// revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Blog{})
|
||||
// revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &Blog{})
|
||||
revel.InterceptFunc(AuthInterceptor, revel.BEFORE, &NoteContentHistory{})
|
||||
|
||||
revel.OnAppStart(func() {
|
||||
|
166
app/views/album/index.html
Normal file
166
app/views/album/index.html
Normal file
@ -0,0 +1,166 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<title>
|
||||
Leanote Album Image Manager
|
||||
</title>
|
||||
|
||||
<link href="/css/bootstrap-min.css" rel="stylesheet" />
|
||||
<link href="/css/font-awesome-4.2.0/css/font-awesome-min.css" rel="stylesheet" />
|
||||
<link href="/public/album/css/style-min.css" rel="stylesheet" />
|
||||
|
||||
</head>
|
||||
<body class="md" id="body">
|
||||
<div style="margin: 3px;">
|
||||
<div class="holder"></div>
|
||||
|
||||
<div class="tabs">
|
||||
<ul id="myTab" class="nav nav-tabs">
|
||||
<li class="active"><a href="#images" data-toggle="tab">{{leaMsg . "Images"}}</a></li>
|
||||
<li class=""><a href="#uploadTab" data-toggle="tab">{{leaMsg . "Upload"}}</a></li>
|
||||
<li class=""><a href="#url" data-toggle="tab">{{leaMsg . "Image URL"}}</a></li>
|
||||
</ul>
|
||||
<div id="myTabContent" class="tab-content">
|
||||
<div class="tab-pane fade active in" id="images">
|
||||
<!-- tools -->
|
||||
<div>
|
||||
<form class="form-inline" role="form">
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="albums">{{leaMsg . "Albums"}}:</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<select class="form-control" id="albumsForList">
|
||||
<option value="">{{leaMsg . "Default"}}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input class="form-control" type="text" id="key" placeholder="{{leaMsg . "File title search"}}"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<a href="javascript:;" title="refresh" id="refresh"><span class="fa fa-refresh"></span></a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div id="imagePage">
|
||||
<ul id="imageList" class="clearfix">
|
||||
</ul>
|
||||
|
||||
<!-- pagination -->
|
||||
<div id="paginationContainer">
|
||||
<ul class="pagination">
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="imageMask">
|
||||
<div id="noImages">
|
||||
<p>{{msg . "No Images"}}!</p>
|
||||
<btn class="btn btn-default" id="goAddImageBtn">{{leaMsg . "Go to upload images"}}</btn>
|
||||
</div>
|
||||
<div id="loading">
|
||||
loading....
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade" id="uploadTab">
|
||||
<div>
|
||||
<form class="form-inline" role="form">
|
||||
<div class="form-group" id="albumSelect">
|
||||
<label class="control-label" for="albums">{{leaMsg . "Albums"}}:</label>
|
||||
|
||||
<select class="form-control" id="albumsForUpload">
|
||||
<option value="">{{leaMsg . "Default"}}</option>
|
||||
</select>
|
||||
|
||||
<a href="javascript:;" id="deleteAlbumBtn">{{leaMsg . "Delete"}}</a> |
|
||||
<a href="javascript:;" id="renameAlbumBtn">{{leaMsg . "Rename"}}</a> |
|
||||
<a href="javascript:;" id="addAlbumBtn">{{leaMsg . "Add"}}</a>
|
||||
</div>
|
||||
|
||||
<!-- rename or add album -->
|
||||
<div class="form-group" style="display: none" id="addOrUpdateAlbumForm">
|
||||
<input type="text" class="form-control" style="width: 150px" id="albumName">
|
||||
<button class="btn btn-success" type="button" id="addOrUpdateAlbumBtn">{{leaMsg . "Add Album"}}</button>
|
||||
<button class="btn btn-default" type="button" id="cancelAlbumBtn">{{leaMsg . "Cancel"}}</button>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<span id="msg" class="alert alert-success" style="padding: 3px; display: none"></span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<form id="upload" method="post" action="/file/uploadImageLeaui" enctype="multipart/form-data" style="margin-top: 5px;">
|
||||
<div id="drop">
|
||||
<a class="btn btn-default">
|
||||
{{leaMsg . "Click to upload images Or Drop images to here"}}
|
||||
</a>
|
||||
<input type="file" name="file" multiple />
|
||||
</div>
|
||||
<ul id="upload-msg">
|
||||
</ul>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="url">
|
||||
<form class="form-inline" id="imageUrlForm" style="">
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="imageUrl">{{leaMsg . "Image URL"}}:</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" id="imageUrl" size="51"/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-success" id="addImageUrlBtn">{{leaMsg . "Add Image"}}</button>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="alert alert-danger" id="msgForUrl"
|
||||
style="display: none; padding: 5px; width: 150px;">
|
||||
{{leaMsg . "Can't load this url"}}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul id="preview" class="clearfix">
|
||||
</ul>
|
||||
|
||||
<!--
|
||||
<div id="previewAttrs" style="margin-left: 10px">
|
||||
<form class="form-inline" role="form">
|
||||
<div class="form-group">
|
||||
<input class="form-control" id="attrTitle" placeholder="title" size="20" disabled/>
|
||||
<input class="form-control" id="attrWidth" placeholder="width" size="5" disabled/> X
|
||||
<input class="form-control" id="attrHeight" placeholder="height" size="5" disabled/>
|
||||
<label><input type="checkbox" value="1" id="attrConstrain" disabled/> Constrain proportions</label>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
-->
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
// javascript global configration
|
||||
var G = {};
|
||||
G.imageSrcPrefix = 'upload';
|
||||
G.perPageItems = 12;
|
||||
G.maxSelected = 1;
|
||||
var UrlPrefix = '{{.siteUrl}}';
|
||||
</script>
|
||||
|
||||
<!--
|
||||
<script src="/js/jquery-1.9.0.min.js"></script>
|
||||
<script src="/js/bootstrap-min.js"></script>
|
||||
<script src="/js/plugins/libs-min/fileupload.js"></script>
|
||||
<script src="/js/jquery.pagination.js"></script>
|
||||
<script src="/public/album/js/main.js"></script>
|
||||
-->
|
||||
|
||||
<script src="/public/album/js/main.all.js"></script>
|
||||
|
||||
</html>
|
1
public/album/css/style-min.css
vendored
Normal file
1
public/album/css/style-min.css
vendored
Normal file
@ -0,0 +1 @@
|
||||
#drop,#imageList li,#upload{position:relative}#imageMask,#upload-msg{position:absolute;top:0}*{font-family:'Open Sans','Helvetica Neue',Arial,'Hiragino Sans GB','Microsoft YaHei','WenQuanYi Micro Hei',sans-serif}#drop{width:99%;min-height:260px;border:1px dotted #000;z-index:2;text-align:center}#drop.in{border:2px solid #000}#drop a{left:33%;top:105px;z-index:15;position:absolute}#drop input{display:none}#upload-msg{list-style-type:none;padding-left:0;margin-left:0;right:10px;width:300px;max-height:240px;overflow:auto;z-index:3}#imageList li,#preview li,.md{overflow:hidden}.tab-pane{padding:10px}#paginationContainer{text-align:right}#imageList{margin:10px 0 0;padding:0;height:196px}#imageList li{display:inline-block;float:left;padding:0;margin:0 3px 3px 0;height:90px;width:122px;border:1px solid #eee}#imageList li .a-img{line-height:80px;display:block;text-align:center}#imageList li:hover{border:1px solid #FF7300}#imageList li.selected{border:2px solid #FF7300}#imageList li img{max-width:100%;vertical-align:middle}#imageList li .tools{position:absolute;bottom:0;left:0;right:0;background-color:#fff;padding-right:2px;text-align:right;opacity:.7}.tools .file-title{width:100px;height:20px;white-space:nowrap;text-overflow:ellipsis;overflow:hidden;text-align:left}#imageList li:hover .tools{display:block;opacity:.9}.alert{padding:5px;margin-bottom:3px}#preview{margin:3px 0 3px 10px;padding:5px 0 0;border-top:1px solid #eee}#preview li{position:relative;display:inline-block;float:left;border:1px solid #E6E5E3;background-color:#FFF;width:64px;height:64px;margin-right:10px;line-height:64px;text-align:center;color:#E1E1E1;font-size:28px;cursor:pointer}#preview li:hover{border:1px solid #FF7300}#preview li.selected{border:2px solid #FF7300}#preview li .tools{position:absolute;bottom:0;right:0;left:0;height:15px;line-height:15px;font-size:14px;text-align:right}#preview li .tools a{color:red}#imagePage{position:relative}#imageMask{background:#fff;left:0;right:0;bottom:20px;font-size:18px;text-align:center;display:none;z-index:2}#previewAttrs .form-control{width:auto}#previewAttrs label{font-weight:400}@media screen and (max-width:700px){#previewAttrs{display:none}#drop{min-height:initial;padding:10px 0}#drop a{position:initial;margin:auto}#url form{margin:0!important}.form-inline .form-group{display:inline-block;margin-bottom:0;vertical-align:middle}.form-inline .form-control{width:auto;display:inline-block}#preview li:nth-child(10),#preview li:nth-child(3n),#preview li:nth-child(4n),#preview li:nth-child(5),#preview li:nth-child(7){display:none}#imageList li{width:90px}}#imageUrlForm{min-height:260px;text-align:center;padding-top:100px}.md{position:relative;height:350px}.md #previewAttrs{display:none}.md #preview{border:none;position:absolute;bottom:0;left:0;z-index:3}.md #drop{min-height:250px}#albumsForUpload{width:150px}
|
243
public/album/css/style.css
Normal file
243
public/album/css/style.css
Normal file
@ -0,0 +1,243 @@
|
||||
* {
|
||||
font-family: 'Open Sans', 'Helvetica Neue', Arial, 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;
|
||||
}
|
||||
/* upload */
|
||||
#upload {
|
||||
position: relative;
|
||||
}
|
||||
#drop {
|
||||
position: relative;
|
||||
width: 99%;
|
||||
min-height: 260px;
|
||||
border: 1px dotted #000000;
|
||||
z-index: 2;
|
||||
text-align: center;
|
||||
}
|
||||
#drop.in {
|
||||
border: 2px solid #000000;
|
||||
}
|
||||
#drop a {
|
||||
left: 33%;
|
||||
top: 105px;
|
||||
z-index: 15;
|
||||
position: absolute;
|
||||
}
|
||||
#drop input {
|
||||
display: none;
|
||||
}
|
||||
#upload-msg {
|
||||
list-style-type: none;
|
||||
padding-left: 0px;
|
||||
margin-left: 0px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 10px;
|
||||
width: 300px;
|
||||
max-height: 240px;
|
||||
overflow: auto;
|
||||
z-index: 3;
|
||||
}
|
||||
/**/
|
||||
.tab-pane {
|
||||
padding: 10px;
|
||||
}
|
||||
#paginationContainer {
|
||||
text-align: right;
|
||||
}
|
||||
#imageList {
|
||||
margin: 0;
|
||||
margin-top: 10px;
|
||||
padding: 0;
|
||||
height: 196px;
|
||||
}
|
||||
#imageList li {
|
||||
display: inline-block;
|
||||
float: left;
|
||||
padding: 0;
|
||||
margin: 0 3px 3px 0;
|
||||
position: relative;
|
||||
height: 90px;
|
||||
width: 122px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #eee;
|
||||
}
|
||||
#imageList li .a-img {
|
||||
line-height: 80px;
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
#imageList li:hover {
|
||||
border: 1px solid #FF7300;
|
||||
}
|
||||
#imageList li.selected {
|
||||
border: solid 2px #FF7300;
|
||||
}
|
||||
#imageList li img {
|
||||
max-width: 100%;
|
||||
vertical-align: middle;
|
||||
}
|
||||
#imageList li .tools {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background-color: #fff;
|
||||
padding-right: 2px;
|
||||
text-align: right;
|
||||
opacity: 0.7;
|
||||
}
|
||||
.tools .file-title {
|
||||
width: 100px;
|
||||
height: 20px;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
text-align: left;
|
||||
}
|
||||
#imageList li:hover .tools {
|
||||
display: block;
|
||||
opacity: 0.9;
|
||||
}
|
||||
.alert {
|
||||
padding: 5px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
.tabs {
|
||||
/*height: 350px;*/
|
||||
}
|
||||
#preview {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
margin-left: 10px;
|
||||
margin-top: 3px;
|
||||
margin-bottom: 3px;
|
||||
padding-top: 5px;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
#preview li {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
float: left;
|
||||
border: solid 1px #E6E5E3;
|
||||
background-color: #FFF;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
overflow: hidden;
|
||||
margin-right: 10px;
|
||||
line-height: 64px;
|
||||
text-align: center;
|
||||
/*font-style: italic;*/
|
||||
color: #E1E1E1;
|
||||
font-size: 28px;
|
||||
cursor: pointer;
|
||||
}
|
||||
#preview li:hover {
|
||||
border: 1px solid #FF7300;
|
||||
}
|
||||
#preview li.selected {
|
||||
border: solid 2px #FF7300;
|
||||
}
|
||||
#preview li .tools {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
left: 0;
|
||||
height: 15px;
|
||||
line-height: 15px;
|
||||
font-size: 14px;
|
||||
text-align: right;
|
||||
}
|
||||
#preview li .tools a {
|
||||
color: red;
|
||||
}
|
||||
/**/
|
||||
#imagePage {
|
||||
position: relative;
|
||||
}
|
||||
#imageMask {
|
||||
position: absolute;
|
||||
background: #fff;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 20px;
|
||||
font-size: 18px;
|
||||
text-align: center;
|
||||
display: none;
|
||||
z-index: 2;
|
||||
}
|
||||
/**/
|
||||
#previewAttrs .form-control {
|
||||
width: auto;
|
||||
}
|
||||
#previewAttrs label {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
@media screen and (max-width:700px) {
|
||||
#previewAttrs {
|
||||
display: none;
|
||||
}
|
||||
#drop {
|
||||
min-height: initial;
|
||||
padding: 10px 0;
|
||||
}
|
||||
#drop a {
|
||||
position: initial;
|
||||
margin: auto;
|
||||
}
|
||||
#url form {
|
||||
margin: 0 !important;
|
||||
margin: auto;
|
||||
}
|
||||
.form-inline .form-group {
|
||||
display: inline-block;
|
||||
margin-bottom: 0;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.form-inline .form-control {
|
||||
width: auto;
|
||||
display: inline-block;
|
||||
}
|
||||
#preview li:nth-child(3n),
|
||||
#preview li:nth-child(4n),
|
||||
#preview li:nth-child(5),
|
||||
#preview li:nth-child(7),
|
||||
#preview li:nth-child(10)
|
||||
{
|
||||
display: none;
|
||||
}
|
||||
#imageList li {
|
||||
width: 90px;
|
||||
}
|
||||
}
|
||||
#imageUrlForm {
|
||||
min-height: 260px;
|
||||
text-align: center;
|
||||
padding-top: 100px;
|
||||
}
|
||||
|
||||
.md {
|
||||
position: relative;
|
||||
height: 350px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.md #previewAttrs {
|
||||
display: none;
|
||||
|
||||
}
|
||||
.md #preview {
|
||||
border: none;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
.md #drop {
|
||||
min-height: 250px;
|
||||
}
|
||||
|
||||
#albumsForUpload {
|
||||
width: 150px;
|
||||
}
|
BIN
public/album/images/ajax-loader.gif
Normal file
BIN
public/album/images/ajax-loader.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 723 B |
7
public/album/js/main.all.js
Normal file
7
public/album/js/main.all.js
Normal file
File diff suppressed because one or more lines are too long
865
public/album/js/main.js
Normal file
865
public/album/js/main.js
Normal file
@ -0,0 +1,865 @@
|
||||
function log(o) {
|
||||
// console.log(o);
|
||||
}
|
||||
function retIsOk(ret) {
|
||||
if(ret && typeof ret == "object" && ret.Ok == 1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
var urlPrefix = UrlPrefix;
|
||||
var getMsg = parent.getMsg;
|
||||
if (!getMsg) {
|
||||
getMsg = function(msg) {
|
||||
return msg;
|
||||
};
|
||||
}
|
||||
|
||||
// load image
|
||||
function getImageSize(url, callback) {
|
||||
var img = document.createElement('img');
|
||||
|
||||
function done(width, height) {
|
||||
img.parentNode.removeChild(img);
|
||||
callback({width: width, height: height});
|
||||
}
|
||||
|
||||
img.onload = function() {
|
||||
done(img.clientWidth, img.clientHeight);
|
||||
};
|
||||
|
||||
img.onerror = function() {
|
||||
done();
|
||||
};
|
||||
|
||||
img.src = url;
|
||||
|
||||
var style = img.style;
|
||||
style.visibility = 'hidden';
|
||||
style.position = 'fixed';
|
||||
style.bottom = style.left = 0;
|
||||
style.width = style.height = 'auto';
|
||||
|
||||
document.body.appendChild(img);
|
||||
}
|
||||
|
||||
var o = {
|
||||
maxSelected: G.maxSelected,
|
||||
selectedZoneO:$("#preview"),
|
||||
previewO: $("#preview"),
|
||||
selectedImages:[], // selected urls
|
||||
imageAttrs: {}, // src => {width, height, title}
|
||||
|
||||
pageNum: 1,
|
||||
|
||||
pagination: function(count) {
|
||||
var self = this;
|
||||
$(".pagination").pagination(count, {
|
||||
items_per_page: G.perPageItems,
|
||||
prev_text: getMsg('Prev'),
|
||||
next_text: getMsg('Next'),
|
||||
callback: function(pageNum) {
|
||||
self.pageNum = pageNum+1;
|
||||
self.renderImages($("#albumsForList").val(), self.pageNum, false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
showMsg: function(msg) {
|
||||
$("#msg").html(msg).css("display", "inline");
|
||||
setTimeout(function() {
|
||||
$("#msg").fadeOut();
|
||||
}, 2000);
|
||||
},
|
||||
|
||||
pageAddAlbum: function(ret) {
|
||||
var html = '<option value="' + ret.AlbumId + '">' + ret.Name + '</option>';
|
||||
$("#albumsForUpload").append(html).val(ret.AlbumId);
|
||||
$("#albumsForList").append(html);
|
||||
},
|
||||
pageUpdateAlbum: function(albumId, albumName) {
|
||||
$('option[value="' + albumId + '"]').html(albumName);
|
||||
},
|
||||
// add, delete, update album
|
||||
processAlbum: function() {
|
||||
var self = this;
|
||||
var isAddAlbum = true;
|
||||
var curAlbum = "";
|
||||
function toggleAddAlbum() {
|
||||
if($("#addOrUpdateAlbumForm").is(":hidden")) {
|
||||
$("#addOrUpdateAlbumForm").show();
|
||||
$("#albumSelect").hide();
|
||||
} else {
|
||||
$("#addOrUpdateAlbumForm").hide();
|
||||
$("#albumSelect").show();
|
||||
}
|
||||
}
|
||||
// rename
|
||||
$("#renameAlbumBtn").click(function(){
|
||||
curAlbum = $("#albumsForUpload").val();
|
||||
if(!curAlbum) {
|
||||
alert(getMsg("Cannot rename default album"));
|
||||
return;
|
||||
}
|
||||
toggleAddAlbum();
|
||||
$("#addOrUpdateAlbumBtn").html(getMsg("Rename Album"));
|
||||
$("#albumName").val($("#albumsForUpload option:selected").html()).focus();
|
||||
isAddAlbum = false;
|
||||
});
|
||||
// add album
|
||||
$("#addAlbumBtn").click(function() {
|
||||
toggleAddAlbum();
|
||||
$("#addOrUpdateAlbumBtn").html(getMsg("Add Album"));
|
||||
$("#albumName").val("").focus();
|
||||
isAddAlbum = true;
|
||||
});
|
||||
$("#cancelAlbumBtn").click(function() {
|
||||
toggleAddAlbum();
|
||||
});
|
||||
// add or update album
|
||||
$("#addOrUpdateAlbumBtn").click(function() {
|
||||
var albumName = $("#albumName").val();
|
||||
if(!albumName) {
|
||||
$("#albumName").focus();
|
||||
return;
|
||||
}
|
||||
if(isAddAlbum) {
|
||||
$.get("/album/addAlbum", {name: albumName}, function(ret) {
|
||||
if(typeof ret == "object" && ret.AlbumId != "") {
|
||||
$("#albumName").val("");
|
||||
self.showMsg(getMsg("Add Success!"));
|
||||
self.pageAddAlbum(ret);
|
||||
|
||||
setTimeout(function() {
|
||||
toggleAddAlbum();
|
||||
}, 200);
|
||||
} else {
|
||||
alert(getMsg("error"));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$.get("/album/updateAlbum", {albumId: curAlbum, name: albumName}, function(ret) {
|
||||
if(typeof ret == "boolean" && ret) {
|
||||
$("#albumName").val("");
|
||||
self.showMsg(getMsg("Rename Success!"));
|
||||
self.pageUpdateAlbum(curAlbum, albumName);
|
||||
|
||||
setTimeout(function() {
|
||||
toggleAddAlbum();
|
||||
}, 200);
|
||||
} else {
|
||||
alert(getMsg("error!"));
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
// delete album
|
||||
$("#deleteAlbumBtn").click(function() {
|
||||
var albumId = $("#albumsForUpload").val();
|
||||
if(!albumId) {
|
||||
alert(getMsg("Cannot delete default album"));
|
||||
return;
|
||||
}
|
||||
$.get("/album/deleteAlbum", {albumId: albumId}, function(ret) {
|
||||
if(typeof ret == "object" && ret.Ok == true) {
|
||||
self.showMsg(getMsg("Delete Success!"));
|
||||
// delete this album from select
|
||||
$("#albumsForUpload option[value='" + albumId + "']").remove();
|
||||
|
||||
// if the albumsForList has select this album, it must refresh list after delete it;
|
||||
if($("#albumsForList").val() == albumId) {
|
||||
self.needRefresh = true;
|
||||
}
|
||||
|
||||
$("#albumsForList option[value='" + albumId + "']").remove();
|
||||
|
||||
} else {
|
||||
alert(getMsg("This album has images, please delete it's images at first."));
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
renderAlbums: function() {
|
||||
var self = this;
|
||||
$.get("/album/getAlbums", function(ret) {
|
||||
if(!ret) return;
|
||||
var html = "";
|
||||
for(var i in ret) {
|
||||
var each = ret[i];
|
||||
var option = '<option value="' + each.AlbumId + '">' + each.Name+ '</option>';
|
||||
html += option;
|
||||
}
|
||||
|
||||
$("#albumsForUpload").append(html);
|
||||
$("#albumsForList").append(html);
|
||||
|
||||
var albumId = $("#albumsForList").val();
|
||||
self.renderImages(albumId, 1, true);
|
||||
});
|
||||
},
|
||||
|
||||
imageMaskO: $("#imageMask"),
|
||||
noImagesO: $("#noImages"),
|
||||
loadingO: $("#loading"),
|
||||
|
||||
loadingStart: function() {
|
||||
if(this.imageMaskO.is(":hidden")) {
|
||||
this.imageMaskO.css("opacity", 0.8).show();
|
||||
}
|
||||
this.noImagesO.hide();
|
||||
this.loadingO.show();
|
||||
},
|
||||
loadingEnd: function() {
|
||||
this.imageMaskO.hide();
|
||||
},
|
||||
|
||||
noImages: function () {
|
||||
this.imageMaskO.show().css("opacity", 1);
|
||||
this.noImagesO.show();
|
||||
this.loadingO.hide();
|
||||
},
|
||||
|
||||
|
||||
search: function() {
|
||||
var self = this;
|
||||
var t1 = 1;
|
||||
$("#key").on("keyup", function() {
|
||||
var t2 = ++t1;
|
||||
var key = $(this).val();
|
||||
var albumId = $("#albumsForList").val();
|
||||
|
||||
self.renderImages(albumId, 1, true, key, function(){
|
||||
return t1 == t2;
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
renderImages: function(albumId, page, needRenderPagination, key, needRender) {
|
||||
var self = this;
|
||||
|
||||
if(!page) {
|
||||
page = 1;
|
||||
}
|
||||
self.loadingStart();
|
||||
$.get("/file/getImages", {albumId: albumId, page: page, key: key}, function(ret) {
|
||||
if(!ret || !ret.Count) {
|
||||
self.noImages();
|
||||
return;
|
||||
}
|
||||
self.loadingEnd();
|
||||
var datas = ret.List;
|
||||
var selectedMap = {};
|
||||
|
||||
for(var i in self.selectedImages) {
|
||||
var src = self.selectedImages[i]; // src include G.imageSrcPrefix
|
||||
selectedMap[src] = true;
|
||||
}
|
||||
// log(self.selectedImages);
|
||||
|
||||
var html = "";
|
||||
for(var i in datas){
|
||||
var each = datas[i];
|
||||
var classes = "";
|
||||
// life edit
|
||||
// 之前的
|
||||
if(each.Path != "" && each.Path[0] == "/") {
|
||||
each.Path = each.Path.substr(1);
|
||||
}
|
||||
if(each.Path != "" && each.Path.substr(0, 7) == "upload/") {
|
||||
var src = urlPrefix + "/" + each.Path;
|
||||
} else {
|
||||
var src = urlPrefix + "/file/outputImage?fileId=" + each.FileId;
|
||||
}
|
||||
// log(src);
|
||||
if(selectedMap[src]) {
|
||||
classes = 'class="selected"';
|
||||
}
|
||||
html += '<li ' + classes + '>';
|
||||
html += '<a title="" href="javascript:;" class="a-img"><img alt="" src="' + src + '" data-original="' + src + '" ></a>';
|
||||
// html += '<div class="tools"><a href="javascript:;" class="del" data-id="' + each.FileId + '"><span class="fa fa-trash"></span></a></div>';
|
||||
html += '<div class="tools clearfix" data-id="' + each.FileId + '"><div class="file-title pull-left">' + each.Title + '</div><div class="pull-right"><a href="javascript:;" class="del" data-id="' + each.FileId + '"><span class="fa fa-trash"></span></a></div></div>';
|
||||
html += "</li>";
|
||||
}
|
||||
|
||||
// var html = $("#tImage").render(datas);
|
||||
$("#imageList").html(html);
|
||||
|
||||
if(needRenderPagination) {
|
||||
self.pagination(ret.Count);
|
||||
}
|
||||
|
||||
// $("#imageList img").lazyload({effect : "fadeIn"});
|
||||
// $("#imageList img").lazyload();
|
||||
});
|
||||
},
|
||||
|
||||
// 初始化已选择的图片区域
|
||||
initSelectedZones: function() {
|
||||
var self = this;
|
||||
num = this.maxSelected;
|
||||
self.previewO.html("");
|
||||
for(var i = 1; i <= num; ++i) {
|
||||
// self.previewO.append("<li>" + i + "</li>");
|
||||
self.previewO.append("<li>?</li>");
|
||||
}
|
||||
},
|
||||
|
||||
reRenderSelectedImages: function(isRemove, addSrc) {
|
||||
var self = this;
|
||||
|
||||
var lis = this.selectedZoneO.find("li");
|
||||
var size = this.selectedImages.length-1;
|
||||
for(var i = 0; i < this.maxSelected; ++i) {
|
||||
var target = lis.eq(i);
|
||||
if(i > size) {
|
||||
target.html('?');
|
||||
} else {
|
||||
src = this.selectedImages[i];
|
||||
|
||||
var data = self.imageAttrs[src];
|
||||
var attrs = "";
|
||||
if(data) {
|
||||
if(data.width) attrs += ' data-width="' + data.width + '"';
|
||||
if(data.height) attrs += ' data-height="' + data.height + '"';
|
||||
if(data.title) attrs += ' data-title="' + data.title + '"';
|
||||
}
|
||||
|
||||
target.html('<img ' + attrs + ' src="' + src + '" width="60"/><div class="tools"><a title="' + getMsg('click to remove this image') + '" href="javascript:;" class="del"><span class="fa fa-trash"></span></a></div>');
|
||||
}
|
||||
|
||||
// remove selected
|
||||
if(isRemove) {
|
||||
target.removeClass("selected");
|
||||
} else {
|
||||
// is add
|
||||
// trigger click and set attrs
|
||||
if(addSrc == src) {
|
||||
target.click();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
removeSelectedImage: function($li) {
|
||||
var self = this;
|
||||
|
||||
var src = $li.find("img").attr('src');
|
||||
for(var i in this.selectedImages) {
|
||||
if(this.selectedImages[i] == src) {
|
||||
this.selectedImages.splice(i, 1)
|
||||
}
|
||||
}
|
||||
this.reRenderSelectedImages(true);
|
||||
|
||||
// clear attrs and disable it
|
||||
self.clearAttrs();
|
||||
},
|
||||
addSelectedImage: function($li) {
|
||||
if(this.maxSelected > 1 && this.maxSelected <= this.selectedImages.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// life 为了图片安全
|
||||
if(typeof $li == "object") {
|
||||
var src = $li.find("img").attr('src');
|
||||
} else {
|
||||
// 也有可能来自url
|
||||
if($li.indexOf("http://") != -1 || $li.indexOf("https://") != -1) {
|
||||
src = $li;
|
||||
} else {
|
||||
// 来自内部
|
||||
src = urlPrefix + "/file/outputImage?fileId=" + $li;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果只允许选1个
|
||||
if(this.maxSelected == 1) {
|
||||
// 先把其它的去掉
|
||||
$("#imageList li").removeClass("selected");
|
||||
this.selectedImages = [src];
|
||||
} else {
|
||||
this.selectedImages.push(src);
|
||||
}
|
||||
|
||||
this.reRenderSelectedImages(false, src);
|
||||
|
||||
return true;
|
||||
},
|
||||
initDataFromTinymce: function() {
|
||||
var self = this;
|
||||
var datas = top.LEAUI_DATAS;
|
||||
var lastSrc = "";
|
||||
if(datas && datas.length > 0) {
|
||||
for(var i in datas) {
|
||||
var data = datas[i];
|
||||
data.constrain = true;
|
||||
lastSrc = data.src;
|
||||
self.selectedImages.push(data.src);
|
||||
self.imageAttrs[data.src] = data;
|
||||
}
|
||||
|
||||
self.reRenderSelectedImages(false, lastSrc);
|
||||
}
|
||||
},
|
||||
|
||||
init: function() {
|
||||
var self = this;
|
||||
|
||||
self.processAlbum();
|
||||
|
||||
$("#albumsForList").change(function() {
|
||||
var albumId = $(this).val();
|
||||
self.renderImages(albumId, 1, true);
|
||||
});
|
||||
|
||||
$("#imageList").on("click", 'li', function() {
|
||||
if($(this).hasClass("selected")) {
|
||||
$(this).removeClass("selected");
|
||||
self.removeSelectedImage($(this));
|
||||
} else {
|
||||
if(self.addSelectedImage($(this))){
|
||||
$(this).addClass("selected");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// delete file
|
||||
$("#imageList").on("click", '.del', function(e) {
|
||||
var t = this;
|
||||
e.stopPropagation();
|
||||
|
||||
if(confirm(getMsg("Are you sure to delete this image ?"))) {
|
||||
var fileId = $(this).data('id');
|
||||
$.get("/file/deleteImage", {fileId: fileId}, function(ret) {
|
||||
if(ret) {
|
||||
var $li = $(t).closest('li');
|
||||
if($li.hasClass("selected")) {
|
||||
self.removeSelectedImage($li);
|
||||
}
|
||||
$(t).closest('li').remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// edit file title
|
||||
$("#imageList").on("click", '.file-title', function(e) {
|
||||
var p = this;
|
||||
var t = this;
|
||||
e.stopPropagation();
|
||||
if($(this).children().eq(0).is("input")){
|
||||
return;
|
||||
}
|
||||
var fileId = $(p).parent().data('id');
|
||||
var fileTitle = $(this).text();
|
||||
$(this).html('<input type="text" value="' + fileTitle + '" />');
|
||||
|
||||
var $input = $(this).find("input");
|
||||
$input.focus();
|
||||
$input.keydown(function(e){
|
||||
if(e.keyCode==13){
|
||||
$(this).trigger("blur");
|
||||
}
|
||||
});
|
||||
$input.blur(function() {
|
||||
var title = $(this).val();
|
||||
if(!title) {
|
||||
title = fileTitle;
|
||||
} else {
|
||||
$.post("/file/updateImageTitle", {fileId: fileId, title: title});
|
||||
}
|
||||
$(p).html(title);
|
||||
});
|
||||
});
|
||||
|
||||
// remove preview
|
||||
$("#preview").on("click", '.del', function(e) {
|
||||
e.stopPropagation();
|
||||
var $li = $(this).closest("li");
|
||||
var src = $li.find("img").attr("src");
|
||||
self.removeSelectedImage($li);
|
||||
|
||||
// 在当前的imagesList下看是否有
|
||||
$("#imageList img").each(function() {
|
||||
var src2 = $(this).attr('src');
|
||||
if(src == src2) {
|
||||
$(this).parent().parent().removeClass("selected");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//
|
||||
$("#goAddImageBtn").click(function() {
|
||||
$("#albumsForUpload").val($("#albumsForList").val());
|
||||
$('#myTab li:eq(1) a').tab('show');
|
||||
});
|
||||
|
||||
// toggle tab
|
||||
// refresh
|
||||
$('#myTab a').on('shown.bs.tab', function(e) {
|
||||
e.preventDefault()
|
||||
$(this).tab('show');
|
||||
var href = $(this).attr("href");
|
||||
|
||||
if(self.needRefresh && href == "#images") {
|
||||
setTimeout(function(){
|
||||
var albumId = $("#albumsForList").val();
|
||||
var key = $("#key").val();
|
||||
self.renderImages(albumId, self.pageNum, true, key);
|
||||
}, 200);
|
||||
self.needRefresh = false;
|
||||
}
|
||||
|
||||
if(href == "#url") {
|
||||
$("#imageUrl").focus();
|
||||
}
|
||||
});
|
||||
$("#refresh").click(function() {
|
||||
var albumId = $("#albumsForList").val();
|
||||
var key = $("#key").val();
|
||||
self.renderImages(albumId, self.pageNum, false, key);
|
||||
});
|
||||
|
||||
// add url
|
||||
$("#addImageUrlBtn").click(function(e) {
|
||||
e.preventDefault();
|
||||
var url = $.trim($("#imageUrl").val());
|
||||
if(!url) {
|
||||
$("#imageUrl").focus();
|
||||
return;
|
||||
}
|
||||
|
||||
getImageSize(url, function(ret) {
|
||||
if(!ret.width || !ret.height){
|
||||
$("#msgForUrl").show();
|
||||
return;
|
||||
}
|
||||
$("#msgForUrl").hide();
|
||||
$("#imageUrl").val("");
|
||||
self.addSelectedImage(url);
|
||||
});
|
||||
});
|
||||
|
||||
// 设置属性
|
||||
$("#preview").on("click", 'li', function() {
|
||||
if($(this).hasClass("selected")) {
|
||||
// $(this).removeClass("selected");
|
||||
} else {
|
||||
if($(this).find("img").length){
|
||||
$("#preview li").removeClass("selected");
|
||||
$(this).addClass("selected");
|
||||
|
||||
self.initAttr($(this));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$("#attrTitle, #attrWidth, #attrHeight").on("keyup", function(){
|
||||
self.modifyAttr($(this));
|
||||
});
|
||||
$("#attrConstrain").on("click", function(){
|
||||
self.modifyAttr($(this));
|
||||
});
|
||||
|
||||
// file search
|
||||
self.search();
|
||||
|
||||
self.initSelectedZones();
|
||||
|
||||
self.initDataFromTinymce();
|
||||
|
||||
self.renderAlbums();
|
||||
//...
|
||||
self.initUploader();
|
||||
},
|
||||
|
||||
// 设置
|
||||
curSrc: "",
|
||||
curLi: null,
|
||||
attrTitleO: $("#attrTitle"),
|
||||
attrWidthO: $("#attrWidth"),
|
||||
attrHeightO: $("#attrHeight"),
|
||||
attrConstrainO: $("#attrConstrain"),
|
||||
// clear attrs and disable it
|
||||
clearAttrs: function() {
|
||||
var self = this;
|
||||
self.attrTitleO.val("").attr("disabled", true);
|
||||
self.attrHeightO.val("").attr("disabled", true);
|
||||
self.attrWidthO.val("").attr("disabled", true);
|
||||
self.attrConstrainO.prop("checked", false).attr("disabled", true);
|
||||
},
|
||||
scale: function(isWidth) {
|
||||
var self = this;
|
||||
var autoScale = self.attrConstrainO.is(":checked");
|
||||
var width = +self.attrWidthO.val();
|
||||
var height = +self.attrHeightO.val();
|
||||
if(isNaN(width) || isNaN(height)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var curAttrs = self.getCurAttrs();
|
||||
var preWidth = curAttrs.preWidth || curAttrs.width;
|
||||
var preHeight = curAttrs.preHeight || curAttrs.height;
|
||||
|
||||
if(autoScale && preWidth && preHeight) {
|
||||
if(isWidth) {
|
||||
height = parseInt((width/preWidth) * preHeight);
|
||||
self.attrHeightO.val(height);
|
||||
} else {
|
||||
width = parseInt((height/preHeight) * preWidth);
|
||||
self.attrWidthO.val(width);
|
||||
}
|
||||
}
|
||||
var ret = {width: width, height: height};
|
||||
return ret;
|
||||
},
|
||||
getCurAttrs: function() {
|
||||
var self = this;
|
||||
return self.imageAttrs[self.curSrc];
|
||||
},
|
||||
setCurDataAttrs: function(attrs) {
|
||||
var self = this;
|
||||
var img = self.curLi.find("img");
|
||||
img.attr("data-width", attrs.width);
|
||||
img.attr("data-height", attrs.height);
|
||||
img.attr("data-title", attrs.title);
|
||||
|
||||
self.imageAttrs[self.curSrc] = attrs;
|
||||
},
|
||||
// 修改属性
|
||||
modifyAttr: function($target){
|
||||
var self = this;
|
||||
var id = $target.attr("id");
|
||||
var val = $target.val();
|
||||
var curAttrs = self.getCurAttrs();
|
||||
if(!curAttrs) {
|
||||
return;
|
||||
}
|
||||
switch(id) {
|
||||
case "attrConstrain":
|
||||
val = 0;
|
||||
if($target.is(":checked")) {
|
||||
val = 1;
|
||||
}
|
||||
curAttrs['constrain'] = val;
|
||||
break;
|
||||
case "attrTitle":
|
||||
curAttrs['title'] = val;
|
||||
break;
|
||||
case "attrWidth":
|
||||
$.extend(curAttrs, self.scale(true));
|
||||
break;
|
||||
case "attrHeight":
|
||||
$.extend(curAttrs, self.scale(false));
|
||||
break;
|
||||
}
|
||||
|
||||
self.setCurDataAttrs(curAttrs);
|
||||
},
|
||||
// when click preview li
|
||||
initAttr: function($li) {
|
||||
var self = this;
|
||||
if(typeof $li != "object") {
|
||||
$li = $("#preview").find('img[src="' + $li + '"]').parent();
|
||||
};
|
||||
|
||||
var src = $li.find("img").attr("src");
|
||||
self.curSrc = src;
|
||||
self.curLi = $li;
|
||||
|
||||
var attrs = self.imageAttrs[src];
|
||||
function setAttr(attrs) {
|
||||
attrs = attrs || {};
|
||||
self.attrTitleO.val(attrs.title).attr("disabled", false);
|
||||
self.attrWidthO.val(attrs.width).attr("disabled", false);
|
||||
self.attrHeightO.val(attrs.height).attr("disabled", false);
|
||||
self.attrConstrainO.attr("disabled", false);
|
||||
|
||||
if(attrs.constrain) {
|
||||
self.attrConstrainO.prop('checked', true);
|
||||
} else {
|
||||
self.attrConstrainO.prop('checked', false);
|
||||
}
|
||||
|
||||
self.setCurDataAttrs(attrs);
|
||||
}
|
||||
attrs = attrs || {};
|
||||
if(!attrs || !attrs.width || !attrs.height) {
|
||||
getImageSize(src, function(ret) {
|
||||
ret.title = attrs.title || "";
|
||||
ret.constrain = 1;
|
||||
ret.preWidth = ret.width;
|
||||
ret.preHeight = ret.height;
|
||||
if(src != self.curSrc) {
|
||||
self.imageAttrs[src] = ret;
|
||||
// in case user click fast
|
||||
self.setCurDataAttrs(attrs);
|
||||
return;
|
||||
}
|
||||
// set attrs
|
||||
setAttr(ret);
|
||||
return;
|
||||
});
|
||||
} else {
|
||||
setAttr(attrs);
|
||||
}
|
||||
},
|
||||
|
||||
needRefresh: false,
|
||||
|
||||
uploadRefreshImageList: function() {
|
||||
var self = this;
|
||||
// check albumId
|
||||
var albumId = $("#albumsForList").val();
|
||||
if(albumId == $("#albumsForUpload").val()){
|
||||
self.needRefresh = true;
|
||||
}
|
||||
},
|
||||
|
||||
initUploader: function() {
|
||||
var self = this;
|
||||
var ul = $('#upload ul');
|
||||
|
||||
$('#drop a').click(function() {
|
||||
// trigger to show file select
|
||||
$(this).parent().find('input').click();
|
||||
});
|
||||
// Initialize the jQuery File Upload plugin
|
||||
$('#upload').fileupload({
|
||||
dataType: 'json',
|
||||
pasteZone: '',
|
||||
acceptFileTypes: /(\.|\/)(gif|jpg|jpeg|png|jpe)$/i,
|
||||
// maxFileSize: 210000,
|
||||
|
||||
// This element will accept file drag/drop uploading
|
||||
dropZone: $('#drop'),
|
||||
formData: function(form) {
|
||||
return [{name: 'albumId', value: $("#albumsForUpload").val()}]
|
||||
},
|
||||
/*
|
||||
urlFunc: function() {
|
||||
return 'server/index.php?action=file:uploadImage&album_id=' + $("#albumsForUpload").val();
|
||||
},
|
||||
*/
|
||||
|
||||
// This function is called when a file is added to the queue;
|
||||
// either via the browse button, or via drag/drop:
|
||||
add: function(e, data) {
|
||||
// 文件大小限制
|
||||
var size = data.files[0].size;
|
||||
var maxFileSize = +parent.GlobalConfigs["uploadImageSize"] || 100;
|
||||
if(typeof size == 'number' && size > 1024 * 1024 * maxFileSize) {
|
||||
var tpl = $('<li><div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div></li>');
|
||||
tpl.find('div').append('<b>Warning:</b> ' + data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>] is bigger than ' + maxFileSize + 'M</small> ');
|
||||
tpl.appendTo(ul);
|
||||
return;
|
||||
}
|
||||
|
||||
var tpl = $('<li><div class="alert alert-info"><img class="loader" src="/public/album/images/ajax-loader.gif"> <a class="close" data-dismiss="alert">×</a></div></li>');
|
||||
// Append the file name and file size
|
||||
tpl.find('div').append(data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small>');
|
||||
|
||||
// Add the HTML to the UL element
|
||||
data.context = tpl.appendTo(ul);
|
||||
|
||||
// data.form[0].action += "&album_id=" + $("#albumsForUpload").val();
|
||||
|
||||
// Automatically upload the file once it is added to the queue
|
||||
var jqXHR = data.submit();
|
||||
},
|
||||
|
||||
|
||||
done: function(e, data) {
|
||||
if (data.result.Ok == true) {
|
||||
data.context.remove();
|
||||
|
||||
// add image to preview
|
||||
self.addSelectedImage(data.result.Id);
|
||||
// reresh image list
|
||||
self.uploadRefreshImageList();
|
||||
} else {
|
||||
data.context.empty();
|
||||
var tpl = $('<li><div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div></li>');
|
||||
tpl.find('div').append('<b>' + getMsg('Error') + ':</b> ' + data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small> ' + data.result.Msg);
|
||||
data.context.append(tpl);
|
||||
setTimeout((function(tpl) {
|
||||
return function() {
|
||||
tpl.remove();
|
||||
}
|
||||
})(tpl), 3000);
|
||||
}
|
||||
$("#upload-msg").scrollTop(1000);
|
||||
},
|
||||
fail: function(e, data) {
|
||||
data.context.empty();
|
||||
var tpl = $('<li><div class="alert alert-danger"><a class="close" data-dismiss="alert">×</a></div></li>');
|
||||
tpl.find('div').append('<b>Error:</b> ' + data.files[0].name + ' <small>[<i>' + formatFileSize(data.files[0].size) + '</i>]</small> ' + data.errorThrown);
|
||||
data.context.append(tpl);
|
||||
|
||||
$("#upload-msg").scrollTop(1000);
|
||||
}
|
||||
});
|
||||
|
||||
// Prevent the default action when a file is dropped on the window
|
||||
$(document).on('drop dragover', function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
// Helper function that formats the file sizes
|
||||
function formatFileSize(bytes) {
|
||||
if (typeof bytes !== 'number') {
|
||||
return '';
|
||||
}
|
||||
if (bytes >= 1000000000) {
|
||||
return (bytes / 1000000000).toFixed(2) + ' GB';
|
||||
}
|
||||
if (bytes >= 1000000) {
|
||||
return (bytes / 1000000).toFixed(2) + ' MB';
|
||||
}
|
||||
return (bytes / 1000).toFixed(2) + ' KB';
|
||||
}
|
||||
|
||||
// drag css
|
||||
$(document).bind('dragover', function (e) {
|
||||
var dropZone = $('#drop'),
|
||||
timeout = window.dropZoneTimeout;
|
||||
if (!timeout) {
|
||||
dropZone.addClass('in');
|
||||
} else {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
var found = false,
|
||||
node = e.target;
|
||||
do {
|
||||
if (node === dropZone[0]) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
node = node.parentNode;
|
||||
} while (node != null);
|
||||
if (found) {
|
||||
dropZone.addClass('hover');
|
||||
} else {
|
||||
dropZone.removeClass('hover');
|
||||
}
|
||||
window.dropZoneTimeout = setTimeout(function () {
|
||||
window.dropZoneTimeout = null;
|
||||
dropZone.removeClass('in hover');
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(function() {
|
||||
o.init();
|
||||
});
|
||||
|
||||
// 为md得到图片链接
|
||||
function mdGetImgSrc() {
|
||||
if(o.selectedImages && o.selectedImages.length) {
|
||||
return o.selectedImages[0];
|
||||
}
|
||||
return "";
|
||||
}
|
@ -79,6 +79,8 @@ tinymce.addI18n('zh',{
|
||||
"Insert\/edit mind map": "新建/编辑思维导图",
|
||||
"Insert Mind Map": "插入思维导图",
|
||||
"Mind Map": "思维导图",
|
||||
"Image": "图片",
|
||||
"Insert Image": "插入",
|
||||
"General": "\u666e\u901a",
|
||||
"Advanced": "\u9ad8\u7ea7",
|
||||
"Source": "\u5730\u5740",
|
||||
|
@ -1 +1 @@
|
||||
tinymce.PluginManager.requireLangPack("leanote_code"),tinymce.PluginManager.add("leanote_code",function(a,b){function c(a){return a?("object"==typeof a&&(a=$(a).html()),a.replace(/\<br *\/*\>/gi,"\n").replace(/<\/(p|li|div|ul|ol|hr)>/,"\n").replace(/(<([^>]+)>)/gi,"").replace(/\n\n/g,"\n")):a}function d(a){return a?("object"==typeof a&&(a=$(a).html()),a.replace(/\n/g,"<br />")):a}function e(a){g=tinymce.activeEditor;var b,e=g.selection.getNode(),f=g.selection.getContent(),h=LeaAce.isInAce(e),i=!1,j=!1;h&&(i=h[0],j=h[1]),$("#editorContent .toggle-raw").remove();var k='class="brush:'+a+'"';if(a&&"convert"!=a){if(i&&i.session.setMode("ace/mode/"+a),j||"PRE"!=e.nodeName||(j=$(e)),j){var l=LeaAce.getPreBrush(j);return void j.removeClass(l).addClass("brush:"+a)}}else if(a&&("BODY"==e.nodeName||"editorContent"==$(e).attr("id")))return;if(LeaAce.canAce()){var m=LeaAce.getAceId();if(LeaAce.disableAddHistory(),i){var n=i.getValue();n=n.replace(/</g,"<"),n=n.replace(/>/g,">"),n=n.replace(/\n/g,"<br />"),j.replaceWith("<p>"+n+"</p>"),i.destroy()}else{if("PRE"==e.nodeName){var j=$(e),n=j.html();return n&&(n=n.replace(/\n/g,"<br />")),void j.replaceWith("<p>"+n+"</p>")}var b=f;if(!b&&("BODY"==e.nodeName||"editorContent"==$(e).attr("id")))return;b?(b=c(b),g.insertContent('<pre id="'+m+'" '+k+">"+b+"</pre>")):(b=c(e),$(e).replaceWith("<pre id='"+m+"'"+k+">"+b+"</pre>"));var i=LeaAce.initAce(m);i&&(i.focus(),a&&"convert"!=a&&i.session.setMode("ace/mode/"+a))}LeaAce.resetAddHistory()}else if("PRE"!=e.nodeName&&(e=$(e).closest("pre").get(0)),e&&"PRE"==e.nodeName){var j=$(e),n=j.html();n&&(n=n.replace(/\n/g,"<br />")),j.replaceWith("<p>"+n+"</p>")}else{try{b=$.trim($(f).text())}catch(o){}b||(b=$.trim(f));var p=null,m=LeaAce.getAceId();b?(b=d(b),p='<pre id="'+m+'" '+k+">"+b+"</pre>",g.insertContent(p)):e?(b=d(e),p='<pre id="'+m+'" '+k+">"+b+"</pre>",$(e).replaceWith(p)):(p='<pre id="'+m+'" '+k+">"+b+"</pre>",g.insertContent(p))}}function f(){return function(){var b=this;a.on("nodeChange",function(){var c=null;try{var d=a.selection.getNode();if("PRE"!=d.nodeName&&(d=$(d).closest("pre").get(0)),d){var e=LeaAce.isInAce(d),f=!1,g=!1;if(e||"PRE"==d.nodeName){e?(f=e[0],g=e[1]):g=$(d);var h=LeaAce.getPreBrush(g);c=$.trim(h.split(":")[1]),b.diableValue("convert",!1)}else b.diableValue("convert",!0)}}catch(i){log(i)}"convert"!=c&&b.value(c)})}}var g=a;a.addButton("leanote_code",function(){var a=["Convert Code:convert","CSS:css","HTML:html","Javascript:javascript","C/C++:c_cpp","C#:csharp","Java:java","Objective-c:objectivec","PHP:php","Python:python","Ruby:ruby","Shell:sh","Delphi:delphi","Golang:golang","Erlang:erlang","Groovy:groovy","Latex:latex","Xml:xml","ActionScript:actionScript"],b=[];for(var c in a){var d=a[c].split(":");b.push({text:d[0],value:d[1]})}return{type:"listbox",text:"codeLang",tooltip:"toggleCode",values:b,fixedWidth:!0,onselect:function(a){a.control.settings.value&&e(a.control.settings.value)},onPostRender:f(b)}}),a.addButton("leanote_inline_code",{icon:"code",tooltip:"Inline Code",stateSelector:"code",onclick:function(){a.execCommand("mceToggleFormat",!1,"code")}}),LeaAce.canAce()&&a.addButton("leanote_ace_pre",{icon:"code",image:b+"/img/ace-pre2.png",tooltip:"Toggle ace with raw html",active:LeaAce.isAce===!1,onclick:function(){LeaAce.isAce===!1?(this.active(!1),LeaAce.isAce=!0,LeaAce.initAceFromContent(a)):(this.active(!0),LeaAce.allToPre(a),LeaAce.isAce=!1)}}),g.addCommand("toggleCode",e),g.addShortcut("ctrl+shift+c","","toggleCode"),g.addShortcut("command+shift+c","","toggleCode"),LeaAce.canAce()&&a.on("keydown",function(a){var b=LeaAce.nowIsInAce();return b?(setTimeout(function(){b[0].focus()}),!0):void 0}),g.on("keydown",function(a){var b=a.which?a.which:a.keyCode;return 9==b?(a.shiftKey||g.insertContent(" "),a.preventDefault(),a.stopPropagation(),!1):void 0})});
|
||||
tinymce.PluginManager.requireLangPack("leanote_code"),tinymce.PluginManager.add("leanote_code",function(a,b){function c(a){return a?("object"==typeof a&&(a=$(a).html()),a.replace(/\<br *\/*\>/gi,"\n").replace(/<\/(p|li|div|ul|ol|hr)>/,"\n").replace(/(<([^>]+)>)/gi,"").replace(/\n\n/g,"\n")):a}function d(a){return a?("object"==typeof a&&(a=$(a).html()),a.replace(/\n/g,"<br />")):a}function e(){var a=$("#editorContent").children(),b=a&&a.length>0?a[a.length-1]:null;b&&"P"==b.tagName||$("#editorContent").append('<p><br data-mce-bogus="1"></p>')}function f(a){h=tinymce.activeEditor;var b,f=h.selection.getNode(),g=h.selection.getContent(),i=LeaAce.isInAce(f),j=!1,k=!1;i&&(j=i[0],k=i[1]),$("#editorContent .toggle-raw").remove();var l='class="brush:'+a+'"';if(a&&"convert"!=a){if(j&&j.session.setMode("ace/mode/"+a),k||"PRE"!=f.nodeName||(k=$(f)),k){var m=LeaAce.getPreBrush(k);return void k.removeClass(m).addClass("brush:"+a)}}else if(a&&("BODY"==f.nodeName||"editorContent"==$(f).attr("id")))return;if(LeaAce.canAce()){var n=LeaAce.getAceId();if(LeaAce.disableAddHistory(),j){var o=j.getValue();o=o.replace(/</g,"<"),o=o.replace(/>/g,">"),o=o.replace(/\n/g,"<br />"),k.replaceWith("<p>"+o+"</p>"),j.destroy()}else{if("PRE"==f.nodeName){var k=$(f),o=k.html();return o&&(o=o.replace(/\n/g,"<br />")),void k.replaceWith("<p>"+o+"</p>")}var b=g;if(!b&&("BODY"==f.nodeName||"editorContent"==$(f).attr("id")))return;b?(b=c(b),h.insertContent('<pre id="'+n+'" '+l+">"+b+"</pre>")):(b=c(f),$(f).replaceWith("<pre id='"+n+"'"+l+">"+b+"</pre>"));var j=LeaAce.initAce(n);j&&(j.focus(),a&&"convert"!=a&&j.session.setMode("ace/mode/"+a),e())}LeaAce.resetAddHistory()}else if("PRE"!=f.nodeName&&(f=$(f).closest("pre").get(0)),f&&"PRE"==f.nodeName){var k=$(f),o=k.html();o&&(o=o.replace(/\n/g,"<br />")),k.replaceWith("<p>"+o+"</p>")}else{try{b=$.trim($(g).text())}catch(p){}b||(b=$.trim(g));var q=null,n=LeaAce.getAceId();b?(b=d(b),q='<pre id="'+n+'" '+l+">"+b+"</pre>",h.insertContent(q)):f?(b=d(f),q='<pre id="'+n+'" '+l+">"+b+"</pre>",$(f).replaceWith(q)):(q='<pre id="'+n+'" '+l+">"+b+"</pre>",h.insertContent(q)),q&&e()}}function g(){return function(){var b=this;a.on("nodeChange",function(){var c=null;try{var d=a.selection.getNode();if("PRE"!=d.nodeName&&(d=$(d).closest("pre").get(0)),d){var e=LeaAce.isInAce(d),f=!1,g=!1;if(e||"PRE"==d.nodeName){e?(f=e[0],g=e[1]):g=$(d);var h=LeaAce.getPreBrush(g);c=$.trim(h.split(":")[1]),b.diableValue("convert",!1)}else b.diableValue("convert",!0)}}catch(i){log(i)}"convert"!=c&&b.value(c)})}}var h=a;a.addButton("leanote_code",function(){var a=["Convert Code:convert","CSS:css","HTML:html","Javascript:javascript","C/C++:c_cpp","C#:csharp","Java:java","Objective-c:objectivec","PHP:php","Python:python","Ruby:ruby","Shell:sh","Delphi:delphi","Golang:golang","Erlang:erlang","Groovy:groovy","Latex:latex","Xml:xml","ActionScript:actionScript"],b=[];for(var c in a){var d=a[c].split(":");b.push({text:d[0],value:d[1]})}return{type:"listbox",text:"codeLang",tooltip:"toggleCode",values:b,fixedWidth:!0,onselect:function(a){a.control.settings.value&&f(a.control.settings.value)},onPostRender:g(b)}}),a.addButton("leanote_inline_code",{icon:"code",tooltip:"Inline Code",stateSelector:"code",onclick:function(){a.execCommand("mceToggleFormat",!1,"code")}}),LeaAce.canAce()&&a.addButton("leanote_ace_pre",{icon:"ace-pre",tooltip:"Toggle ace with raw html",active:LeaAce.isAce===!1,onclick:function(){LeaAce.isAce===!1?(this.active(!1),LeaAce.isAce=!0,LeaAce.initAceFromContent(a)):(this.active(!0),LeaAce.allToPre(a),LeaAce.isAce=!1)}}),h.addCommand("toggleCode",f),h.addShortcut("ctrl+shift+c","","toggleCode"),h.addShortcut("command+shift+c","","toggleCode"),LeaAce.canAce()&&a.on("keydown",function(a){var b=LeaAce.nowIsInAce();return b?(setTimeout(function(){b[0].focus()}),!0):void 0}),h.on("keydown",function(a){var b=a.which?a.which:a.keyCode;return 9==b?(a.shiftKey||h.insertContent(" "),a.preventDefault(),a.stopPropagation(),!1):void 0})});
|
@ -57,7 +57,7 @@ tinymce.PluginManager.add('leaui_image', function(editor, url) {
|
||||
LEAUI_DATAS = datas;
|
||||
|
||||
function GetTheHtml(){
|
||||
var html = '<iframe id="leauiIfr" src="'+ url + '/index.html'+ '?' + new Date().getTime() + '" frameborder="0"></iframe>';
|
||||
var html = '<iframe id="leauiIfr" src="/album/index'+ '?' + new Date().getTime() + '" frameborder="0"></iframe>';
|
||||
return html;
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ tinymce.PluginManager.add('leaui_image', function(editor, url) {
|
||||
icon: 'image',
|
||||
tooltip: 'Insert/edit image',
|
||||
onclick: showDialog,
|
||||
stateSelector: 'img:not([data-mce-object])'
|
||||
stateSelector: 'img:not([data-mind-json])'
|
||||
});
|
||||
|
||||
editor.addMenuItem('leaui_image', {
|
||||
|
@ -1 +1 @@
|
||||
var LEAUI_DATAS=[];tinymce.PluginManager.add("leaui_image",function(a,b){function c(a,b){function c(a,c){d.parentNode.removeChild(d),b({width:a,height:c})}var d=document.createElement("img");d.onload=function(){c(d.clientWidth,d.clientHeight)},d.onerror=function(){c()},d.src=a;var e=d.style;e.visibility="hidden",e.position="fixed",e.bottom=e.left=0,e.width=e.height="auto",document.body.appendChild(d)}function d(){function d(){var a='<iframe id="leauiIfr" src="'+b+"/index.html?"+(new Date).getTime()+'" frameborder="0"></iframe>';return a}var e=a.dom,f=a.selection.getContent(),g=/<img.*?\/>/g,h=f.match(g),i=document.createElement("p"),j=[];for(var k in h){i.innerHTML=h[k];var l=i.firstChild;if(l&&"IMG"==l.nodeName){var m={};m.src=e.getAttrib(l,"data-src")||e.getAttrib(l,"src"),m.width=e.getAttrib(l,"width"),m.height=e.getAttrib(l,"height"),m.title=e.getAttrib(l,"title"),j.push(m)}}LEAUI_DATAS=j;var n=$(document).width()-10;n>805&&(n=805);var o=$(document).height()-100;o>365&&(o=365),win=a.windowManager.open({title:"Image",width:n,height:o,html:d(),buttons:[{text:"Cancel",onclick:function(){this.parent().parent().close()}},{text:"Insert Image",subtype:"primary",onclick:function(d){for(var f=document.getElementById("leauiIfr").contentWindow,g=f.document.getElementById("preview"),h=g.childNodes,i=[],j=0;j<h.length;++j){var d=h[j];if(d.firstChild&&"IMG"==d.firstChild.nodeName){var k=d.firstChild,l={};l.src=k.getAttribute("src"),l.width=k.getAttribute("data-width"),l.height=k.getAttribute("data-height"),l.title=k.getAttribute("data-title"),i.push(l)}}for(var j in i){var m,n=i[j],o=n.src;m=-1!=o.indexOf("http://")||-1!=o.indexOf("https://")?o:b+"/"+o,n.src=m;var p=function(b){var d=function(b,c){var d,f={};return f.id="__mcenew"+c,f.src="http://leanote.com/images/loading-24.gif",d=e.createHTML("img",f),a.insertContent(d),d=e.get(f.id),function(a){a&&a.width&&(a.width>600&&(a.width=600),b.width=a.width),e.setAttrib(d,"src",b.src),e.setAttrib(d,"title",b.title),e.setAttrib(d,"id",null)}}(b,j);c(b.src,d)},q="";if(fileIds=m.split("fileId="),2==fileIds.length&&fileIds[1].length=="53aecf8a8a039a43c8036282".length&&(q=fileIds[1]),q){var r;Note&&Note.getCurNote&&(r=Note.getCurNote()),r&&r.UserId!=UserInfo.UserId?!function(a){ajaxPost("/file/copyImage",{userId:UserInfo.UserId,fileId:q,toUserId:r.UserId},function(b){if(reIsOk(b)&&b.Id){var c=UrlPrefix;a.src=c+"/file/outputImage?fileId="+b.Id}p(a)})}(n):p(n)}else p(n)}this.parent().parent().close()}}]})}a.addButton("leaui_image",{icon:"image",tooltip:"Insert/edit image",onclick:d,stateSelector:"img:not([data-mind-json])"}),a.addMenuItem("leaui_image",{icon:"image",text:"Insert image",onclick:d,context:"insert",prependToContext:!0});var e=!1;a.on("dragstart",function(a){e=!0}),a.on("dragend",function(a){e=!1}),a.on("dragover",function(a){e||$("body").trigger("dragover")})});
|
||||
var LEAUI_DATAS=[];tinymce.PluginManager.add("leaui_image",function(a,b){function c(a,b){function c(a,c){d.parentNode.removeChild(d),b({width:a,height:c})}var d=document.createElement("img");d.onload=function(){c(d.clientWidth,d.clientHeight)},d.onerror=function(){c()},d.src=a;var e=d.style;e.visibility="hidden",e.position="fixed",e.bottom=e.left=0,e.width=e.height="auto",document.body.appendChild(d)}function d(){function d(){var a='<iframe id="leauiIfr" src="/album/index?'+(new Date).getTime()+'" frameborder="0"></iframe>';return a}var e=a.dom,f=a.selection.getContent(),g=/<img.*?\/>/g,h=f.match(g),i=document.createElement("p"),j=[];for(var k in h){i.innerHTML=h[k];var l=i.firstChild;if(l&&"IMG"==l.nodeName){var m={};m.src=e.getAttrib(l,"data-src")||e.getAttrib(l,"src"),m.width=e.getAttrib(l,"width"),m.height=e.getAttrib(l,"height"),m.title=e.getAttrib(l,"title"),j.push(m)}}LEAUI_DATAS=j;var n=$(document).width()-10;n>805&&(n=805);var o=$(document).height()-100;o>365&&(o=365),win=a.windowManager.open({title:"Image",width:n,height:o,html:d(),buttons:[{text:"Cancel",onclick:function(){this.parent().parent().close()}},{text:"Insert Image",subtype:"primary",onclick:function(d){for(var f=document.getElementById("leauiIfr").contentWindow,g=f.document.getElementById("preview"),h=g.childNodes,i=[],j=0;j<h.length;++j){var d=h[j];if(d.firstChild&&"IMG"==d.firstChild.nodeName){var k=d.firstChild,l={};l.src=k.getAttribute("src"),l.width=k.getAttribute("data-width"),l.height=k.getAttribute("data-height"),l.title=k.getAttribute("data-title"),i.push(l)}}for(var j in i){var m,n=i[j],o=n.src;m=-1!=o.indexOf("http://")||-1!=o.indexOf("https://")?o:b+"/"+o,n.src=m;var p=function(b){var d=function(b,c){var d,f={};return f.id="__mcenew"+c,f.src="http://leanote.com/images/loading-24.gif",d=e.createHTML("img",f),a.insertContent(d),d=e.get(f.id),function(a){a&&a.width&&(a.width>600&&(a.width=600),b.width=a.width),e.setAttrib(d,"src",b.src),e.setAttrib(d,"title",b.title),e.setAttrib(d,"id",null)}}(b,j);c(b.src,d)},q="";if(fileIds=m.split("fileId="),2==fileIds.length&&fileIds[1].length=="53aecf8a8a039a43c8036282".length&&(q=fileIds[1]),q){var r;Note&&Note.getCurNote&&(r=Note.getCurNote()),r&&r.UserId!=UserInfo.UserId?!function(a){ajaxPost("/file/copyImage",{userId:UserInfo.UserId,fileId:q,toUserId:r.UserId},function(b){if(reIsOk(b)&&b.Id){var c=UrlPrefix;a.src=c+"/file/outputImage?fileId="+b.Id}p(a)})}(n):p(n)}else p(n)}this.parent().parent().close()}}]})}a.addButton("leaui_image",{icon:"image",tooltip:"Insert/edit image",onclick:d,stateSelector:"img:not([data-mind-json])"}),a.addMenuItem("leaui_image",{icon:"image",text:"Insert image",onclick:d,context:"insert",prependToContext:!0});var e=!1;a.on("dragstart",function(a){e=!0}),a.on("dragend",function(a){e=!1}),a.on("dragover",function(a){e||$("body").trigger("dragover")})});
|
172
public/tinymce/plugins/leaui_mind/plugin.js
Normal file
172
public/tinymce/plugins/leaui_mind/plugin.js
Normal file
@ -0,0 +1,172 @@
|
||||
/**
|
||||
* leaui album image manager plugin
|
||||
* copyright leaui
|
||||
* leaui.com
|
||||
*/
|
||||
var LEAUI_MIND = {};
|
||||
tinymce.PluginManager.add('leaui_mind', function(editor, url) {
|
||||
|
||||
function showDialog() {
|
||||
var dom = editor.dom;
|
||||
|
||||
var content = editor.selection.getContent();
|
||||
// get images and attrs
|
||||
var p = /<img.*?\/>/g;
|
||||
var images = content.match(p);
|
||||
var newNode = document.createElement("p");
|
||||
LEAUI_MIND = {};
|
||||
for(var i in images) {
|
||||
newNode.innerHTML = images[i];
|
||||
var imgElm = newNode.firstChild;
|
||||
if(imgElm && imgElm.nodeName == "IMG") {
|
||||
LEAUI_MIND.json = dom.getAttrib(imgElm, 'data-mind-json');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function GetTheHtml(){
|
||||
var lang = editor.settings.language;
|
||||
var u = '//leanote.com/public/libs/mind/edit.html';
|
||||
// u = 'http://localhost:9000/public/libs/mind/edit.html';
|
||||
var html = '<iframe id="leauiIfr" src="'+ u + '?' + new Date().getTime() + '&lang=' + lang + '" frameborder="0"></iframe>';
|
||||
return html;
|
||||
}
|
||||
|
||||
var w = $(document).width() - 10;
|
||||
var h = $(document).height() - 100;
|
||||
|
||||
win = editor.windowManager.open({
|
||||
title: "Mind Map",
|
||||
width : w,
|
||||
height : h,
|
||||
html: GetTheHtml(),
|
||||
buttons: [
|
||||
{
|
||||
text: 'Cancel',
|
||||
onclick: function() {
|
||||
this.parent().parent().close();
|
||||
}
|
||||
},
|
||||
{
|
||||
text: 'Insert Mind Map',
|
||||
subtype: 'primary',
|
||||
onclick: function(e) {
|
||||
var me = this;
|
||||
var _iframe = document.getElementById('leauiIfr').contentWindow;
|
||||
var km = _iframe.km;
|
||||
km.exportData('png').then(function(data) {
|
||||
var json = JSON.stringify(km.exportJson());
|
||||
// console.log(json);
|
||||
var img = '<img src="' + data + '" data-mce-src="-" data-mind-json=\'' + json + '\'>';
|
||||
editor.insertContent(img);
|
||||
|
||||
me.parent().parent().close();
|
||||
});
|
||||
return;
|
||||
|
||||
var _div =_iframe.document.getElementById('preview');
|
||||
var ii = _div.childNodes;
|
||||
//console.log(ii);
|
||||
var datas = [];
|
||||
for(var i = 0; i < ii.length; ++i) {
|
||||
var e = ii[i];
|
||||
//console.log(e);
|
||||
// 有些没有image
|
||||
if(e.firstChild && e.firstChild.nodeName == "IMG") {
|
||||
var img = e.firstChild;
|
||||
var d = {};
|
||||
d.src = img.getAttribute("src");
|
||||
d.width = img.getAttribute("data-width");
|
||||
d.height = img.getAttribute("data-height");
|
||||
d.title = img.getAttribute("data-title");
|
||||
|
||||
datas.push(d);
|
||||
}
|
||||
};
|
||||
|
||||
for(var i in datas) {
|
||||
var data = datas[i];
|
||||
var src = data.src;
|
||||
// the network image
|
||||
var trueSrc;
|
||||
if(src.indexOf("http://") != -1 || src.indexOf("https://") != -1) {
|
||||
trueSrc = src;
|
||||
} else {
|
||||
trueSrc = url + "/" + src;
|
||||
}
|
||||
data.src = trueSrc;
|
||||
|
||||
var renderImage = function(data) {
|
||||
// 这里, 如果图片宽度过大, 这里设置成500px
|
||||
var back = (function(data2, i) {
|
||||
var d = {};
|
||||
var imgElm;
|
||||
// 先显示loading...
|
||||
d.id = '__mcenew' + i;
|
||||
d.src = "http://leanote.com/images/loading-24.gif";
|
||||
imgElm = dom.createHTML('img', d);
|
||||
editor.insertContent(imgElm);
|
||||
imgElm = dom.get(d.id);
|
||||
|
||||
return function(wh) {
|
||||
if(wh && wh.width) {
|
||||
if(wh.width > 600) {
|
||||
wh.width = 600;
|
||||
}
|
||||
data2.width = wh.width;
|
||||
}
|
||||
dom.setAttrib(imgElm, 'src', data2.src);
|
||||
// dom.setAttrib(imgElm, 'width', data2.width);
|
||||
dom.setAttrib(imgElm, 'title', data2.title);
|
||||
|
||||
dom.setAttrib(imgElm, 'id', null);
|
||||
}
|
||||
})(data, i);
|
||||
getImageSize(data.src, back);
|
||||
}
|
||||
|
||||
// outputImage?fileId=123232323
|
||||
var fileId = "";
|
||||
fileIds = trueSrc.split("fileId=")
|
||||
if(fileIds.length == 2 && fileIds[1].length == "53aecf8a8a039a43c8036282".length) {
|
||||
fileId = fileIds[1];
|
||||
}
|
||||
if(fileId) {
|
||||
// 得到fileId, 如果这个笔记不是我的, 那么肯定是协作的笔记, 那么需要将图片copy给原note owner
|
||||
// 博客设置中不用没有Note
|
||||
var curNote;
|
||||
if(Note && Note.getCurNote) {
|
||||
curNote = Note.getCurNote();
|
||||
}
|
||||
if(curNote && curNote.UserId != UserInfo.UserId) {
|
||||
(function(data) {
|
||||
ajaxPost("/file/copyImage", {userId: UserInfo.UserId, fileId: fileId, toUserId: curNote.UserId}, function(re) {
|
||||
if(reIsOk(re) && re.Id) {
|
||||
var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host;
|
||||
data.src = urlPrefix + "/file/outputImage?fileId=" + re.Id;
|
||||
}
|
||||
renderImage(data);
|
||||
});
|
||||
})(data);
|
||||
} else {
|
||||
renderImage(data);
|
||||
}
|
||||
} else {
|
||||
renderImage(data);
|
||||
}
|
||||
|
||||
} // end for
|
||||
|
||||
this.parent().parent().close();
|
||||
}
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
editor.addButton('leaui_mind', {
|
||||
icon: 'mind',
|
||||
tooltip: 'Insert/edit mind map',
|
||||
onclick: showDialog,
|
||||
stateSelector: 'img[data-mind-json]'
|
||||
});
|
||||
});
|
1
public/tinymce/plugins/leaui_mind/plugin.min.js
vendored
Normal file
1
public/tinymce/plugins/leaui_mind/plugin.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var LEAUI_MIND={};tinymce.PluginManager.add("leaui_mind",function(a,b){function c(){function b(){var b=a.settings.language,c="//leanote.com/public/libs/mind/edit.html",d='<iframe id="leauiIfr" src="'+c+"?"+(new Date).getTime()+"&lang="+b+'" frameborder="0"></iframe>';return d}var c=a.dom,d=a.selection.getContent(),e=/<img.*?\/>/g,f=d.match(e),g=document.createElement("p");LEAUI_MIND={};for(var h in f){g.innerHTML=f[h];var i=g.firstChild;if(i&&"IMG"==i.nodeName){LEAUI_MIND.json=c.getAttrib(i,"data-mind-json");break}}var j=$(document).width()-10,k=$(document).height()-100;win=a.windowManager.open({title:"Mind Map",width:j,height:k,html:b(),buttons:[{text:"Cancel",onclick:function(){this.parent().parent().close()}},{text:"Insert Mind Map",subtype:"primary",onclick:function(b){var c=this,d=document.getElementById("leauiIfr").contentWindow,e=d.km;return void e.exportData("png").then(function(b){var d=JSON.stringify(e.exportJson()),f='<img src="'+b+'" data-mce-src="-" data-mind-json=\''+d+"'>";a.insertContent(f),c.parent().parent().close()})}}]})}a.addButton("leaui_mind",{icon:"mind",tooltip:"Insert/edit mind map",onclick:c,stateSelector:"img[data-mind-json]"})});
|
611
public/tinymce/plugins/paste_raw/classes/Clipboard.js
Executable file
611
public/tinymce/plugins/paste_raw/classes/Clipboard.js
Executable file
@ -0,0 +1,611 @@
|
||||
/**
|
||||
* Clipboard.js
|
||||
*
|
||||
* Copyright, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class contains logic for getting HTML contents out of the clipboard.
|
||||
*
|
||||
* We need to make a lot of ugly hacks to get the contents out of the clipboard since
|
||||
* the W3C Clipboard API is broken in all browsers that have it: Gecko/WebKit/Blink.
|
||||
* We might rewrite this the way those API:s stabilize. Browsers doesn't handle pasting
|
||||
* from applications like Word the same way as it does when pasting into a contentEditable area
|
||||
* so we need to do lots of extra work to try to get to this clipboard data.
|
||||
*
|
||||
* Current implementation steps:
|
||||
* 1. On keydown with paste keys Ctrl+V or Shift+Insert create
|
||||
* a paste bin element and move focus to that element.
|
||||
* 2. Wait for the browser to fire a "paste" event and get the contents out of the paste bin.
|
||||
* 3. Check if the paste was successful if true, process the HTML.
|
||||
* (4). If the paste was unsuccessful use IE execCommand, Clipboard API, document.dataTransfer old WebKit API etc.
|
||||
*
|
||||
* @class tinymce.pasteplugin.Clipboard
|
||||
* @private
|
||||
*/
|
||||
define("tinymce/pasteplugin/Clipboard", [
|
||||
"tinymce/Env",
|
||||
"tinymce/dom/RangeUtils",
|
||||
"tinymce/util/VK",
|
||||
"tinymce/pasteplugin/Utils"
|
||||
], function(Env, RangeUtils, VK, Utils) {
|
||||
return function(editor) {
|
||||
var self = this, pasteBinElm, lastRng, keyboardPasteTimeStamp = 0, draggingInternally = false;
|
||||
var pasteBinDefaultContent = '%MCEPASTEBIN%', keyboardPastePlainTextState;
|
||||
var mceInternalUrlPrefix = 'data:text/mce-internal,';
|
||||
|
||||
/**
|
||||
* Pastes the specified HTML. This means that the HTML is filtered and then
|
||||
* inserted at the current selection in the editor. It will also fire paste events
|
||||
* for custom user filtering.
|
||||
*
|
||||
* @param {String} html HTML code to paste into the current selection.
|
||||
*/
|
||||
function pasteHtml(html) {
|
||||
var args, dom = editor.dom;
|
||||
|
||||
args = editor.fire('BeforePastePreProcess', {content: html}); // Internal event used by Quirks
|
||||
args = editor.fire('PastePreProcess', args);
|
||||
html = args.content;
|
||||
|
||||
if (!args.isDefaultPrevented()) {
|
||||
// User has bound PastePostProcess events then we need to pass it through a DOM node
|
||||
// This is not ideal but we don't want to let the browser mess up the HTML for example
|
||||
// some browsers add to P tags etc
|
||||
if (editor.hasEventListeners('PastePostProcess') && !args.isDefaultPrevented()) {
|
||||
// We need to attach the element to the DOM so Sizzle selectors work on the contents
|
||||
var tempBody = dom.add(editor.getBody(), 'div', {style: 'display:none'}, html);
|
||||
args = editor.fire('PastePostProcess', {node: tempBody});
|
||||
dom.remove(tempBody);
|
||||
html = args.node.innerHTML;
|
||||
}
|
||||
|
||||
if (!args.isDefaultPrevented()) {
|
||||
editor.insertContent(html, {merge: editor.settings.paste_merge_formats !== false});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pastes the specified text. This means that the plain text is processed
|
||||
* and converted into BR and P elements. It will fire paste events for custom filtering.
|
||||
*
|
||||
* @param {String} text Text to paste as the current selection location.
|
||||
*/
|
||||
function pasteText(text) {
|
||||
text = editor.dom.encode(text).replace(/\r\n/g, '\n');
|
||||
|
||||
var startBlock = editor.dom.getParent(editor.selection.getStart(), editor.dom.isBlock);
|
||||
|
||||
// Create start block html for example <p attr="value">
|
||||
var forcedRootBlockName = editor.settings.forced_root_block;
|
||||
var forcedRootBlockStartHtml;
|
||||
if (forcedRootBlockName) {
|
||||
forcedRootBlockStartHtml = editor.dom.createHTML(forcedRootBlockName, editor.settings.forced_root_block_attrs);
|
||||
forcedRootBlockStartHtml = forcedRootBlockStartHtml.substr(0, forcedRootBlockStartHtml.length - 3) + '>';
|
||||
}
|
||||
|
||||
if ((startBlock && /^(PRE|DIV)$/.test(startBlock.nodeName)) || !forcedRootBlockName) {
|
||||
text = Utils.filter(text, [
|
||||
[/\n/g, "<br>"]
|
||||
]);
|
||||
} else {
|
||||
text = Utils.filter(text, [
|
||||
[/\n\n/g, "</p>" + forcedRootBlockStartHtml],
|
||||
[/^(.*<\/p>)(<p>)$/, forcedRootBlockStartHtml + '$1'],
|
||||
[/\n/g, "<br />"]
|
||||
]);
|
||||
|
||||
if (text.indexOf('<p>') != -1) {
|
||||
text = forcedRootBlockStartHtml + text;
|
||||
}
|
||||
}
|
||||
|
||||
pasteHtml(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a paste bin element as close as possible to the current caret location and places the focus inside that element
|
||||
* so that when the real paste event occurs the contents gets inserted into this element
|
||||
* instead of the current editor selection element.
|
||||
*/
|
||||
function createPasteBin() {
|
||||
var dom = editor.dom, body = editor.getBody();
|
||||
var viewport = editor.dom.getViewPort(editor.getWin()), scrollTop = viewport.y, top = 20;
|
||||
var scrollContainer;
|
||||
|
||||
lastRng = editor.selection.getRng();
|
||||
|
||||
if (editor.inline) {
|
||||
scrollContainer = editor.selection.getScrollContainer();
|
||||
|
||||
// Can't always rely on scrollTop returning a useful value.
|
||||
// It returns 0 if the browser doesn't support scrollTop for the element or is non-scrollable
|
||||
if (scrollContainer && scrollContainer.scrollTop > 0) {
|
||||
scrollTop = scrollContainer.scrollTop;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rect of the current caret if the caret is in an empty block before a
|
||||
* BR we insert a temporary invisible character that we get the rect this way we always get a proper rect.
|
||||
*
|
||||
* TODO: This might be useful in core.
|
||||
*/
|
||||
function getCaretRect(rng) {
|
||||
var rects, textNode, node, container = rng.startContainer;
|
||||
|
||||
rects = rng.getClientRects();
|
||||
if (rects.length) {
|
||||
return rects[0];
|
||||
}
|
||||
|
||||
if (!rng.collapsed || container.nodeType != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
node = container.childNodes[lastRng.startOffset];
|
||||
|
||||
// Skip empty whitespace nodes
|
||||
while (node && node.nodeType == 3 && !node.data.length) {
|
||||
node = node.nextSibling;
|
||||
}
|
||||
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the location is |<br>
|
||||
// TODO: Might need to expand this to say |<table>
|
||||
if (node.tagName == 'BR') {
|
||||
textNode = dom.doc.createTextNode('\uFEFF');
|
||||
node.parentNode.insertBefore(textNode, node);
|
||||
|
||||
rng = dom.createRng();
|
||||
rng.setStartBefore(textNode);
|
||||
rng.setEndAfter(textNode);
|
||||
|
||||
rects = rng.getClientRects();
|
||||
dom.remove(textNode);
|
||||
}
|
||||
|
||||
if (rects.length) {
|
||||
return rects[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate top cordinate this is needed to avoid scrolling to top of document
|
||||
// We want the paste bin to be as close to the caret as possible to avoid scrolling
|
||||
if (lastRng.getClientRects) {
|
||||
var rect = getCaretRect(lastRng);
|
||||
|
||||
if (rect) {
|
||||
// Client rects gets us closes to the actual
|
||||
// caret location in for example a wrapped paragraph block
|
||||
top = scrollTop + (rect.top - dom.getPos(body).y);
|
||||
} else {
|
||||
top = scrollTop;
|
||||
|
||||
// Check if we can find a closer location by checking the range element
|
||||
var container = lastRng.startContainer;
|
||||
if (container) {
|
||||
if (container.nodeType == 3 && container.parentNode != body) {
|
||||
container = container.parentNode;
|
||||
}
|
||||
|
||||
if (container.nodeType == 1) {
|
||||
top = dom.getPos(container, scrollContainer || body).y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a pastebin
|
||||
pasteBinElm = dom.add(editor.getBody(), 'div', {
|
||||
id: "mcepastebin",
|
||||
contentEditable: true,
|
||||
"data-mce-bogus": "all",
|
||||
style: 'position: absolute; top: ' + top + 'px;' +
|
||||
'width: 10px; height: 10px; overflow: hidden; opacity: 0'
|
||||
}, pasteBinDefaultContent);
|
||||
|
||||
// Move paste bin out of sight since the controlSelection rect gets displayed otherwise on IE and Gecko
|
||||
if (Env.ie || Env.gecko) {
|
||||
dom.setStyle(pasteBinElm, 'left', dom.getStyle(body, 'direction', true) == 'rtl' ? 0xFFFF : -0xFFFF);
|
||||
}
|
||||
|
||||
// Prevent focus events from bubbeling fixed FocusManager issues
|
||||
dom.bind(pasteBinElm, 'beforedeactivate focusin focusout', function(e) {
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
pasteBinElm.focus();
|
||||
editor.selection.select(pasteBinElm, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the paste bin if it exists.
|
||||
*/
|
||||
function removePasteBin() {
|
||||
if (pasteBinElm) {
|
||||
var pasteBinClone;
|
||||
|
||||
// WebKit/Blink might clone the div so
|
||||
// lets make sure we remove all clones
|
||||
// TODO: Man o man is this ugly. WebKit is the new IE! Remove this if they ever fix it!
|
||||
while ((pasteBinClone = editor.dom.get('mcepastebin'))) {
|
||||
editor.dom.remove(pasteBinClone);
|
||||
editor.dom.unbind(pasteBinClone);
|
||||
}
|
||||
|
||||
if (lastRng) {
|
||||
editor.selection.setRng(lastRng);
|
||||
}
|
||||
}
|
||||
|
||||
pasteBinElm = lastRng = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of the paste bin as a HTML string.
|
||||
*
|
||||
* @return {String} Get the contents of the paste bin.
|
||||
*/
|
||||
function getPasteBinHtml() {
|
||||
var html = '', pasteBinClones, i, clone, cloneHtml;
|
||||
|
||||
// Since WebKit/Chrome might clone the paste bin when pasting
|
||||
// for example: <img style="float: right"> we need to check if any of them contains some useful html.
|
||||
// TODO: Man o man is this ugly. WebKit is the new IE! Remove this if they ever fix it!
|
||||
pasteBinClones = editor.dom.select('div[id=mcepastebin]');
|
||||
for (i = 0; i < pasteBinClones.length; i++) {
|
||||
clone = pasteBinClones[i];
|
||||
|
||||
// Pasting plain text produces pastebins in pastebinds makes sence right!?
|
||||
if (clone.firstChild && clone.firstChild.id == 'mcepastebin') {
|
||||
clone = clone.firstChild;
|
||||
}
|
||||
|
||||
cloneHtml = clone.innerHTML;
|
||||
if (html != pasteBinDefaultContent) {
|
||||
html += cloneHtml;
|
||||
}
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets various content types out of a datatransfer object.
|
||||
*
|
||||
* @param {DataTransfer} dataTransfer Event fired on paste.
|
||||
* @return {Object} Object with mime types and data for those mime types.
|
||||
*/
|
||||
function getDataTransferItems(dataTransfer) {
|
||||
var data = {};
|
||||
|
||||
if (dataTransfer) {
|
||||
// Use old WebKit/IE API
|
||||
if (dataTransfer.getData) {
|
||||
var legacyText = dataTransfer.getData('Text');
|
||||
if (legacyText && legacyText.length > 0) {
|
||||
if (legacyText.indexOf(mceInternalUrlPrefix) == -1) {
|
||||
data['text/plain'] = legacyText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (dataTransfer.types) {
|
||||
for (var i = 0; i < dataTransfer.types.length; i++) {
|
||||
var contentType = dataTransfer.types[i];
|
||||
data[contentType] = dataTransfer.getData(contentType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets various content types out of the Clipboard API. It will also get the
|
||||
* plain text using older IE and WebKit API:s.
|
||||
*
|
||||
* @param {ClipboardEvent} clipboardEvent Event fired on paste.
|
||||
* @return {Object} Object with mime types and data for those mime types.
|
||||
*/
|
||||
function getClipboardContent(clipboardEvent) {
|
||||
return getDataTransferItems(clipboardEvent.clipboardData || editor.getDoc().dataTransfer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the clipboard contains image data if it does it will take that data
|
||||
* and convert it into a data url image and paste that image at the caret location.
|
||||
*
|
||||
* @param {ClipboardEvent} e Paste/drop event object.
|
||||
* @param {DOMRange} rng Optional rng object to move selection to.
|
||||
* @return {Boolean} true/false if the image data was found or not.
|
||||
*/
|
||||
function pasteImageData(e, rng) {
|
||||
var dataTransfer = e.clipboardData || e.dataTransfer;
|
||||
|
||||
function processItems(items) {
|
||||
var i, item, reader, hadImage = false;
|
||||
|
||||
function pasteImage(reader) {
|
||||
if (rng) {
|
||||
editor.selection.setRng(rng);
|
||||
rng = null;
|
||||
}
|
||||
|
||||
pasteHtml('<img src="' + reader.result + '">');
|
||||
}
|
||||
|
||||
if (items) {
|
||||
for (i = 0; i < items.length; i++) {
|
||||
item = items[i];
|
||||
|
||||
if (/^image\/(jpeg|png|gif|bmp)$/.test(item.type)) {
|
||||
reader = new FileReader();
|
||||
reader.onload = pasteImage.bind(null, reader);
|
||||
reader.readAsDataURL(item.getAsFile ? item.getAsFile() : item);
|
||||
|
||||
e.preventDefault();
|
||||
hadImage = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hadImage;
|
||||
}
|
||||
|
||||
if (editor.settings.paste_data_images && dataTransfer) {
|
||||
return processItems(dataTransfer.items) || processItems(dataTransfer.files);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Chrome on Android doesn't support proper clipboard access so we have no choice but to allow the browser default behavior.
|
||||
*
|
||||
* @param {Event} e Paste event object to check if it contains any data.
|
||||
* @return {Boolean} true/false if the clipboard is empty or not.
|
||||
*/
|
||||
function isBrokenAndroidClipboardEvent(e) {
|
||||
var clipboardData = e.clipboardData;
|
||||
|
||||
return navigator.userAgent.indexOf('Android') != -1 && clipboardData && clipboardData.items && clipboardData.items.length === 0;
|
||||
}
|
||||
|
||||
function getCaretRangeFromEvent(e) {
|
||||
return RangeUtils.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc());
|
||||
}
|
||||
|
||||
function hasContentType(clipboardContent, mimeType) {
|
||||
return mimeType in clipboardContent && clipboardContent[mimeType].length > 0;
|
||||
}
|
||||
|
||||
function isKeyboardPasteEvent(e) {
|
||||
return (VK.metaKeyPressed(e) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45);
|
||||
}
|
||||
|
||||
function registerEventHandlers() {
|
||||
editor.on('keydown', function(e) {
|
||||
function removePasteBinOnKeyUp(e) {
|
||||
// Ctrl+V or Shift+Insert
|
||||
if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
|
||||
removePasteBin();
|
||||
}
|
||||
}
|
||||
|
||||
// Ctrl+V or Shift+Insert
|
||||
if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
|
||||
keyboardPastePlainTextState = e.shiftKey && e.keyCode == 86;
|
||||
|
||||
// Edge case on Safari on Mac where it doesn't handle Cmd+Shift+V correctly
|
||||
// it fires the keydown but no paste or keyup so we are left with a paste bin
|
||||
if (keyboardPastePlainTextState && Env.webkit && navigator.userAgent.indexOf('Version/') != -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent undoManager keydown handler from making an undo level with the pastebin in it
|
||||
e.stopImmediatePropagation();
|
||||
|
||||
keyboardPasteTimeStamp = new Date().getTime();
|
||||
|
||||
// IE doesn't support Ctrl+Shift+V and it doesn't even produce a paste event
|
||||
// so lets fake a paste event and let IE use the execCommand/dataTransfer methods
|
||||
if (Env.ie && keyboardPastePlainTextState) {
|
||||
e.preventDefault();
|
||||
editor.fire('paste', {ieFake: true});
|
||||
return;
|
||||
}
|
||||
|
||||
removePasteBin();
|
||||
createPasteBin();
|
||||
|
||||
// Remove pastebin if we get a keyup and no paste event
|
||||
// For example pasting a file in IE 11 will not produce a paste event
|
||||
editor.once('keyup', removePasteBinOnKeyUp);
|
||||
editor.once('paste', function() {
|
||||
editor.off('keyup', removePasteBinOnKeyUp);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
editor.on('paste', function(e) {
|
||||
// Getting content from the Clipboard can take some time
|
||||
var clipboardTimer = new Date().getTime();
|
||||
var clipboardContent = getClipboardContent(e);
|
||||
var clipboardDelay = new Date().getTime() - clipboardTimer;
|
||||
|
||||
var isKeyBoardPaste = (new Date().getTime() - keyboardPasteTimeStamp - clipboardDelay) < 1000;
|
||||
var plainTextMode = self.pasteFormat == "text" || keyboardPastePlainTextState;
|
||||
|
||||
keyboardPastePlainTextState = false;
|
||||
|
||||
if (e.isDefaultPrevented() || isBrokenAndroidClipboardEvent(e)) {
|
||||
removePasteBin();
|
||||
return;
|
||||
}
|
||||
|
||||
if (pasteImageData(e)) {
|
||||
removePasteBin();
|
||||
return;
|
||||
}
|
||||
|
||||
// Not a keyboard paste prevent default paste and try to grab the clipboard contents using different APIs
|
||||
if (!isKeyBoardPaste) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
// Try IE only method if paste isn't a keyboard paste
|
||||
if (Env.ie && (!isKeyBoardPaste || e.ieFake)) {
|
||||
createPasteBin();
|
||||
|
||||
editor.dom.bind(pasteBinElm, 'paste', function(e) {
|
||||
e.stopPropagation();
|
||||
});
|
||||
|
||||
editor.getDoc().execCommand('Paste', false, null);
|
||||
clipboardContent["text/html"] = getPasteBinHtml();
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
var content;
|
||||
|
||||
// Grab HTML from Clipboard API or paste bin as a fallback
|
||||
if (hasContentType(clipboardContent, 'text/html')) {
|
||||
content = clipboardContent['text/html'];
|
||||
} else {
|
||||
content = getPasteBinHtml();
|
||||
|
||||
// If paste bin is empty try using plain text mode
|
||||
// since that is better than nothing right
|
||||
if (content == pasteBinDefaultContent) {
|
||||
plainTextMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
content = Utils.trimHtml(content);
|
||||
|
||||
// WebKit has a nice bug where it clones the paste bin if you paste from for example notepad
|
||||
// so we need to force plain text mode in this case
|
||||
if (pasteBinElm && pasteBinElm.firstChild && pasteBinElm.firstChild.id === 'mcepastebin') {
|
||||
plainTextMode = true;
|
||||
}
|
||||
|
||||
removePasteBin();
|
||||
|
||||
// If we got nothing from clipboard API and pastebin then we could try the last resort: plain/text
|
||||
if (!content.length) {
|
||||
plainTextMode = true;
|
||||
}
|
||||
|
||||
// Grab plain text from Clipboard API or convert existing HTML to plain text
|
||||
if (plainTextMode) {
|
||||
// Use plain text contents from Clipboard API unless the HTML contains paragraphs then
|
||||
// we should convert the HTML to plain text since works better when pasting HTML/Word contents as plain text
|
||||
if (hasContentType(clipboardContent, 'text/plain') && content.indexOf('</p>') == -1) {
|
||||
content = clipboardContent['text/plain'];
|
||||
} else {
|
||||
content = Utils.innerText(content);
|
||||
}
|
||||
}
|
||||
|
||||
// If the content is the paste bin default HTML then it was
|
||||
// impossible to get the cliboard data out.
|
||||
if (content == pasteBinDefaultContent) {
|
||||
if (!isKeyBoardPaste) {
|
||||
editor.windowManager.alert('Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents.');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (plainTextMode) {
|
||||
pasteText(content);
|
||||
} else {
|
||||
pasteHtml(content);
|
||||
}
|
||||
}, 0);
|
||||
});
|
||||
|
||||
editor.on('dragstart dragend', function(e) {
|
||||
draggingInternally = e.type == 'dragstart';
|
||||
});
|
||||
|
||||
editor.on('drop', function(e) {
|
||||
var rng = getCaretRangeFromEvent(e);
|
||||
|
||||
if (e.isDefaultPrevented() || draggingInternally) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pasteImageData(e, rng)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (rng && editor.settings.paste_filter_drop !== false) {
|
||||
var dropContent = getDataTransferItems(e.dataTransfer);
|
||||
var content = dropContent['mce-internal'] || dropContent['text/html'] || dropContent['text/plain'];
|
||||
|
||||
if (content) {
|
||||
e.preventDefault();
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
if (dropContent['mce-internal']) {
|
||||
editor.execCommand('Delete');
|
||||
}
|
||||
|
||||
editor.selection.setRng(rng);
|
||||
|
||||
content = Utils.trimHtml(content);
|
||||
|
||||
if (!dropContent['text/html']) {
|
||||
pasteText(content);
|
||||
} else {
|
||||
pasteHtml(content);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
editor.on('dragover dragend', function(e) {
|
||||
if (editor.settings.paste_data_images) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
self.pasteHtml = pasteHtml;
|
||||
self.pasteText = pasteText;
|
||||
|
||||
editor.on('preInit', function() {
|
||||
registerEventHandlers();
|
||||
|
||||
// Remove all data images from paste for example from Gecko
|
||||
// except internal images like video elements
|
||||
editor.parser.addNodeFilter('img', function(nodes) {
|
||||
if (!editor.settings.paste_data_images) {
|
||||
var i = nodes.length;
|
||||
|
||||
while (i--) {
|
||||
var src = nodes[i].attributes.map.src;
|
||||
|
||||
// Some browsers automatically produce data uris on paste
|
||||
// Safari on Mac produces webkit-fake-url see: https://bugs.webkit.org/show_bug.cgi?id=49141
|
||||
if (src && /^(data:image|webkit\-fake\-url)/.test(src)) {
|
||||
if (!nodes[i].attr('data-mce-object') && src !== Env.transparentSrc) {
|
||||
nodes[i].remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
110
public/tinymce/plugins/paste_raw/classes/Plugin.js
Executable file
110
public/tinymce/plugins/paste_raw/classes/Plugin.js
Executable file
@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Plugin.js
|
||||
*
|
||||
* Copyright, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class contains the tinymce plugin logic for the paste plugin.
|
||||
*
|
||||
* @class tinymce.pasteplugin.Plugin
|
||||
* @private
|
||||
*/
|
||||
define("tinymce/pasteplugin/Plugin", [
|
||||
"tinymce/PluginManager",
|
||||
"tinymce/pasteplugin/Clipboard",
|
||||
"tinymce/pasteplugin/WordFilter",
|
||||
"tinymce/pasteplugin/Quirks"
|
||||
], function(PluginManager, Clipboard, WordFilter, Quirks) {
|
||||
var userIsInformed;
|
||||
|
||||
PluginManager.add('paste', function(editor) {
|
||||
var self = this, clipboard, settings = editor.settings;
|
||||
|
||||
function togglePlainTextPaste() {
|
||||
if (clipboard.pasteFormat == "text") {
|
||||
this.active(false);
|
||||
clipboard.pasteFormat = "html";
|
||||
} else {
|
||||
clipboard.pasteFormat = "text";
|
||||
this.active(true);
|
||||
|
||||
if (!userIsInformed) {
|
||||
editor.windowManager.alert(
|
||||
'Paste is now in plain text mode. Contents will now ' +
|
||||
'be pasted as plain text until you toggle this option off.'
|
||||
);
|
||||
|
||||
userIsInformed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.clipboard = clipboard = new Clipboard(editor);
|
||||
self.quirks = new Quirks(editor);
|
||||
self.wordFilter = new WordFilter(editor);
|
||||
|
||||
if (editor.settings.paste_as_text) {
|
||||
self.clipboard.pasteFormat = "text";
|
||||
}
|
||||
|
||||
if (settings.paste_preprocess) {
|
||||
editor.on('PastePreProcess', function(e) {
|
||||
settings.paste_preprocess.call(self, self, e);
|
||||
});
|
||||
}
|
||||
|
||||
if (settings.paste_postprocess) {
|
||||
editor.on('PastePostProcess', function(e) {
|
||||
settings.paste_postprocess.call(self, self, e);
|
||||
});
|
||||
}
|
||||
|
||||
editor.addCommand('mceInsertClipboardContent', function(ui, value) {
|
||||
if (value.content) {
|
||||
self.clipboard.pasteHtml(value.content);
|
||||
}
|
||||
|
||||
if (value.text) {
|
||||
self.clipboard.pasteText(value.text);
|
||||
}
|
||||
});
|
||||
|
||||
// Block all drag/drop events
|
||||
if (editor.paste_block_drop) {
|
||||
editor.on('dragend dragover draggesture dragdrop drop drag', function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
});
|
||||
}
|
||||
|
||||
// Prevent users from dropping data images on Gecko
|
||||
if (!editor.settings.paste_data_images) {
|
||||
editor.on('drop', function(e) {
|
||||
var dataTransfer = e.dataTransfer;
|
||||
|
||||
if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
editor.addButton('pastetext', {
|
||||
icon: 'pastetext',
|
||||
tooltip: 'Paste as text',
|
||||
onclick: togglePlainTextPaste,
|
||||
active: self.clipboard.pasteFormat == "text"
|
||||
});
|
||||
|
||||
editor.addMenuItem('pastetext', {
|
||||
text: 'Paste as text',
|
||||
selectable: true,
|
||||
active: clipboard.pasteFormat,
|
||||
onclick: togglePlainTextPaste
|
||||
});
|
||||
});
|
||||
});
|
159
public/tinymce/plugins/paste_raw/classes/Quirks.js
Executable file
159
public/tinymce/plugins/paste_raw/classes/Quirks.js
Executable file
@ -0,0 +1,159 @@
|
||||
/**
|
||||
* Quirks.js
|
||||
*
|
||||
* Copyright, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class contains various fixes for browsers. These issues can not be feature
|
||||
* detected since we have no direct control over the clipboard. However we might be able
|
||||
* to remove some of these fixes once the browsers gets updated/fixed.
|
||||
*
|
||||
* @class tinymce.pasteplugin.Quirks
|
||||
* @private
|
||||
*/
|
||||
define("tinymce/pasteplugin/Quirks", [
|
||||
"tinymce/Env",
|
||||
"tinymce/util/Tools",
|
||||
"tinymce/pasteplugin/WordFilter",
|
||||
"tinymce/pasteplugin/Utils"
|
||||
], function(Env, Tools, WordFilter, Utils) {
|
||||
"use strict";
|
||||
|
||||
return function(editor) {
|
||||
function addPreProcessFilter(filterFunc) {
|
||||
editor.on('BeforePastePreProcess', function(e) {
|
||||
e.content = filterFunc(e.content);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes BR elements after block elements. IE9 has a nasty bug where it puts a BR element after each
|
||||
* block element when pasting from word. This removes those elements.
|
||||
*
|
||||
* This:
|
||||
* <p>a</p><br><p>b</p>
|
||||
*
|
||||
* Becomes:
|
||||
* <p>a</p><p>b</p>
|
||||
*/
|
||||
function removeExplorerBrElementsAfterBlocks(html) {
|
||||
// Only filter word specific content
|
||||
if (!WordFilter.isWordContent(html)) {
|
||||
return html;
|
||||
}
|
||||
|
||||
// Produce block regexp based on the block elements in schema
|
||||
var blockElements = [];
|
||||
|
||||
Tools.each(editor.schema.getBlockElements(), function(block, blockName) {
|
||||
blockElements.push(blockName);
|
||||
});
|
||||
|
||||
var explorerBlocksRegExp = new RegExp(
|
||||
'(?:<br> [\\s\\r\\n]+|<br>)*(<\\/?(' + blockElements.join('|') + ')[^>]*>)(?:<br> [\\s\\r\\n]+|<br>)*',
|
||||
'g'
|
||||
);
|
||||
|
||||
// Remove BR:s from: <BLOCK>X</BLOCK><BR>
|
||||
html = Utils.filter(html, [
|
||||
[explorerBlocksRegExp, '$1']
|
||||
]);
|
||||
|
||||
// IE9 also adds an extra BR element for each soft-linefeed and it also adds a BR for each word wrap break
|
||||
html = Utils.filter(html, [
|
||||
[/<br><br>/g, '<BR><BR>'], // Replace multiple BR elements with uppercase BR to keep them intact
|
||||
[/<br>/g, ' '], // Replace single br elements with space since they are word wrap BR:s
|
||||
[/<BR><BR>/g, '<br>'] // Replace back the double brs but into a single BR
|
||||
]);
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
* WebKit has a nasty bug where the all computed styles gets added to style attributes when copy/pasting contents.
|
||||
* This fix solves that by simply removing the whole style attribute.
|
||||
*
|
||||
* The paste_webkit_styles option can be set to specify what to keep:
|
||||
* paste_webkit_styles: "none" // Keep no styles
|
||||
* paste_webkit_styles: "all", // Keep all of them
|
||||
* paste_webkit_styles: "font-weight color" // Keep specific ones
|
||||
*
|
||||
* @param {String} content Content that needs to be processed.
|
||||
* @return {String} Processed contents.
|
||||
*/
|
||||
function removeWebKitStyles(content) {
|
||||
// Passthrough all styles from Word and let the WordFilter handle that junk
|
||||
if (WordFilter.isWordContent(content)) {
|
||||
return content;
|
||||
}
|
||||
|
||||
// Filter away styles that isn't matching the target node
|
||||
var webKitStyles = editor.settings.paste_webkit_styles;
|
||||
|
||||
if (editor.settings.paste_remove_styles_if_webkit === false || webKitStyles == "all") {
|
||||
return content;
|
||||
}
|
||||
|
||||
if (webKitStyles) {
|
||||
webKitStyles = webKitStyles.split(/[, ]/);
|
||||
}
|
||||
|
||||
// Keep specific styles that doesn't match the current node computed style
|
||||
if (webKitStyles) {
|
||||
var dom = editor.dom, node = editor.selection.getNode();
|
||||
|
||||
content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, function(all, before, value, after) {
|
||||
var inputStyles = dom.parseStyle(value, 'span'), outputStyles = {};
|
||||
|
||||
if (webKitStyles === "none") {
|
||||
return before + after;
|
||||
}
|
||||
|
||||
for (var i = 0; i < webKitStyles.length; i++) {
|
||||
var inputValue = inputStyles[webKitStyles[i]], currentValue = dom.getStyle(node, webKitStyles[i], true);
|
||||
|
||||
if (/color/.test(webKitStyles[i])) {
|
||||
inputValue = dom.toHex(inputValue);
|
||||
currentValue = dom.toHex(currentValue);
|
||||
}
|
||||
|
||||
if (currentValue != inputValue) {
|
||||
outputStyles[webKitStyles[i]] = inputValue;
|
||||
}
|
||||
}
|
||||
|
||||
outputStyles = dom.serializeStyle(outputStyles, 'span');
|
||||
if (outputStyles) {
|
||||
return before + ' style="' + outputStyles + '"' + after;
|
||||
}
|
||||
|
||||
return before + after;
|
||||
});
|
||||
} else {
|
||||
// Remove all external styles
|
||||
content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, '$1$3');
|
||||
}
|
||||
|
||||
// Keep internal styles
|
||||
content = content.replace(/(<[^>]+) data-mce-style="([^"]+)"([^>]*>)/gi, function(all, before, value, after) {
|
||||
return before + ' style="' + value + '"' + after;
|
||||
});
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
// Sniff browsers and apply fixes since we can't feature detect
|
||||
if (Env.webkit) {
|
||||
addPreProcessFilter(removeWebKitStyles);
|
||||
}
|
||||
|
||||
if (Env.ie) {
|
||||
addPreProcessFilter(removeExplorerBrElementsAfterBlocks);
|
||||
}
|
||||
};
|
||||
});
|
129
public/tinymce/plugins/paste_raw/classes/Utils.js
Executable file
129
public/tinymce/plugins/paste_raw/classes/Utils.js
Executable file
@ -0,0 +1,129 @@
|
||||
/**
|
||||
* Utils.js
|
||||
*
|
||||
* Copyright, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class contails various utility functions for the paste plugin.
|
||||
*
|
||||
* @class tinymce.pasteplugin.Utils
|
||||
*/
|
||||
define("tinymce/pasteplugin/Utils", [
|
||||
"tinymce/util/Tools",
|
||||
"tinymce/html/DomParser",
|
||||
"tinymce/html/Schema"
|
||||
], function(Tools, DomParser, Schema) {
|
||||
function filter(content, items) {
|
||||
Tools.each(items, function(v) {
|
||||
if (v.constructor == RegExp) {
|
||||
content = content.replace(v, '');
|
||||
} else {
|
||||
content = content.replace(v[0], v[1]);
|
||||
}
|
||||
});
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the innerText of the specified element. It will handle edge cases
|
||||
* and works better than textContent on Gecko.
|
||||
*
|
||||
* @param {String} html HTML string to get text from.
|
||||
* @return {String} String of text with line feeds.
|
||||
*/
|
||||
function innerText(html) {
|
||||
var schema = new Schema(), domParser = new DomParser({}, schema), text = '';
|
||||
var shortEndedElements = schema.getShortEndedElements();
|
||||
var ignoreElements = Tools.makeMap('script noscript style textarea video audio iframe object', ' ');
|
||||
var blockElements = schema.getBlockElements();
|
||||
|
||||
function walk(node) {
|
||||
var name = node.name, currentNode = node;
|
||||
|
||||
if (name === 'br') {
|
||||
text += '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
// img/input/hr
|
||||
if (shortEndedElements[name]) {
|
||||
text += ' ';
|
||||
}
|
||||
|
||||
// Ingore script, video contents
|
||||
if (ignoreElements[name]) {
|
||||
text += ' ';
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.type == 3) {
|
||||
text += node.value;
|
||||
}
|
||||
|
||||
// Walk all children
|
||||
if (!node.shortEnded) {
|
||||
if ((node = node.firstChild)) {
|
||||
do {
|
||||
walk(node);
|
||||
} while ((node = node.next));
|
||||
}
|
||||
}
|
||||
|
||||
// Add \n or \n\n for blocks or P
|
||||
if (blockElements[name] && currentNode.next) {
|
||||
text += '\n';
|
||||
|
||||
if (name == 'p') {
|
||||
text += '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
html = filter(html, [
|
||||
/<!\[[^\]]+\]>/g // Conditional comments
|
||||
]);
|
||||
|
||||
walk(domParser.parse(html));
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims the specified HTML by removing all WebKit fragments, all elements wrapping the body trailing BR elements etc.
|
||||
*
|
||||
* @param {String} html Html string to trim contents on.
|
||||
* @return {String} Html contents that got trimmed.
|
||||
*/
|
||||
function trimHtml(html) {
|
||||
function trimSpaces(all, s1, s2) {
|
||||
// WebKit meant to preserve multiple spaces but instead inserted around all inline tags,
|
||||
// including the spans with inline styles created on paste
|
||||
if (!s1 && !s2) {
|
||||
return ' ';
|
||||
}
|
||||
|
||||
return '\u00a0';
|
||||
}
|
||||
|
||||
html = filter(html, [
|
||||
/^[\s\S]*<body[^>]*>\s*|\s*<\/body[^>]*>[\s\S]*$/g, // Remove anything but the contents within the BODY element
|
||||
/<!--StartFragment-->|<!--EndFragment-->/g, // Inner fragments (tables from excel on mac)
|
||||
[/( ?)<span class="Apple-converted-space">\u00a0<\/span>( ?)/g, trimSpaces],
|
||||
/<br>$/i // Trailing BR elements
|
||||
]);
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
return {
|
||||
filter: filter,
|
||||
innerText: innerText,
|
||||
trimHtml: trimHtml
|
||||
};
|
||||
});
|
498
public/tinymce/plugins/paste_raw/classes/WordFilter.js
Executable file
498
public/tinymce/plugins/paste_raw/classes/WordFilter.js
Executable file
@ -0,0 +1,498 @@
|
||||
/**
|
||||
* WordFilter.js
|
||||
*
|
||||
* Copyright, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class parses word HTML into proper TinyMCE markup.
|
||||
*
|
||||
* @class tinymce.pasteplugin.WordFilter
|
||||
* @private
|
||||
*/
|
||||
define("tinymce/pasteplugin/WordFilter", [
|
||||
"tinymce/util/Tools",
|
||||
"tinymce/html/DomParser",
|
||||
"tinymce/html/Schema",
|
||||
"tinymce/html/Serializer",
|
||||
"tinymce/html/Node",
|
||||
"tinymce/pasteplugin/Utils"
|
||||
], function(Tools, DomParser, Schema, Serializer, Node, Utils) {
|
||||
/**
|
||||
* Checks if the specified content is from any of the following sources: MS Word/Office 365/Google docs.
|
||||
*/
|
||||
function isWordContent(content) {
|
||||
return (
|
||||
(/<font face="Times New Roman"|class="?Mso|style="[^"]*\bmso-|style='[^'']*\bmso-|w:WordDocument/i).test(content) ||
|
||||
(/class="OutlineElement/).test(content) ||
|
||||
(/id="?docs\-internal\-guid\-/.test(content))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the specified text starts with "1. " or "a. " etc.
|
||||
*/
|
||||
function isNumericList(text) {
|
||||
var found, patterns;
|
||||
|
||||
patterns = [
|
||||
/^[IVXLMCD]{1,2}\.[ \u00a0]/, // Roman upper case
|
||||
/^[ivxlmcd]{1,2}\.[ \u00a0]/, // Roman lower case
|
||||
/^[a-z]{1,2}[\.\)][ \u00a0]/, // Alphabetical a-z
|
||||
/^[A-Z]{1,2}[\.\)][ \u00a0]/, // Alphabetical A-Z
|
||||
/^[0-9]+\.[ \u00a0]/, // Numeric lists
|
||||
/^[\u3007\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d]+\.[ \u00a0]/, // Japanese
|
||||
/^[\u58f1\u5f10\u53c2\u56db\u4f0d\u516d\u4e03\u516b\u4e5d\u62fe]+\.[ \u00a0]/ // Chinese
|
||||
];
|
||||
|
||||
text = text.replace(/^[\u00a0 ]+/, '');
|
||||
|
||||
Tools.each(patterns, function(pattern) {
|
||||
if (pattern.test(text)) {
|
||||
found = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
function isBulletList(text) {
|
||||
return /^[\s\u00a0]*[\u2022\u00b7\u00a7\u25CF]\s*/.test(text);
|
||||
}
|
||||
|
||||
function WordFilter(editor) {
|
||||
var settings = editor.settings;
|
||||
|
||||
editor.on('BeforePastePreProcess', function(e) {
|
||||
var content = e.content, retainStyleProperties, validStyles;
|
||||
|
||||
// Remove google docs internal guid markers
|
||||
content = content.replace(/<b[^>]+id="?docs-internal-[^>]*>/gi, '');
|
||||
content = content.replace(/<br class="?Apple-interchange-newline"?>/gi, '');
|
||||
|
||||
retainStyleProperties = settings.paste_retain_style_properties;
|
||||
if (retainStyleProperties) {
|
||||
validStyles = Tools.makeMap(retainStyleProperties.split(/[, ]/));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts fake bullet and numbered lists to real semantic OL/UL.
|
||||
*
|
||||
* @param {tinymce.html.Node} node Root node to convert children of.
|
||||
*/
|
||||
function convertFakeListsToProperLists(node) {
|
||||
var currentListNode, prevListNode, lastLevel = 1;
|
||||
|
||||
function getText(node) {
|
||||
var txt = '';
|
||||
|
||||
if (node.type === 3) {
|
||||
return node.value;
|
||||
}
|
||||
|
||||
if ((node = node.firstChild)) {
|
||||
do {
|
||||
txt += getText(node);
|
||||
} while ((node = node.next));
|
||||
}
|
||||
|
||||
return txt;
|
||||
}
|
||||
|
||||
function trimListStart(node, regExp) {
|
||||
if (node.type === 3) {
|
||||
if (regExp.test(node.value)) {
|
||||
node.value = node.value.replace(regExp, '');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = node.firstChild)) {
|
||||
do {
|
||||
if (!trimListStart(node, regExp)) {
|
||||
return false;
|
||||
}
|
||||
} while ((node = node.next));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function removeIgnoredNodes(node) {
|
||||
if (node._listIgnore) {
|
||||
node.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((node = node.firstChild)) {
|
||||
do {
|
||||
removeIgnoredNodes(node);
|
||||
} while ((node = node.next));
|
||||
}
|
||||
}
|
||||
|
||||
function convertParagraphToLi(paragraphNode, listName, start) {
|
||||
var level = paragraphNode._listLevel || lastLevel;
|
||||
|
||||
// Handle list nesting
|
||||
if (level != lastLevel) {
|
||||
if (level < lastLevel) {
|
||||
// Move to parent list
|
||||
if (currentListNode) {
|
||||
currentListNode = currentListNode.parent.parent;
|
||||
}
|
||||
} else {
|
||||
// Create new list
|
||||
prevListNode = currentListNode;
|
||||
currentListNode = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentListNode || currentListNode.name != listName) {
|
||||
prevListNode = prevListNode || currentListNode;
|
||||
currentListNode = new Node(listName, 1);
|
||||
|
||||
if (start > 1) {
|
||||
currentListNode.attr('start', '' + start);
|
||||
}
|
||||
|
||||
paragraphNode.wrap(currentListNode);
|
||||
} else {
|
||||
currentListNode.append(paragraphNode);
|
||||
}
|
||||
|
||||
paragraphNode.name = 'li';
|
||||
|
||||
// Append list to previous list if it exists
|
||||
if (level > lastLevel && prevListNode) {
|
||||
prevListNode.lastChild.append(currentListNode);
|
||||
}
|
||||
|
||||
lastLevel = level;
|
||||
|
||||
// Remove start of list item "1. " or "· " etc
|
||||
removeIgnoredNodes(paragraphNode);
|
||||
trimListStart(paragraphNode, /^\u00a0+/);
|
||||
trimListStart(paragraphNode, /^\s*([\u2022\u00b7\u00a7\u25CF]|\w+\.)/);
|
||||
trimListStart(paragraphNode, /^\u00a0+/);
|
||||
}
|
||||
|
||||
// Build a list of all root level elements before we start
|
||||
// altering them in the loop below.
|
||||
var elements = [], child = node.firstChild;
|
||||
while (typeof child !== 'undefined' && child !== null) {
|
||||
elements.push(child);
|
||||
|
||||
child = child.walk();
|
||||
if (child !== null) {
|
||||
while (typeof child !== 'undefined' && child.parent !== node) {
|
||||
child = child.walk();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
node = elements[i];
|
||||
|
||||
if (node.name == 'p' && node.firstChild) {
|
||||
// Find first text node in paragraph
|
||||
var nodeText = getText(node);
|
||||
|
||||
// Detect unordered lists look for bullets
|
||||
if (isBulletList(nodeText)) {
|
||||
convertParagraphToLi(node, 'ul');
|
||||
continue;
|
||||
}
|
||||
|
||||
// Detect ordered lists 1., a. or ixv.
|
||||
if (isNumericList(nodeText)) {
|
||||
// Parse OL start number
|
||||
var matches = /([0-9]+)\./.exec(nodeText);
|
||||
var start = 1;
|
||||
if (matches) {
|
||||
start = parseInt(matches[1], 10);
|
||||
}
|
||||
|
||||
convertParagraphToLi(node, 'ol', start);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Convert paragraphs marked as lists but doesn't look like anything
|
||||
if (node._listLevel) {
|
||||
convertParagraphToLi(node, 'ul', 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
currentListNode = null;
|
||||
} else {
|
||||
// If the root level element isn't a p tag which can be
|
||||
// processed by convertParagraphToLi, it interrupts the
|
||||
// lists, causing a new list to start instead of having
|
||||
// elements from the next list inserted above this tag.
|
||||
prevListNode = currentListNode;
|
||||
currentListNode = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function filterStyles(node, styleValue) {
|
||||
var outputStyles = {}, matches, styles = editor.dom.parseStyle(styleValue);
|
||||
|
||||
Tools.each(styles, function(value, name) {
|
||||
// Convert various MS styles to W3C styles
|
||||
switch (name) {
|
||||
case 'mso-list':
|
||||
// Parse out list indent level for lists
|
||||
matches = /\w+ \w+([0-9]+)/i.exec(styleValue);
|
||||
if (matches) {
|
||||
node._listLevel = parseInt(matches[1], 10);
|
||||
}
|
||||
|
||||
// Remove these nodes <span style="mso-list:Ignore">o</span>
|
||||
// Since the span gets removed we mark the text node and the span
|
||||
if (/Ignore/i.test(value) && node.firstChild) {
|
||||
node._listIgnore = true;
|
||||
node.firstChild._listIgnore = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "horiz-align":
|
||||
name = "text-align";
|
||||
break;
|
||||
|
||||
case "vert-align":
|
||||
name = "vertical-align";
|
||||
break;
|
||||
|
||||
case "font-color":
|
||||
case "mso-foreground":
|
||||
name = "color";
|
||||
break;
|
||||
|
||||
case "mso-background":
|
||||
case "mso-highlight":
|
||||
name = "background";
|
||||
break;
|
||||
|
||||
case "font-weight":
|
||||
case "font-style":
|
||||
if (value != "normal") {
|
||||
outputStyles[name] = value;
|
||||
}
|
||||
return;
|
||||
|
||||
case "mso-element":
|
||||
// Remove track changes code
|
||||
if (/^(comment|comment-list)$/i.test(value)) {
|
||||
node.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (name.indexOf('mso-comment') === 0) {
|
||||
node.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
// Never allow mso- prefixed names
|
||||
if (name.indexOf('mso-') === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Output only valid styles
|
||||
if (retainStyleProperties == "all" || (validStyles && validStyles[name])) {
|
||||
outputStyles[name] = value;
|
||||
}
|
||||
});
|
||||
|
||||
// Convert bold style to "b" element
|
||||
if (/(bold)/i.test(outputStyles["font-weight"])) {
|
||||
delete outputStyles["font-weight"];
|
||||
node.wrap(new Node("b", 1));
|
||||
}
|
||||
|
||||
// Convert italic style to "i" element
|
||||
if (/(italic)/i.test(outputStyles["font-style"])) {
|
||||
delete outputStyles["font-style"];
|
||||
node.wrap(new Node("i", 1));
|
||||
}
|
||||
|
||||
// Serialize the styles and see if there is something left to keep
|
||||
outputStyles = editor.dom.serializeStyle(outputStyles, node.name);
|
||||
if (outputStyles) {
|
||||
return outputStyles;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (settings.paste_enable_default_filters === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Detect is the contents is Word junk HTML
|
||||
if (isWordContent(e.content)) {
|
||||
e.wordContent = true; // Mark it for other processors
|
||||
|
||||
// Remove basic Word junk
|
||||
content = Utils.filter(content, [
|
||||
// Word comments like conditional comments etc
|
||||
/<!--[\s\S]+?-->/gi,
|
||||
|
||||
// Remove comments, scripts (e.g., msoShowComment), XML tag, VML content,
|
||||
// MS Office namespaced tags, and a few other tags
|
||||
/<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,
|
||||
|
||||
// Convert <s> into <strike> for line-though
|
||||
[/<(\/?)s>/gi, "<$1strike>"],
|
||||
|
||||
// Replace nsbp entites to char since it's easier to handle
|
||||
[/ /gi, "\u00a0"],
|
||||
|
||||
// Convert <span style="mso-spacerun:yes">___</span> to string of alternating
|
||||
// breaking/non-breaking spaces of same length
|
||||
[/<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi,
|
||||
function(str, spaces) {
|
||||
return (spaces.length > 0) ?
|
||||
spaces.replace(/./, " ").slice(Math.floor(spaces.length / 2)).split("").join("\u00a0") : "";
|
||||
}
|
||||
]
|
||||
]);
|
||||
|
||||
var validElements = settings.paste_word_valid_elements;
|
||||
if (!validElements) {
|
||||
validElements = (
|
||||
'-strong/b,-em/i,-u,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,' +
|
||||
'-p/div,-a[href|name],sub,sup,strike,br,del,table[width],tr,' +
|
||||
'td[colspan|rowspan|width],th[colspan|rowspan|width],thead,tfoot,tbody'
|
||||
);
|
||||
}
|
||||
|
||||
// Setup strict schema
|
||||
var schema = new Schema({
|
||||
valid_elements: validElements,
|
||||
valid_children: '-li[p]'
|
||||
});
|
||||
|
||||
// Add style/class attribute to all element rules since the user might have removed them from
|
||||
// paste_word_valid_elements config option and we need to check them for properties
|
||||
Tools.each(schema.elements, function(rule) {
|
||||
/*eslint dot-notation:0*/
|
||||
if (!rule.attributes["class"]) {
|
||||
rule.attributes["class"] = {};
|
||||
rule.attributesOrder.push("class");
|
||||
}
|
||||
|
||||
if (!rule.attributes.style) {
|
||||
rule.attributes.style = {};
|
||||
rule.attributesOrder.push("style");
|
||||
}
|
||||
});
|
||||
|
||||
// Parse HTML into DOM structure
|
||||
var domParser = new DomParser({}, schema);
|
||||
|
||||
// Filter styles to remove "mso" specific styles and convert some of them
|
||||
domParser.addAttributeFilter('style', function(nodes) {
|
||||
var i = nodes.length, node;
|
||||
|
||||
while (i--) {
|
||||
node = nodes[i];
|
||||
node.attr('style', filterStyles(node, node.attr('style')));
|
||||
|
||||
// Remove pointess spans
|
||||
if (node.name == 'span' && node.parent && !node.attributes.length) {
|
||||
node.unwrap();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Check the class attribute for comments or del items and remove those
|
||||
domParser.addAttributeFilter('class', function(nodes) {
|
||||
var i = nodes.length, node, className;
|
||||
|
||||
while (i--) {
|
||||
node = nodes[i];
|
||||
|
||||
className = node.attr('class');
|
||||
if (/^(MsoCommentReference|MsoCommentText|msoDel)$/i.test(className)) {
|
||||
node.remove();
|
||||
}
|
||||
|
||||
node.attr('class', null);
|
||||
}
|
||||
});
|
||||
|
||||
// Remove all del elements since we don't want the track changes code in the editor
|
||||
domParser.addNodeFilter('del', function(nodes) {
|
||||
var i = nodes.length;
|
||||
|
||||
while (i--) {
|
||||
nodes[i].remove();
|
||||
}
|
||||
});
|
||||
|
||||
// Keep some of the links and anchors
|
||||
domParser.addNodeFilter('a', function(nodes) {
|
||||
var i = nodes.length, node, href, name;
|
||||
|
||||
while (i--) {
|
||||
node = nodes[i];
|
||||
href = node.attr('href');
|
||||
name = node.attr('name');
|
||||
|
||||
if (href && href.indexOf('#_msocom_') != -1) {
|
||||
node.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (href && href.indexOf('file://') === 0) {
|
||||
href = href.split('#')[1];
|
||||
if (href) {
|
||||
href = '#' + href;
|
||||
}
|
||||
}
|
||||
|
||||
if (!href && !name) {
|
||||
node.unwrap();
|
||||
} else {
|
||||
// Remove all named anchors that aren't specific to TOC, Footnotes or Endnotes
|
||||
if (name && !/^_?(?:toc|edn|ftn)/i.test(name)) {
|
||||
node.unwrap();
|
||||
continue;
|
||||
}
|
||||
|
||||
node.attr({
|
||||
href: href,
|
||||
name: name
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Parse into DOM structure
|
||||
var rootNode = domParser.parse(content);
|
||||
|
||||
// Process DOM
|
||||
if (settings.paste_convert_word_fake_lists !== false) {
|
||||
convertFakeListsToProperLists(rootNode);
|
||||
}
|
||||
|
||||
// Serialize DOM back to HTML
|
||||
e.content = new Serializer({}, schema).serialize(rootNode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
WordFilter.isWordContent = isWordContent;
|
||||
|
||||
return WordFilter;
|
||||
});
|
120
public/tinymce/plugins/paste_raw/plugin.dev.js
Executable file
120
public/tinymce/plugins/paste_raw/plugin.dev.js
Executable file
@ -0,0 +1,120 @@
|
||||
/**
|
||||
* Inline development version. Only to be used while developing since it uses document.write to load scripts.
|
||||
*/
|
||||
|
||||
/*jshint smarttabs:true, undef:true, latedef:true, curly:true, bitwise:true, camelcase:true */
|
||||
/*globals $code */
|
||||
|
||||
(function(exports) {
|
||||
"use strict";
|
||||
|
||||
var html = "", baseDir;
|
||||
var modules = {}, exposedModules = [], moduleCount = 0;
|
||||
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
for (var i = 0; i < scripts.length; i++) {
|
||||
var src = scripts[i].src;
|
||||
|
||||
if (src.indexOf('/plugin.dev.js') != -1) {
|
||||
baseDir = src.substring(0, src.lastIndexOf('/'));
|
||||
}
|
||||
}
|
||||
|
||||
function require(ids, callback) {
|
||||
var module, defs = [];
|
||||
|
||||
for (var i = 0; i < ids.length; ++i) {
|
||||
module = modules[ids[i]] || resolve(ids[i]);
|
||||
if (!module) {
|
||||
throw 'module definition dependecy not found: ' + ids[i];
|
||||
}
|
||||
|
||||
defs.push(module);
|
||||
}
|
||||
|
||||
callback.apply(null, defs);
|
||||
}
|
||||
|
||||
function resolve(id) {
|
||||
var target = exports;
|
||||
var fragments = id.split(/[.\/]/);
|
||||
|
||||
for (var fi = 0; fi < fragments.length; ++fi) {
|
||||
if (!target[fragments[fi]]) {
|
||||
return;
|
||||
}
|
||||
|
||||
target = target[fragments[fi]];
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
function register(id) {
|
||||
var target = exports;
|
||||
var fragments = id.split(/[.\/]/);
|
||||
|
||||
for (var fi = 0; fi < fragments.length - 1; ++fi) {
|
||||
if (target[fragments[fi]] === undefined) {
|
||||
target[fragments[fi]] = {};
|
||||
}
|
||||
|
||||
target = target[fragments[fi]];
|
||||
}
|
||||
|
||||
target[fragments[fragments.length - 1]] = modules[id];
|
||||
}
|
||||
|
||||
function define(id, dependencies, definition) {
|
||||
if (typeof id !== 'string') {
|
||||
throw 'invalid module definition, module id must be defined and be a string';
|
||||
}
|
||||
|
||||
if (dependencies === undefined) {
|
||||
throw 'invalid module definition, dependencies must be specified';
|
||||
}
|
||||
|
||||
if (definition === undefined) {
|
||||
throw 'invalid module definition, definition function must be specified';
|
||||
}
|
||||
|
||||
require(dependencies, function() {
|
||||
modules[id] = definition.apply(null, arguments);
|
||||
});
|
||||
|
||||
if (--moduleCount === 0) {
|
||||
for (var i = 0; i < exposedModules.length; i++) {
|
||||
register(exposedModules[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function expose(ids) {
|
||||
exposedModules = ids;
|
||||
}
|
||||
|
||||
function writeScripts() {
|
||||
document.write(html);
|
||||
}
|
||||
|
||||
function load(path) {
|
||||
html += '<script type="text/javascript" src="' + baseDir + '/' + path + '"></script>\n';
|
||||
moduleCount++;
|
||||
}
|
||||
|
||||
// Expose globally
|
||||
exports.define = define;
|
||||
exports.require = require;
|
||||
|
||||
expose(["tinymce/pasteplugin/Utils"]);
|
||||
|
||||
load('classes/Utils.js');
|
||||
load('classes/Clipboard.js');
|
||||
load('classes/WordFilter.js');
|
||||
load('classes/Quirks.js');
|
||||
load('classes/Plugin.js');
|
||||
|
||||
writeScripts();
|
||||
})(this);
|
||||
|
||||
// $hash: 81d4a05c04adf0776e1e2ca9a3e818bd
|
1606
public/tinymce/plugins/paste_raw/plugin.js
Executable file
1606
public/tinymce/plugins/paste_raw/plugin.js
Executable file
File diff suppressed because it is too large
Load Diff
1
public/tinymce/plugins/paste_raw/plugin.min.js
vendored
Executable file
1
public/tinymce/plugins/paste_raw/plugin.min.js
vendored
Executable file
File diff suppressed because one or more lines are too long
@ -39846,7 +39846,7 @@ tinymce.PluginManager.add('leaui_image', function(editor, url) {
|
||||
LEAUI_DATAS = datas;
|
||||
|
||||
function GetTheHtml(){
|
||||
var html = '<iframe id="leauiIfr" src="'+ url + '/index.html'+ '?' + new Date().getTime() + '" frameborder="0"></iframe>';
|
||||
var html = '<iframe id="leauiIfr" src="/album/index'+ '?' + new Date().getTime() + '" frameborder="0"></iframe>';
|
||||
return html;
|
||||
}
|
||||
|
||||
|
2
public/tinymce/tinymce.full.min.js
vendored
2
public/tinymce/tinymce.full.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user