复制外链图片, 下载到本地

https://github.com/leanote/desktop-app/issues/65
This commit is contained in:
life
2015-10-19 14:47:09 +08:00
parent a669f0750a
commit 4bb3dd5750
4 changed files with 41 additions and 44 deletions

21
node_modules/file.js generated vendored
View File

@@ -589,8 +589,27 @@ var File = {
} }
}); });
} }
}, },
// 复制外站图片
copyOtherSiteImage: function(src, callback) {
var me = this;
me.downloadImg(src, function (filePath) {
if (filePath) {
me._addImage(Common.objectId(), filePath, function(file) {
if (file) {
callback(Evt.getImageLocalUrl(file.FileId));
}
else {
callback(false);
}
});
}
else {
callback(false);
}
});
}
}; };
module.exports = File; module.exports = File;

View File

@@ -452,7 +452,7 @@ function initEditor() {
// parentHeight: $("#content").height(), // parentHeight: $("#content").height(),
// content_css : ["public/css/editor/editor.css"], // content_css : ["public/css/editor/editor.css"],
// skin : "custom", // skin : "custom",
language: Api.curLang == 'zh-cn' ? 'zh' : 'en', // 语言 language: Api.curLang.indexOf('zh') >= 0 ? 'zh' : 'en', // 语言
plugins : [ plugins : [
"autolink link image lists charmap hr", "paste", "autolink link image lists charmap hr", "paste",
"searchreplace leanote_nav leanote_code tabfocus", "searchreplace leanote_nav leanote_code tabfocus",
@@ -2020,7 +2020,7 @@ function userMenu(allUsers) {
this.menu.append(themeMenu); this.menu.append(themeMenu);
} }
var height = 180; var height = 210;
if(!isMac()) { if(!isMac()) {
this.menu.append(new gui.MenuItem({ type: 'separator' })); this.menu.append(new gui.MenuItem({ type: 'separator' }));
@@ -2028,7 +2028,7 @@ function userMenu(allUsers) {
this.menu.append(Pren.view); this.menu.append(Pren.view);
this.menu.append(Pren.fullScreen); this.menu.append(Pren.fullScreen);
height = 270; height += 90;
} }
this.menu.append(new gui.MenuItem({ type: 'separator' })); this.menu.append(new gui.MenuItem({ type: 'separator' }));

View File

@@ -79,6 +79,8 @@ tinymce.addI18n('zh',{
"Insert\/edit mind map": "新建/编辑思维导图", "Insert\/edit mind map": "新建/编辑思维导图",
"Insert Mind Map": "插入思维导图", "Insert Mind Map": "插入思维导图",
"Mind Map": "思维导图", "Mind Map": "思维导图",
"Image": "图片",
"Insert Image": "插入",
"General": "\u666e\u901a", "General": "\u666e\u901a",
"Advanced": "\u9ad8\u7ea7", "Advanced": "\u9ad8\u7ea7",
"Source": "\u5730\u5740", "Source": "\u5730\u5740",
@@ -180,4 +182,4 @@ tinymce.addI18n('zh',{
"View": "\u89c6\u56fe", "View": "\u89c6\u56fe",
"Table": "\u8868\u683c", "Table": "\u8868\u683c",
"Format": "\u683c\u5f0f" "Format": "\u683c\u5f0f"
}); });

View File

@@ -222,26 +222,24 @@ define("tinymce/pasteplugin/Clipboard", [
var pasteBinDefaultContent = '%MCEPASTEBIN%', keyboardPastePlainTextState; var pasteBinDefaultContent = '%MCEPASTEBIN%', keyboardPastePlainTextState;
/** /**
* Pastes the specified HTML. This means that the HTML is filtered and then * 复制外链图片, copy到本地
* 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 copyImage(src, ids) { function copyImage(src, ids) {
ajaxPost("/file/copyHttpImage", {src: src}, function(ret) { FileService.copyOtherSiteImage(src, function(url) {
if(reIsOk(ret)) { if (url) {
// 将图片替换之 // 将图片替换之
var src = urlPrefix + "/" + ret.Item; var dom = editor.dom;
var dom = editor.dom
for(var i in ids) { for(var i in ids) {
var id = ids[i]; var id = ids[i];
var imgElm = dom.get(id); var imgElm = dom.get(id);
dom.setAttrib(imgElm, 'src', src); if (imgElm) {
dom.setAttrib(imgElm, 'src', url);
}
} }
} }
}); });
} }
// 粘贴HTML // 粘贴HTML
// 当在pre下时不能粘贴成HTML // 当在pre下时不能粘贴成HTML
// life add text // life add text
@@ -299,15 +297,15 @@ define("tinymce/pasteplugin/Clipboard", [
var needCopyImages = {}; // src => [id1,id2] var needCopyImages = {}; // src => [id1,id2]
var time = (new Date()).getTime(); var time = (new Date()).getTime();
try { try {
var $html = $("<div>" + html + "</div"); var $html = $("<div>" + html + "</div>");
var $imgs = $html.find("img"); var $imgs = $html.find("img");
for(var i = 0; i < $imgs.length; ++i) { for(var i = 0; i < $imgs.length; ++i) {
var $img = $imgs.eq(i) var $img = $imgs.eq(i)
var src = $img.attr("src"); var src = $img.attr("src");
// 是否是外链 // 是否是外链
if(src.indexOf(urlPrefix) == -1) { if(src.indexOf(urlPrefix) == -1 && src.indexOf('http://127.0.0.1') == -1) {
time++; time++;
var id = "__LEANOTE_IMAGE_" + time; var id = "__LEANOTE_D_IMG_" + time;
$img.attr("id", id); $img.attr("id", id);
if(needCopyImages[src]) { if(needCopyImages[src]) {
needCopyImages[src].push(id); needCopyImages[src].push(id);
@@ -317,7 +315,7 @@ define("tinymce/pasteplugin/Clipboard", [
} }
} }
editor.insertContent($html.html()); editor.insertContent($html.html());
for(var src in needCopyImages) { for(var src in needCopyImages) {
var ids = needCopyImages[src]; var ids = needCopyImages[src];
copyImage(src, ids); copyImage(src, ids);
@@ -1043,26 +1041,11 @@ define("tinymce/pasteplugin/Plugin", [
} }
} }
} }
function togglePasteCopyImage() {
if (clipboard.copyImage) {
this.active(false);
clipboard.copyImage = false
} else {
clipboard.copyImage = true;
this.active(true);
if (!userIsInformed2) {
editor.windowManager.alert(
"When copy other site's images (not in leanote) into editor, it will copy the image into your album."
);
userIsInformed2 = true;
}
}
}
self.clipboard = clipboard = new Clipboard(editor); self.clipboard = clipboard = new Clipboard(editor);
self.quirks = new Quirks(editor); self.quirks = new Quirks(editor);
self.wordFilter = new WordFilter(editor); self.wordFilter = new WordFilter(editor);
clipboard.copyImage = true;
if (editor.settings.paste_as_text) { if (editor.settings.paste_as_text) {
self.clipboard.pasteFormat = "text"; self.clipboard.pasteFormat = "text";
@@ -1115,13 +1098,6 @@ define("tinymce/pasteplugin/Plugin", [
onclick: togglePlainTextPaste, onclick: togglePlainTextPaste,
active: self.clipboard.pasteFormat == "text" active: self.clipboard.pasteFormat == "text"
}); });
editor.addButton('pasteCopyImage', {
icon: 'copy',
tooltip: "When Paste other site's image, copy it into my album as public image",
onclick: togglePasteCopyImage,
active: self.clipboard.copyImage === true
});
editor.addMenuItem('pastetext', { editor.addMenuItem('pastetext', {
text: 'Paste as text', text: 'Paste as text',
@@ -1133,4 +1109,4 @@ define("tinymce/pasteplugin/Plugin", [
}); });
expose(["tinymce/pasteplugin/Utils","tinymce/pasteplugin/WordFilter"]); expose(["tinymce/pasteplugin/Utils","tinymce/pasteplugin/WordFilter"]);
})(this); })(this);