(
function
() {
var
factory =
function
(exports) {
var
pluginName =
"link-dialog"
;
exports.fn.linkDialog =
function
() {
var
_this =
this
;
var
cm =
this
.cm;
var
editor =
this
.editor;
var
settings =
this
.settings;
var
selection = cm.getSelection();
var
lang =
this
.lang;
var
linkLang = lang.dialog.link;
var
classPrefix =
this
.classPrefix;
var
dialogName = classPrefix + pluginName, dialog;
cm.focus();
if
(editor.find(
"."
+ dialogName).length > 0)
{
dialog = editor.find(
"."
+ dialogName);
dialog.find(
"[data-url]"
).val(
"http://"
);
dialog.find(
"[data-title]"
).val(selection);
this
.dialogShowMask(dialog);
this
.dialogLockScreen();
dialog.show();
}
else
{
var
dialogHTML =
"<div class=\""
+ classPrefix +
"form\">"
+
"<label>"
+ linkLang.url +
"</label>"
+
"<input type=\"text\" value=\"http://\" data-url />"
+
"<br/>"
+
"<label>"
+ linkLang.urlTitle +
"</label>"
+
"<input type=\"text\" value=\""
+ selection +
"\" data-title />"
+
"<br/>"
+
"</div>"
;
dialog =
this
.createDialog({
title : linkLang.title,
width : 380,
height : 211,
content : dialogHTML,
mask : settings.dialogShowMask,
drag : settings.dialogDraggable,
lockScreen : settings.dialogLockScreen,
maskStyle : {
opacity : settings.dialogMaskOpacity,
backgroundColor : settings.dialogMaskBgColor
},
buttons : {
enter : [lang.buttons.enter,
function
() {
var
url =
this
.find(
"[data-url]"
).val();
var
title =
this
.find(
"[data-title]"
).val();
if
(url ===
"http://"
|| url ===
""
)
{
alert(linkLang.urlEmpty);
return
false
;
}
var
str =
"["
+ title +
"]("
+ url +
" \""
+ title +
"\")"
;
if
(title ==
""
)
{
str =
"["
+ url +
"]("
+ url +
")"
;
}
cm.replaceSelection(str);
this
.hide().lockScreen(
false
).hideMask();
return
false
;
}],
cancel : [lang.buttons.cancel,
function
() {
this
.hide().lockScreen(
false
).hideMask();
return
false
;
}]
}
});
}
};
};
if
(
typeof
require ===
"function"
&&
typeof
exports ===
"object"
&&
typeof
module ===
"object"
)
{
module.exports = factory;
}
else
if
(
typeof
define ===
"function"
)
{
if
(define.amd) {
define([
"editormd"
],
function
(editormd) {
factory(editormd);
});
}
else
{
define(
function
(require) {
var
editormd = require(
"./../../editormd"
);
factory(editormd);
});
}
}
else
{
factory(window.editormd);
}
})();