123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- /*!
- * Link dialog plugin for Editor.md
- *
- * @file link-dialog.js
- * @author pandao
- * @version 1.2.1
- * @updateTime 2015-06-09
- * {@link https://github.com/pandao/editor.md}
- * @license MIT
- */
- (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;
- }
- /*if (title === "")
- {
- alert(linkLang.titleEmpty);
- 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;
- }]
- }
- });
- }
- };
- };
-
- // CommonJS/Node.js
- if (typeof require === "function" && typeof exports === "object" && typeof module === "object")
- {
- module.exports = factory;
- }
- else if (typeof define === "function") // AMD/CMD/Sea.js
- {
- if (define.amd) { // for Require.js
- define(["editormd"], function(editormd) {
- factory(editormd);
- });
- } else { // for Sea.js
- define(function(require) {
- var editormd = require("./../../editormd");
- factory(editormd);
- });
- }
- }
- else
- {
- factory(window.editormd);
- }
- })();
|