build tinymce

This commit is contained in:
life
2017-01-20 17:15:13 +08:00
parent 73fa5c2beb
commit 91e1e91014
11 changed files with 96 additions and 1645 deletions

View File

@@ -658,7 +658,7 @@ window.debug = false;
</script>
<!-- 渲染view -->
<script src="public/tinymce/tinymce.js"></script>
<script src="public/tinymce/tinymce.min.js"></script>
<script src="public/libs/ace/ace.js"></script>
<script src="public/js/app/api.js"></script> <!-- 本地api -->
<script src="public/js/app/native.js"></script>

View File

@@ -0,0 +1 @@
tinymce.PluginManager.add("image",function(a,b){function c(){insertLocalImage()}a.addButton("image",{icon:"image",tooltip:"Insert image",onclick:c,stateSelector:"img:not([data-mind-json])"});a.on("dragstart",function(a){LEA.readOnly&&(a.preventDefault(),a.stopPropagation())}),a.on("dragend",function(a){}),a.on("dragover",function(a){})});

View File

@@ -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(){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,"&lt;"),o=o.replace(/>/g,"&gt;"),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;if(9==b&&!a.shiftKey){var c=h.selection.getNode();return c&&"LI"===c.nodeName?!0:(h.insertContent("&nbsp;&nbsp;&nbsp;&nbsp;"),a.preventDefault(),a.stopPropagation(),!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(){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,"&lt;"),o=o.replace(/>/g,"&gt;"),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","Matlab:matlab","Scala:scala","Sql:sql"],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("meta+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;if(9==b&&!a.shiftKey){var c=h.selection.getNode();return c&&("LI"==c.nodeName||$(c.closest("li")).length>0)?!0:(h.insertContent("&nbsp;&nbsp;&nbsp;&nbsp;"),a.preventDefault(),a.stopPropagation(),!1)}})});

View File

@@ -1,79 +1 @@
/**
* leaui mind map plugin
* copyright leaui
* leaui.com
*/
var LEAUI_MIND = {};
tinymce.PluginManager.add('leaui_mindmap', 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 = url + '/mindmap/index.html?i=1';
var html = '<iframe id="leauiMindMapIfr" src="'+ u + '?' + new Date().getTime() + '&lang=' + lang + '" frameborder="0"></iframe>';
return html;
}
var w = window.innerWidth - 10;
var h = window.innerHeight - 150;
win = editor.windowManager.open({
title: "Mind Map",
width : w,
height : h,
html: GetTheHtml(),
buttons: [
{
text: 'Cancel',
onclick: function() {
this.parent().parent().close();
}
},
{
text: 'Insert',
subtype: 'primary',
onclick: function(e) {
var me = this;
var _iframe = document.getElementById('leauiMindMapIfr').contentWindow;
var km = _iframe.km;
// window.km= km;
// return
km.exportData('png').then(function(data) {
var json = JSON.stringify(km.exportJson());
// console.log(json);
var img = '<img src="' + data + '" data-mind-json=\'' + json + '\'>';
editor.insertContent(img);
me.parent().parent().close();
});
return;
}
}]
});
}
editor.addButton('leaui_mindmap', {
// image: url + '/icon.png',
icon: 'mind',
tooltip: 'Insert/edit mind map',
onclick: showDialog,
stateSelector: 'img[data-mind-json]'
});
});
var LEAUI_MIND={};tinymce.PluginManager.add("leaui_mindmap",function(a,b){function c(){function c(){var c=a.settings.language,d=b+"/mindmap/index.html?i=1",e='<iframe id="leauiMindMapIfr" src="'+d+"?"+(new Date).getTime()+"&lang="+c+'" frameborder="0"></iframe>';return e}var d=a.dom,e=a.selection.getContent(),f=/<img.*?\/>/g,g=e.match(f),h=document.createElement("p");LEAUI_MIND={};for(var i in g){h.innerHTML=g[i];var j=h.firstChild;if(j&&"IMG"==j.nodeName){LEAUI_MIND.json=d.getAttrib(j,"data-mind-json");break}}var k=window.innerWidth-10,l=window.innerHeight-150;win=a.windowManager.open({title:"Mind Map",width:k,height:l,html:c(),buttons:[{text:"Cancel",onclick:function(){this.parent().parent().close()}},{text:"Insert",subtype:"primary",onclick:function(b){var c=this,d=document.getElementById("leauiMindMapIfr").contentWindow,e=d.km;e.exportData("png").then(function(b){var d=JSON.stringify(e.exportJson()),f='<img src="'+b+"\" data-mind-json='"+d+"'>";a.insertContent(f),c.parent().parent().close()})}}]})}a.addButton("leaui_mindmap",{icon:"mind",tooltip:"Insert/edit mind map",onclick:c,stateSelector:"img[data-mind-json]"})});

