Mercurial Hosting > sceditor
annotate src/formats/bbcode.js @ 37:0c4e4b5ef40d
remove fragmentToHtml
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 17 Aug 2022 12:00:57 -0600 |
parents | 21090996a131 |
children | 7491026f7623 |
rev | line source |
---|---|
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 * SCEditor BBCode Plugin |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 * http://www.sceditor.com/ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 * Copyright (C) 2011-2017, Sam Clarke (samclarke.com) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 * SCEditor is licensed under the MIT license: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 * http://www.opensource.org/licenses/mit-license.php |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 * @fileoverview SCEditor BBCode Format |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 * @author Sam Clarke |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 (function (sceditor) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 /*eslint max-depth: off*/ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 'use strict'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 var escapeEntities = sceditor.escapeEntities; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 var escapeUriScheme = sceditor.escapeUriScheme; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 var dom = sceditor.dom; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 var utils = sceditor.utils; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 var css = dom.css; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 var attr = dom.attr; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 var is = dom.is; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 var extend = utils.extend; |
30
db061869f28f
remove sceditor.command, add options.onCreate
Franklin Schmidt <fschmidt@gmail.com>
parents:
27
diff
changeset
|
26 var extendDeep = utils.extendDeep; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 var each = utils.each; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 var EMOTICON_DATA_ATTR = 'data-sceditor-emoticon'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 |
30
db061869f28f
remove sceditor.command, add options.onCreate
Franklin Schmidt <fschmidt@gmail.com>
parents:
27
diff
changeset
|
31 function getEditorCommand(cmd) { |
db061869f28f
remove sceditor.command, add options.onCreate
Franklin Schmidt <fschmidt@gmail.com>
parents:
27
diff
changeset
|
32 return sceditor.commands[cmd]; |
db061869f28f
remove sceditor.command, add options.onCreate
Franklin Schmidt <fschmidt@gmail.com>
parents:
27
diff
changeset
|
33 } |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 var QuoteType = { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
36 /** @lends BBCodeParser.QuoteType */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
37 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 * Always quote the attribute value |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 * @type {Number} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 always: 1, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 * Never quote the attributes value |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 * @type {Number} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
47 never: 2, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
48 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
49 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 * Only quote the attributes value when it contains spaces to equals |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 * @type {Number} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 auto: 3 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
54 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
55 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
56 var defaultCommandsOverrides = { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
57 bold: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
58 txtExec: ['[b]', '[/b]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
59 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
60 italic: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
61 txtExec: ['[i]', '[/i]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
62 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
63 underline: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
64 txtExec: ['[u]', '[/u]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
65 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
66 strike: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
67 txtExec: ['[s]', '[/s]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
68 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
69 subscript: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
70 txtExec: ['[sub]', '[/sub]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
71 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
72 superscript: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
73 txtExec: ['[sup]', '[/sup]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
74 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
75 left: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
76 txtExec: ['[left]', '[/left]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
77 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
78 center: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
79 txtExec: ['[center]', '[/center]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
80 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
81 right: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
82 txtExec: ['[right]', '[/right]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
83 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
84 justify: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
85 txtExec: ['[justify]', '[/justify]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
86 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
87 font: { |
17 | 88 txtExec: function (editor, caller) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
89 getEditorCommand('font')._dropDown( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
90 editor, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
91 caller, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
92 function (fontName) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
93 editor.insertText( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
94 '[font=' + fontName + ']', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
95 '[/font]' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
96 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
97 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
98 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
99 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
100 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
101 size: { |
17 | 102 txtExec: function (editor, caller) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
103 getEditorCommand('size')._dropDown( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
104 editor, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
105 caller, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
106 function (fontSize) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
107 editor.insertText( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
108 '[size=' + fontSize + ']', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
109 '[/size]' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
110 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
111 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
112 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
113 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
114 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
115 color: { |
17 | 116 txtExec: function (editor, caller) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
117 getEditorCommand('color')._dropDown( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
118 editor, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
119 caller, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
120 function (color) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
121 editor.insertText( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
122 '[color=' + color + ']', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
123 '[/color]' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
124 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
125 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
126 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
127 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
128 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
129 bulletlist: { |
17 | 130 txtExec: function (editor, caller, selected) { |
131 editor.insertText( | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
132 '[ul]\n[li]' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
133 selected.split(/\r?\n/).join('[/li]\n[li]') + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
134 '[/li]\n[/ul]' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
135 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
136 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
137 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
138 orderedlist: { |
17 | 139 txtExec: function (editor, caller, selected) { |
140 editor.insertText( | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
141 '[ol]\n[li]' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
142 selected.split(/\r?\n/).join('[/li]\n[li]') + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
143 '[/li]\n[/ol]' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
144 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
145 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
146 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
147 table: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
148 txtExec: ['[table][tr][td]', '[/td][/tr][/table]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
149 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
150 horizontalrule: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
151 txtExec: ['[hr]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
152 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
153 code: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
154 txtExec: ['[code]', '[/code]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
155 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
156 image: { |
17 | 157 txtExec: function (editor, caller, selected) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
158 getEditorCommand('image')._dropDown( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
159 editor, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
160 caller, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
161 selected, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
162 function (url, width, height) { |
35 | 163 if( width || height ) { |
164 editor.insertText( | |
165 '[img=' + width + 'x' + height + ']' + url + '[/img]' | |
166 ); | |
167 } else { | |
168 editor.insertText( | |
169 '[img]' + url + '[/img]' | |
170 ); | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
171 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
172 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
173 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
174 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
175 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
176 email: { |
17 | 177 txtExec: function (editor, caller, selected) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
178 getEditorCommand('email')._dropDown( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
179 editor, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
180 caller, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
181 function (url, text) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
182 editor.insertText( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
183 '[email=' + url + ']' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
184 (text || selected || url) + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
185 '[/email]' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
186 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
187 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
188 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
189 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
190 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
191 link: { |
17 | 192 txtExec: function (editor, caller, selected) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
193 getEditorCommand('link')._dropDown( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
194 editor, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
195 caller, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
196 function (url, text) { |
34 | 197 if(text) { |
198 editor.insertText( | |
199 '[url=' + url + ']' + | |
200 (text || selected) + | |
201 '[/url]' | |
202 ); | |
203 } else { | |
204 editor.insertText( | |
205 '[url]' + | |
206 (selected || url) + | |
207 '[/url]' | |
208 ); | |
209 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
210 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
211 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
212 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
213 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
214 quote: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
215 txtExec: ['[quote]', '[/quote]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
216 }, |
33 | 217 emoticon: { |
218 txtExec: function (editor, caller) { | |
219 editor.commands.emoticon.base(editor, caller, function(target) { | |
220 return '[emoticon]' + target.getAttribute(EMOTICON_DATA_ATTR) + '[/emoticon]'; | |
221 } ); | |
222 }, | |
223 }, | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
224 youtube: { |
17 | 225 txtExec: function (editor, caller) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
226 getEditorCommand('youtube')._dropDown( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
227 editor, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
228 caller, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
229 function (id) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
230 editor.insertText('[youtube]' + id + '[/youtube]'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
231 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
232 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
233 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
234 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
235 rtl: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
236 txtExec: ['[rtl]', '[/rtl]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
237 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
238 ltr: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
239 txtExec: ['[ltr]', '[/ltr]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
240 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
241 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
242 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
243 var bbcodeHandlers = { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
244 // START_COMMAND: Bold |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
245 b: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
246 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
247 b: null, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
248 strong: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
249 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
250 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
251 // 401 is for FF 3.5 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
252 'font-weight': ['bold', 'bolder', '401', '700', '800', '900'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
253 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
254 format: '[b]{0}[/b]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
255 html: '<strong>{0}</strong>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
256 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
257 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
258 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
259 // START_COMMAND: Italic |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
260 i: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
261 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
262 i: null, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
263 em: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
264 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
265 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
266 'font-style': ['italic', 'oblique'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
267 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
268 format: '[i]{0}[/i]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
269 html: '<em>{0}</em>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
270 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
271 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
272 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
273 // START_COMMAND: Underline |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
274 u: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
275 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
276 u: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
277 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
278 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
279 'text-decoration': ['underline'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
280 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
281 format: '[u]{0}[/u]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
282 html: '<u>{0}</u>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
283 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
284 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
285 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
286 // START_COMMAND: Strikethrough |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
287 s: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
288 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
289 s: null, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
290 strike: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
291 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
292 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
293 'text-decoration': ['line-through'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
294 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
295 format: '[s]{0}[/s]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
296 html: '<s>{0}</s>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
297 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
298 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
299 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
300 // START_COMMAND: Subscript |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
301 sub: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
302 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
303 sub: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
304 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
305 format: '[sub]{0}[/sub]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
306 html: '<sub>{0}</sub>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
307 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
308 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
309 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
310 // START_COMMAND: Superscript |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
311 sup: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
312 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
313 sup: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
314 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
315 format: '[sup]{0}[/sup]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
316 html: '<sup>{0}</sup>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
317 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
318 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
319 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
320 // START_COMMAND: Font |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
321 font: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
322 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
323 font: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
324 face: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
325 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
326 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
327 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
328 'font-family': null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
329 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
330 quoteType: QuoteType.never, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
331 format: function (element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
332 var font; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
333 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
334 if (!is(element, 'font') || !(font = attr(element, 'face'))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
335 font = css(element, 'font-family'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
336 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
337 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
338 return '[font=' + _stripQuotes(font) + ']' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
339 content + '[/font]'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
340 }, |
35 | 341 html: '<font face="{attrib}">{0}</font>' |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
342 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
343 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
344 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
345 // START_COMMAND: Size |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
346 size: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
347 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
348 font: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
349 size: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
350 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
351 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
352 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
353 'font-size': null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
354 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
355 format: function (element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
356 var fontSize = attr(element, 'size'), |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
357 size = 2; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
358 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
359 if (!fontSize) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
360 fontSize = css(element, 'fontSize'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
361 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
362 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
363 // Most browsers return px value but IE returns 1-7 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
364 if (fontSize.indexOf('px') > -1) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
365 // convert size to an int |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
366 fontSize = fontSize.replace('px', '') - 0; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
367 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
368 if (fontSize < 12) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
369 size = 1; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
370 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
371 if (fontSize > 15) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
372 size = 3; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
373 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
374 if (fontSize > 17) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
375 size = 4; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
376 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
377 if (fontSize > 23) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
378 size = 5; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
379 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
380 if (fontSize > 31) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
381 size = 6; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
382 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
383 if (fontSize > 47) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
384 size = 7; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
385 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
386 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
387 size = fontSize; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
388 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
389 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
390 return '[size=' + size + ']' + content + '[/size]'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
391 }, |
35 | 392 html: '<font size="{attrib}">{!0}</font>' |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
393 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
394 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
395 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
396 // START_COMMAND: Color |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
397 color: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
398 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
399 font: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
400 color: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
401 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
402 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
403 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
404 color: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
405 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
406 quoteType: QuoteType.never, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
407 format: function (elm, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
408 var color; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
409 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
410 if (!is(elm, 'font') || !(color = attr(elm, 'color'))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
411 color = elm.style.color || css(elm, 'color'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
412 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
413 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
414 return '[color=' + _normaliseColour(color) + ']' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
415 content + '[/color]'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
416 }, |
35 | 417 html: function (token, attrib, content) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
418 return '<font color="' + |
35 | 419 escapeEntities(_normaliseColour(attrib), true) + |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
420 '">' + content + '</font>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
421 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
422 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
423 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
424 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
425 // START_COMMAND: Lists |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
426 ul: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
427 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
428 ul: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
429 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
430 breakStart: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
431 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
432 skipLastLineBreak: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
433 format: '[ul]{0}[/ul]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
434 html: '<ul>{0}</ul>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
435 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
436 list: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
437 breakStart: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
438 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
439 skipLastLineBreak: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
440 html: '<ul>{0}</ul>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
441 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
442 ol: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
443 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
444 ol: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
445 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
446 breakStart: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
447 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
448 skipLastLineBreak: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
449 format: '[ol]{0}[/ol]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
450 html: '<ol>{0}</ol>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
451 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
452 li: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
453 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
454 li: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
455 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
456 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
457 closedBy: ['/ul', '/ol', '/list', '*', 'li'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
458 format: '[li]{0}[/li]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
459 html: '<li>{0}</li>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
460 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
461 '*': { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
462 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
463 closedBy: ['/ul', '/ol', '/list', '*', 'li'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
464 html: '<li>{0}</li>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
465 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
466 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
467 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
468 // START_COMMAND: Table |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
469 table: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
470 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
471 table: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
472 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
473 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
474 isHtmlInline: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
475 skipLastLineBreak: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
476 format: '[table]{0}[/table]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
477 html: '<table>{0}</table>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
478 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
479 tr: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
480 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
481 tr: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
482 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
483 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
484 skipLastLineBreak: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
485 format: '[tr]{0}[/tr]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
486 html: '<tr>{0}</tr>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
487 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
488 th: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
489 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
490 th: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
491 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
492 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
493 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
494 format: '[th]{0}[/th]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
495 html: '<th>{0}</th>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
496 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
497 td: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
498 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
499 td: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
500 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
501 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
502 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
503 format: '[td]{0}[/td]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
504 html: '<td>{0}</td>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
505 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
506 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
507 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
508 // START_COMMAND: Emoticons |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
509 emoticon: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
510 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
511 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
512 img: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
513 src: null, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
514 'data-sceditor-emoticon': null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
515 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
516 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
517 format: function (element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
518 return attr(element, EMOTICON_DATA_ATTR) + content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
519 }, |
35 | 520 html: function (token, attrib, content, editor) { |
33 | 521 return editor.allEmoticons[content] || token.val + content + token.closing.val; |
522 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
523 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
524 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
525 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
526 // START_COMMAND: Horizontal Rule |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
527 hr: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
528 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
529 hr: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
530 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
531 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
532 isSelfClosing: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
533 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
534 format: '[hr]{0}', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
535 html: '<hr />' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
536 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
537 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
538 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
539 // START_COMMAND: Image |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
540 img: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
541 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
542 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
543 img: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
544 src: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
545 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
546 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
547 allowedChildren: ['#'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
548 quoteType: QuoteType.never, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
549 format: function (element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
550 var width, height, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
551 attribs = '', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
552 style = function (name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
553 return element.style ? element.style[name] : null; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
554 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
555 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
556 // check if this is an emoticon image |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
557 if (attr(element, EMOTICON_DATA_ATTR)) { |
33 | 558 return '[emoticon]' + content + '[/emoticon]'; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
559 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
560 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
561 width = attr(element, 'width') || style('width'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
562 height = attr(element, 'height') || style('height'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
563 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
564 // only add width and height if one is specified |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
565 if ((element.complete && (width || height)) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
566 (width && height)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
567 |
35 | 568 attribs = '=' + width + 'x' + |
569 height; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
570 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
571 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
572 return '[img' + attribs + ']' + attr(element, 'src') + '[/img]'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
573 }, |
35 | 574 html: function (token, attrib, content) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
575 var undef, width, height, match, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
576 attribs = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
577 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
578 // handle [img=340x240]url[/img] |
35 | 579 if (attrib) { |
580 match = attrib.split(/x/i); | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
581 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
582 width = match[0]; |
35 | 583 height = match[1]; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
584 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
585 |
35 | 586 if (width) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
587 attribs += ' width="' + escapeEntities(width, true) + '"'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
588 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
589 |
35 | 590 if (height) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
591 attribs += ' height="' + escapeEntities(height, true) + '"'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
592 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
593 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
594 return '<img' + attribs + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
595 ' src="' + escapeUriScheme(content) + '" />'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
596 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
597 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
598 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
599 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
600 // START_COMMAND: URL |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
601 url: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
602 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
603 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
604 a: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
605 href: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
606 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
607 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
608 quoteType: QuoteType.never, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
609 format: function (element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
610 var url = attr(element, 'href'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
611 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
612 // make sure this link is not an e-mail, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
613 // if it is return e-mail BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
614 if (url.substr(0, 7) === 'mailto:') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
615 return '[email="' + url.substr(7) + '"]' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
616 content + '[/email]'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
617 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
618 |
34 | 619 if( url === content ) { |
620 return '[url]' + content + '[/url]'; | |
621 } else { | |
622 return '[url=' + url + ']' + content + '[/url]'; | |
623 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
624 }, |
35 | 625 html: function (token, attrib, content) { |
626 attrib = | |
627 escapeEntities(attrib, true) || content; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
628 |
35 | 629 return '<a href="' + escapeUriScheme(attrib) + '">' + |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
630 content + '</a>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
631 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
632 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
633 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
634 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
635 // START_COMMAND: E-mail |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
636 email: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
637 quoteType: QuoteType.never, |
35 | 638 html: function (token, attrib, content) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
639 return '<a href="mailto:' + |
35 | 640 (escapeEntities(attrib, true) || content) + |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
641 '">' + content + '</a>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
642 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
643 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
644 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
645 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
646 // START_COMMAND: Quote |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
647 quote: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
648 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
649 blockquote: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
650 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
651 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
652 quoteType: QuoteType.never, |
26 | 653 format: function (element, content, bbcodeFormat) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
654 var authorAttr = 'data-author'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
655 var author = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
656 var cite; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
657 var children = element.children; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
658 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
659 for (var i = 0; !cite && i < children.length; i++) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
660 if (is(children[i], 'cite')) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
661 cite = children[i]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
662 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
663 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
664 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
665 if (cite || attr(element, authorAttr)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
666 author = cite && cite.textContent || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
667 attr(element, authorAttr); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
668 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
669 attr(element, authorAttr, author); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
670 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
671 if (cite) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
672 element.removeChild(cite); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
673 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
674 |
26 | 675 content = bbcodeFormat.elementToBbcode(element); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
676 author = '=' + author.replace(/(^\s+|\s+$)/g, ''); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
677 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
678 if (cite) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
679 element.insertBefore(cite, element.firstChild); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
680 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
681 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
682 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
683 return '[quote' + author + ']' + content + '[/quote]'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
684 }, |
35 | 685 html: function (token, attrib, content) { |
686 if (attrib) { | |
687 content = '<cite>' + escapeEntities(attrib) + | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
688 '</cite>' + content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
689 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
690 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
691 return '<blockquote>' + content + '</blockquote>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
692 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
693 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
694 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
695 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
696 // START_COMMAND: Code |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
697 code: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
698 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
699 code: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
700 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
701 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
702 allowedChildren: ['#', '#newline'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
703 format: '[code]{0}[/code]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
704 html: '<code>{0}</code>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
705 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
706 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
707 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
708 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
709 // START_COMMAND: Left |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
710 left: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
711 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
712 'text-align': [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
713 'left', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
714 '-webkit-left', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
715 '-moz-left', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
716 '-khtml-left' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
717 ] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
718 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
719 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
720 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
721 format: '[left]{0}[/left]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
722 html: '<div align="left">{0}</div>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
723 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
724 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
725 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
726 // START_COMMAND: Centre |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
727 center: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
728 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
729 'text-align': [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
730 'center', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
731 '-webkit-center', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
732 '-moz-center', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
733 '-khtml-center' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
734 ] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
735 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
736 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
737 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
738 format: '[center]{0}[/center]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
739 html: '<div align="center">{0}</div>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
740 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
741 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
742 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
743 // START_COMMAND: Right |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
744 right: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
745 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
746 'text-align': [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
747 'right', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
748 '-webkit-right', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
749 '-moz-right', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
750 '-khtml-right' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
751 ] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
752 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
753 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
754 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
755 format: '[right]{0}[/right]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
756 html: '<div align="right">{0}</div>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
757 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
758 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
759 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
760 // START_COMMAND: Justify |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
761 justify: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
762 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
763 'text-align': [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
764 'justify', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
765 '-webkit-justify', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
766 '-moz-justify', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
767 '-khtml-justify' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
768 ] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
769 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
770 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
771 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
772 format: '[justify]{0}[/justify]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
773 html: '<div align="justify">{0}</div>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
774 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
775 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
776 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
777 // START_COMMAND: YouTube |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
778 youtube: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
779 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
780 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
781 iframe: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
782 'data-youtube-id': null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
783 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
784 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
785 format: function (element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
786 element = attr(element, 'data-youtube-id'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
787 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
788 return element ? '[youtube]' + element + '[/youtube]' : content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
789 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
790 html: '<iframe width="560" height="315" frameborder="0" ' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
791 'src="https://www.youtube-nocookie.com/embed/{0}?wmode=opaque" ' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
792 'data-youtube-id="{0}" allowfullscreen></iframe>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
793 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
794 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
795 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
796 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
797 // START_COMMAND: Rtl |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
798 rtl: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
799 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
800 direction: ['rtl'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
801 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
802 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
803 format: '[rtl]{0}[/rtl]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
804 html: '<div style="direction: rtl">{0}</div>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
805 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
806 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
807 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
808 // START_COMMAND: Ltr |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
809 ltr: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
810 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
811 direction: ['ltr'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
812 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
813 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
814 format: '[ltr]{0}[/ltr]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
815 html: '<div style="direction: ltr">{0}</div>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
816 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
817 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
818 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
819 // this is here so that commands above can be removed |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
820 // without having to remove the , after the last one. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
821 // Needed for IE. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
822 ignore: {} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
823 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
824 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
825 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
826 * Formats a string replacing {name} with the values of |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
827 * obj.name properties. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
828 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
829 * If there is no property for the specified {name} then |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
830 * it will be left intact. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
831 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
832 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
833 * @param {Object} obj |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
834 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
835 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
836 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
837 function formatBBCodeString(str, obj) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
838 return str.replace(/\{([^}]+)\}/g, function (match, group) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
839 var undef, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
840 escape = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
841 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
842 if (group.charAt(0) === '!') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
843 escape = false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
844 group = group.substring(1); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
845 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
846 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
847 if (group === '0') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
848 escape = false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
849 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
850 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
851 if (obj[group] === undef) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
852 return match; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
853 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
854 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
855 return escape ? escapeEntities(obj[group], true) : obj[group]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
856 }); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
857 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
858 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
859 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
860 * Removes the first and last divs from the HTML. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
861 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
862 * This is needed for pasting |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
863 * @param {string} html |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
864 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
865 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
866 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
867 function removeFirstLastDiv(html) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
868 var node, next, removeDiv, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
869 output = document.createElement('div'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
870 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
871 removeDiv = function (node, isFirst) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
872 // Don't remove divs that have styling |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
873 if (dom.hasStyling(node)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
874 return; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
875 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
876 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
877 if ((node.childNodes.length !== 1 || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
878 !is(node.firstChild, 'br'))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
879 while ((next = node.firstChild)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
880 output.insertBefore(next, node); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
881 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
882 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
883 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
884 if (isFirst) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
885 var lastChild = output.lastChild; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
886 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
887 if (node !== lastChild && is(lastChild, 'div') && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
888 node.nextSibling === lastChild) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
889 output.insertBefore(document.createElement('br'), node); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
890 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
891 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
892 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
893 output.removeChild(node); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
894 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
895 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
896 css(output, 'display', 'none'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
897 output.innerHTML = html.replace(/<\/div>\n/g, '</div>'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
898 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
899 if ((node = output.firstChild) && is(node, 'div')) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
900 removeDiv(node, true); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
901 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
902 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
903 if ((node = output.lastChild) && is(node, 'div')) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
904 removeDiv(node); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
905 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
906 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
907 return output.innerHTML; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
908 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
909 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
910 function isFunction(fn) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
911 return typeof fn === 'function'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
912 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
913 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
914 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
915 * Removes any leading or trailing quotes ('") |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
916 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
917 * @return string |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
918 * @since v1.4.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
919 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
920 function _stripQuotes(str) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
921 return str ? |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
922 str.replace(/\\(.)/g, '$1').replace(/^(["'])(.*?)\1$/, '$2') : str; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
923 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
924 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
925 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
926 * Formats a string replacing {0}, {1}, {2}, ect. with |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
927 * the params provided |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
928 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
929 * @param {string} str The string to format |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
930 * @param {...string} arg The strings to replace |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
931 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
932 * @since v1.4.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
933 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
934 function _formatString(str) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
935 var undef; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
936 var args = arguments; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
937 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
938 return str.replace(/\{(\d+)\}/g, function (_, matchNum) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
939 return args[matchNum - 0 + 1] !== undef ? |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
940 args[matchNum - 0 + 1] : |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
941 '{' + matchNum + '}'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
942 }); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
943 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
944 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
945 var TOKEN_OPEN = 'open'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
946 var TOKEN_CONTENT = 'content'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
947 var TOKEN_NEWLINE = 'newline'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
948 var TOKEN_CLOSE = 'close'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
949 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
950 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
951 /* |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
952 * @typedef {Object} TokenizeToken |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
953 * @property {string} type |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
954 * @property {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
955 * @property {string} val |
35 | 956 * @property {string} attrib |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
957 * @property {array} children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
958 * @property {TokenizeToken} closing |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
959 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
960 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
961 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
962 * Tokenize token object |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
963 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
964 * @param {string} type The type of token this is, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
965 * should be one of tokenType |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
966 * @param {string} name The name of this token |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
967 * @param {string} val The originally matched string |
35 | 968 * @param {string} attrib Any attributes. Only set on |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
969 * TOKEN_TYPE_OPEN tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
970 * @param {array} children Any children of this token |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
971 * @param {TokenizeToken} closing This tokens closing tag. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
972 * Only set on TOKEN_TYPE_OPEN tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
973 * @name {TokenizeToken} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
974 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
975 // eslint-disable-next-line max-params |
36
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
976 function newTokenizeToken(type, name, val, attrib, children, closing) { |
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
977 let base = {}; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
978 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
979 base.type = type; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
980 base.name = name; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
981 base.val = val; |
35 | 982 base.attrib = attrib; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
983 base.children = children || []; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
984 base.closing = closing || null; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
985 |
36
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
986 base.clone = function () { |
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
987 return newTokenizeToken( |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
988 base.type, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
989 base.name, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
990 base.val, |
35 | 991 base.attrib, |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
992 [], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
993 base.closing ? base.closing.clone() : null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
994 ); |
36
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
995 }; |
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
996 |
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
997 base.splitAt = function (splitAt) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
998 var clone = base.clone(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
999 var offset = base.children.indexOf(splitAt); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1000 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1001 if (offset > -1) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1002 // Work out how many items are on the right side of the split |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1003 // to pass to splice() |
36
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
1004 let offsetLength = base.children.length - offset; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1005 clone.children = base.children.splice(offset, offsetLength); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1006 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1007 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1008 return clone; |
36
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
1009 }; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1010 |
36
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
1011 return base; |
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
1012 } |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1013 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1014 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1015 * SCEditor BBCode parser class |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1016 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1017 * @param {Object} options |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1018 * @class BBCodeParser |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1019 * @name BBCodeParser |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1020 * @since v1.4.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1021 */ |
33 | 1022 function newBBCodeParser(editor) { |
25 | 1023 var base = {}; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1024 |
33 | 1025 base.opts = extend({}, BBCodeParser.defaults, editor.opts.parserOptions); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1026 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1027 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1028 * Takes a BBCode string and splits it into open, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1029 * content and close tags. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1030 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1031 * It does no checking to verify a tag has a matching open |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1032 * or closing tag or if the tag is valid child of any tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1033 * before it. For that the tokens should be passed to the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1034 * parse function. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1035 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1036 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1037 * @return {array} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1038 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1039 base.tokenize = function (str) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1040 var matches, type, i; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1041 var tokens = []; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1042 // The token types in reverse order of precedence |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1043 // (they're looped in reverse) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1044 var tokenTypes = [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1045 { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1046 type: TOKEN_CONTENT, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1047 regex: /^([^\[\r\n]+|\[)/ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1048 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1049 { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1050 type: TOKEN_NEWLINE, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1051 regex: /^(\r\n|\r|\n)/ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1052 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1053 { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1054 type: TOKEN_OPEN, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1055 regex: /^\[[^\[\]]+\]/ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1056 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1057 // Close must come before open as they are |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1058 // the same except close has a / at the start. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1059 { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1060 type: TOKEN_CLOSE, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1061 regex: /^\[\/[^\[\]]+\]/ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1062 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1063 ]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1064 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1065 strloop: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1066 while (str.length) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1067 i = tokenTypes.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1068 while (i--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1069 type = tokenTypes[i].type; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1070 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1071 // Check if the string matches any of the tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1072 if (!(matches = str.match(tokenTypes[i].regex)) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1073 !matches[0]) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1074 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1075 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1076 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1077 // Add the match to the tokens list |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1078 tokens.push(tokenizeTag(type, matches[0])); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1079 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1080 // Remove the match from the string |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1081 str = str.substr(matches[0].length); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1082 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1083 // The token has been added so start again |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1084 continue strloop; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1085 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1086 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1087 // If there is anything left in the string which doesn't match |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1088 // any of the tokens then just assume it's content and add it. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1089 if (str.length) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1090 tokens.push(tokenizeTag(TOKEN_CONTENT, str)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1091 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1092 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1093 str = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1094 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1095 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1096 return tokens; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1097 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1098 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1099 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1100 * Extracts the name an params from a tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1101 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1102 * @param {string} type |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1103 * @param {string} val |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1104 * @return {Object} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1105 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1106 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1107 function tokenizeTag(type, val) { |
35 | 1108 var matches, attrib, name, |
1109 openRegex = /\[([^\]\s=]+)(?:=([^\]]+))?\]/, | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1110 closeRegex = /\[\/([^\[\]]+)\]/; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1111 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1112 // Extract the name and attributes from opening tags and |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1113 // just the name from closing tags. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1114 if (type === TOKEN_OPEN && (matches = val.match(openRegex))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1115 name = lower(matches[1]); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1116 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1117 if (matches[2] && (matches[2] = matches[2].trim())) { |
35 | 1118 attrib = _stripQuotes(matches[2]); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1119 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1120 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1121 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1122 if (type === TOKEN_CLOSE && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1123 (matches = val.match(closeRegex))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1124 name = lower(matches[1]); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1125 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1126 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1127 if (type === TOKEN_NEWLINE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1128 name = '#newline'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1129 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1130 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1131 // Treat all tokens without a name and |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1132 // all unknown BBCodes as content |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1133 if (!name || ((type === TOKEN_OPEN || type === TOKEN_CLOSE) && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1134 !bbcodeHandlers[name])) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1135 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1136 type = TOKEN_CONTENT; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1137 name = '#'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1138 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1139 |
36
21090996a131
clean up TokenizeToken
Franklin Schmidt <fschmidt@gmail.com>
parents:
35
diff
changeset
|
1140 return newTokenizeToken(type, name, val, attrib); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1141 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1142 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1143 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1144 * Parses a string into an array of BBCodes |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1145 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1146 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1147 * @param {boolean} preserveNewLines If to preserve all new lines, not |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1148 * strip any based on the passed |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1149 * formatting options |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1150 * @return {array} Array of BBCode objects |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1151 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1152 base.parse = function (str, preserveNewLines) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1153 var ret = parseTokens(base.tokenize(str)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1154 var opts = base.opts; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1155 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1156 if (opts.fixInvalidNesting) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1157 fixNesting(ret); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1158 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1159 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1160 normaliseNewLines(ret, null, preserveNewLines); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1161 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1162 if (opts.removeEmptyTags) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1163 removeEmpty(ret); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1164 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1165 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1166 return ret; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1167 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1168 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1169 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1170 * Checks if an array of TokenizeToken's contains the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1171 * specified token. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1172 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1173 * Checks the tokens name and type match another tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1174 * name and type in the array. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1175 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1176 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1177 * @param {string} type |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1178 * @param {array} arr |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1179 * @return {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1180 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1181 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1182 function hasTag(name, type, arr) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1183 var i = arr.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1184 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1185 while (i--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1186 if (arr[i].type === type && arr[i].name === name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1187 return true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1188 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1189 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1190 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1191 return false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1192 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1193 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1194 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1195 * Checks if the child tag is allowed as one |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1196 * of the parent tags children. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1197 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1198 * @param {TokenizeToken} parent |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1199 * @param {TokenizeToken} child |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1200 * @return {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1201 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1202 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1203 function isChildAllowed(parent, child) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1204 var parentBBCode = parent ? bbcodeHandlers[parent.name] : {}, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1205 allowedChildren = parentBBCode.allowedChildren; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1206 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1207 if (base.opts.fixInvalidChildren && allowedChildren) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1208 return allowedChildren.indexOf(child.name || '#') > -1; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1209 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1210 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1211 return true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1212 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1213 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1214 // TODO: Tidy this parseTokens() function up a bit. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1215 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1216 * Parses an array of tokens created by tokenize() |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1217 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1218 * @param {array} toks |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1219 * @return {array} Parsed tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1220 * @see tokenize() |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1221 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1222 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1223 function parseTokens(toks) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1224 var token, bbcode, curTok, clone, i, next, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1225 cloned = [], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1226 output = [], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1227 openTags = [], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1228 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1229 * Returns the currently open tag or undefined |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1230 * @return {TokenizeToken} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1231 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1232 currentTag = function () { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1233 return last(openTags); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1234 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1235 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1236 * Adds a tag to either the current tags children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1237 * or to the output array. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1238 * @param {TokenizeToken} token |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1239 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1240 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1241 addTag = function (token) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1242 if (currentTag()) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1243 currentTag().children.push(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1244 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1245 output.push(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1246 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1247 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1248 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1249 * Checks if this tag closes the current tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1250 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1251 * @return {Void} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1252 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1253 closesCurrentTag = function (name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1254 return currentTag() && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1255 (bbcode = bbcodeHandlers[currentTag().name]) && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1256 bbcode.closedBy && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1257 bbcode.closedBy.indexOf(name) > -1; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1258 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1259 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1260 while ((token = toks.shift())) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1261 next = toks[0]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1262 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1263 /* |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1264 * Fixes any invalid children. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1265 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1266 * If it is an element which isn't allowed as a child of it's |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1267 * parent then it will be converted to content of the parent |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1268 * element. i.e. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1269 * [code]Code [b]only[/b] allows text.[/code] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1270 * Will become: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1271 * <code>Code [b]only[/b] allows text.</code> |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1272 * Instead of: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1273 * <code>Code <b>only</b> allows text.</code> |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1274 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1275 // Ignore tags that can't be children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1276 if (!isChildAllowed(currentTag(), token)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1277 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1278 // exclude closing tags of current tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1279 if (token.type !== TOKEN_CLOSE || !currentTag() || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1280 token.name !== currentTag().name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1281 token.name = '#'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1282 token.type = TOKEN_CONTENT; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1283 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1284 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1285 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1286 switch (token.type) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1287 case TOKEN_OPEN: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1288 // Check it this closes a parent, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1289 // e.g. for lists [*]one [*]two |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1290 if (closesCurrentTag(token.name)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1291 openTags.pop(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1292 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1293 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1294 addTag(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1295 bbcode = bbcodeHandlers[token.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1296 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1297 // If this tag is not self closing and it has a closing |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1298 // tag then it is open and has children so add it to the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1299 // list of open tags. If has the closedBy property then |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1300 // it is closed by other tags so include everything as |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1301 // it's children until one of those tags is reached. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1302 if (bbcode && !bbcode.isSelfClosing && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1303 (bbcode.closedBy || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1304 hasTag(token.name, TOKEN_CLOSE, toks))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1305 openTags.push(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1306 } else if (!bbcode || !bbcode.isSelfClosing) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1307 token.type = TOKEN_CONTENT; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1308 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1309 break; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1310 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1311 case TOKEN_CLOSE: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1312 // check if this closes the current tag, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1313 // e.g. [/list] would close an open [*] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1314 if (currentTag() && token.name !== currentTag().name && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1315 closesCurrentTag('/' + token.name)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1316 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1317 openTags.pop(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1318 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1319 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1320 // If this is closing the currently open tag just pop |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1321 // the close tag off the open tags array |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1322 if (currentTag() && token.name === currentTag().name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1323 currentTag().closing = token; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1324 openTags.pop(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1325 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1326 // If this is closing an open tag that is the parent of |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1327 // the current tag then clone all the tags including the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1328 // current one until reaching the parent that is being |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1329 // closed. Close the parent and then add the clones back |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1330 // in. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1331 } else if (hasTag(token.name, TOKEN_OPEN, openTags)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1332 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1333 // Remove the tag from the open tags |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1334 while ((curTok = openTags.pop())) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1335 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1336 // If it's the tag that is being closed then |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1337 // discard it and break the loop. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1338 if (curTok.name === token.name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1339 curTok.closing = token; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1340 break; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1341 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1342 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1343 // Otherwise clone this tag and then add any |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1344 // previously cloned tags as it's children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1345 clone = curTok.clone(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1346 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1347 if (cloned.length) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1348 clone.children.push(last(cloned)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1349 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1350 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1351 cloned.push(clone); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1352 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1353 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1354 // Place block linebreak before cloned tags |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1355 if (next && next.type === TOKEN_NEWLINE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1356 bbcode = bbcodeHandlers[token.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1357 if (bbcode && bbcode.isInline === false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1358 addTag(next); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1359 toks.shift(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1360 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1361 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1362 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1363 // Add the last cloned child to the now current tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1364 // (the parent of the tag which was being closed) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1365 addTag(last(cloned)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1366 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1367 // Add all the cloned tags to the open tags list |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1368 i = cloned.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1369 while (i--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1370 openTags.push(cloned[i]); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1371 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1372 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1373 cloned.length = 0; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1374 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1375 // This tag is closing nothing so treat it as content |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1376 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1377 token.type = TOKEN_CONTENT; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1378 addTag(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1379 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1380 break; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1381 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1382 case TOKEN_NEWLINE: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1383 // handle things like |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1384 // [*]list\nitem\n[*]list1 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1385 // where it should come out as |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1386 // [*]list\nitem[/*]\n[*]list1[/*] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1387 // instead of |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1388 // [*]list\nitem\n[/*][*]list1[/*] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1389 if (currentTag() && next && closesCurrentTag( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1390 (next.type === TOKEN_CLOSE ? '/' : '') + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1391 next.name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1392 )) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1393 // skip if the next tag is the closing tag for |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1394 // the option tag, i.e. [/*] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1395 if (!(next.type === TOKEN_CLOSE && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1396 next.name === currentTag().name)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1397 bbcode = bbcodeHandlers[currentTag().name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1398 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1399 if (bbcode && bbcode.breakAfter) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1400 openTags.pop(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1401 } else if (bbcode && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1402 bbcode.isInline === false && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1403 base.opts.breakAfterBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1404 bbcode.breakAfter !== false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1405 openTags.pop(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1406 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1407 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1408 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1409 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1410 addTag(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1411 break; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1412 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1413 default: // content |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1414 addTag(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1415 break; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1416 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1417 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1418 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1419 return output; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1420 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1421 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1422 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1423 * Normalise all new lines |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1424 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1425 * Removes any formatting new lines from the BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1426 * leaving only content ones. I.e. for a list: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1427 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1428 * [list] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1429 * [*] list item one |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1430 * with a line break |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1431 * [*] list item two |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1432 * [/list] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1433 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1434 * would become |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1435 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1436 * [list] [*] list item one |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1437 * with a line break [*] list item two [/list] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1438 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1439 * Which makes it easier to convert to HTML or add |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1440 * the formatting new lines back in when converting |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1441 * back to BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1442 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1443 * @param {array} children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1444 * @param {TokenizeToken} parent |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1445 * @param {boolean} onlyRemoveBreakAfter |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1446 * @return {void} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1447 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1448 function normaliseNewLines(children, parent, onlyRemoveBreakAfter) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1449 var token, left, right, parentBBCode, bbcode, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1450 removedBreakEnd, removedBreakBefore, remove; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1451 var childrenLength = children.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1452 // TODO: this function really needs tidying up |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1453 if (parent) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1454 parentBBCode = bbcodeHandlers[parent.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1455 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1456 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1457 var i = childrenLength; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1458 while (i--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1459 if (!(token = children[i])) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1460 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1461 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1462 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1463 if (token.type === TOKEN_NEWLINE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1464 left = i > 0 ? children[i - 1] : null; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1465 right = i < childrenLength - 1 ? children[i + 1] : null; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1466 remove = false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1467 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1468 // Handle the start and end new lines |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1469 // e.g. [tag]\n and \n[/tag] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1470 if (!onlyRemoveBreakAfter && parentBBCode && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1471 parentBBCode.isSelfClosing !== true) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1472 // First child of parent so must be opening line break |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1473 // (breakStartBlock, breakStart) e.g. [tag]\n |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1474 if (!left) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1475 if (parentBBCode.isInline === false && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1476 base.opts.breakStartBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1477 parentBBCode.breakStart !== false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1478 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1479 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1480 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1481 if (parentBBCode.breakStart) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1482 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1483 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1484 // Last child of parent so must be end line break |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1485 // (breakEndBlock, breakEnd) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1486 // e.g. \n[/tag] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1487 // remove last line break (breakEndBlock, breakEnd) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1488 } else if (!removedBreakEnd && !right) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1489 if (parentBBCode.isInline === false && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1490 base.opts.breakEndBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1491 parentBBCode.breakEnd !== false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1492 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1493 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1494 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1495 if (parentBBCode.breakEnd) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1496 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1497 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1498 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1499 removedBreakEnd = remove; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1500 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1501 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1502 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1503 if (left && left.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1504 if ((bbcode = bbcodeHandlers[left.name])) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1505 if (!onlyRemoveBreakAfter) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1506 if (bbcode.isInline === false && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1507 base.opts.breakAfterBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1508 bbcode.breakAfter !== false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1509 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1510 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1511 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1512 if (bbcode.breakAfter) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1513 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1514 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1515 } else if (bbcode.isInline === false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1516 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1517 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1518 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1519 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1520 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1521 if (!onlyRemoveBreakAfter && !removedBreakBefore && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1522 right && right.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1523 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1524 if ((bbcode = bbcodeHandlers[right.name])) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1525 if (bbcode.isInline === false && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1526 base.opts.breakBeforeBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1527 bbcode.breakBefore !== false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1528 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1529 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1530 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1531 if (bbcode.breakBefore) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1532 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1533 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1534 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1535 removedBreakBefore = remove; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1536 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1537 if (remove) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1538 children.splice(i, 1); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1539 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1540 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1541 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1542 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1543 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1544 if (remove) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1545 children.splice(i, 1); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1546 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1547 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1548 // reset double removedBreakBefore removal protection. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1549 // This is needed for cases like \n\n[\tag] where |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1550 // only 1 \n should be removed but without this they both |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1551 // would be. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1552 removedBreakBefore = false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1553 } else if (token.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1554 normaliseNewLines(token.children, token, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1555 onlyRemoveBreakAfter); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1556 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1557 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1558 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1559 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1560 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1561 * Fixes any invalid nesting. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1562 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1563 * If it is a block level element inside 1 or more inline elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1564 * then those inline elements will be split at the point where the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1565 * block level is and the block level element placed between the split |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1566 * parts. i.e. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1567 * [inline]A[blocklevel]B[/blocklevel]C[/inline] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1568 * Will become: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1569 * [inline]A[/inline][blocklevel]B[/blocklevel][inline]C[/inline] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1570 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1571 * @param {array} children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1572 * @param {array} [parents] Null if there is no parents |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1573 * @param {boolea} [insideInline] If inside an inline element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1574 * @param {array} [rootArr] Root array if there is one |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1575 * @return {array} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1576 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1577 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1578 function fixNesting(children, parents, insideInline, rootArr) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1579 var token, i, parent, parentIndex, parentParentChildren, right; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1580 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1581 var isInline = function (token) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1582 var bbcode = bbcodeHandlers[token.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1583 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1584 return !bbcode || bbcode.isInline !== false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1585 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1586 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1587 parents = parents || []; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1588 rootArr = rootArr || children; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1589 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1590 // This must check the length each time as it can change when |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1591 // tokens are moved to fix the nesting. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1592 for (i = 0; i < children.length; i++) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1593 if (!(token = children[i]) || token.type !== TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1594 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1595 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1596 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1597 if (insideInline && !isInline(token)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1598 // if this is a blocklevel element inside an inline one then |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1599 // split the parent at the block level element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1600 parent = last(parents); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1601 right = parent.splitAt(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1602 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1603 parentParentChildren = parents.length > 1 ? |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1604 parents[parents.length - 2].children : rootArr; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1605 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1606 // If parent inline is allowed inside this tag, clone it and |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1607 // wrap this tags children in it. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1608 if (isChildAllowed(token, parent)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1609 var clone = parent.clone(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1610 clone.children = token.children; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1611 token.children = [clone]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1612 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1613 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1614 parentIndex = parentParentChildren.indexOf(parent); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1615 if (parentIndex > -1) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1616 // remove the block level token from the right side of |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1617 // the split inline element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1618 right.children.splice(0, 1); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1619 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1620 // insert the block level token and the right side after |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1621 // the left side of the inline token |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1622 parentParentChildren.splice( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1623 parentIndex + 1, 0, token, right |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1624 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1625 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1626 // If token is a block and is followed by a newline, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1627 // then move the newline along with it to the new parent |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1628 var next = right.children[0]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1629 if (next && next.type === TOKEN_NEWLINE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1630 if (!isInline(token)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1631 right.children.splice(0, 1); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1632 parentParentChildren.splice( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1633 parentIndex + 2, 0, next |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1634 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1635 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1636 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1637 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1638 // return to parents loop as the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1639 // children have now increased |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1640 return; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1641 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1642 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1643 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1644 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1645 parents.push(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1646 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1647 fixNesting( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1648 token.children, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1649 parents, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1650 insideInline || isInline(token), |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1651 rootArr |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1652 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1653 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1654 parents.pop(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1655 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1656 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1657 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1658 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1659 * Removes any empty BBCodes which are not allowed to be empty. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1660 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1661 * @param {array} tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1662 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1663 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1664 function removeEmpty(tokens) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1665 var token, bbcode; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1666 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1667 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1668 * Checks if all children are whitespace or not |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1669 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1670 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1671 var isTokenWhiteSpace = function (children) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1672 var j = children.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1673 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1674 while (j--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1675 var type = children[j].type; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1676 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1677 if (type === TOKEN_OPEN || type === TOKEN_CLOSE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1678 return false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1679 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1680 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1681 if (type === TOKEN_CONTENT && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1682 /\S|\u00A0/.test(children[j].val)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1683 return false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1684 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1685 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1686 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1687 return true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1688 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1689 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1690 var i = tokens.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1691 while (i--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1692 // So skip anything that isn't a tag since only tags can be |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1693 // empty, content can't |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1694 if (!(token = tokens[i]) || token.type !== TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1695 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1696 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1697 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1698 bbcode = bbcodeHandlers[token.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1699 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1700 // Remove any empty children of this tag first so that if they |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1701 // are all removed this one doesn't think it's not empty. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1702 removeEmpty(token.children); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1703 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1704 if (isTokenWhiteSpace(token.children) && bbcode && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1705 !bbcode.isSelfClosing && !bbcode.allowsEmpty) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1706 tokens.splice.apply(tokens, [i, 1].concat(token.children)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1707 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1708 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1709 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1710 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1711 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1712 * Converts a BBCode string to HTML |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1713 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1714 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1715 * @param {boolean} preserveNewLines If to preserve all new lines, not |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1716 * strip any based on the passed |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1717 * formatting options |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1718 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1719 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1720 base.toHTML = function (str, preserveNewLines) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1721 return convertToHTML(base.parse(str, preserveNewLines), true); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1722 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1723 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1724 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1725 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1726 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1727 function convertToHTML(tokens, isRoot) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1728 var undef, token, bbcode, content, html, needsBlockWrap, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1729 blockWrapOpen, isInline, lastChild, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1730 ret = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1731 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1732 isInline = function (bbcode) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1733 return (!bbcode || (bbcode.isHtmlInline !== undef ? |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1734 bbcode.isHtmlInline : bbcode.isInline)) !== false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1735 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1736 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1737 while (tokens.length > 0) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1738 if (!(token = tokens.shift())) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1739 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1740 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1741 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1742 if (token.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1743 lastChild = token.children[token.children.length - 1] || {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1744 bbcode = bbcodeHandlers[token.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1745 needsBlockWrap = isRoot && isInline(bbcode); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1746 content = convertToHTML(token.children, false); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1747 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1748 if (bbcode && bbcode.html) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1749 // Only add a line break to the end if this is |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1750 // blocklevel and the last child wasn't block-level |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1751 if (!isInline(bbcode) && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1752 isInline(bbcodeHandlers[lastChild.name]) && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1753 !bbcode.isPreFormatted && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1754 !bbcode.skipLastLineBreak) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1755 // Add placeholder br to end of block level |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1756 // elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1757 content += '<br />'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1758 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1759 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1760 if (!isFunction(bbcode.html)) { |
35 | 1761 token['0'] = content; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1762 html = formatBBCodeString( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1763 bbcode.html, |
35 | 1764 token |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1765 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1766 } else { |
26 | 1767 html = bbcode.html( |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1768 token, |
35 | 1769 token.attrib, |
33 | 1770 content, |
1771 editor | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1772 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1773 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1774 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1775 html = token.val + content + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1776 (token.closing ? token.closing.val : ''); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1777 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1778 } else if (token.type === TOKEN_NEWLINE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1779 if (!isRoot) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1780 ret += '<br />'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1781 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1782 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1783 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1784 // If not already in a block wrap then start a new block |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1785 if (!blockWrapOpen) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1786 ret += '<div>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1787 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1788 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1789 ret += '<br />'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1790 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1791 // Normally the div acts as a line-break with by moving |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1792 // whatever comes after onto a new line. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1793 // If this is the last token, add an extra line-break so it |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1794 // shows as there will be nothing after it. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1795 if (!tokens.length) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1796 ret += '<br />'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1797 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1798 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1799 ret += '</div>\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1800 blockWrapOpen = false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1801 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1802 // content |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1803 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1804 needsBlockWrap = isRoot; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1805 html = escapeEntities(token.val, true); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1806 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1807 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1808 if (needsBlockWrap && !blockWrapOpen) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1809 ret += '<div>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1810 blockWrapOpen = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1811 } else if (!needsBlockWrap && blockWrapOpen) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1812 ret += '</div>\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1813 blockWrapOpen = false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1814 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1815 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1816 ret += html; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1817 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1818 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1819 if (blockWrapOpen) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1820 ret += '</div>\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1821 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1822 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1823 return ret; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1824 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1825 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1826 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1827 * Takes a BBCode string, parses it then converts it back to BBCode. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1828 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1829 * This will auto fix the BBCode and format it with the specified |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1830 * options. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1831 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1832 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1833 * @param {boolean} preserveNewLines If to preserve all new lines, not |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1834 * strip any based on the passed |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1835 * formatting options |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1836 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1837 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1838 base.toBBCode = function (str, preserveNewLines) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1839 return convertToBBCode(base.parse(str, preserveNewLines)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1840 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1841 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1842 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1843 * Converts parsed tokens back into BBCode with the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1844 * formatting specified in the options and with any |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1845 * fixes specified. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1846 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1847 * @param {array} toks Array of parsed tokens from base.parse() |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1848 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1849 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1850 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1851 function convertToBBCode(toks) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1852 var token, attr, bbcode, isBlock, isSelfClosing, quoteType, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1853 breakBefore, breakStart, breakEnd, breakAfter, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1854 ret = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1855 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1856 while (toks.length > 0) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1857 if (!(token = toks.shift())) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1858 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1859 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1860 // TODO: tidy this |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1861 bbcode = bbcodeHandlers[token.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1862 isBlock = !(!bbcode || bbcode.isInline !== false); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1863 isSelfClosing = bbcode && bbcode.isSelfClosing; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1864 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1865 breakBefore = (isBlock && base.opts.breakBeforeBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1866 bbcode.breakBefore !== false) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1867 (bbcode && bbcode.breakBefore); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1868 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1869 breakStart = (isBlock && !isSelfClosing && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1870 base.opts.breakStartBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1871 bbcode.breakStart !== false) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1872 (bbcode && bbcode.breakStart); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1873 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1874 breakEnd = (isBlock && base.opts.breakEndBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1875 bbcode.breakEnd !== false) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1876 (bbcode && bbcode.breakEnd); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1877 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1878 breakAfter = (isBlock && base.opts.breakAfterBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1879 bbcode.breakAfter !== false) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1880 (bbcode && bbcode.breakAfter); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1881 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1882 quoteType = (bbcode ? bbcode.quoteType : null) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1883 base.opts.quoteType || QuoteType.auto; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1884 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1885 if (!bbcode && token.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1886 ret += token.val; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1887 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1888 if (token.children) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1889 ret += convertToBBCode(token.children); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1890 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1891 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1892 if (token.closing) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1893 ret += token.closing.val; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1894 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1895 } else if (token.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1896 if (breakBefore) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1897 ret += '\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1898 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1899 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1900 // Convert the tag and it's attributes to BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1901 ret += '[' + token.name; |
35 | 1902 if (token.attrib) { |
1903 ret += '=' + quote( | |
1904 token.attrib, | |
1905 quoteType | |
1906 ); | |
1907 delete token.attrib; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1908 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1909 ret += ']'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1910 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1911 if (breakStart) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1912 ret += '\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1913 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1914 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1915 // Convert the tags children to BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1916 if (token.children) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1917 ret += convertToBBCode(token.children); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1918 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1919 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1920 // add closing tag if not self closing |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1921 if (!isSelfClosing && !bbcode.excludeClosing) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1922 if (breakEnd) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1923 ret += '\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1924 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1925 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1926 ret += '[/' + token.name + ']'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1927 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1928 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1929 if (breakAfter) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1930 ret += '\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1931 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1932 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1933 // preserve whatever was recognized as the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1934 // closing tag if it is a self closing tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1935 if (token.closing && isSelfClosing) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1936 ret += token.closing.val; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1937 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1938 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1939 ret += token.val; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1940 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1941 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1942 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1943 return ret; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1944 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1945 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1946 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1947 * Quotes an attribute |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1948 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1949 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1950 * @param {BBCodeParser.QuoteType} quoteType |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1951 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1952 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1953 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1954 */ |
35 | 1955 function quote(str, quoteType) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1956 var needsQuotes = /\s|=/.test(str); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1957 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1958 if (isFunction(quoteType)) { |
35 | 1959 return quoteType(str); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1960 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1961 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1962 if (quoteType === QuoteType.never || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1963 (quoteType === QuoteType.auto && !needsQuotes)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1964 return str; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1965 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1966 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1967 return '"' + str.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1968 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1969 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1970 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1971 * Returns the last element of an array or null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1972 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1973 * @param {array} arr |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1974 * @return {Object} Last element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1975 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1976 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1977 function last(arr) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1978 if (arr.length) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1979 return arr[arr.length - 1]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1980 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1981 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1982 return null; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1983 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1984 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1985 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1986 * Converts a string to lowercase. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1987 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1988 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1989 * @return {string} Lowercase version of str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1990 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1991 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1992 function lower(str) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1993 return str.toLowerCase(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1994 } |
25 | 1995 |
1996 return base; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1997 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1998 |
25 | 1999 var BBCodeParser = {}; |
2000 | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2001 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2002 * Quote type |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2003 * @type {Object} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2004 * @class QuoteType |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2005 * @name BBCodeParser.QuoteType |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2006 * @since 1.4.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2007 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2008 BBCodeParser.QuoteType = QuoteType; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2009 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2010 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2011 * Default BBCode parser options |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2012 * @type {Object} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2013 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2014 BBCodeParser.defaults = { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2015 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2016 * If to add a new line before block level elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2017 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2018 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2019 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2020 breakBeforeBlock: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2021 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2022 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2023 * If to add a new line after the start of block level elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2024 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2025 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2026 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2027 breakStartBlock: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2028 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2029 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2030 * If to add a new line before the end of block level elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2031 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2032 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2033 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2034 breakEndBlock: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2035 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2036 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2037 * If to add a new line after block level elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2038 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2039 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2040 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2041 breakAfterBlock: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2042 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2043 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2044 * If to remove empty tags |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2045 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2046 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2047 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2048 removeEmptyTags: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2049 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2050 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2051 * If to fix invalid nesting, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2052 * i.e. block level elements inside inline elements. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2053 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2054 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2055 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2056 fixInvalidNesting: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2057 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2058 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2059 * If to fix invalid children. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2060 * i.e. A tag which is inside a parent that doesn't |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2061 * allow that type of tag. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2062 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2063 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2064 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2065 fixInvalidChildren: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2066 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2067 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2068 * Attribute quote type |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2069 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2070 * @type {BBCodeParser.QuoteType} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2071 * @since 1.4.1 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2072 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2073 quoteType: QuoteType.auto, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2074 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2075 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2076 * Whether to use strict matching on attributes and styles. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2077 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2078 * When true this will perform AND matching requiring all tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2079 * attributes and styles to match. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2080 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2081 * When false will perform OR matching and will match if any of |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2082 * a tags attributes or styles match. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2083 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2084 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2085 * @since 3.1.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2086 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2087 strictMatch: false |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2088 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2089 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2090 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2091 * Converts a number 0-255 to hex. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2092 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2093 * Will return 00 if number is not a valid number. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2094 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2095 * @param {any} number |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2096 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2097 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2098 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2099 function toHex(number) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2100 number = parseInt(number, 10); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2101 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2102 if (isNaN(number)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2103 return '00'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2104 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2105 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2106 number = Math.max(0, Math.min(number, 255)).toString(16); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2107 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2108 return number.length < 2 ? '0' + number : number; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2109 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2110 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2111 * Normalises a CSS colour to hex #xxxxxx format |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2112 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2113 * @param {string} colorStr |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2114 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2115 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2116 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2117 function _normaliseColour(colorStr) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2118 var match; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2119 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2120 colorStr = colorStr || '#000'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2121 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2122 // rgb(n,n,n); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2123 if ((match = |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2124 colorStr.match(/rgb\((\d{1,3}),\s*?(\d{1,3}),\s*?(\d{1,3})\)/i))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2125 return '#' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2126 toHex(match[1]) + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2127 toHex(match[2]) + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2128 toHex(match[3]); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2129 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2130 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2131 // expand shorthand |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2132 if ((match = colorStr.match(/#([0-f])([0-f])([0-f])\s*?$/i))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2133 return '#' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2134 match[1] + match[1] + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2135 match[2] + match[2] + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2136 match[3] + match[3]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2137 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2138 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2139 return colorStr; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2140 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2141 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2142 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2143 * SCEditor BBCode format |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2144 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2145 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2146 function bbcodeFormat() { |
25 | 2147 var base = {}; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2148 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2149 base.stripQuotes = _stripQuotes; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2150 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2151 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2152 * cache of all the tags pointing to their bbcodes to enable |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2153 * faster lookup of which bbcode a tag should have |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2154 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2155 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2156 var tagsToBBCodes = {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2157 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2158 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2159 * Allowed children of specific HTML tags. Empty array if no |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2160 * children other than text nodes are allowed |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2161 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2162 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2163 var validChildren = { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2164 ul: ['li', 'ol', 'ul'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2165 ol: ['li', 'ol', 'ul'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2166 table: ['tr'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2167 tr: ['td', 'th'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2168 code: ['br', 'p', 'div'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2169 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2170 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2171 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2172 * Populates tagsToBBCodes and stylesToBBCodes for easier lookups |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2173 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2174 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2175 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2176 function buildBbcodeCache() { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2177 each(bbcodeHandlers, function (bbcode, handler) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2178 var |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2179 isBlock = handler.isInline === false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2180 tags = bbcodeHandlers[bbcode].tags, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2181 styles = bbcodeHandlers[bbcode].styles; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2182 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2183 if (styles) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2184 tagsToBBCodes['*'] = tagsToBBCodes['*'] || {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2185 tagsToBBCodes['*'][isBlock] = |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2186 tagsToBBCodes['*'][isBlock] || {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2187 tagsToBBCodes['*'][isBlock][bbcode] = [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2188 ['style', Object.entries(styles)] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2189 ]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2190 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2191 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2192 if (tags) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2193 each(tags, function (tag, values) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2194 if (values && values.style) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2195 values.style = Object.entries(values.style); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2196 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2197 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2198 tagsToBBCodes[tag] = tagsToBBCodes[tag] || {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2199 tagsToBBCodes[tag][isBlock] = |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2200 tagsToBBCodes[tag][isBlock] || {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2201 tagsToBBCodes[tag][isBlock][bbcode] = |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2202 values && Object.entries(values); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2203 }); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2204 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2205 }); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2206 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2207 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2208 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2209 * Handles adding newlines after block level elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2210 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2211 * @param {HTMLElement} element The element to convert |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2212 * @param {string} content The tags text content |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2213 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2214 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2215 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2216 function handleBlockNewlines(element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2217 var tag = element.nodeName.toLowerCase(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2218 var isInline = dom.isInline; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2219 if (!isInline(element, true) || tag === 'br') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2220 var isLastBlockChild, parent, parentLastChild, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2221 previousSibling = element.previousSibling; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2222 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2223 // Skips selection makers and ignored elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2224 // Skip empty inline elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2225 while (previousSibling && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2226 previousSibling.nodeType === 1 && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2227 !is(previousSibling, 'br') && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2228 isInline(previousSibling, true) && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2229 !previousSibling.firstChild) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2230 previousSibling = previousSibling.previousSibling; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2231 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2232 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2233 // If it's the last block of an inline that is the last |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2234 // child of a block then it shouldn't cause a line break |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2235 // <block><inline><br></inline></block> |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2236 do { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2237 parent = element.parentNode; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2238 parentLastChild = parent && parent.lastChild; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2239 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2240 isLastBlockChild = parentLastChild === element; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2241 element = parent; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2242 } while (parent && isLastBlockChild && isInline(parent, true)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2243 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2244 // If this block is: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2245 // * Not the last child of a block level element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2246 // * Is a <li> tag (lists are blocks) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2247 if (!isLastBlockChild || tag === 'li') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2248 content += '\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2249 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2250 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2251 // Check for: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2252 // <block>text<block>text</block></block> |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2253 // |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2254 // The second opening <block> opening tag should cause a |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2255 // line break because the previous sibing is inline. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2256 if (tag !== 'br' && previousSibling && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2257 !is(previousSibling, 'br') && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2258 isInline(previousSibling, true)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2259 content = '\n' + content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2260 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2261 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2262 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2263 return content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2264 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2265 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2266 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2267 * Handles a HTML tag and finds any matching BBCodes |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2268 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2269 * @param {HTMLElement} element The element to convert |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2270 * @param {string} content The Tags text content |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2271 * @param {boolean} blockLevel |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2272 * @return {string} Content with any matching BBCode tags |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2273 * wrapped around it. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2274 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2275 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2276 function handleTags(element, content, blockLevel) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2277 function isStyleMatch(style) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2278 var property = style[0]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2279 var values = style[1]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2280 var val = dom.getStyle(element, property); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2281 var parent = element.parentNode; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2282 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2283 // if the parent has the same style use that instead of this one |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2284 // so you don't end up with [i]parent[i]child[/i][/i] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2285 if (!val || parent && dom.hasStyle(parent, property, val)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2286 return false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2287 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2288 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2289 return !values || values.includes(val); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2290 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2291 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2292 function createAttributeMatch(isStrict) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2293 return function (attribute) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2294 var name = attribute[0]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2295 var value = attribute[1]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2296 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2297 // code tags should skip most styles |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2298 if (name === 'style' && element.nodeName === 'CODE') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2299 return false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2300 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2301 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2302 if (name === 'style' && value) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2303 return value[isStrict ? 'every' : 'some'](isStyleMatch); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2304 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2305 var val = attr(element, name); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2306 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2307 return val && (!value || value.includes(val)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2308 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2309 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2310 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2311 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2312 function handleTag(tag) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2313 if (!tagsToBBCodes[tag] || !tagsToBBCodes[tag][blockLevel]) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2314 return; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2315 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2316 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2317 // loop all bbcodes for this tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2318 each(tagsToBBCodes[tag][blockLevel], function (bbcode, attrs) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2319 var fn, format, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2320 isStrict = bbcodeHandlers[bbcode].strictMatch; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2321 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2322 if (typeof isStrict === 'undefined') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2323 isStrict = base.opts.strictMatch; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2324 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2325 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2326 // Skip if the element doesn't have the attribute or the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2327 // attribute doesn't match one of the required values |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2328 fn = isStrict ? 'every' : 'some'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2329 if (attrs && !attrs[fn](createAttributeMatch(isStrict))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2330 return; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2331 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2332 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2333 format = bbcodeHandlers[bbcode].format; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2334 if (isFunction(format)) { |
26 | 2335 content = format(element, content, base); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2336 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2337 content = _formatString(format, content); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2338 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2339 return false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2340 }); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2341 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2342 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2343 handleTag('*'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2344 handleTag(element.nodeName.toLowerCase()); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2345 return content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2346 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2347 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2348 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2349 * Converts a HTML dom element to BBCode starting from |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2350 * the innermost element and working backwards |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2351 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2352 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2353 * @param {HTMLElement} element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2354 * @return {string} BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2355 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2356 function elementToBbcode(element) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2357 var toBBCode = function (node, vChildren) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2358 var ret = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2359 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2360 dom.traverse(node, function (node) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2361 var content = '', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2362 nodeType = node.nodeType, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2363 tag = node.nodeName.toLowerCase(), |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2364 vChild = validChildren[tag], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2365 firstChild = node.firstChild, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2366 isValidChild = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2367 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2368 if (typeof vChildren === 'object') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2369 isValidChild = vChildren.indexOf(tag) > -1; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2370 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2371 // Emoticons should always be converted |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2372 if (is(node, 'img') && attr(node, EMOTICON_DATA_ATTR)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2373 isValidChild = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2374 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2375 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2376 // if this tag is one of the parents allowed children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2377 // then set this tags allowed children to whatever it |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2378 // allows, otherwise set to what the parent allows |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2379 if (!isValidChild) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2380 vChild = vChildren; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2381 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2382 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2383 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2384 // 3 = text and 1 = element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2385 if (nodeType !== 3 && nodeType !== 1) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2386 return; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2387 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2388 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2389 if (nodeType === 1) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2390 // skip empty nlf elements (new lines automatically |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2391 // added after block level elements like quotes) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2392 if (is(node, '.sceditor-nlf') && !firstChild) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2393 return; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2394 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2395 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2396 // don't convert iframe contents |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2397 if (tag !== 'iframe') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2398 content = toBBCode(node, vChild); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2399 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2400 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2401 // TODO: isValidChild is no longer needed. Should use |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2402 // valid children bbcodes instead by creating BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2403 // tokens like the parser. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2404 if (isValidChild) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2405 // code tags should skip most styles |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2406 if (tag !== 'code') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2407 // First parse inline codes |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2408 content = handleTags(node, content, false); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2409 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2410 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2411 content = handleTags(node, content, true); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2412 ret += handleBlockNewlines(node, content); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2413 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2414 ret += content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2415 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2416 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2417 ret += node.nodeValue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2418 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2419 }, false, true); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2420 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2421 return ret; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2422 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2423 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2424 return toBBCode(element); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2425 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2426 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2427 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2428 * Initializer |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2429 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2430 */ |
24 | 2431 base.init = function (editor) { |
33 | 2432 base.editor = editor; |
24 | 2433 base.opts = editor.opts; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2434 base.elementToBbcode = elementToBbcode; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2435 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2436 // build the BBCode cache |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2437 buildBbcodeCache(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2438 |
30
db061869f28f
remove sceditor.command, add options.onCreate
Franklin Schmidt <fschmidt@gmail.com>
parents:
27
diff
changeset
|
2439 editor.commands = extendDeep( |
33 | 2440 {}, editor.commands, defaultCommandsOverrides |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2441 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2442 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2443 // Add BBCode helper methods |
24 | 2444 editor.toBBCode = base.toSource; |
2445 editor.fromBBCode = base.toHtml; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2446 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2447 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2448 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2449 * Converts BBCode into HTML |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2450 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2451 * @param {string} source |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2452 */ |
37 | 2453 function toHtml(source) { |
2454 let parser = newBBCodeParser(base.editor); | |
2455 let html = parser.toHTML( | |
2456 base.opts.bbcodeTrim ? source.trim() : source | |
2457 ); | |
2458 return html; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2459 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2460 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2461 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2462 * Converts HTML into BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2463 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2464 * @param {boolean} asFragment |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2465 * @param {string} html |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2466 * @param {!Document} [context] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2467 * @param {!HTMLElement} [parent] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2468 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2469 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2470 */ |
27 | 2471 function toSource(asFragment) { |
2472 return function(html, context, parent) { | |
2473 context = context || document; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2474 |
27 | 2475 var bbcode, elements; |
2476 var containerParent = context.createElement('div'); | |
2477 var container = context.createElement('div'); | |
33 | 2478 var parser = newBBCodeParser(base.editor); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2479 |
27 | 2480 container.innerHTML = html; |
2481 css(containerParent, 'visibility', 'hidden'); | |
2482 containerParent.appendChild(container); | |
2483 context.body.appendChild(containerParent); | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2484 |
27 | 2485 if (asFragment) { |
2486 // Add text before and after so removeWhiteSpace doesn't remove | |
2487 // leading and trailing whitespace | |
2488 containerParent.insertBefore( | |
2489 context.createTextNode('#'), | |
2490 containerParent.firstChild | |
2491 ); | |
2492 containerParent.appendChild(context.createTextNode('#')); | |
2493 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2494 |
27 | 2495 // Match parents white-space handling |
2496 if (parent) { | |
2497 css(container, 'whiteSpace', css(parent, 'whiteSpace')); | |
2498 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2499 |
27 | 2500 // Remove all nodes with sceditor-ignore class |
2501 elements = container.getElementsByClassName('sceditor-ignore'); | |
2502 while (elements.length) { | |
2503 elements[0].parentNode.removeChild(elements[0]); | |
2504 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2505 |
27 | 2506 dom.removeWhiteSpace(containerParent); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2507 |
27 | 2508 bbcode = elementToBbcode(container); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2509 |
27 | 2510 context.body.removeChild(containerParent); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2511 |
27 | 2512 bbcode = parser.toBBCode(bbcode, true); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2513 |
27 | 2514 if (base.opts.bbcodeTrim) { |
2515 bbcode = bbcode.trim(); | |
2516 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2517 |
27 | 2518 return bbcode; |
2519 }; | |
2520 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2521 |
37 | 2522 base.toHtml = toHtml; |
27 | 2523 base.toSource = toSource(false); |
2524 base.fragmentToSource = toSource(true); | |
25 | 2525 |
2526 return base; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2527 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2528 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2529 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2530 * Gets a BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2531 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2532 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2533 * @return {Object|null} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2534 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2535 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2536 bbcodeFormat.get = function (name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2537 return bbcodeHandlers[name] || null; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2538 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2539 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2540 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2541 * Adds a BBCode to the parser or updates an existing |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2542 * BBCode if a BBCode with the specified name already exists. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2543 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2544 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2545 * @param {Object} bbcode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2546 * @return {this} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2547 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2548 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2549 bbcodeFormat.set = function (name, bbcode) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2550 if (name && bbcode) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2551 // merge any existing command properties |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2552 bbcode = extend(bbcodeHandlers[name] || {}, bbcode); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2553 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2554 bbcode.remove = function () { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2555 delete bbcodeHandlers[name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2556 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2557 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2558 bbcodeHandlers[name] = bbcode; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2559 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2560 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2561 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2562 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2563 * Renames a BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2564 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2565 * This does not change the format or HTML handling, those must be |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2566 * changed manually. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2567 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2568 * @param {string} name [description] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2569 * @param {string} newName [description] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2570 * @return {this|false} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2571 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2572 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2573 bbcodeFormat.rename = function (name, newName) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2574 if (name in bbcodeHandlers) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2575 bbcodeHandlers[newName] = bbcodeHandlers[name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2576 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2577 delete bbcodeHandlers[name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2578 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2579 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2580 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2581 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2582 * Removes a BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2583 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2584 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2585 * @return {this} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2586 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2587 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2588 bbcodeFormat.remove = function (name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2589 if (name in bbcodeHandlers) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2590 delete bbcodeHandlers[name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2591 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2592 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2593 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2594 bbcodeFormat.formatBBCodeString = formatBBCodeString; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2595 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2596 sceditor.formats.bbcode = bbcodeFormat; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2597 sceditor.BBCodeParser = BBCodeParser; |
14
0cb206904499
formats set default format
Franklin Schmidt <fschmidt@gmail.com>
parents:
4
diff
changeset
|
2598 sceditor.defaultOptions.format = 'bbcode'; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2599 }(sceditor)); |