PageSourceSearch

https://novinlib.com/assets/admincp/tinymce/plugins/noneditable/plugin.js

js novinlib.com collected 2026-09-24 13:17:14 UTC 4,548 bytes, 124 lines download raw bytes

1/**
2 * Copyright (c) Tiny Technologies, Inc. All rights reserved.
3 * Licensed under the LGPL or a commercial license.
4 * For LGPL see License.txt in the project root for license information.
5 * For commercial licenses see https://www.tiny.cloud/
6 *
7 * Version: 5.0.15 (2019-09-02)
8 */
9(function () {
10    'use strict';
11
12    var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
13
14    var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
15
16    var getNonEditableClass = function (editor) {
17      return editor.getParam('noneditable_noneditable_class', 'mceNonEditable');
18    };
19    var getEditableClass = function (editor) {
20      return editor.getParam('noneditable_editable_class', 'mceEditable');
21    };
22    var getNonEditableRegExps = function (editor) {
23      var nonEditableRegExps = editor.getParam('noneditable_regexp', []);
24      if (nonEditableRegExps && nonEditableRegExps.constructor === RegExp) {
25        return [nonEditableRegExps];
26      } else {
27        return nonEditableRegExps;
28      }
29    };
30    var Settings = {
31      getNonEditableClass: getNonEditableClass,
32      getEditableClass: getEditableClass,
33      getNonEditableRegExps: getNonEditableRegExps
34    };
35
36    var hasClass = function (checkClassName) {
37      return function (node) {
38        return (' ' + node.attr('class') + ' ').indexOf(checkClassName) !== -1;
39      };
40    };
41    var replaceMatchWithSpan = function (editor, content, cls) {
42      return function (match) {
43        var args = arguments, index = args[args.length - 2];
44        var prevChar = index > 0 ? content.charAt(index - 1) : '';
45        if (prevChar === '"') {
46          return match;
47        }
48        if (prevChar === '>') {
49          var findStartTagIndex = content.lastIndexOf('<', index);
50          if (findStartTagIndex !== -1) {
51            var tagHtml = content.substring(findStartTagIndex, index);
52            if (tagHtml.indexOf('contenteditable="false"') !== -1) {
53              return match;
54            }
55          }
56        }
57        return '<span class="' + cls + '" data-mce-content="' + editor.dom.encode(args[0]) + '">' + editor.dom.encode(typeof args[1] === 'string' ? args[1] : args[0]) + '</span>';
58      };
59    };
60    var convertRegExpsToNonEditable = function (editor, nonEditableRegExps, e) {
61      var i = nonEditableRegExps.length, content = e.content;
62      if (e.format === 'raw') {
63        return;
64      }
65      while (i--) {
66        content = content.replace(nonEditableRegExps[i], replaceMatchWithSpan(editor, content, Settings.getNonEditableClass(editor)));
67      }
68      e.content = content;
69    };
70    var setup = function (editor) {
71      var editClass, nonEditClass;
72      var contentEditableAttrName = 'contenteditable';
73      editClass = ' ' + global$1.trim(Settings.getEditableClass(editor)) + ' ';
74      nonEditClass = ' ' + global$1.trim(Settings.getNonEditableClass(editor)) + ' ';
75      var hasEditClass = hasClass(editClass);
76      var hasNonEditClass = hasClass(nonEditClass);
77      var nonEditableRegExps = Settings.getNonEditableRegExps(editor);
78      editor.on('PreInit', function () {
79        if (nonEditableRegExps.length > 0) {
80          editor.on('BeforeSetContent', function (e) {
81            convertRegExpsToNonEditable(editor, nonEditableRegExps, e);
82          });
83        }
84        editor.parser.addAttributeFilter('class', function (nodes) {
85          var i = nodes.length, node;
86          while (i--) {
87            node = nodes[i];
88            if (hasEditClass(node)) {
89              node.attr(contentEditableAttrName, 'true');
90            } else if (hasNonEditClass(node)) {
91              node.attr(contentEditableAttrName, 'false');
92            }
93          }
94        });
95        editor.serializer.addAttributeFilter(contentEditableAttrName, function (nodes) {
96          var i = nodes.length, node;
97          while (i--) {
98            node = nodes[i];
99            if (!hasEditClass(node) && !hasNonEditClass(node)) {
100              continue;
101            }
102            if (nonEditableRegExps.length > 0 && node.attr('data-mce-content')) {
103              node.name = '#text';
104              node.type = 3;
105              node.raw = true;
106              node.value = node.attr('data-mce-content');
107            } else {
108              node.attr(contentEditableAttrName, null);
109            }
110          }
111        });
112      });
113    };
114    var FilterContent = { setup: setup };
115
116    function Plugin () {
117      global.add('noneditable', function (editor) {
118        FilterContent.setup(editor);
119      });
120    }
121
122    Plugin();
123
124}());

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.