comparison src/plugins/format.js @ 4:b7725dab7482

move /development/* to /
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 04 Aug 2022 17:59:02 -0600
parents src/development/plugins/format.js@4c4fc447baea
children a199722647d0
comparison
equal deleted inserted replaced
3:ec68006a495e 4:b7725dab7482
1 /**
2 * SCEditor Paragraph Formatting Plugin
3 * http://www.sceditor.com/
4 *
5 * Copyright (C) 2011-2013, Sam Clarke (samclarke.com)
6 *
7 * SCEditor is licensed under the MIT license:
8 * http://www.opensource.org/licenses/mit-license.php
9 *
10 * @fileoverview SCEditor Paragraph Formatting Plugin
11 * @author Sam Clarke
12 */
13 (function (sceditor) {
14 'use strict';
15
16 sceditor.plugins.format = function () {
17 var base = this;
18
19 /**
20 * Default tags
21 * @type {Object}
22 * @private
23 */
24 var tags = {
25 p: 'Paragraph',
26 h1: 'Heading 1',
27 h2: 'Heading 2',
28 h3: 'Heading 3',
29 h4: 'Heading 4',
30 h5: 'Heading 5',
31 h6: 'Heading 6',
32 address: 'Address',
33 pre: 'Preformatted Text'
34 };
35
36 /**
37 * Private functions
38 * @private
39 */
40 var insertTag,
41 formatCmd;
42
43
44 base.init = function () {
45 var opts = this.opts,
46 pOpts = opts.paragraphformat;
47
48 // Don't enable if the BBCode plugin is enabled.
49 if (opts.format && opts.format === 'bbcode') {
50 return;
51 }
52
53 if (pOpts) {
54 if (pOpts.tags) {
55 tags = pOpts.tags;
56 }
57
58 if (pOpts.excludeTags) {
59 pOpts.excludeTags.forEach(function (val) {
60 delete tags[val];
61 });
62 }
63 }
64
65 if (!this.commands.format) {
66 this.commands.format = {
67 exec: formatCmd,
68 txtExec: formatCmd,
69 tooltip: 'Format Paragraph'
70 };
71 }
72
73 if (opts.toolbar === sceditor.defaultOptions.toolbar) {
74 opts.toolbar = opts.toolbar.replace(',color,',
75 ',color,format,');
76 }
77 };
78
79 /**
80 * Inserts the specified tag into the editor
81 *
82 * @param {sceditor} editor
83 * @param {string} tag
84 * @private
85 */
86 insertTag = function (editor, tag) {
87 if (editor.sourceMode()) {
88 editor.insert('<' + tag + '>', '</' + tag + '>');
89 } else {
90 editor.execCommand('formatblock', '<' + tag + '>');
91 }
92
93 };
94
95 /**
96 * Function for the exec and txtExec properties
97 *
98 * @param {node} caller
99 * @private
100 */
101 formatCmd = function (caller) {
102 var editor = this,
103 content = document.createElement('div');
104
105 sceditor.utils.each(tags, function (tag, val) {
106 var link = document.createElement('a');
107 link.className = 'sceditor-option';
108 link.textContent = val.name || val;
109 link.addEventListener('click', function (e) {
110 editor.closeDropDown(true);
111
112 if (val.exec) {
113 val.exec(editor);
114 } else {
115 insertTag(editor, tag);
116 }
117
118 e.preventDefault();
119 });
120
121 content.appendChild(link);
122 });
123
124 editor.createDropDown(caller, 'format', content);
125 };
126 };
127 })(sceditor);