attachment feature #10

This commit is contained in:
life
2014-09-21 22:05:04 +08:00
parent ab242b10f2
commit c556ab59b5
26 changed files with 1197 additions and 135 deletions

View File

@@ -1317,7 +1317,37 @@
}
});
}
// life 新添加函数
// life
function insertLinkLife(link, text) {
inputBox.focus();
if (undoManager) {
undoManager.setCommandMode();
}
var state = new TextareaState(panels);
if (!state) {
return;
}
var chunks = state.getChunks(); // 得到chunk
var fixupInputArea = function () {
inputBox.focus();
if (chunks) {
state.setChunks(chunks);
}
state.restore();
previewManager.refresh();
};
var a = commandProto.insertLink(chunks, fixupInputArea, link, text);
if(!a) fixupInputArea();
}
MarkdownEditor.insertLink = insertLinkLife;
// Perform the button's action.
function doClick(button) {
@@ -1369,6 +1399,7 @@
var noCleanup = button.textOp(chunks, fixupInputArea);
// 这里生成
if (!noCleanup) {
fixupInputArea();
}
@@ -1378,6 +1409,7 @@
if (button.execute) {
button.execute(undoManager);
}
};
function setupButton(button, isEnabled) {
@@ -1707,6 +1739,68 @@
return title ? link + ' "' + title + '"' : link;
});
}
// life 添加
commandProto.insertLink = function (chunk, postProcessing, link, text) {
isImage = false;
chunk.trimWhitespace();
chunk.findTags(/\s*!?\[/, /\][ ]?(?:\n[ ]*)?(\[.*?\])?/);
var background;
if (chunk.endTag.length > 1 && chunk.startTag.length > 0) {
chunk.startTag = chunk.startTag.replace(/!?\[/, "");
chunk.endTag = "";
this.addLinkDef(chunk, null);
}
else {
// We're moving start and end tag back into the selection, since (as we're in the else block) we're not
// *removing* a link, but *adding* one, so whatever findTags() found is now back to being part of the
// link text. linkEnteredCallback takes care of escaping any brackets.
chunk.selection = chunk.startTag + chunk.selection + chunk.endTag;
chunk.startTag = chunk.endTag = "";
if (/\n\n/.test(chunk.selection)) {
this.addLinkDef(chunk, null);
return;
}
var that = this;
// The function to be executed when you enter a link and press OK or Cancel.
// Marks up the link and adds the ref.
var linkEnteredCallback = function (link) {
background.parentNode.removeChild(background);
if (link !== null) {
chunk.selection = (" " + chunk.selection).replace(/([^\\](?:\\\\)*)(?=[[\]])/g, "$1\\").substr(1);
var linkDef = " [999]: " + properlyEncoded(link);
var num = that.addLinkDef(chunk, linkDef);
chunk.startTag = isImage ? "![" : "[";
chunk.endTag = "][" + num + "]";
chunk.selection = text;
}
postProcessing();
};
background = ui.createBackground();
linkEnteredCallback(link);
/*
if (isImage) {
if (!this.hooks.insertImageDialog(linkEnteredCallback))
ui.prompt(this.getString("imagedialog"), imageDefaultText, linkEnteredCallback);
}
else {
if (!this.hooks.insertLinkDialog(linkEnteredCallback)) // jiawzhang
ui.prompt(this.getString("linkdialog"), linkDefaultText, linkEnteredCallback);
}
*/
return true;
}
};
commandProto.doLinkOrImage = function (chunk, postProcessing, isImage) {