v1.0
只读模式 group, 分享 评论更多问题 博客标签总是存在一个
This commit is contained in:
@ -1,250 +0,0 @@
|
||||
/**
|
||||
* life
|
||||
*/
|
||||
|
||||
var tinymce = top.tinymce;
|
||||
var editor = tinymce.EditorManager.activeEditor;
|
||||
var dom = editor.dom;
|
||||
var imgElm = editor.selection.getNode();
|
||||
|
||||
var jbImagesDialog = {
|
||||
resized : false,
|
||||
iframeOpened : false,
|
||||
timeoutStore : false,
|
||||
|
||||
inProgress : function() {
|
||||
document.getElementById("upload_infobar").style.display = 'none';
|
||||
document.getElementById("upload_additional_info").innerHTML = '';
|
||||
document.getElementById("upload_form_container").style.display = 'none';
|
||||
document.getElementById("upload_in_progress").style.display = 'block';
|
||||
this.timeoutStore = window.setTimeout(function(){
|
||||
document.getElementById("upload_additional_info").innerHTML = 'This is taking longer than usual.' + '<br />' + 'An error may have occurred.' + '<br /><a href="#" onClick="jbImagesDialog.showIframe()">' + 'View script\'s output' + '</a>';
|
||||
// tinyMCEPopup.editor.windowManager.resizeBy(0, 30, tinyMCEPopup.id);
|
||||
}, 20000);
|
||||
},
|
||||
|
||||
showIframe : function() {
|
||||
if (this.iframeOpened == false)
|
||||
{
|
||||
document.getElementById("upload_target").className = 'upload_target_visible';
|
||||
// tinyMCEPopup.editor.windowManager.resizeBy(0, 190, tinyMCEPopup.id);
|
||||
this.iframeOpened = true;
|
||||
}
|
||||
},
|
||||
|
||||
uploadFinish : function(result) {
|
||||
if (result.resultCode == '0')
|
||||
{
|
||||
window.clearTimeout(this.timeoutStore);
|
||||
document.getElementById("upload_in_progress").style.display = 'none';
|
||||
document.getElementById("upload_infobar").style.display = 'block';
|
||||
$("#upload_infobar").html(result.result).show();
|
||||
document.getElementById("upload_form_container").style.display = 'block';
|
||||
|
||||
if (this.resized == false)
|
||||
{
|
||||
// tinyMCEPopup.editor.windowManager.resizeBy(0, 30, tinyMCEPopup.id);
|
||||
this.resized = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
document.getElementById("upload_in_progress").style.display = 'none';
|
||||
document.getElementById("upload_infobar").style.display = 'block';
|
||||
document.getElementById("upload_infobar").innerHTML = 'Upload Complete';
|
||||
|
||||
var w = this.getWin();
|
||||
tinymce = w.tinymce;
|
||||
|
||||
tinymce.EditorManager.activeEditor.insertContent('<img src="' + result.filename +'">');
|
||||
|
||||
this.close();
|
||||
|
||||
// 添加undo
|
||||
// var editor = tinymce.activeEditor;
|
||||
// editor.undoManager.transact(function() {
|
||||
// });
|
||||
}
|
||||
},
|
||||
|
||||
getWin : function() {
|
||||
return (!window.frameElement && window.dialogArguments) || opener || parent || top;
|
||||
},
|
||||
|
||||
close : function() {
|
||||
var t = this;
|
||||
|
||||
// To avoid domain relaxing issue in Opera
|
||||
function close() {
|
||||
tinymce.EditorManager.activeEditor.windowManager.close(window);
|
||||
tinymce = tinyMCE = t.editor = t.params = t.dom = t.dom.doc = null; // Cleanup
|
||||
};
|
||||
|
||||
if (tinymce.isOpera)
|
||||
this.getWin().setTimeout(close, 0);
|
||||
else
|
||||
close();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//----------------------- url
|
||||
|
||||
$(function() {
|
||||
top.hiddenIframeBorder();
|
||||
|
||||
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 {
|
||||
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();
|
||||
}
|
@ -1,105 +0,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) {
|
||||
jbImagesDialog.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);
|
||||
}
|
||||
|
||||
});
|
@ -1,326 +0,0 @@
|
||||
/*
|
||||
* 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);
|
Reference in New Issue
Block a user