File diff suppressed because one or more lines are too long

View File

@@ -114,4 +114,4 @@
writeScripts();
})(this);
// $hash: 8ef1e488b0d8feeb6f98855715dbda69
// $hash: 7f014edd21d9dadc674b3ee20ce581a2

View File

@@ -115,4 +115,4 @@
writeScripts();
})(this);
// $hash: 79c1674ebd5e6bf17b5996c1cdb2b5e2
// $hash: 2a940e42d1d5586ee4cb1c4edfddd911

View File

@@ -220,4 +220,4 @@
writeScripts();
})(this);
// $hash: f202b94de3f0ddec78c07447b0d9d26e
// $hash: 5298883a2388fa3b9e124259f4f9b892

View File

@@ -39788,229 +39788,50 @@ tinymce.PluginManager.add('link', function(editor) {
});
});
/**
* leaui album image manager plugin
* copyright leaui
* leaui.com
* plugin.js
*
* Copyright, Moxiecode Systems AB
* Released under LGPL License.
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
var LEAUI_DATAS = [];
tinymce.PluginManager.add('leaui_image', function(editor, url) {
//当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);
}
/*global tinymce:true */
tinymce.PluginManager.add('image', 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");
var datas = [];
for(var i in images) {
newNode.innerHTML = images[i];
var imgElm = newNode.firstChild;
if(imgElm && imgElm.nodeName == "IMG") {
var data = {};
data.src = dom.getAttrib(imgElm, 'data-src') || dom.getAttrib(imgElm, 'src');
data.width = dom.getAttrib(imgElm, 'width');
data.height = dom.getAttrib(imgElm, 'height');
data.title = dom.getAttrib(imgElm, 'title');
datas.push(data);
}
}
LEAUI_DATAS = datas;
function GetTheHtml(){
var html = '<iframe id="leauiIfr" src="'+ url + '/index.html'+ '?' + new Date().getTime() + '" frameborder="0"></iframe>';
return html;
}
var w = $(document).width() - 10;
if(w > 805) {
w = 805;
}
var h = $(document).height() - 100;
if(h > 365) {
h = 365;
}
win = editor.windowManager.open({
title: "Image",
width : w,
height : h,
html: GetTheHtml(),
buttons: [
{
text: 'Cancel',
onclick: function() {
this.parent().parent().close();
}
},
{
text: 'Insert Image',
subtype: 'primary',
onclick: function(e) {
var _iframe = document.getElementById('leauiIfr').contentWindow;
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();
}
}]
});
insertLocalImage();
}
editor.addButton('leaui_image', {
// 添加按钮
editor.addButton('image', {
icon: 'image',
tooltip: 'Insert/edit image',
tooltip: 'Insert image',
onclick: showDialog,
stateSelector: 'img:not([data-mind-json])'
});
editor.addMenuItem('leaui_image', {
icon: 'image',
text: 'Insert image',
onclick: showDialog,
context: 'insert',
prependToContext: true
});
// 为解决在editor里拖动图片问题
// 2014/7/8 21:43 浮躁的一天终有收获
var dragStart = false;
editor.on("dragstart", function(e) {
dragStart = true;
});
editor.on("dragend", function(e) {
dragStart = false;
});
editor.on("dragover", function(e) {
if(!dragStart) {
$("body").trigger("dragover");
// 只读模式下不能拖动
if (LEA.readOnly) {
e.preventDefault();
e.stopPropagation();
}
});
});
/**
* leaui album image manager plugin
editor.on("dragend", function(e) {
});
editor.on("dragover", function(e) {
});
});/**
* leaui mind map plugin
* copyright leaui
* leaui.com
*/
var LEAUI_MIND = {};
tinymce.PluginManager.add('leaui_mind', function(editor, url) {
tinymce.PluginManager.add('leaui_mindmap', function(editor, url) {
function showDialog() {
var dom = editor.dom;
@@ -40032,15 +39853,14 @@ tinymce.PluginManager.add('leaui_mind', function(editor, url) {
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>';
var u = url + '/mindmap/index.html?i=1';
var html = '<iframe id="leauiMindMapIfr" src="'+ u + '?' + new Date().getTime() + '&lang=' + lang + '" frameborder="0"></iframe>';
return html;
}
var w = $(document).width() - 10;
var h = $(document).height() - 100;
var w = window.innerWidth - 10;
var h = window.innerHeight - 150;
win = editor.windowManager.open({
title: "Mind Map",
width : w,
@@ -40054,122 +39874,30 @@ tinymce.PluginManager.add('leaui_mind', function(editor, url) {
}
},
{
text: 'Insert Mind Map',
text: 'Insert',
subtype: 'primary',
onclick: function(e) {
var me = this;
var _iframe = document.getElementById('leauiIfr').contentWindow;
var _iframe = document.getElementById('leauiMindMapIfr').contentWindow;
var km = _iframe.km;
// window.km= km;
// return
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 + '\'>';
var img = '<img src="' + data + '" 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', {
editor.addButton('leaui_mindmap', {
// image: url + '/icon.png',
icon: 'mind',
tooltip: 'Insert/edit mind map',
onclick: showDialog,
@@ -41243,26 +40971,24 @@ define("tinymce/pasteplugin/Clipboard", [
var pasteBinDefaultContent = '%MCEPASTEBIN%', keyboardPastePlainTextState;
/**
* 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.
* 复制外链图片, copy到本地
*/
function copyImage(src, ids) {
ajaxPost("/file/copyHttpImage", {src: src}, function(ret) {
if(reIsOk(ret)) {
function copyImage(src, ids) {
FileService.copyOtherSiteImage(src, function(url) {
if (url) {
// 将图片替换之
var src = urlPrefix + "/" + ret.Item;
var dom = editor.dom
var dom = editor.dom;
for(var i in ids) {
var id = ids[i];
var imgElm = dom.get(id);
dom.setAttrib(imgElm, 'src', src);
if (imgElm) {
dom.setAttrib(imgElm, 'src', url);
}
}
}
});
}
// 粘贴HTML
// 当在pre下时不能粘贴成HTML
// life add text
@@ -41320,15 +41046,15 @@ define("tinymce/pasteplugin/Clipboard", [
var needCopyImages = {}; // src => [id1,id2]
var time = (new Date()).getTime();
try {
var $html = $("<div>" + html + "</div");
var $html = $("<div>" + html + "</div>");
var $imgs = $html.find("img");
for(var i = 0; i < $imgs.length; ++i) {
var $img = $imgs.eq(i)
var src = $img.attr("src");
// 是否是外链
if(src.indexOf(urlPrefix) == -1) {
if(src.indexOf(urlPrefix) == -1 && src.indexOf('http://127.0.0.1') == -1) {
time++;
var id = "__LEANOTE_IMAGE_" + time;
var id = "__LEANOTE_D_IMG_" + time;
$img.attr("id", id);
if(needCopyImages[src]) {
needCopyImages[src].push(id);
@@ -41338,7 +41064,7 @@ define("tinymce/pasteplugin/Clipboard", [
}
}
editor.insertContent($html.html());
for(var src in needCopyImages) {
var ids = needCopyImages[src];
copyImage(src, ids);
@@ -41545,75 +41271,24 @@ define("tinymce/pasteplugin/Clipboard", [
document.body.appendChild(img);
}
// 上传图片
function pasteImage(event) {
// use event.originalEvent.clipboard for newer chrome versions
var items = (event.clipboardData || event.originalEvent.clipboardData).items; // 可能有多个file, 找到属于图片的file
log(JSON.stringify(items)); // will give you the mime types
// find pasted image among pasted items
var blob;
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf("image") === 0) {
blob = items[i].getAsFile();
}
}
// load image if there is a pasted image
if (blob) {
var reader = new FileReader();
reader.onload = function(event) {
// 上传之
var c = new FormData;
c.append("from", "pasteImage");
c.append("file", blob);
c.append("noteId", Note.curNoteId); // life
// var d;
// d = $.ajaxSettings.xhr();
// d.withCredentials = i;var d = {};
// 先显示loading...
var editor = tinymce.EditorManager.activeEditor;
var dom = editor.dom;
var d = {};
d.id = '__mcenew';
d.src = "http://leanote.com/images/loading-24.gif"; // 写死了
editor.insertContent(dom.createHTML('img', d));
var imgElm = dom.get('__mcenew');
$.ajax({url: "/file/pasteImage", contentType:false, processData:false , data: c, type: "POST"}
).done(function(re) {
if(!re || typeof re != "object" || !re.Ok) {
// 删除
dom.remove(imgElm);
return;
}
// 这里, 如果图片宽度过大, 这里设置成500px
var urlPrefix = UrlPrefix; // window.location.protocol + "//" + window.location.host;
var src = urlPrefix + "/file/outputImage?fileId=" + re.Id;
getImageSize(src, 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', src);
});
dom.setAttrib(imgElm, 'id', null);
});
};
reader.readAsDataURL(blob);
return true;
}
return false;
}
var ever;
editor.on('paste', function(e) {
if(inAcePrevent()) {
return;
}
// start
// 以下只是linux需要
// -----
// 为什么要这个, 因为linux的原因, pasteImage会触发paste事件, 导致多次复制
if (ever && new Date().getTime() - ever < 100) {
e.preventDefault();
return;
}
ever = new Date().getTime();
// end
var clipboardContent = getClipboardContent(e);
var isKeyBoardPaste = new Date().getTime() - keyboardPasteTimeStamp < 100;
var plainTextMode = self.pasteFormat == "text" || keyboardPastePlainTextState;
@@ -41668,12 +41343,17 @@ define("tinymce/pasteplugin/Clipboard", [
//-----------
// paste image
try {
// common.js
pasteImage(e);
return;
/*
if(pasteImage(e)) {
return;
}
*/
} catch(e) {};
} catch(e) {
console.error(e);
};
});
@@ -42124,26 +41804,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.quirks = new Quirks(editor);
self.wordFilter = new WordFilter(editor);
clipboard.copyImage = true;
if (editor.settings.paste_as_text) {
self.clipboard.pasteFormat = "text";
@@ -42196,13 +41861,6 @@ define("tinymce/pasteplugin/Plugin", [
onclick: togglePlainTextPaste,
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', {
text: 'Paste as text',
@@ -42214,7 +41872,8 @@ define("tinymce/pasteplugin/Plugin", [
});
expose(["tinymce/pasteplugin/Utils","tinymce/pasteplugin/WordFilter"]);
})(this);/**
})(this);
/**
* plugin.js
*
* Copyright, Moxiecode Systems AB
@@ -43143,6 +42802,9 @@ tinymce.PluginManager.add('leanote_code', function(editor, url) {
"Latex:latex",
"Xml:xml",
"ActionScript:actionScript",
"Matlab:matlab",
"Scala:scala",
"Sql:sql"
];
var items = [];
for(var i in langs) {
@@ -43202,7 +42864,7 @@ tinymce.PluginManager.add('leanote_code', function(editor, url) {
ed.addCommand('toggleCode', toggleCode);
ed.addShortcut('ctrl+shift+c', '', 'toggleCode');
ed.addShortcut('command+shift+c', '', 'toggleCode');
ed.addShortcut('meta+shift+c', '', 'toggleCode');
// life
if(LeaAce.canAce()) {
@@ -43236,26 +42898,27 @@ tinymce.PluginManager.add('leanote_code', function(editor, url) {
var num = e.which ? e.which : e.keyCode;
if (num == 9) { // tab pressed
if(!e.shiftKey) {
// ed.execCommand('Indent');
// TODO 如果当前在li, ul, ol下不执行!!
// 如果在pre下就加tab
// var node = ed.selection.getNode();
/*
if(node.nodeName == "PRE") {
ed.execCommand('mceInsertHTML', false, '\x09'); // inserts tab
} else {
*/
// 如果是在li下的, 就不要控制
var node = ed.selection.getNode();
if (node && (node.nodeName == 'LI' || $(node.closest('li')).length > 0)) {
return true;
}
ed.insertContent("&nbsp;&nbsp;&nbsp;&nbsp;");
e.preventDefault();
e.stopPropagation();
return false;
// ed.execCommand('mceInsertHTML', false, "&nbsp;&nbsp;&nbsp;&nbsp;"); // inserts 空格
// }
} else {
// delete 4 个空格
// ed.execCommand('Outdent');
}
e.preventDefault();
e.stopPropagation();
return false;
}
});
});/**

File diff suppressed because one or more lines are too long

View File

@@ -220,4 +220,4 @@
writeScripts();
})(this);
// $hash: 777fc5b68209cf2659ea1aa7c90e8d6d
// $hash: ded07386598c5a9d19e059af0deb9ca5