init
This commit is contained in:
175
public/tinymce/plugins/leanote_image/dialog.html
Normal file
175
public/tinymce/plugins/leanote_image/dialog.html
Normal file
@ -0,0 +1,175 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>上传图片</title>
|
||||
|
||||
<!-- 本插件使用了bootstrap插件, 请修改地址 -->
|
||||
<link href="/css/bootstrap.css" rel="stylesheet" type="text/css">
|
||||
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
position: relative;
|
||||
padding: 0 5px;
|
||||
}
|
||||
|
||||
#bottomBtns {
|
||||
border-top: 1px solid #ccc;
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
padding: 5px 10px 2px 0;
|
||||
}
|
||||
|
||||
#bottomBtns div {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
#upload {
|
||||
margin-top: 10px;
|
||||
}
|
||||
#uploadTarget {
|
||||
border: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.uploadInfobar {
|
||||
display: none;
|
||||
font-size: 12pt;
|
||||
background: #fff;
|
||||
margin: 0;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.uploadInfobar img {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
#uploadAdditionalInfo {
|
||||
padding-left: 26px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* 拖拽 */
|
||||
|
||||
#dropbox {
|
||||
border-radius: 3px;
|
||||
position: relative;
|
||||
min-height: 200px;
|
||||
overflow: hidden;
|
||||
padding-bottom: 40px;
|
||||
border: 1px solid #ccc;
|
||||
width: 100%;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
#dropbox .message {
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
padding-top: 80px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
#dropbox .message i {
|
||||
color: #ccc;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
#dropbox:before {
|
||||
border-radius: 3px 3px 0 0;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<ul id="myTab" class="nav nav-tabs">
|
||||
<li class="active"><a href="#upload" data-toggle="tab">上传图片</a></li>
|
||||
<li class=""><a href="#url" data-toggle="tab">图片URL</a></li>
|
||||
</ul>
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
|
||||
<div class="tab-pane active" id="upload">
|
||||
<!-- 请修改图片接收地址 -->
|
||||
<form class="form-inline" id="upl" name="upl"
|
||||
action="/file/uploadImage"
|
||||
method="post" enctype="multipart/form-data"
|
||||
target="uploadTarget"
|
||||
>
|
||||
<div id="uploadInProgress" class="alert alert-warning uploadInfobar">
|
||||
<img src="img/loading-24.gif" /> 正在上传...
|
||||
</div>
|
||||
|
||||
<p id="uploadFormContainer">
|
||||
<input id="uploader" name="file" type="file" class="form-control" />
|
||||
</p>
|
||||
</form>
|
||||
<iframe id="uploadTarget" name="uploadTarget" src="#"></iframe>
|
||||
|
||||
<!--
|
||||
拖拽上传
|
||||
TODO 判断浏览器是否支持, 若不支持则不显示
|
||||
-->
|
||||
<div id="dropbox">
|
||||
<div class="message">
|
||||
或将图片拖到这里上传.
|
||||
<div class="progress">
|
||||
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- tinymce 自带的image插件 -->
|
||||
<div class="tab-pane" id="url" style="margin-top: 10px;">
|
||||
<form class="form-inline" id="imageSrc2">
|
||||
<table style="width: 100%">
|
||||
<tr>
|
||||
<th style="width: 50px"><label for="imageSrc">地址</label></th>
|
||||
<td><input type="url" id="imageSrc" name="src" class="form-control"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><label for="imageWidth">大小</label></th>
|
||||
<td>
|
||||
<input type="text" class="form-control" id="imageWidth" name="width" style="width: 100px; display: inline-block"/>
|
||||
X
|
||||
<input type="text" class="form-control" id="imageHeight" name="height" style="width: 100px; display: inline-block"/>
|
||||
<label>
|
||||
<input type="checkbox" checked="checked" id="autoScale"/>
|
||||
按比例缩放
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="bottomBtns">
|
||||
<div>
|
||||
<button class="btn btn-success" id="insertImageBtn">确定</button>
|
||||
<button class="btn btn-default" id="closeBtn" onclick="">关闭</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 本插件使用了jquery和bottstrap, 请修改地址 -->
|
||||
<script src="/js/jquery-1.9.0.min.js"></script>
|
||||
<script src="/js/bootstrap.js"></script>
|
||||
|
||||
<!-- locale -->
|
||||
<script type="text/javascript" src="js/dialog.js"></script>
|
||||
<script type="text/javascript" src="js/jquery.filedrop.js"></script>
|
||||
<script type="text/javascript" src="js/drop.js"></script>
|
||||
</body>
|
||||
</html>
|
BIN
public/tinymce/plugins/leanote_image/img/loading-24.gif
Normal file
BIN
public/tinymce/plugins/leanote_image/img/loading-24.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
230
public/tinymce/plugins/leanote_image/js/dialog.js
Normal file
230
public/tinymce/plugins/leanote_image/js/dialog.js
Normal file
@ -0,0 +1,230 @@
|
||||
|
||||
/**
|
||||
* http://leanote.com
|
||||
*/
|
||||
|
||||
var tinymce = top.tinymce;
|
||||
var editor = tinymce.EditorManager.activeEditor;
|
||||
var dom = editor.dom;
|
||||
var imgElm = editor.selection.getNode();
|
||||
|
||||
$(function() {
|
||||
// 隐藏iframe border
|
||||
// top.hiddenIframeBorder();
|
||||
|
||||
// bind event
|
||||
$("#uploader").change(function() {
|
||||
$("#upl").submit();
|
||||
leanoteImagesDialog.inProgress();
|
||||
});
|
||||
|
||||
$("#insertImageBtn").click(function() {
|
||||
insertImage();
|
||||
});
|
||||
$("#closeBtn").click(function() {
|
||||
closeWin();
|
||||
});
|
||||
|
||||
// 是否选择了image
|
||||
|
||||
var oldWidth, oldHeihgt;
|
||||
// 是否选择的是image
|
||||
if(imgElm.nodeName == "IMG") {
|
||||
var $node = $(imgElm);
|
||||
$("#imageSrc").val($node.attr("src"));
|
||||
oldWidth = $node.width();
|
||||
oldHeight = $node.height();
|
||||
$("#imageWidth").val(oldWidth);
|
||||
$("#imageHeight").val(oldHeight);
|
||||
|
||||
$('#myTab a:last').tab('show');
|
||||
} else {
|
||||
imgElm = null;
|
||||
}
|
||||
|
||||
$("#imageSrc").blur(function(){
|
||||
getImageSize($(this).val(), function(ret) {
|
||||
if(ret.width) {
|
||||
oldWidth = ret.width;
|
||||
oldHeight = ret.Height;
|
||||
|
||||
$("#imageWidth").val(ret.width);
|
||||
$("#imageHeight").val(ret.height);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 按比例缩放
|
||||
function scale(isWidth) {
|
||||
var autoScale = $("#autoScale").is(":checked");
|
||||
var width = $("#imageWidth").val();
|
||||
var height = $("#imageHeight").val();
|
||||
|
||||
if(autoScale && oldWidth && oldHeight) {
|
||||
if(isWidth) {
|
||||
height = parseInt((width/oldWidth) * oldHeight);
|
||||
$("#imageHegiht").val(height);
|
||||
} else {
|
||||
width = parseInt((height/oldHeight) * oldWidth);
|
||||
$("#imageWidth").val(width);
|
||||
}
|
||||
}
|
||||
|
||||
oldWidth = width;
|
||||
oldHeight = height;
|
||||
}
|
||||
|
||||
$("#imageWidth").blur(function() {
|
||||
scale(true);
|
||||
});
|
||||
$("#imageHeight").blur(function() {
|
||||
scale(false);
|
||||
});
|
||||
});
|
||||
|
||||
//当url改变时, 得到图片的大小
|
||||
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);
|
||||
}
|
||||
|
||||
function closeWin() {
|
||||
try {
|
||||
top.closeDialog();
|
||||
// editor.windowManager.close();
|
||||
// editor.windowManager.close();
|
||||
} catch(e) {
|
||||
}
|
||||
}
|
||||
|
||||
// 插入之
|
||||
var insertImage = function() {
|
||||
// 判断是否是第二个tab active
|
||||
if($("#myTab li:last").attr("class") != "active") {
|
||||
closeWin();
|
||||
return;
|
||||
}
|
||||
|
||||
// 加载图片并插入之
|
||||
function waitLoad(imgElm) {
|
||||
function selectImage() {
|
||||
imgElm.onload = imgElm.onerror = null;
|
||||
editor.selection.select(imgElm);
|
||||
editor.nodeChanged();
|
||||
}
|
||||
|
||||
// 如果没有设置width, height, 就用图片本身的大小
|
||||
imgElm.onload = function() {
|
||||
if (!data.width && !data.height) {
|
||||
dom.setAttribs(imgElm, {
|
||||
width: imgElm.clientWidth,
|
||||
height: imgElm.clientHeight
|
||||
});
|
||||
}
|
||||
|
||||
selectImage();
|
||||
};
|
||||
|
||||
imgElm.onerror = selectImage;
|
||||
}
|
||||
|
||||
// 这是通过url插入图片
|
||||
// iframe里得到...
|
||||
var data = {width:null, height:null, src:null, style:null};
|
||||
data.width = $("#imageWidth").val();
|
||||
data.height = $("#imageHeight").val();
|
||||
data.src = $("#imageSrc").val();
|
||||
data.alt = "";
|
||||
|
||||
editor.undoManager.transact(function() {
|
||||
// 删除图片
|
||||
if (!data.src) {
|
||||
if (imgElm) {
|
||||
dom.remove(imgElm);
|
||||
editor.nodeChanged();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!imgElm) {
|
||||
data.id = '__mcenew';
|
||||
editor.selection.setContent(dom.createHTML('img', data));
|
||||
imgElm = dom.get('__mcenew');
|
||||
dom.setAttrib(imgElm, 'id', null);
|
||||
} else {
|
||||
dom.setAttribs(imgElm, data);
|
||||
}
|
||||
|
||||
waitLoad(imgElm);
|
||||
});
|
||||
|
||||
closeWin();
|
||||
}
|
||||
|
||||
// 使用input上传
|
||||
var leanoteImagesDialog = {
|
||||
timeoutStore : false,
|
||||
|
||||
// 上传时
|
||||
inProgress : function() {
|
||||
$("#uploadFormContainer").hide();
|
||||
$("#uploadInProgress").show();
|
||||
// 可能是返回的数据不对
|
||||
this.timeoutStore = window.setTimeout(function() {
|
||||
$("#uploadInProgress").html("服务器发生错误, 超时.");
|
||||
}, 20000);
|
||||
},
|
||||
|
||||
// 上传结束后, 关闭窗口, 填充image
|
||||
uploadFinish : function(result) {
|
||||
if (result.resultCode == '0') {
|
||||
window.clearTimeout(this.timeoutStore);
|
||||
$("#uploadInProgress").html("服务器发生错误: " + result.result);
|
||||
} else {
|
||||
$("#uploadInProgress").html("上传成功!");
|
||||
|
||||
// 这里, 如果图片宽度过大, 这里设置成500px
|
||||
var d = {};
|
||||
var imgElm;
|
||||
getImageSize(result.filename, function(wh) {
|
||||
// life 4/25
|
||||
if(wh && wh.width) {
|
||||
if(wh.width > 600) {
|
||||
wh.width = 600;
|
||||
}
|
||||
d.width = wh.width;
|
||||
dom.setAttrib(imgElm, 'width', d.width);
|
||||
}
|
||||
dom.setAttrib(imgElm, 'src', result.filename);
|
||||
});
|
||||
// 先显示loading...
|
||||
d.id = '__mcenew';
|
||||
d.src = "http://leanote.com/images/loading-24.gif";
|
||||
editor.insertContent(dom.createHTML('img', d));
|
||||
imgElm = dom.get('__mcenew');
|
||||
dom.setAttrib(imgElm, 'id', null);
|
||||
closeWin();
|
||||
}
|
||||
}
|
||||
};
|
115
public/tinymce/plugins/leanote_image/js/drop.js
Normal file
115
public/tinymce/plugins/leanote_image/js/drop.js
Normal file
@ -0,0 +1,115 @@
|
||||
/**
|
||||
* 使用拖拽的返回是json数据
|
||||
* {
|
||||
* filename:"", // 文件路径
|
||||
* result: "", // 信息
|
||||
* code:"1" 或 "0"
|
||||
* }
|
||||
*/
|
||||
$(function() {
|
||||
var dropbox = $('#dropbox'),
|
||||
message = $('.message', dropbox);
|
||||
|
||||
dropbox.filedrop({
|
||||
// The name of the $_FILES entry:
|
||||
paramname: 'file',
|
||||
|
||||
maxfiles: 1,
|
||||
maxfilesize: 3,
|
||||
|
||||
// 在此修改服务器地址
|
||||
url: '/file/uploadImageJson',
|
||||
|
||||
uploadFinished: function(i, file, re) {
|
||||
leanoteImagesDialog.uploadFinish({
|
||||
filename: re.Id,
|
||||
result: re.Msg,
|
||||
resultCode: re.Code + ''
|
||||
});
|
||||
|
||||
// $.data(file).addClass('done');
|
||||
},
|
||||
|
||||
error: function(err, file) {
|
||||
switch(err) {
|
||||
case 'BrowserNotSupported':
|
||||
showMessage('您的浏览器不支持拖拉上传文件, 请使用chrome或firefox浏览器');
|
||||
break;
|
||||
case 'TooManyFiles':
|
||||
alert('文件太多了');
|
||||
break;
|
||||
case 'FileTooLarge':
|
||||
alert(file.name+'文件太大, 最大支持3M图片');
|
||||
break;
|
||||
default:
|
||||
alert("出错了");
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
// Called before each upload is started
|
||||
beforeEach: function(file){
|
||||
if(!file.type.match(/^image\//)){
|
||||
alert('只能上传图片!');
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
uploadStarted:function(i, file, len){
|
||||
//createImage(file);
|
||||
},
|
||||
|
||||
progressUpdated: function(i, file, progress) {
|
||||
$('.progress-bar').css("width", progress + "%");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var template = '<div class="preview">'+
|
||||
'<span class="imageHolder">'+
|
||||
'<img />'+
|
||||
'<span class="uploaded"></span>'+
|
||||
'</span>'+
|
||||
'<div class="progressHolder">'+
|
||||
'<div class="progress"></div>'+
|
||||
'</div>'+
|
||||
'</div>';
|
||||
|
||||
|
||||
function createImage(file){
|
||||
|
||||
var preview = $(template),
|
||||
image = $('img', preview);
|
||||
|
||||
var reader = new FileReader();
|
||||
|
||||
image.width = 100;
|
||||
image.height = 100;
|
||||
|
||||
reader.onload = function(e){
|
||||
|
||||
// e.target.result holds the DataURL which
|
||||
// can be used as a source of the image:
|
||||
|
||||
image.attr('src',e.target.result);
|
||||
image.css("max-width", "200px")
|
||||
};
|
||||
|
||||
// Reading the file as a DataURL. When finished,
|
||||
// this will trigger the onload function above:
|
||||
reader.readAsDataURL(file);
|
||||
|
||||
message.hide();
|
||||
preview.appendTo(dropbox);
|
||||
|
||||
// Associating a preview container
|
||||
// with the file, using jQuery's $.data():
|
||||
|
||||
$.data(file,preview);
|
||||
}
|
||||
|
||||
function showMessage(msg){
|
||||
message.html(msg);
|
||||
}
|
||||
|
||||
});
|
326
public/tinymce/plugins/leanote_image/js/jquery.filedrop.js
Normal file
326
public/tinymce/plugins/leanote_image/js/jquery.filedrop.js
Normal file
@ -0,0 +1,326 @@
|
||||
/*
|
||||
* Default text - jQuery plugin for html5 dragging files from desktop to browser
|
||||
*
|
||||
* Author: Weixi Yen
|
||||
*
|
||||
* Email: [Firstname][Lastname]@gmail.com
|
||||
*
|
||||
* Copyright (c) 2010 Resopollution
|
||||
*
|
||||
* Licensed under the MIT license:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
* Project home:
|
||||
* http://www.github.com/weixiyen/jquery-filedrop
|
||||
*
|
||||
* Version: 0.1.0
|
||||
*
|
||||
* Features:
|
||||
* Allows sending of extra parameters with file.
|
||||
* Works with Firefox 3.6+
|
||||
* Future-compliant with HTML5 spec (will work with Webkit browsers and IE9)
|
||||
* Usage:
|
||||
* See README at project homepage
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
jQuery.event.props.push("dataTransfer");
|
||||
var opts = {},
|
||||
default_opts = {
|
||||
url: '',
|
||||
refresh: 1000,
|
||||
paramname: 'userfile',
|
||||
maxfiles: 25,
|
||||
maxfilesize: 1, // MBs
|
||||
data: {},
|
||||
drop: empty,
|
||||
dragEnter: empty,
|
||||
dragOver: empty,
|
||||
dragLeave: empty,
|
||||
docEnter: empty,
|
||||
docOver: empty,
|
||||
docLeave: empty,
|
||||
beforeEach: empty,
|
||||
afterAll: empty,
|
||||
rename: empty,
|
||||
error: function(err, file, i){alert(err);},
|
||||
uploadStarted: empty,
|
||||
uploadFinished: empty,
|
||||
progressUpdated: empty,
|
||||
speedUpdated: empty
|
||||
},
|
||||
errors = ["BrowserNotSupported", "TooManyFiles", "FileTooLarge"],
|
||||
doc_leave_timer,
|
||||
stop_loop = false,
|
||||
files_count = 0,
|
||||
files;
|
||||
|
||||
$.fn.filedrop = function(options) {
|
||||
opts = $.extend( {}, default_opts, options );
|
||||
|
||||
this.bind('drop', drop).bind('dragenter', dragEnter).bind('dragover', dragOver).bind('dragleave', dragLeave);
|
||||
$(document).bind('drop', docDrop).bind('dragenter', docEnter).bind('dragover', docOver).bind('dragleave', docLeave);
|
||||
};
|
||||
|
||||
function drop(e) {
|
||||
opts.drop(e);
|
||||
files = e.dataTransfer.files;
|
||||
if (files === null || files === undefined) {
|
||||
opts.error(errors[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
files_count = files.length;
|
||||
upload();
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
function getBuilder(filename, filedata, boundary) {
|
||||
var dashdash = '--',
|
||||
crlf = '\r\n',
|
||||
builder = '';
|
||||
|
||||
$.each(opts.data, function(i, val) {
|
||||
if (typeof val === 'function') val = val();
|
||||
builder += dashdash;
|
||||
builder += boundary;
|
||||
builder += crlf;
|
||||
builder += 'Content-Disposition: form-data; name="'+i+'"';
|
||||
builder += crlf;
|
||||
builder += crlf;
|
||||
builder += val;
|
||||
builder += crlf;
|
||||
});
|
||||
|
||||
builder += dashdash;
|
||||
builder += boundary;
|
||||
builder += crlf;
|
||||
builder += 'Content-Disposition: form-data; name="'+opts.paramname+'"';
|
||||
// 当filename很中文,英文, 空格时有问题
|
||||
// 得到ext
|
||||
var pos = filename.lastIndexOf(".");
|
||||
var seconds = (new Date()).getTime();
|
||||
var filename2 = "leanote_" + seconds;
|
||||
if(pos != -1) {
|
||||
var ext = filename.substr(pos)
|
||||
filename2 += ext;
|
||||
}
|
||||
builder += '; filename="' + filename2 + '"';
|
||||
builder += crlf;
|
||||
|
||||
builder += 'Content-Type: application/octet-stream';
|
||||
builder += crlf;
|
||||
builder += crlf;
|
||||
|
||||
builder += filedata;
|
||||
builder += crlf;
|
||||
|
||||
builder += dashdash;
|
||||
builder += boundary;
|
||||
builder += dashdash;
|
||||
builder += crlf;
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
function progress(e) {
|
||||
if (e.lengthComputable) {
|
||||
var percentage = Math.round((e.loaded * 100) / e.total);
|
||||
if (this.currentProgress != percentage) {
|
||||
|
||||
this.currentProgress = percentage;
|
||||
opts.progressUpdated(this.index, this.file, this.currentProgress);
|
||||
|
||||
var elapsed = new Date().getTime();
|
||||
var diffTime = elapsed - this.currentStart;
|
||||
if (diffTime >= opts.refresh) {
|
||||
var diffData = e.loaded - this.startData;
|
||||
var speed = diffData / diffTime; // KB per second
|
||||
opts.speedUpdated(this.index, this.file, speed);
|
||||
this.startData = e.loaded;
|
||||
this.currentStart = elapsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function upload() {
|
||||
stop_loop = false;
|
||||
if (!files) {
|
||||
opts.error(errors[0]);
|
||||
return false;
|
||||
}
|
||||
var filesDone = 0,
|
||||
filesRejected = 0;
|
||||
|
||||
if (files_count > opts.maxfiles) {
|
||||
opts.error(errors[1]);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i=0; i<files_count; i++) {
|
||||
if (stop_loop) return false;
|
||||
try {
|
||||
if (beforeEach(files[i]) != false) {
|
||||
if (i === files_count) return;
|
||||
var reader = new FileReader(),
|
||||
max_file_size = 1048576 * opts.maxfilesize;
|
||||
|
||||
reader.index = i;
|
||||
if (files[i].size > max_file_size) {
|
||||
opts.error(errors[2], files[i], i);
|
||||
filesRejected++;
|
||||
continue;
|
||||
}
|
||||
|
||||
reader.onloadend = send;
|
||||
reader.readAsBinaryString(files[i]);
|
||||
} else {
|
||||
filesRejected++;
|
||||
}
|
||||
} catch(err) {
|
||||
opts.error(errors[0]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function send(e) {
|
||||
// Sometimes the index is not attached to the
|
||||
// event object. Find it by size. Hack for sure.
|
||||
if (e.target.index == undefined) {
|
||||
e.target.index = getIndexBySize(e.total);
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest(),
|
||||
upload = xhr.upload,
|
||||
file = files[e.target.index],
|
||||
index = e.target.index,
|
||||
start_time = new Date().getTime(),
|
||||
boundary = '------multipartformboundary' + (new Date).getTime(),
|
||||
builder;
|
||||
|
||||
|
||||
newName = rename(file.name);
|
||||
if (typeof newName === "string") {
|
||||
builder = getBuilder(newName, e.target.result, boundary);
|
||||
} else {
|
||||
builder = getBuilder(file.name, e.target.result, boundary);
|
||||
}
|
||||
|
||||
upload.index = index;
|
||||
upload.file = file;
|
||||
upload.downloadStartTime = start_time;
|
||||
upload.currentStart = start_time;
|
||||
upload.currentProgress = 0;
|
||||
upload.startData = 0;
|
||||
upload.addEventListener("progress", progress, false);
|
||||
|
||||
xhr.open("POST", opts.url, true);
|
||||
xhr.setRequestHeader('content-type', 'multipart/form-data; boundary='
|
||||
+ boundary);
|
||||
|
||||
xhr.sendAsBinary(builder);
|
||||
|
||||
opts.uploadStarted(index, file, files_count);
|
||||
|
||||
xhr.onload = function() {
|
||||
if (xhr.responseText) {
|
||||
var now = new Date().getTime(),
|
||||
timeDiff = now - start_time,
|
||||
result = opts.uploadFinished(index, file, jQuery.parseJSON(xhr.responseText), timeDiff);
|
||||
filesDone++;
|
||||
if (filesDone == files_count - filesRejected) {
|
||||
afterAll();
|
||||
}
|
||||
if (result === false) stop_loop = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function getIndexBySize(size) {
|
||||
for (var i=0; i < files_count; i++) {
|
||||
if (files[i].size == size) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function rename(name) {
|
||||
return opts.rename(name);
|
||||
}
|
||||
|
||||
function beforeEach(file) {
|
||||
return opts.beforeEach(file);
|
||||
}
|
||||
|
||||
function afterAll() {
|
||||
return opts.afterAll();
|
||||
}
|
||||
|
||||
function dragEnter(e) {
|
||||
clearTimeout(doc_leave_timer);
|
||||
e.preventDefault();
|
||||
opts.dragEnter(e);
|
||||
}
|
||||
|
||||
function dragOver(e) {
|
||||
clearTimeout(doc_leave_timer);
|
||||
e.preventDefault();
|
||||
opts.docOver(e);
|
||||
opts.dragOver(e);
|
||||
}
|
||||
|
||||
function dragLeave(e) {
|
||||
clearTimeout(doc_leave_timer);
|
||||
opts.dragLeave(e);
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
function docDrop(e) {
|
||||
e.preventDefault();
|
||||
opts.docLeave(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
function docEnter(e) {
|
||||
clearTimeout(doc_leave_timer);
|
||||
e.preventDefault();
|
||||
opts.docEnter(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
function docOver(e) {
|
||||
clearTimeout(doc_leave_timer);
|
||||
e.preventDefault();
|
||||
opts.docOver(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
function docLeave(e) {
|
||||
doc_leave_timer = setTimeout(function(){
|
||||
opts.docLeave(e);
|
||||
}, 200);
|
||||
}
|
||||
|
||||
function empty(){}
|
||||
|
||||
try {
|
||||
if (XMLHttpRequest.prototype.sendAsBinary) return;
|
||||
XMLHttpRequest.prototype.sendAsBinary = function(datastr) {
|
||||
function byteValue(x) {
|
||||
return x.charCodeAt(0) & 0xff;
|
||||
}
|
||||
var ords = Array.prototype.map.call(datastr, byteValue);
|
||||
var ui8a = new Uint8Array(ords);
|
||||
this.send(ui8a.buffer);
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
})(jQuery);
|
33
public/tinymce/plugins/leanote_image/plugin.js
Normal file
33
public/tinymce/plugins/leanote_image/plugin.js
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 图片上传插件
|
||||
* 结合了原tinymce image插件
|
||||
* 添加了input上传和拖拽上传
|
||||
* http://leanote.com
|
||||
*/
|
||||
|
||||
tinymce.PluginManager.add('leanote_image', function(editor, url) {
|
||||
// 弹框
|
||||
function showDialog() {
|
||||
/*
|
||||
win = editor.windowManager.open({
|
||||
title: 'Insert/edit image',
|
||||
file : url + '/dialog.html',
|
||||
width : 550,
|
||||
height: 345
|
||||
});
|
||||
*/
|
||||
showDialog2("#imageDialog", {postShow:function() {
|
||||
$("#imageDialog iframe").attr("src", url + '/dialog.html');
|
||||
}});
|
||||
}
|
||||
|
||||
// 添加按钮
|
||||
editor.addButton('leanote_image', {
|
||||
icon: 'image',
|
||||
tooltip: 'ctrl+shift+i 插入/修改图片',
|
||||
onclick: showDialog,
|
||||
stateSelector: 'img:not([data-mce-object])'
|
||||
});
|
||||
|
||||
editor.addShortcut('ctrl+shift+i', '', showDialog);
|
||||
});
|
1
public/tinymce/plugins/leanote_image/plugin.min.js
vendored
Normal file
1
public/tinymce/plugins/leanote_image/plugin.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
tinymce.PluginManager.add("leanote_image",function(t,i){function a(){showDialog2("#imageDialog",{postShow:function(){$("#imageDialog iframe").attr("src",i+"/dialog.html")}})}t.addButton("leanote_image",{icon:"image",tooltip:"ctrl+shift+i 插入/修改图片",onclick:a,stateSelector:"img:not([data-mce-object])"}),t.addShortcut("ctrl+shift+i","",a)});
|
5
public/tinymce/plugins/leanote_image/readme
Normal file
5
public/tinymce/plugins/leanote_image/readme
Normal file
@ -0,0 +1,5 @@
|
||||
leanote image插件安装
|
||||
|
||||
1. 依赖 jquery, bootstrap. 请修改dialog.html的jquery, boostrap, js和css路径
|
||||
2. 传统input上传后返回的是html页面, 返回的结果请参考result.html. 服务器地址修改在dialog.html
|
||||
3. 拖拽上传返回的json数据, 用户请参考js/drop.js. 服务器地址修改在js/drop.js
|
15
public/tinymce/plugins/leanote_image/result.html
Normal file
15
public/tinymce/plugins/leanote_image/result.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<script type="text/javascript">
|
||||
|
||||
<!-- 上传之后跳转至该页面 -->
|
||||
window.parent.leanoteImagesDialog.uploadFinish({
|
||||
filename: '{{.fileUrlPath}}', // 文件路径
|
||||
result: '{{.resultMsg}}', // 描述
|
||||
resultCode: '{{.resultCode}}' // 1成功, 0失败
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
</html>
|
Reference in New Issue
Block a user