Dotclear

source: plugins/dcCKEditor/js/popup_link.js @ 3880:e6d1f6d9d7df

Revision 3880:e6d1f6d9d7df, 1.4 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Use let and const rather than var (ES2015/ES6), use template string where is more efficient

Line 
1/*global $ */
2'use strict';
3
4$(function() {
5  $('#link-insert-cancel').click(function() {
6    window.close();
7  });
8
9  $('#link-insert-ok').click(function() {
10    const insert_form = $('#link-insert-form').get(0);
11    if (insert_form == undefined) {
12      return;
13    }
14
15    const editor_name = window.opener.$.getEditorName();
16    const editor = window.opener.CKEDITOR.instances[editor_name];
17    let link = '';
18    let selected_element;
19    if (editor.getSelection().getSelectedElement() != null) {
20      selected_element = editor.getSelection().getSelectedElement();
21    } else {
22      selected_element = editor.getSelection().getNative().toString();
23    }
24
25    if (editor.mode == 'wysiwyg') {
26      link = editor.document.createElement('a');
27      link.setAttribute('href', insert_form.elements.href.value);
28      if (insert_form.elements.title.value != '') {
29        link.setAttribute(
30          'title',
31          window.opener.CKEDITOR.tools.htmlEncodeAttr(insert_form.elements.title.value)
32        );
33      }
34      if (insert_form.elements.hreflang.value != '') {
35        link.setAttribute(
36          'hreflang',
37          window.opener.CKEDITOR.tools.htmlEncodeAttr(insert_form.elements.hreflang.value)
38        );
39      }
40      if (editor.getSelection().getSelectedElement() != null) {
41        selected_element.appendTo(link);
42      } else {
43        link.appendText(selected_element);
44      }
45      editor.insertElement(link);
46    }
47    window.close();
48  });
49});
Note: See TracBrowser for help on using the repository browser.

Sites map