link.js 29.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
/*
 Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
 For licensing, see LICENSE.md or http://ckeditor.com/license
*/
(function() {
    CKEDITOR.dialog.add("link",
    function(e) {
        var m = CKEDITOR.plugins.link,
        p,
        q = function() {
          var a = this.getDialog(),
          b = a.getContentElement("target", "popupFeatures"),
          a = a.getContentElement("target", "linkTargetName"),
          n = this.getValue();
          if (b && a) switch (b = b.getElement(), b.hide(), a.setValue(""), n) {
          case "frame":
              a.setLabel(e.lang.link.targetFrameName);
              a.getElement().show();
              break;
          case "popup":
              b.show();
              a.setLabel(e.lang.link.targetPopupName);
              a.getElement().show();
              break;
          default:
              a.setValue(n),
              a.getElement().hide()
          }
        },
        h = function(a) {
            a.target && this.setValue(a.target[this.id] || "")
        },
        f = function(a) {
            a.advanced && this.setValue(a.advanced[this.id] || "")
        },
        k = function(a) {
            a.target || (a.target = {});
            a.target[this.id] = this.getValue() || ""
        },
        l = function(a) {
            a.advanced || (a.advanced = {});
            a.advanced[this.id] = this.getValue() || ""
        },
        c = e.lang.common,
        b = e.lang.link,
        g;
        return {
            title: b.title,
            minWidth: "moono-lisa" == (CKEDITOR.skinName || e.config.skin) ? 450 : 350,
            minHeight: 240,
            contents: [{
                id: "info",
                label: b.info,
                title: b.info,
                elements: [{
                    type: "text",
                    id: "linkDisplayText",
                    label: b.displayText,
                    setup: function() {
                        this.enable();
                        this.setValue(e.getSelection().getSelectedText());
                        p = this.getValue()
                    },
                    commit: function(a) {
                        a.linkText = this.isEnabled() ? this.getValue() : ""
                    }
                },
                {
                    id: "linkType",
                    type: "select",
                    label: b.type,
                    "default": "url",
                    items: [[b.toUrl, "url"], [b.toAnchor, "anchor"], [b.toEmail, "email"]],
                    onChange: function() {
                        var a = this.getDialog(),
                        b = ["urlOptions", "anchorOptions", "emailOptions"],
                        n = this.getValue(),
                        d = a.definition.getContents("upload"),
                        d = d && d.hidden;
                        "url" == n ? (e.config.linkShowTargetTab && a.showPage("target"), d || a.showPage("upload")) : (a.hidePage("target"), d || a.hidePage("upload"));
                        // cjm 2019-08-14 切换超链接类型,设置锚点的时候 target改为_self,其他为_blank
                        var t = this.getDialog().getContentElement("target", "linkTargetName");
                        "anchor" === n ? t && t.setValue('_self') : t && t.setValue('_blank');
                        for (d = 0; d < b.length; d++) {
                            var c = a.getContentElement("info", b[d]);
                            c && (c = c.getElement().getParent().getParent(), b[d] == n + "Options" ? c.show() : c.hide())
                        }
                        a.layout()
                    },
                    setup: function(a) {
                        this.setValue(a.type || "url")
                    },
                    commit: function(a) {
                        a.type = this.getValue()
                    }
                },
                {
                    type: "vbox",
                    id: "urlOptions",
                    children: [{
                        type: "hbox",
                        widths: ["25%", "75%"],
                        children: [{
                            id: "protocol",
                            type: "select",
                            label: c.protocol,
                            "default": "http://",
                            items: [["http://‎", "http://"], ["https://‎", "https://"], ["ftp://‎", "ftp://"], ["news://‎", "news://"], [b.other, ""]],
                            setup: function(a) {
                                a.url && this.setValue(a.url.protocol || "")
                            },
                            commit: function(a) {
                                a.url || (a.url = {});
                                a.url.protocol = this.getValue()
                            }
                        },
                        {
                            type: "text",
                            id: "url",
                            label: c.url,
                            required: !0,
                            onLoad: function() {
                                this.allowOnChange = !0
                            },
                            onKeyUp: function() {
                                this.allowOnChange = !1;
                                var a = this.getDialog().getContentElement("info", "protocol"),
                                b = this.getValue(),
                                c = /^((javascript:)|[#\/\.\?])/i,
                                d = /^(http|https|ftp|news):\/\/(?=.)/i.exec(b);
                                d ? (this.setValue(b.substr(d[0].length)), a.setValue(d[0].toLowerCase())) : c.test(b) && a.setValue("");
                                this.allowOnChange = !0
                            },
                            onChange: function() {
                                if (this.allowOnChange) this.onKeyUp()
                            },
                            validate: function() {
                                var a = this.getDialog();
                                return a.getContentElement("info", "linkType") && "url" != a.getValueOf("info", "linkType") ? !0 : !e.config.linkJavaScriptLinksAllowed && /javascript\:/.test(this.getValue()) ? (alert(c.invalidValue), !1) : this.getDialog().fakeObj ? !0 : CKEDITOR.dialog.validate.notEmpty(b.noUrl).apply(this)
                            },
                            setup: function(a) {
                                this.allowOnChange = !1;
                                a.url && this.setValue(a.url.url);
                                this.allowOnChange = !0
                            },
                            commit: function(a) {
                                this.onChange();
                                a.url || (a.url = {});
                                a.url.url = this.getValue();
                                this.allowOnChange = !1
                            }
                        }],
                        setup: function() {
                            this.getDialog().getContentElement("info", "linkType") || this.getElement().show()
                        }
                    },
                    {
                        type: "button",
                        id: "browse",
                        hidden: "true",
                        filebrowser: "info:url",
                        label: c.browseServer
                    }]
                },
                {
                    type: "vbox",
                    id: "anchorOptions",
                    width: 260,
                    align: "center",
                    padding: 0,
                    children: [{
                        type: "fieldset",
                        id: "selectAnchorText",
                        label: b.selectAnchor,
                        setup: function() {
                            g = m.getEditorAnchors(e);
                            this.getElement()[g && g.length ? "show": "hide"]()
                        },
                        children: [{
                            type: "hbox",
                            id: "selectAnchor",
                            children: [{
                                type: "select",
                                id: "anchorName",
                                "default": "",
                                label: b.anchorName,
                                style: "width: 100%;",
                                items: [[""]],
                                setup: function(a) {
                                    this.clear();
                                    this.add("");
                                    if (g) for (var b = 0; b < g.length; b++) g[b].name && this.add(g[b].name);
                                    a.anchor && this.setValue(a.anchor.name); (a = this.getDialog().getContentElement("info", "linkType")) && "email" == a.getValue() && this.focus()
                                },
                                commit: function(a) {
                                    a.anchor || (a.anchor = {});
                                    a.anchor.name = this.getValue()
                                }
                            },
                            {
                                type: "select",
                                id: "anchorId",
                                "default": "",
                                label: b.anchorId,
                                style: "width: 100%;",
                                items: [[""]],
                                setup: function(a) {
                                    this.clear();
                                    this.add("");
                                    if (g) for (var b = 0; b < g.length; b++) g[b].id && this.add(g[b].id);
                                    a.anchor && this.setValue(a.anchor.id)
                                },
                                commit: function(a) {
                                    a.anchor || (a.anchor = {});
                                    a.anchor.id = this.getValue()
                                }
                            }],
                            setup: function() {
                                this.getElement()[g && g.length ? "show": "hide"]()
                            }
                        }]
                    },
                    {
                        type: "html",
                        id: "noAnchors",
                        style: "text-align: center;",
                        html: '\x3cdiv role\x3d"note" tabIndex\x3d"-1"\x3e' + CKEDITOR.tools.htmlEncode(b.noAnchors) + "\x3c/div\x3e",
                        focus: !0,
                        setup: function() {
                            this.getElement()[g && g.length ? "hide": "show"]()
                        }
                    }],
                    setup: function() {
                        this.getDialog().getContentElement("info", "linkType") || this.getElement().hide()
                    }
                },
                {
                    type: "vbox",
                    id: "emailOptions",
                    padding: 1,
                    children: [{
                        type: "text",
                        id: "emailAddress",
                        label: b.emailAddress,
                        required: !0,
                        validate: function() {
                            var a = this.getDialog();
                            return a.getContentElement("info", "linkType") && "email" == a.getValueOf("info", "linkType") ? CKEDITOR.dialog.validate.notEmpty(b.noEmail).apply(this) : !0
                        },
                        setup: function(a) {
                            a.email && this.setValue(a.email.address); (a = this.getDialog().getContentElement("info", "linkType")) && "email" == a.getValue() && this.select()
                        },
                        commit: function(a) {
                            a.email || (a.email = {});
                            a.email.address = this.getValue()
                        }
                    },
                    {
                        type: "text",
                        id: "emailSubject",
                        label: b.emailSubject,
                        setup: function(a) {
                            a.email && this.setValue(a.email.subject)
                        },
                        commit: function(a) {
                            a.email || (a.email = {});
                            a.email.subject = this.getValue()
                        }
                    },
                    {
                        type: "textarea",
                        id: "emailBody",
                        label: b.emailBody,
                        rows: 3,
                        "default": "",
                        setup: function(a) {
                            a.email && this.setValue(a.email.body)
                        },
                        commit: function(a) {
                            a.email || (a.email = {});
                            a.email.body = this.getValue()
                        }
                    }],
                    setup: function() {
                        this.getDialog().getContentElement("info", "linkType") || this.getElement().hide()
                    }
                }]
            },
            {
                id: "target",
                requiredContent: "a[target]",
                label: b.target,
                title: b.target,
                elements: [{
                    type: "hbox",
                    widths: ["50%", "50%"],
                    children: [{
                        type: "select",
                        id: "linkTargetType",
                        label: c.target,
                        "default": "_blank", // 默认新窗口打开
                        style: "width : 100%;",
                        items: [[c.notSet, "notSet"], [b.targetFrame, "frame"], [b.targetPopup, "popup"], [c.targetNew, "_blank"], [c.targetTop, "_top"], [c.targetSelf, "_self"], [c.targetParent, "_parent"]],
                        onChange: q,
                        setup: function(a) {
                            a.target && this.setValue(a.target.type || "notSet");
                            q.call(this)
                        },
                        commit: function(a) {
                            a.target || (a.target = {});
                            a.target.type = this.getValue()
                        }
                    },
                    {
                        type: "text",
                        id: "linkTargetName",
                        label: b.targetFrameName,
                        "default": "",
                        setup: function(a) {
                            a.target && this.setValue(a.target.name)
                        },
                        commit: function(a) {
                            a.target || (a.target = {});
                            a.target.name = this.getValue().replace(/([^\x00-\x7F]|\s)/gi, "")
                        }
                    }]
                },
                {
                    type: "vbox",
                    width: "100%",
                    align: "center",
                    padding: 2,
                    id: "popupFeatures",
                    children: [{
                        type: "fieldset",
                        label: b.popupFeatures,
                        children: [{
                            type: "hbox",
                            children: [{
                                type: "checkbox",
                                id: "resizable",
                                label: b.popupResizable,
                                setup: h,
                                commit: k
                            },
                            {
                                type: "checkbox",
                                id: "status",
                                label: b.popupStatusBar,
                                setup: h,
                                commit: k
                            }]
                        },
                        {
                            type: "hbox",
                            children: [{
                                type: "checkbox",
                                id: "location",
                                label: b.popupLocationBar,
                                setup: h,
                                commit: k
                            },
                            {
                                type: "checkbox",
                                id: "toolbar",
                                label: b.popupToolbar,
                                setup: h,
                                commit: k
                            }]
                        },
                        {
                            type: "hbox",
                            children: [{
                                type: "checkbox",
                                id: "menubar",
                                label: b.popupMenuBar,
                                setup: h,
                                commit: k
                            },
                            {
                                type: "checkbox",
                                id: "fullscreen",
                                label: b.popupFullScreen,
                                setup: h,
                                commit: k
                            }]
                        },
                        {
                            type: "hbox",
                            children: [{
                                type: "checkbox",
                                id: "scrollbars",
                                label: b.popupScrollBars,
                                setup: h,
                                commit: k
                            },
                            {
                                type: "checkbox",
                                id: "dependent",
                                label: b.popupDependent,
                                setup: h,
                                commit: k
                            }]
                        },
                        {
                            type: "hbox",
                            children: [{
                                type: "text",
                                widths: ["50%", "50%"],
                                labelLayout: "horizontal",
                                label: c.width,
                                id: "width",
                                setup: h,
                                commit: k
                            },
                            {
                                type: "text",
                                labelLayout: "horizontal",
                                widths: ["50%", "50%"],
                                label: b.popupLeft,
                                id: "left",
                                setup: h,
                                commit: k
                            }]
                        },
                        {
                            type: "hbox",
                            children: [{
                                type: "text",
                                labelLayout: "horizontal",
                                widths: ["50%", "50%"],
                                label: c.height,
                                id: "height",
                                setup: h,
                                commit: k
                            },
                            {
                                type: "text",
                                labelLayout: "horizontal",
                                label: b.popupTop,
                                widths: ["50%", "50%"],
                                id: "top",
                                setup: h,
                                commit: k
                            }]
                        }]
                    }]
                }]
            },
            {
                id: "upload",
                label: b.upload,
                title: b.upload,
                hidden: !0,
                filebrowser: "uploadButton",
                elements: [{
                    type: "file",
                    id: "upload",
                    label: c.upload,
                    style: "height:40px",
                    size: 29
                },
                {
                    type: "fileButton",
                    id: "uploadButton",
                    label: c.uploadSubmit,
                    filebrowser: "info:url",
                    "for": ["upload", "upload"]
                }]
            },
            {
                id: "advanced",
                label: b.advanced,
                title: b.advanced,
                elements: [{
                    type: "vbox",
                    padding: 1,
                    children: [{
                        type: "hbox",
                        widths: ["45%", "35%", "20%"],
                        children: [{
                            type: "text",
                            id: "advId",
                            requiredContent: "a[id]",
                            label: b.id,
                            setup: f,
                            commit: l
                        },
                        {
                            type: "select",
                            id: "advLangDir",
                            requiredContent: "a[dir]",
                            label: b.langDir,
                            "default": "",
                            style: "width:110px",
                            items: [[c.notSet, ""], [b.langDirLTR, "ltr"], [b.langDirRTL, "rtl"]],
                            setup: f,
                            commit: l
                        },
                        {
                            type: "text",
                            id: "advAccessKey",
                            requiredContent: "a[accesskey]",
                            width: "80px",
                            label: b.acccessKey,
                            maxLength: 1,
                            setup: f,
                            commit: l
                        }]
                    },
                    {
                        type: "hbox",
                        widths: ["45%", "35%", "20%"],
                        children: [{
                            type: "text",
                            label: b.name,
                            id: "advName",
                            requiredContent: "a[name]",
                            setup: f,
                            commit: l
                        },
                        {
                            type: "text",
                            label: b.langCode,
                            id: "advLangCode",
                            requiredContent: "a[lang]",
                            width: "110px",
                            "default": "",
                            setup: f,
                            commit: l
                        },
                        {
                            type: "text",
                            label: b.tabIndex,
                            id: "advTabIndex",
                            requiredContent: "a[tabindex]",
                            width: "80px",
                            maxLength: 5,
                            setup: f,
                            commit: l
                        }]
                    }]
                },
                {
                    type: "vbox",
                    padding: 1,
                    children: [{
                        type: "hbox",
                        widths: ["45%", "55%"],
                        children: [{
                            type: "text",
                            label: b.advisoryTitle,
                            requiredContent: "a[title]",
                            "default": "",
                            id: "advTitle",
                            setup: f,
                            commit: l
                        },
                        {
                            type: "text",
                            label: b.advisoryContentType,
                            requiredContent: "a[type]",
                            "default": "",
                            id: "advContentType",
                            setup: f,
                            commit: l
                        }]
                    },
                    {
                        type: "hbox",
                        widths: ["45%", "55%"],
                        children: [{
                            type: "text",
                            label: b.cssClasses,
                            requiredContent: "a(cke-xyz)",
                            "default": "",
                            id: "advCSSClasses",
                            setup: f,
                            commit: l
                        },
                        {
                            type: "text",
                            label: b.charset,
                            requiredContent: "a[charset]",
                            "default": "",
                            id: "advCharset",
                            setup: f,
                            commit: l
                        }]
                    },
                    {
                        type: "hbox",
                        widths: ["45%", "55%"],
                        children: [{
                            type: "text",
                            label: b.rel,
                            requiredContent: "a[rel]",
                            "default": "",
                            id: "advRel",
                            setup: f,
                            commit: l
                        },
                        {
                            type: "text",
                            label: b.styles,
                            requiredContent: "a{cke-xyz}",
                            "default": "",
                            id: "advStyles",
                            validate: CKEDITOR.dialog.validate.inlineStyle(e.lang.common.invalidInlineStyle),
                            setup: f,
                            commit: l
                        }]
                    },
                    {
                        type: "hbox",
                        widths: ["45%", "55%"],
                        children: [{
                            type: "checkbox",
                            id: "download",
                            requiredContent: "a[download]",
                            label: b.download,
                            setup: function(a) {
                                void 0 !== a.download && this.setValue("checked", "checked")
                            },
                            commit: function(a) {
                                this.getValue() && (a.download = this.getValue())
                            }
                        }]
                    }]
                }]
            }],
            onShow: function() {
                var a = this.getParentEditor(),
                b = a.getSelection(),
                c = b.getSelectedElement(),
                d = this.getContentElement("info", "linkDisplayText").getElement().getParent().getParent(),
                e = null; (e = m.getSelectedLink(a)) && e.hasAttribute("href") ? c || (b.selectElement(e), c = e) : e = null;
                m.showDisplayTextForElement(c, a) ? d.show() : d.hide();
                a = m.parseLinkAttributes(a, e);
                this._.selectedElement = e;
                this.setupContent(a)
            },
            onOk: function() {
                var a = {};
                this.commitContent(a);
                var b = e.getSelection(),
                c = m.getLinkAttributes(e, a);
                if (this._.selectedElement) {
                    var d = this._.selectedElement,
                    g = d.data("cke-saved-href"),
                    h = d.getHtml(),
                    f;
                    d.setAttributes(c.set);
                    d.removeAttributes(c.removed);
                    if (a.linkText && p != a.linkText) f = a.linkText;
                    else if (g == h || "email" == a.type && -1 != h.indexOf("@")) f = "email" == a.type ? a.email.address: c.set["data-cke-saved-href"];
                    f && (d.setText(f), b.selectElement(d));
                    delete this._.selectedElement
                } else {
                    b = b.getRanges()[0];
                    b.collapsed ? (a = new CKEDITOR.dom.text(a.linkText || ("email" == a.type ? a.email.address: c.set["data-cke-saved-href"]), e.document), b.insertNode(a), b.selectNodeContents(a)) : p !== a.linkText && (a = new CKEDITOR.dom.text(a.linkText, e.document), b.shrink(CKEDITOR.SHRINK_TEXT), e.editable().extractHtmlFromRange(b), b.insertNode(a));
                    a = b._find("a");
                    for (d = 0; d < a.length; d++) a[d].remove(!0);
                    c = new CKEDITOR.style({
                        element: "a",
                        attributes: c.set
                    });
                    c.type = CKEDITOR.STYLE_INLINE;
                    c.applyToRange(b, e);
                    b.select()
                }
            },
            onLoad: function() {
                e.config.linkShowAdvancedTab || this.hidePage("advanced");
                e.config.linkShowTargetTab || this.hidePage("target")
            },
            onFocus: function() {
                var a = this.getContentElement("info", "linkType");
                a && "url" == a.getValue() && (a = this.getContentElement("info", "url"), a.select())
            }
        }
    })
})();