Mercurial Hosting > sceditor
annotate src/formats/bbcode.js @ 33:c23475f3f466
improve emoticons
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 14 Aug 2022 20:36:17 -0600 |
parents | db061869f28f |
children | 20d1f23225fe |
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) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
163 var attrs = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
164 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
165 if (width) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
166 attrs += ' width=' + width; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
167 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
168 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
169 if (height) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
170 attrs += ' height=' + height; |
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 editor.insertText( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
174 '[img' + attrs + ']' + url + '[/img]' |
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 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
177 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
178 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
179 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
180 email: { |
17 | 181 txtExec: function (editor, caller, selected) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
182 getEditorCommand('email')._dropDown( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
183 editor, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
184 caller, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
185 function (url, text) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
186 editor.insertText( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
187 '[email=' + url + ']' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
188 (text || selected || url) + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
189 '[/email]' |
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 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
192 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
193 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
194 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
195 link: { |
17 | 196 txtExec: function (editor, caller, selected) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
197 getEditorCommand('link')._dropDown( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
198 editor, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
199 caller, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
200 function (url, text) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
201 editor.insertText( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
202 '[url=' + url + ']' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
203 (text || selected || url) + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
204 '[/url]' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
205 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
206 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
207 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
208 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
209 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
210 quote: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
211 txtExec: ['[quote]', '[/quote]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
212 }, |
33 | 213 emoticon: { |
214 txtExec: function (editor, caller) { | |
215 editor.commands.emoticon.base(editor, caller, function(target) { | |
216 return '[emoticon]' + target.getAttribute(EMOTICON_DATA_ATTR) + '[/emoticon]'; | |
217 } ); | |
218 }, | |
219 }, | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
220 youtube: { |
17 | 221 txtExec: function (editor, caller) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
222 getEditorCommand('youtube')._dropDown( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
223 editor, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
224 caller, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
225 function (id) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
226 editor.insertText('[youtube]' + id + '[/youtube]'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
227 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
228 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
229 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
230 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
231 rtl: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
232 txtExec: ['[rtl]', '[/rtl]'] |
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 ltr: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
235 txtExec: ['[ltr]', '[/ltr]'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
236 } |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
239 var bbcodeHandlers = { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
240 // START_COMMAND: Bold |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
241 b: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
242 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
243 b: null, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
244 strong: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
245 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
246 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
247 // 401 is for FF 3.5 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
248 'font-weight': ['bold', 'bolder', '401', '700', '800', '900'] |
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 format: '[b]{0}[/b]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
251 html: '<strong>{0}</strong>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
252 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
253 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
254 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
255 // START_COMMAND: Italic |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
256 i: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
257 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
258 i: null, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
259 em: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
260 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
261 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
262 'font-style': ['italic', 'oblique'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
263 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
264 format: '[i]{0}[/i]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
265 html: '<em>{0}</em>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
266 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
267 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
268 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
269 // START_COMMAND: Underline |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
270 u: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
271 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
272 u: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
273 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
274 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
275 'text-decoration': ['underline'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
276 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
277 format: '[u]{0}[/u]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
278 html: '<u>{0}</u>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
279 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
280 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
281 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
282 // START_COMMAND: Strikethrough |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
283 s: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
284 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
285 s: null, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
286 strike: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
287 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
288 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
289 'text-decoration': ['line-through'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
290 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
291 format: '[s]{0}[/s]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
292 html: '<s>{0}</s>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
293 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
294 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
295 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
296 // START_COMMAND: Subscript |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
297 sub: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
298 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
299 sub: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
300 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
301 format: '[sub]{0}[/sub]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
302 html: '<sub>{0}</sub>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
303 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
304 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
305 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
306 // START_COMMAND: Superscript |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
307 sup: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
308 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
309 sup: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
310 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
311 format: '[sup]{0}[/sup]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
312 html: '<sup>{0}</sup>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
313 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
314 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
315 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
316 // START_COMMAND: Font |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
317 font: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
318 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
319 font: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
320 face: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
321 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
322 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
323 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
324 'font-family': 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 quoteType: QuoteType.never, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
327 format: function (element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
328 var font; |
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 if (!is(element, 'font') || !(font = attr(element, 'face'))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
331 font = css(element, 'font-family'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
332 } |
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 return '[font=' + _stripQuotes(font) + ']' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
335 content + '[/font]'; |
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 html: '<font face="{defaultattr}">{0}</font>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
338 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
339 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
340 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
341 // START_COMMAND: Size |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
342 size: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
343 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
344 font: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
345 size: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
346 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
347 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
348 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
349 'font-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 format: function (element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
352 var fontSize = attr(element, 'size'), |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
353 size = 2; |
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 if (!fontSize) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
356 fontSize = css(element, 'fontSize'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
357 } |
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 // 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
|
360 if (fontSize.indexOf('px') > -1) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
361 // convert size to an int |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
362 fontSize = fontSize.replace('px', '') - 0; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
363 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
364 if (fontSize < 12) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
365 size = 1; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
366 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
367 if (fontSize > 15) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
368 size = 3; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
369 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
370 if (fontSize > 17) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
371 size = 4; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
372 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
373 if (fontSize > 23) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
374 size = 5; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
375 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
376 if (fontSize > 31) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
377 size = 6; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
378 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
379 if (fontSize > 47) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
380 size = 7; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
381 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
382 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
383 size = fontSize; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
384 } |
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 return '[size=' + size + ']' + content + '[/size]'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
387 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
388 html: '<font size="{defaultattr}">{!0}</font>' |
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 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
391 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
392 // START_COMMAND: Color |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
393 color: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
394 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
395 font: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
396 color: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
397 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
398 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
399 styles: { |
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 quoteType: QuoteType.never, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
403 format: function (elm, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
404 var color; |
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 if (!is(elm, 'font') || !(color = attr(elm, 'color'))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
407 color = elm.style.color || css(elm, 'color'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
408 } |
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 return '[color=' + _normaliseColour(color) + ']' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
411 content + '[/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 html: function (token, attrs, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
414 return '<font color="' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
415 escapeEntities(_normaliseColour(attrs.defaultattr), true) + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
416 '">' + content + '</font>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
417 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
418 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
419 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
420 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
421 // START_COMMAND: Lists |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
422 ul: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
423 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
424 ul: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
425 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
426 breakStart: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
427 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
428 skipLastLineBreak: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
429 format: '[ul]{0}[/ul]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
430 html: '<ul>{0}</ul>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
431 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
432 list: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
433 breakStart: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
434 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
435 skipLastLineBreak: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
436 html: '<ul>{0}</ul>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
437 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
438 ol: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
439 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
440 ol: null |
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 breakStart: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
443 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
444 skipLastLineBreak: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
445 format: '[ol]{0}[/ol]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
446 html: '<ol>{0}</ol>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
447 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
448 li: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
449 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
450 li: null |
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 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
453 closedBy: ['/ul', '/ol', '/list', '*', 'li'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
454 format: '[li]{0}[/li]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
455 html: '<li>{0}</li>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
456 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
457 '*': { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
458 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
459 closedBy: ['/ul', '/ol', '/list', '*', 'li'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
460 html: '<li>{0}</li>' |
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 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
463 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
464 // START_COMMAND: Table |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
465 table: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
466 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
467 table: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
468 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
469 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
470 isHtmlInline: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
471 skipLastLineBreak: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
472 format: '[table]{0}[/table]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
473 html: '<table>{0}</table>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
474 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
475 tr: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
476 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
477 tr: null |
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 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
480 skipLastLineBreak: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
481 format: '[tr]{0}[/tr]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
482 html: '<tr>{0}</tr>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
483 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
484 th: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
485 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
486 th: null |
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 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
489 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
490 format: '[th]{0}[/th]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
491 html: '<th>{0}</th>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
492 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
493 td: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
494 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
495 td: null |
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 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
498 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
499 format: '[td]{0}[/td]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
500 html: '<td>{0}</td>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
501 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
502 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
503 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
504 // START_COMMAND: Emoticons |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
505 emoticon: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
506 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
507 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
508 img: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
509 src: null, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
510 'data-sceditor-emoticon': null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
511 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
512 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
513 format: function (element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
514 return attr(element, EMOTICON_DATA_ATTR) + content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
515 }, |
33 | 516 html: function (token, attrs, content, editor) { |
517 return editor.allEmoticons[content] || token.val + content + token.closing.val; | |
518 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
519 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
520 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
521 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
522 // START_COMMAND: Horizontal Rule |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
523 hr: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
524 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
525 hr: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
526 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
527 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
528 isSelfClosing: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
529 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
530 format: '[hr]{0}', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
531 html: '<hr />' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
532 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
533 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
534 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
535 // START_COMMAND: Image |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
536 img: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
537 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
538 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
539 img: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
540 src: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
541 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
542 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
543 allowedChildren: ['#'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
544 quoteType: QuoteType.never, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
545 format: function (element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
546 var width, height, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
547 attribs = '', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
548 style = function (name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
549 return element.style ? element.style[name] : null; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
550 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
551 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
552 // check if this is an emoticon image |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
553 if (attr(element, EMOTICON_DATA_ATTR)) { |
33 | 554 return '[emoticon]' + content + '[/emoticon]'; |
0
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
557 width = attr(element, 'width') || style('width'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
558 height = attr(element, 'height') || style('height'); |
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 // only add width and height if one is specified |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
561 if ((element.complete && (width || height)) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
562 (width && 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 attribs = '=' + dom.width(element) + 'x' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
565 dom.height(element); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
566 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
567 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
568 return '[img' + attribs + ']' + attr(element, 'src') + '[/img]'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
569 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
570 html: function (token, attrs, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
571 var undef, width, height, match, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
572 attribs = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
573 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
574 // handle [img width=340 height=240]url[/img] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
575 width = attrs.width; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
576 height = attrs.height; |
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] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
579 if (attrs.defaultattr) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
580 match = attrs.defaultattr.split(/x/i); |
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]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
583 height = (match.length === 2 ? match[1] : match[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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
586 if (width !== undef) { |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
590 if (height !== undef) { |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
619 return '[url=' + url + ']' + content + '[/url]'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
620 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
621 html: function (token, attrs, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
622 attrs.defaultattr = |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
623 escapeEntities(attrs.defaultattr, true) || content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
624 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
625 return '<a href="' + escapeUriScheme(attrs.defaultattr) + '">' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
626 content + '</a>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
627 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
628 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
629 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
630 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
631 // START_COMMAND: E-mail |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
632 email: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
633 quoteType: QuoteType.never, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
634 html: function (token, attrs, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
635 return '<a href="mailto:' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
636 (escapeEntities(attrs.defaultattr, true) || content) + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
637 '">' + content + '</a>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
638 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
639 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
640 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
641 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
642 // START_COMMAND: Quote |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
643 quote: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
644 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
645 blockquote: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
646 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
647 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
648 quoteType: QuoteType.never, |
26 | 649 format: function (element, content, bbcodeFormat) { |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
650 var authorAttr = 'data-author'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
651 var author = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
652 var cite; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
653 var children = element.children; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
654 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
655 for (var i = 0; !cite && i < children.length; i++) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
656 if (is(children[i], 'cite')) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
657 cite = children[i]; |
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 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
660 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
661 if (cite || attr(element, authorAttr)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
662 author = cite && cite.textContent || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
663 attr(element, authorAttr); |
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 attr(element, authorAttr, author); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
666 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
667 if (cite) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
668 element.removeChild(cite); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
669 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
670 |
26 | 671 content = bbcodeFormat.elementToBbcode(element); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
672 author = '=' + author.replace(/(^\s+|\s+$)/g, ''); |
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 if (cite) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
675 element.insertBefore(cite, element.firstChild); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
676 } |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
679 return '[quote' + author + ']' + content + '[/quote]'; |
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 html: function (token, attrs, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
682 if (attrs.defaultattr) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
683 content = '<cite>' + escapeEntities(attrs.defaultattr) + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
684 '</cite>' + content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
685 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
686 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
687 return '<blockquote>' + content + '</blockquote>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
688 } |
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 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
691 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
692 // START_COMMAND: Code |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
693 code: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
694 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
695 code: null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
696 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
697 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
698 allowedChildren: ['#', '#newline'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
699 format: '[code]{0}[/code]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
700 html: '<code>{0}</code>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
701 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
702 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
703 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
704 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
705 // START_COMMAND: Left |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
706 left: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
707 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
708 'text-align': [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
709 'left', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
710 '-webkit-left', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
711 '-moz-left', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
712 '-khtml-left' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
713 ] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
714 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
715 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
716 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
717 format: '[left]{0}[/left]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
718 html: '<div align="left">{0}</div>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
719 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
720 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
721 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
722 // START_COMMAND: Centre |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
723 center: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
724 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
725 'text-align': [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
726 'center', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
727 '-webkit-center', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
728 '-moz-center', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
729 '-khtml-center' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
730 ] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
731 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
732 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
733 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
734 format: '[center]{0}[/center]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
735 html: '<div align="center">{0}</div>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
736 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
737 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
738 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
739 // START_COMMAND: Right |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
740 right: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
741 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
742 'text-align': [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
743 'right', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
744 '-webkit-right', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
745 '-moz-right', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
746 '-khtml-right' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
747 ] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
748 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
749 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
750 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
751 format: '[right]{0}[/right]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
752 html: '<div align="right">{0}</div>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
753 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
754 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
755 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
756 // START_COMMAND: Justify |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
757 justify: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
758 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
759 'text-align': [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
760 'justify', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
761 '-webkit-justify', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
762 '-moz-justify', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
763 '-khtml-justify' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
764 ] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
765 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
766 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
767 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
768 format: '[justify]{0}[/justify]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
769 html: '<div align="justify">{0}</div>' |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
770 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
771 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
772 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
773 // START_COMMAND: YouTube |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
774 youtube: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
775 allowsEmpty: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
776 tags: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
777 iframe: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
778 'data-youtube-id': null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
779 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
780 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
781 format: function (element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
782 element = attr(element, 'data-youtube-id'); |
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 return element ? '[youtube]' + element + '[/youtube]' : content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
785 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
786 html: '<iframe width="560" height="315" frameborder="0" ' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
787 '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
|
788 'data-youtube-id="{0}" allowfullscreen></iframe>' |
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 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
791 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
792 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
793 // START_COMMAND: Rtl |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
794 rtl: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
795 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
796 direction: ['rtl'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
797 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
798 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
799 format: '[rtl]{0}[/rtl]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
800 html: '<div style="direction: rtl">{0}</div>' |
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 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
803 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
804 // START_COMMAND: Ltr |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
805 ltr: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
806 styles: { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
807 direction: ['ltr'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
808 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
809 isInline: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
810 format: '[ltr]{0}[/ltr]', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
811 html: '<div style="direction: ltr">{0}</div>' |
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 // END_COMMAND |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
814 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
815 // 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
|
816 // without having to remove the , after the last one. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
817 // Needed for IE. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
818 ignore: {} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
819 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
820 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
821 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
822 * Formats a string replacing {name} with the values of |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
823 * obj.name properties. |
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 * 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
|
826 * it will be left intact. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
827 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
828 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
829 * @param {Object} obj |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
830 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
831 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
832 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
833 function formatBBCodeString(str, obj) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
834 return str.replace(/\{([^}]+)\}/g, function (match, group) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
835 var undef, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
836 escape = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
837 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
838 if (group.charAt(0) === '!') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
839 escape = false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
840 group = group.substring(1); |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
843 if (group === '0') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
844 escape = false; |
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 (obj[group] === undef) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
848 return match; |
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 return escape ? escapeEntities(obj[group], true) : obj[group]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
852 }); |
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 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
856 * Removes the first and last divs from the HTML. |
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 * This is needed for pasting |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
859 * @param {string} html |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
860 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
861 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
862 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
863 function removeFirstLastDiv(html) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
864 var node, next, removeDiv, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
865 output = document.createElement('div'); |
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 removeDiv = function (node, isFirst) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
868 // Don't remove divs that have styling |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
869 if (dom.hasStyling(node)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
870 return; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
871 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
872 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
873 if ((node.childNodes.length !== 1 || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
874 !is(node.firstChild, 'br'))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
875 while ((next = node.firstChild)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
876 output.insertBefore(next, node); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
877 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
878 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
879 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
880 if (isFirst) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
881 var lastChild = output.lastChild; |
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 if (node !== lastChild && is(lastChild, 'div') && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
884 node.nextSibling === lastChild) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
885 output.insertBefore(document.createElement('br'), node); |
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 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
888 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
889 output.removeChild(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 css(output, 'display', 'none'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
893 output.innerHTML = html.replace(/<\/div>\n/g, '</div>'); |
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 if ((node = output.firstChild) && is(node, 'div')) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
896 removeDiv(node, true); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
897 } |
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.lastChild) && is(node, 'div')) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
900 removeDiv(node); |
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 return output.innerHTML; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
904 } |
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 function isFunction(fn) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
907 return typeof fn === 'function'; |
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 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
911 * Removes any leading or trailing quotes ('") |
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 * @return string |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
914 * @since v1.4.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
915 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
916 function _stripQuotes(str) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
917 return str ? |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
918 str.replace(/\\(.)/g, '$1').replace(/^(["'])(.*?)\1$/, '$2') : str; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
921 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
922 * Formats a string replacing {0}, {1}, {2}, ect. with |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
923 * the params provided |
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 * @param {string} str The string to format |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
926 * @param {...string} arg The strings to replace |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
927 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
928 * @since v1.4.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
929 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
930 function _formatString(str) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
931 var undef; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
932 var args = arguments; |
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 return str.replace(/\{(\d+)\}/g, function (_, matchNum) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
935 return args[matchNum - 0 + 1] !== undef ? |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
936 args[matchNum - 0 + 1] : |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
937 '{' + matchNum + '}'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
938 }); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
939 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
940 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
941 var TOKEN_OPEN = 'open'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
942 var TOKEN_CONTENT = 'content'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
943 var TOKEN_NEWLINE = 'newline'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
944 var TOKEN_CLOSE = 'close'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
945 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
946 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
947 /* |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
948 * @typedef {Object} TokenizeToken |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
949 * @property {string} type |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
950 * @property {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
951 * @property {string} val |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
952 * @property {Object.<string, string>} attrs |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
953 * @property {array} children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
954 * @property {TokenizeToken} closing |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
955 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
956 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
957 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
958 * Tokenize token object |
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 * @param {string} type The type of token this is, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
961 * should be one of tokenType |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
962 * @param {string} name The name of this token |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
963 * @param {string} val The originally matched string |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
964 * @param {array} attrs Any attributes. Only set on |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
965 * TOKEN_TYPE_OPEN tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
966 * @param {array} children Any children of this token |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
967 * @param {TokenizeToken} closing This tokens closing tag. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
968 * Only set on TOKEN_TYPE_OPEN tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
969 * @class {TokenizeToken} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
970 * @name {TokenizeToken} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
971 * @memberOf BBCodeParser.prototype |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
972 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
973 // eslint-disable-next-line max-params |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
974 function TokenizeToken(type, name, val, attrs, children, closing) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
975 var base = this; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
976 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
977 base.type = type; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
978 base.name = name; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
979 base.val = val; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
980 base.attrs = attrs || {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
981 base.children = children || []; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
982 base.closing = closing || null; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
983 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
984 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
985 TokenizeToken.prototype = { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
986 /** @lends BBCodeParser.prototype.TokenizeToken */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
987 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
988 * Clones this token |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
989 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
990 * @return {TokenizeToken} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
991 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
992 clone: function () { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
993 var base = this; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
994 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
995 return new TokenizeToken( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
996 base.type, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
997 base.name, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
998 base.val, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
999 extend({}, base.attrs), |
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 base.closing ? base.closing.clone() : null |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1002 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1003 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1004 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1005 * Splits this token at the specified child |
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 * @param {TokenizeToken} splitAt The child to split at |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1008 * @return {TokenizeToken} The right half of the split token or |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1009 * empty clone if invalid splitAt lcoation |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1010 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1011 splitAt: function (splitAt) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1012 var offsetLength; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1013 var base = this; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1014 var clone = base.clone(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1015 var offset = base.children.indexOf(splitAt); |
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 if (offset > -1) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1018 // 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
|
1019 // to pass to splice() |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1020 offsetLength = base.children.length - offset; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1021 clone.children = base.children.splice(offset, offsetLength); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1022 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1023 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1024 return clone; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1025 } |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1029 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1030 * SCEditor BBCode parser class |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1031 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1032 * @param {Object} options |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1033 * @class BBCodeParser |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1034 * @name BBCodeParser |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1035 * @since v1.4.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1036 */ |
33 | 1037 function newBBCodeParser(editor) { |
25 | 1038 var base = {}; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1039 |
33 | 1040 base.opts = extend({}, BBCodeParser.defaults, editor.opts.parserOptions); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1041 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1042 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1043 * Takes a BBCode string and splits it into open, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1044 * content and close tags. |
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 * 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
|
1047 * 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
|
1048 * 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
|
1049 * parse function. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1050 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1051 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1052 * @return {array} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1053 * @memberOf BBCodeParser.prototype |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1054 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1055 base.tokenize = function (str) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1056 var matches, type, i; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1057 var tokens = []; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1058 // The token types in reverse order of precedence |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1059 // (they're looped in reverse) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1060 var tokenTypes = [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1061 { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1062 type: TOKEN_CONTENT, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1063 regex: /^([^\[\r\n]+|\[)/ |
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 { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1066 type: TOKEN_NEWLINE, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1067 regex: /^(\r\n|\r|\n)/ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1068 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1069 { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1070 type: TOKEN_OPEN, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1071 regex: /^\[[^\[\]]+\]/ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1072 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1073 // Close must come before open as they are |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1074 // the same except close has a / at the start. |
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 type: TOKEN_CLOSE, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1077 regex: /^\[\/[^\[\]]+\]/ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1078 } |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1081 strloop: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1082 while (str.length) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1083 i = tokenTypes.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1084 while (i--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1085 type = tokenTypes[i].type; |
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 // Check if the string matches any of the tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1088 if (!(matches = str.match(tokenTypes[i].regex)) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1089 !matches[0]) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1090 continue; |
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 // Add the match to the tokens list |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1094 tokens.push(tokenizeTag(type, matches[0])); |
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 // Remove the match from the string |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1097 str = str.substr(matches[0].length); |
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 // The token has been added so start again |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1100 continue strloop; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1103 // 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
|
1104 // 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
|
1105 if (str.length) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1106 tokens.push(tokenizeTag(TOKEN_CONTENT, str)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1107 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1108 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1109 str = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1110 } |
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 return tokens; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1113 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1114 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1115 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1116 * Extracts the name an params from a tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1117 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1118 * @param {string} type |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1119 * @param {string} val |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1120 * @return {Object} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1121 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1122 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1123 function tokenizeTag(type, val) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1124 var matches, attrs, name, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1125 openRegex = /\[([^\]\s=]+)(?:([^\]]+))?\]/, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1126 closeRegex = /\[\/([^\[\]]+)\]/; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1127 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1128 // Extract the name and attributes from opening tags and |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1129 // just the name from closing tags. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1130 if (type === TOKEN_OPEN && (matches = val.match(openRegex))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1131 name = lower(matches[1]); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1132 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1133 if (matches[2] && (matches[2] = matches[2].trim())) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1134 attrs = tokenizeAttrs(matches[2]); |
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 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1137 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1138 if (type === TOKEN_CLOSE && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1139 (matches = val.match(closeRegex))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1140 name = lower(matches[1]); |
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 if (type === TOKEN_NEWLINE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1144 name = '#newline'; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1147 // Treat all tokens without a name and |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1148 // all unknown BBCodes as content |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1149 if (!name || ((type === TOKEN_OPEN || type === TOKEN_CLOSE) && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1150 !bbcodeHandlers[name])) { |
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 type = TOKEN_CONTENT; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1153 name = '#'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1154 } |
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 return new TokenizeToken(type, name, val, attrs); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1157 } |
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 * Extracts the individual attributes from a string containing |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1161 * all the attributes. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1162 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1163 * @param {string} attrs |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1164 * @return {Object} Assoc array of attributes |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1165 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1166 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1167 function tokenizeAttrs(attrs) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1168 var matches, |
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 ([^\s=]+) Anything that's not a space or equals |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1171 = Equals sign = |
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 (?: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1174 (["']) The opening quote |
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 (?:\\\2|[^\2])*? Anything that isn't the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1177 unescaped opening quote |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1178 ) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1179 \2 The opening quote again which |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1180 will close the string |
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 | If not a quoted string then match |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1183 ( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1184 (?:.(?!\s\S+=))*.? Anything that isn't part of |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1185 [space][non-space][=] which |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1186 would be a new attribute |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1187 ) |
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 attrRegex = /([^\s=]+)=(?:(?:(["'])((?:\\\2|[^\2])*?)\2)|((?:.(?!\s\S+=))*.))/g, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1191 ret = {}; |
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 // if only one attribute then remove the = from the start and |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1194 // strip any quotes |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1195 if (attrs.charAt(0) === '=' && attrs.indexOf('=', 1) < 0) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1196 ret.defaultattr = _stripQuotes(attrs.substr(1)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1197 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1198 if (attrs.charAt(0) === '=') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1199 attrs = 'defaultattr' + attrs; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1200 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1201 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1202 // No need to strip quotes here, the regex will do that. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1203 while ((matches = attrRegex.exec(attrs))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1204 ret[lower(matches[1])] = |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1205 _stripQuotes(matches[3]) || matches[4]; |
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 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1208 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1209 return ret; |
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 |
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 * Parses a string into an array of BBCodes |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1214 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1215 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1216 * @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
|
1217 * strip any based on the passed |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1218 * formatting options |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1219 * @return {array} Array of BBCode objects |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1220 * @memberOf BBCodeParser.prototype |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1221 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1222 base.parse = function (str, preserveNewLines) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1223 var ret = parseTokens(base.tokenize(str)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1224 var opts = base.opts; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1225 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1226 if (opts.fixInvalidNesting) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1227 fixNesting(ret); |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1230 normaliseNewLines(ret, null, preserveNewLines); |
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 if (opts.removeEmptyTags) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1233 removeEmpty(ret); |
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 return ret; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1237 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1238 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1239 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1240 * Checks if an array of TokenizeToken's contains the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1241 * specified token. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1242 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1243 * Checks the tokens name and type match another tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1244 * name and type in the array. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1245 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1246 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1247 * @param {string} type |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1248 * @param {array} arr |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1249 * @return {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1250 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1251 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1252 function hasTag(name, type, arr) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1253 var i = arr.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1254 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1255 while (i--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1256 if (arr[i].type === type && arr[i].name === name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1257 return true; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1261 return false; |
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 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1265 * Checks if the child tag is allowed as one |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1266 * of the parent tags children. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1267 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1268 * @param {TokenizeToken} parent |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1269 * @param {TokenizeToken} child |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1270 * @return {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1271 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1272 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1273 function isChildAllowed(parent, child) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1274 var parentBBCode = parent ? bbcodeHandlers[parent.name] : {}, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1275 allowedChildren = parentBBCode.allowedChildren; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1276 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1277 if (base.opts.fixInvalidChildren && allowedChildren) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1278 return allowedChildren.indexOf(child.name || '#') > -1; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1279 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1280 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1281 return true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1282 } |
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 // TODO: Tidy this parseTokens() function up a bit. |
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 * Parses an array of tokens created by tokenize() |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1287 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1288 * @param {array} toks |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1289 * @return {array} Parsed tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1290 * @see tokenize() |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1291 * @private |
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 function parseTokens(toks) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1294 var token, bbcode, curTok, clone, i, next, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1295 cloned = [], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1296 output = [], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1297 openTags = [], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1298 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1299 * Returns the currently open tag or undefined |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1300 * @return {TokenizeToken} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1301 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1302 currentTag = function () { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1303 return last(openTags); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1304 }, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1305 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1306 * Adds a tag to either the current tags children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1307 * or to the output array. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1308 * @param {TokenizeToken} token |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1309 * @private |
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 addTag = function (token) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1312 if (currentTag()) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1313 currentTag().children.push(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1314 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1315 output.push(token); |
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 }, |
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 * Checks if this tag closes the current tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1320 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1321 * @return {Void} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1322 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1323 closesCurrentTag = function (name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1324 return currentTag() && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1325 (bbcode = bbcodeHandlers[currentTag().name]) && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1326 bbcode.closedBy && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1327 bbcode.closedBy.indexOf(name) > -1; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1328 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1329 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1330 while ((token = toks.shift())) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1331 next = toks[0]; |
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 /* |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1334 * Fixes any invalid children. |
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 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
|
1337 * 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
|
1338 * element. i.e. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1339 * [code]Code [b]only[/b] allows text.[/code] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1340 * Will become: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1341 * <code>Code [b]only[/b] allows text.</code> |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1342 * Instead of: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1343 * <code>Code <b>only</b> allows text.</code> |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1344 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1345 // Ignore tags that can't be children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1346 if (!isChildAllowed(currentTag(), token)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1347 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1348 // exclude closing tags of current tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1349 if (token.type !== TOKEN_CLOSE || !currentTag() || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1350 token.name !== currentTag().name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1351 token.name = '#'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1352 token.type = TOKEN_CONTENT; |
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 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1355 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1356 switch (token.type) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1357 case TOKEN_OPEN: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1358 // Check it this closes a parent, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1359 // e.g. for lists [*]one [*]two |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1360 if (closesCurrentTag(token.name)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1361 openTags.pop(); |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1364 addTag(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1365 bbcode = bbcodeHandlers[token.name]; |
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 // 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
|
1368 // 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
|
1369 // 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
|
1370 // 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
|
1371 // 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
|
1372 if (bbcode && !bbcode.isSelfClosing && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1373 (bbcode.closedBy || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1374 hasTag(token.name, TOKEN_CLOSE, toks))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1375 openTags.push(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1376 } else if (!bbcode || !bbcode.isSelfClosing) { |
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 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1379 break; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1380 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1381 case TOKEN_CLOSE: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1382 // check if this closes the current tag, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1383 // e.g. [/list] would close an open [*] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1384 if (currentTag() && token.name !== currentTag().name && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1385 closesCurrentTag('/' + token.name)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1386 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1387 openTags.pop(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1388 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1389 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1390 // 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
|
1391 // the close tag off the open tags array |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1392 if (currentTag() && token.name === currentTag().name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1393 currentTag().closing = token; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1394 openTags.pop(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1395 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1396 // 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
|
1397 // 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
|
1398 // current one until reaching the parent that is being |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1399 // 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
|
1400 // in. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1401 } else if (hasTag(token.name, TOKEN_OPEN, openTags)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1402 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1403 // Remove the tag from the open tags |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1404 while ((curTok = openTags.pop())) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1405 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1406 // 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
|
1407 // discard it and break the loop. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1408 if (curTok.name === token.name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1409 curTok.closing = token; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1410 break; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1411 } |
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 // Otherwise clone this tag and then add any |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1414 // previously cloned tags as it's children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1415 clone = curTok.clone(); |
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 if (cloned.length) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1418 clone.children.push(last(cloned)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1419 } |
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 cloned.push(clone); |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1424 // Place block linebreak before cloned tags |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1425 if (next && next.type === TOKEN_NEWLINE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1426 bbcode = bbcodeHandlers[token.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1427 if (bbcode && bbcode.isInline === false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1428 addTag(next); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1429 toks.shift(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1430 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1431 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1432 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1433 // 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
|
1434 // (the parent of the tag which was being closed) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1435 addTag(last(cloned)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1436 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1437 // 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
|
1438 i = cloned.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1439 while (i--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1440 openTags.push(cloned[i]); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1441 } |
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 cloned.length = 0; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1444 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1445 // 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
|
1446 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1447 token.type = TOKEN_CONTENT; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1448 addTag(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1449 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1450 break; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1451 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1452 case TOKEN_NEWLINE: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1453 // handle things like |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1454 // [*]list\nitem\n[*]list1 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1455 // where it should come out as |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1456 // [*]list\nitem[/*]\n[*]list1[/*] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1457 // instead of |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1458 // [*]list\nitem\n[/*][*]list1[/*] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1459 if (currentTag() && next && closesCurrentTag( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1460 (next.type === TOKEN_CLOSE ? '/' : '') + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1461 next.name |
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 // 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
|
1464 // the option tag, i.e. [/*] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1465 if (!(next.type === TOKEN_CLOSE && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1466 next.name === currentTag().name)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1467 bbcode = bbcodeHandlers[currentTag().name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1468 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1469 if (bbcode && bbcode.breakAfter) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1470 openTags.pop(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1471 } else if (bbcode && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1472 bbcode.isInline === false && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1473 base.opts.breakAfterBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1474 bbcode.breakAfter !== false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1475 openTags.pop(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1476 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1477 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1478 } |
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 addTag(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1481 break; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1482 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1483 default: // content |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1484 addTag(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1485 break; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1486 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1487 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1488 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1489 return output; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1490 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1491 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1492 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1493 * Normalise all new lines |
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 * Removes any formatting new lines from the BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1496 * leaving only content ones. I.e. for a list: |
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 * [list] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1499 * [*] list item one |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1500 * with a line break |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1501 * [*] list item two |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1502 * [/list] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1503 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1504 * would become |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1505 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1506 * [list] [*] list item one |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1507 * with a line break [*] list item two [/list] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1508 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1509 * 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
|
1510 * the formatting new lines back in when converting |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1511 * back to BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1512 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1513 * @param {array} children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1514 * @param {TokenizeToken} parent |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1515 * @param {boolean} onlyRemoveBreakAfter |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1516 * @return {void} |
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 function normaliseNewLines(children, parent, onlyRemoveBreakAfter) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1519 var token, left, right, parentBBCode, bbcode, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1520 removedBreakEnd, removedBreakBefore, remove; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1521 var childrenLength = children.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1522 // TODO: this function really needs tidying up |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1523 if (parent) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1524 parentBBCode = bbcodeHandlers[parent.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1525 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1526 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1527 var i = childrenLength; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1528 while (i--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1529 if (!(token = children[i])) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1530 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1531 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1532 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1533 if (token.type === TOKEN_NEWLINE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1534 left = i > 0 ? children[i - 1] : null; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1535 right = i < childrenLength - 1 ? children[i + 1] : null; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1536 remove = false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1537 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1538 // Handle the start and end new lines |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1539 // e.g. [tag]\n and \n[/tag] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1540 if (!onlyRemoveBreakAfter && parentBBCode && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1541 parentBBCode.isSelfClosing !== true) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1542 // 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
|
1543 // (breakStartBlock, breakStart) e.g. [tag]\n |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1544 if (!left) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1545 if (parentBBCode.isInline === false && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1546 base.opts.breakStartBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1547 parentBBCode.breakStart !== false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1548 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1549 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1550 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1551 if (parentBBCode.breakStart) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1552 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1553 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1554 // 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
|
1555 // (breakEndBlock, breakEnd) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1556 // e.g. \n[/tag] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1557 // remove last line break (breakEndBlock, breakEnd) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1558 } else if (!removedBreakEnd && !right) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1559 if (parentBBCode.isInline === false && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1560 base.opts.breakEndBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1561 parentBBCode.breakEnd !== false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1562 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1563 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1564 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1565 if (parentBBCode.breakEnd) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1566 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1567 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1568 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1569 removedBreakEnd = remove; |
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 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1572 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1573 if (left && left.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1574 if ((bbcode = bbcodeHandlers[left.name])) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1575 if (!onlyRemoveBreakAfter) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1576 if (bbcode.isInline === false && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1577 base.opts.breakAfterBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1578 bbcode.breakAfter !== false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1579 remove = true; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1582 if (bbcode.breakAfter) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1583 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1584 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1585 } else if (bbcode.isInline === false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1586 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1587 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1588 } |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1591 if (!onlyRemoveBreakAfter && !removedBreakBefore && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1592 right && right.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1593 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1594 if ((bbcode = bbcodeHandlers[right.name])) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1595 if (bbcode.isInline === false && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1596 base.opts.breakBeforeBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1597 bbcode.breakBefore !== false) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1598 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1599 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1600 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1601 if (bbcode.breakBefore) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1602 remove = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1603 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1604 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1605 removedBreakBefore = remove; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1606 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1607 if (remove) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1608 children.splice(i, 1); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1609 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1610 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1611 } |
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 if (remove) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1615 children.splice(i, 1); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1616 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1617 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1618 // reset double removedBreakBefore removal protection. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1619 // 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
|
1620 // 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
|
1621 // would be. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1622 removedBreakBefore = false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1623 } else if (token.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1624 normaliseNewLines(token.children, token, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1625 onlyRemoveBreakAfter); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1626 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1627 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1628 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1629 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1630 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1631 * Fixes any invalid nesting. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1632 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1633 * 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
|
1634 * 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
|
1635 * 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
|
1636 * parts. i.e. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1637 * [inline]A[blocklevel]B[/blocklevel]C[/inline] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1638 * Will become: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1639 * [inline]A[/inline][blocklevel]B[/blocklevel][inline]C[/inline] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1640 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1641 * @param {array} children |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1642 * @param {array} [parents] Null if there is no parents |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1643 * @param {boolea} [insideInline] If inside an inline element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1644 * @param {array} [rootArr] Root array if there is one |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1645 * @return {array} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1646 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1647 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1648 function fixNesting(children, parents, insideInline, rootArr) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1649 var token, i, parent, parentIndex, parentParentChildren, right; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1650 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1651 var isInline = function (token) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1652 var bbcode = bbcodeHandlers[token.name]; |
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 return !bbcode || bbcode.isInline !== false; |
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 parents = parents || []; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1658 rootArr = rootArr || children; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1659 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1660 // 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
|
1661 // tokens are moved to fix the nesting. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1662 for (i = 0; i < children.length; i++) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1663 if (!(token = children[i]) || token.type !== TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1664 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1665 } |
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 if (insideInline && !isInline(token)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1668 // 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
|
1669 // split the parent at the block level element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1670 parent = last(parents); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1671 right = parent.splitAt(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1672 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1673 parentParentChildren = parents.length > 1 ? |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1674 parents[parents.length - 2].children : rootArr; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1675 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1676 // 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
|
1677 // wrap this tags children in it. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1678 if (isChildAllowed(token, parent)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1679 var clone = parent.clone(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1680 clone.children = token.children; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1681 token.children = [clone]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1682 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1683 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1684 parentIndex = parentParentChildren.indexOf(parent); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1685 if (parentIndex > -1) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1686 // 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
|
1687 // the split inline element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1688 right.children.splice(0, 1); |
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 // 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
|
1691 // the left side of the inline token |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1692 parentParentChildren.splice( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1693 parentIndex + 1, 0, token, right |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1694 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1695 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1696 // 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
|
1697 // 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
|
1698 var next = right.children[0]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1699 if (next && next.type === TOKEN_NEWLINE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1700 if (!isInline(token)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1701 right.children.splice(0, 1); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1702 parentParentChildren.splice( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1703 parentIndex + 2, 0, next |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1704 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1705 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1706 } |
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 // return to parents loop as the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1709 // children have now increased |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1710 return; |
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 |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1715 parents.push(token); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1716 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1717 fixNesting( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1718 token.children, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1719 parents, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1720 insideInline || isInline(token), |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1721 rootArr |
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 parents.pop(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1725 } |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1728 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1729 * 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
|
1730 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1731 * @param {array} tokens |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1732 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1733 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1734 function removeEmpty(tokens) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1735 var token, bbcode; |
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 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1738 * Checks if all children are whitespace or not |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1739 * @private |
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 var isTokenWhiteSpace = function (children) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1742 var j = children.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1743 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1744 while (j--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1745 var type = children[j].type; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1746 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1747 if (type === TOKEN_OPEN || type === TOKEN_CLOSE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1748 return false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1749 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1750 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1751 if (type === TOKEN_CONTENT && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1752 /\S|\u00A0/.test(children[j].val)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1753 return false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1754 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1755 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1756 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1757 return true; |
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 var i = tokens.length; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1761 while (i--) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1762 // 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
|
1763 // empty, content can't |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1764 if (!(token = tokens[i]) || token.type !== TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1765 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1766 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1767 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1768 bbcode = bbcodeHandlers[token.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1769 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1770 // 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
|
1771 // 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
|
1772 removeEmpty(token.children); |
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 if (isTokenWhiteSpace(token.children) && bbcode && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1775 !bbcode.isSelfClosing && !bbcode.allowsEmpty) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1776 tokens.splice.apply(tokens, [i, 1].concat(token.children)); |
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 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1779 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1780 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1781 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1782 * Converts a BBCode string to HTML |
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 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1785 * @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
|
1786 * strip any based on the passed |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1787 * formatting options |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1788 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1789 * @memberOf BBCodeParser.prototype |
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 base.toHTML = function (str, preserveNewLines) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1792 return convertToHTML(base.parse(str, preserveNewLines), true); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1793 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1794 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1795 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1796 * @private |
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 function convertToHTML(tokens, isRoot) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1799 var undef, token, bbcode, content, html, needsBlockWrap, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1800 blockWrapOpen, isInline, lastChild, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1801 ret = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1802 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1803 isInline = function (bbcode) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1804 return (!bbcode || (bbcode.isHtmlInline !== undef ? |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1805 bbcode.isHtmlInline : bbcode.isInline)) !== false; |
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 while (tokens.length > 0) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1809 if (!(token = tokens.shift())) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1810 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1811 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1812 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1813 if (token.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1814 lastChild = token.children[token.children.length - 1] || {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1815 bbcode = bbcodeHandlers[token.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1816 needsBlockWrap = isRoot && isInline(bbcode); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1817 content = convertToHTML(token.children, false); |
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 (bbcode && bbcode.html) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1820 // 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
|
1821 // blocklevel and the last child wasn't block-level |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1822 if (!isInline(bbcode) && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1823 isInline(bbcodeHandlers[lastChild.name]) && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1824 !bbcode.isPreFormatted && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1825 !bbcode.skipLastLineBreak) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1826 // Add placeholder br to end of block level |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1827 // elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1828 content += '<br />'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1829 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1830 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1831 if (!isFunction(bbcode.html)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1832 token.attrs['0'] = content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1833 html = formatBBCodeString( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1834 bbcode.html, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1835 token.attrs |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1836 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1837 } else { |
26 | 1838 html = bbcode.html( |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1839 token, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1840 token.attrs, |
33 | 1841 content, |
1842 editor | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1843 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1844 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1845 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1846 html = token.val + content + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1847 (token.closing ? token.closing.val : ''); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1848 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1849 } else if (token.type === TOKEN_NEWLINE) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1850 if (!isRoot) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1851 ret += '<br />'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1852 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1853 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1854 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1855 // 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
|
1856 if (!blockWrapOpen) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1857 ret += '<div>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1858 } |
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 ret += '<br />'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1861 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1862 // 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
|
1863 // whatever comes after onto a new line. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1864 // 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
|
1865 // shows as there will be nothing after it. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1866 if (!tokens.length) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1867 ret += '<br />'; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1870 ret += '</div>\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1871 blockWrapOpen = false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1872 continue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1873 // content |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1874 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1875 needsBlockWrap = isRoot; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1876 html = escapeEntities(token.val, true); |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1879 if (needsBlockWrap && !blockWrapOpen) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1880 ret += '<div>'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1881 blockWrapOpen = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1882 } else if (!needsBlockWrap && blockWrapOpen) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1883 ret += '</div>\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1884 blockWrapOpen = false; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1885 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1886 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1887 ret += html; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1888 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1889 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1890 if (blockWrapOpen) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1891 ret += '</div>\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1892 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1893 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1894 return ret; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1895 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1896 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1897 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1898 * 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
|
1899 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1900 * 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
|
1901 * options. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1902 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1903 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1904 * @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
|
1905 * strip any based on the passed |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1906 * formatting options |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1907 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1908 * @memberOf BBCodeParser.prototype |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1909 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1910 base.toBBCode = function (str, preserveNewLines) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1911 return convertToBBCode(base.parse(str, preserveNewLines)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1912 }; |
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 * Converts parsed tokens back into BBCode with the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1916 * formatting specified in the options and with any |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1917 * fixes specified. |
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 * @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
|
1920 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1921 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1922 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1923 function convertToBBCode(toks) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1924 var token, attr, bbcode, isBlock, isSelfClosing, quoteType, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1925 breakBefore, breakStart, breakEnd, breakAfter, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1926 ret = ''; |
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 while (toks.length > 0) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1929 if (!(token = toks.shift())) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1930 continue; |
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 // TODO: tidy this |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1933 bbcode = bbcodeHandlers[token.name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1934 isBlock = !(!bbcode || bbcode.isInline !== false); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1935 isSelfClosing = bbcode && bbcode.isSelfClosing; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1936 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1937 breakBefore = (isBlock && base.opts.breakBeforeBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1938 bbcode.breakBefore !== false) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1939 (bbcode && bbcode.breakBefore); |
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 breakStart = (isBlock && !isSelfClosing && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1942 base.opts.breakStartBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1943 bbcode.breakStart !== false) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1944 (bbcode && bbcode.breakStart); |
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 breakEnd = (isBlock && base.opts.breakEndBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1947 bbcode.breakEnd !== false) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1948 (bbcode && bbcode.breakEnd); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1949 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1950 breakAfter = (isBlock && base.opts.breakAfterBlock && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1951 bbcode.breakAfter !== false) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1952 (bbcode && bbcode.breakAfter); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1953 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1954 quoteType = (bbcode ? bbcode.quoteType : null) || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1955 base.opts.quoteType || QuoteType.auto; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1956 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1957 if (!bbcode && token.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1958 ret += token.val; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1959 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1960 if (token.children) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1961 ret += convertToBBCode(token.children); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1962 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1963 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1964 if (token.closing) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1965 ret += token.closing.val; |
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 } else if (token.type === TOKEN_OPEN) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1968 if (breakBefore) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1969 ret += '\n'; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1972 // Convert the tag and it's attributes to BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1973 ret += '[' + token.name; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1974 if (token.attrs) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1975 if (token.attrs.defaultattr) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1976 ret += '=' + quote( |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1977 token.attrs.defaultattr, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1978 quoteType, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1979 'defaultattr' |
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 delete token.attrs.defaultattr; |
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 for (attr in token.attrs) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1986 if (token.attrs.hasOwnProperty(attr)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1987 ret += ' ' + attr + '=' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1988 quote(token.attrs[attr], quoteType, attr); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1989 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1990 } |
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 ret += ']'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1993 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1994 if (breakStart) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1995 ret += '\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1996 } |
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 // Convert the tags children to BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1999 if (token.children) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2000 ret += convertToBBCode(token.children); |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2003 // add closing tag if not self closing |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2004 if (!isSelfClosing && !bbcode.excludeClosing) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2005 if (breakEnd) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2006 ret += '\n'; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2009 ret += '[/' + token.name + ']'; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2012 if (breakAfter) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2013 ret += '\n'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2014 } |
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 // preserve whatever was recognized as the |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2017 // closing tag if it is a self closing tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2018 if (token.closing && isSelfClosing) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2019 ret += token.closing.val; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2020 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2021 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2022 ret += token.val; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2023 } |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2026 return ret; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2027 } |
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 * Quotes an attribute |
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 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2033 * @param {BBCodeParser.QuoteType} quoteType |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2034 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2035 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2036 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2037 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2038 function quote(str, quoteType, name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2039 var needsQuotes = /\s|=/.test(str); |
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 if (isFunction(quoteType)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2042 return quoteType(str, name); |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2045 if (quoteType === QuoteType.never || |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2046 (quoteType === QuoteType.auto && !needsQuotes)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2047 return str; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2048 } |
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 return '"' + str.replace(/\\/g, '\\\\').replace(/"/g, '\\"') + '"'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2051 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2052 |
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 * Returns the last element of an array or null |
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 * @param {array} arr |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2057 * @return {Object} Last element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2058 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2059 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2060 function last(arr) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2061 if (arr.length) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2062 return arr[arr.length - 1]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2063 } |
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 return null; |
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 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2069 * Converts a string to lowercase. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2070 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2071 * @param {string} str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2072 * @return {string} Lowercase version of str |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2073 * @private |
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 function lower(str) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2076 return str.toLowerCase(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2077 } |
25 | 2078 |
2079 return base; | |
0
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 |
25 | 2082 var BBCodeParser = {}; |
2083 | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2084 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2085 * Quote type |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2086 * @type {Object} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2087 * @class QuoteType |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2088 * @name BBCodeParser.QuoteType |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2089 * @since 1.4.0 |
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 BBCodeParser.QuoteType = QuoteType; |
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 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2094 * Default BBCode parser options |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2095 * @type {Object} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2096 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2097 BBCodeParser.defaults = { |
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 * 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
|
2100 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2101 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2102 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2103 breakBeforeBlock: false, |
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 * 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
|
2107 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2108 * @type {Boolean} |
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 breakStartBlock: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2111 |
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 * 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
|
2114 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2115 * @type {Boolean} |
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 breakEndBlock: false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2118 |
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 * 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
|
2121 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2122 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2123 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2124 breakAfterBlock: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2125 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2126 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2127 * If to remove empty tags |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2128 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2129 * @type {Boolean} |
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 removeEmptyTags: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2132 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2133 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2134 * If to fix invalid nesting, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2135 * i.e. block level elements inside inline elements. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2136 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2137 * @type {Boolean} |
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 fixInvalidNesting: true, |
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 * If to fix invalid children. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2143 * 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
|
2144 * allow that type of tag. |
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 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2147 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2148 fixInvalidChildren: true, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2149 |
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 * Attribute quote type |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2152 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2153 * @type {BBCodeParser.QuoteType} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2154 * @since 1.4.1 |
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 quoteType: QuoteType.auto, |
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 * Whether to use strict matching on attributes and styles. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2160 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2161 * 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
|
2162 * attributes and styles to match. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2163 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2164 * 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
|
2165 * a tags attributes or styles match. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2166 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2167 * @type {Boolean} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2168 * @since 3.1.0 |
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 strictMatch: false |
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 |
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 * Converts a number 0-255 to hex. |
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 * 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
|
2177 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2178 * @param {any} number |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2179 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2180 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2181 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2182 function toHex(number) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2183 number = parseInt(number, 10); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2184 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2185 if (isNaN(number)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2186 return '00'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2187 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2188 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2189 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
|
2190 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2191 return number.length < 2 ? '0' + number : number; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2192 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2193 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2194 * Normalises a CSS colour to hex #xxxxxx format |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2195 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2196 * @param {string} colorStr |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2197 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2198 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2199 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2200 function _normaliseColour(colorStr) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2201 var match; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2202 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2203 colorStr = colorStr || '#000'; |
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 // rgb(n,n,n); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2206 if ((match = |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2207 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
|
2208 return '#' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2209 toHex(match[1]) + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2210 toHex(match[2]) + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2211 toHex(match[3]); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2212 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2213 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2214 // expand shorthand |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2215 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
|
2216 return '#' + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2217 match[1] + match[1] + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2218 match[2] + match[2] + |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2219 match[3] + match[3]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2220 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2221 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2222 return colorStr; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2223 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2224 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2225 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2226 * SCEditor BBCode format |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2227 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2228 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2229 function bbcodeFormat() { |
25 | 2230 var base = {}; |
0
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 base.stripQuotes = _stripQuotes; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2233 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2234 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2235 * 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
|
2236 * faster lookup of which bbcode a tag should have |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2237 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2238 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2239 var tagsToBBCodes = {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2240 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2241 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2242 * 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
|
2243 * children other than text nodes are allowed |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2244 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2245 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2246 var validChildren = { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2247 ul: ['li', 'ol', 'ul'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2248 ol: ['li', 'ol', 'ul'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2249 table: ['tr'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2250 tr: ['td', 'th'], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2251 code: ['br', 'p', 'div'] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2252 }; |
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 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2255 * Populates tagsToBBCodes and stylesToBBCodes for easier lookups |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2256 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2257 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2258 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2259 function buildBbcodeCache() { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2260 each(bbcodeHandlers, function (bbcode, handler) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2261 var |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2262 isBlock = handler.isInline === false, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2263 tags = bbcodeHandlers[bbcode].tags, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2264 styles = bbcodeHandlers[bbcode].styles; |
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 if (styles) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2267 tagsToBBCodes['*'] = tagsToBBCodes['*'] || {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2268 tagsToBBCodes['*'][isBlock] = |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2269 tagsToBBCodes['*'][isBlock] || {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2270 tagsToBBCodes['*'][isBlock][bbcode] = [ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2271 ['style', Object.entries(styles)] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2272 ]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2273 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2274 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2275 if (tags) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2276 each(tags, function (tag, values) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2277 if (values && values.style) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2278 values.style = Object.entries(values.style); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2279 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2280 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2281 tagsToBBCodes[tag] = tagsToBBCodes[tag] || {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2282 tagsToBBCodes[tag][isBlock] = |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2283 tagsToBBCodes[tag][isBlock] || {}; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2284 tagsToBBCodes[tag][isBlock][bbcode] = |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2285 values && Object.entries(values); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2286 }); |
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 }; |
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 * Handles adding newlines after block level elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2293 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2294 * @param {HTMLElement} element The element to convert |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2295 * @param {string} content The tags text content |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2296 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2297 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2298 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2299 function handleBlockNewlines(element, content) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2300 var tag = element.nodeName.toLowerCase(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2301 var isInline = dom.isInline; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2302 if (!isInline(element, true) || tag === 'br') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2303 var isLastBlockChild, parent, parentLastChild, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2304 previousSibling = element.previousSibling; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2305 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2306 // Skips selection makers and ignored elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2307 // Skip empty inline elements |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2308 while (previousSibling && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2309 previousSibling.nodeType === 1 && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2310 !is(previousSibling, 'br') && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2311 isInline(previousSibling, true) && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2312 !previousSibling.firstChild) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2313 previousSibling = previousSibling.previousSibling; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2314 } |
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 // 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
|
2317 // 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
|
2318 // <block><inline><br></inline></block> |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2319 do { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2320 parent = element.parentNode; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2321 parentLastChild = parent && parent.lastChild; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2322 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2323 isLastBlockChild = parentLastChild === element; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2324 element = parent; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2325 } while (parent && isLastBlockChild && isInline(parent, true)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2326 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2327 // If this block is: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2328 // * Not the last child of a block level element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2329 // * Is a <li> tag (lists are blocks) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2330 if (!isLastBlockChild || tag === 'li') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2331 content += '\n'; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2334 // Check for: |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2335 // <block>text<block>text</block></block> |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2336 // |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2337 // The second opening <block> opening tag should cause a |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2338 // line break because the previous sibing is inline. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2339 if (tag !== 'br' && previousSibling && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2340 !is(previousSibling, 'br') && |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2341 isInline(previousSibling, true)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2342 content = '\n' + content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2343 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2344 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2345 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2346 return content; |
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 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2350 * Handles a HTML tag and finds any matching BBCodes |
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 * @param {HTMLElement} element The element to convert |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2353 * @param {string} content The Tags text content |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2354 * @param {boolean} blockLevel |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2355 * @return {string} Content with any matching BBCode tags |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2356 * wrapped around it. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2357 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2358 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2359 function handleTags(element, content, blockLevel) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2360 function isStyleMatch(style) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2361 var property = style[0]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2362 var values = style[1]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2363 var val = dom.getStyle(element, property); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2364 var parent = element.parentNode; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2365 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2366 // 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
|
2367 // 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
|
2368 if (!val || parent && dom.hasStyle(parent, property, val)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2369 return false; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2372 return !values || values.includes(val); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2373 } |
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 function createAttributeMatch(isStrict) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2376 return function (attribute) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2377 var name = attribute[0]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2378 var value = attribute[1]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2379 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2380 // code tags should skip most styles |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2381 if (name === 'style' && element.nodeName === 'CODE') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2382 return false; |
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 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2385 if (name === 'style' && value) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2386 return value[isStrict ? 'every' : 'some'](isStyleMatch); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2387 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2388 var val = attr(element, name); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2389 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2390 return val && (!value || value.includes(val)); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2391 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2392 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2393 } |
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 function handleTag(tag) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2396 if (!tagsToBBCodes[tag] || !tagsToBBCodes[tag][blockLevel]) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2397 return; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2398 } |
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 // loop all bbcodes for this tag |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2401 each(tagsToBBCodes[tag][blockLevel], function (bbcode, attrs) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2402 var fn, format, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2403 isStrict = bbcodeHandlers[bbcode].strictMatch; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2404 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2405 if (typeof isStrict === 'undefined') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2406 isStrict = base.opts.strictMatch; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2407 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2408 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2409 // 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
|
2410 // attribute doesn't match one of the required values |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2411 fn = isStrict ? 'every' : 'some'; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2412 if (attrs && !attrs[fn](createAttributeMatch(isStrict))) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2413 return; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2414 } |
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 format = bbcodeHandlers[bbcode].format; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2417 if (isFunction(format)) { |
26 | 2418 content = format(element, content, base); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2419 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2420 content = _formatString(format, content); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2421 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2422 return false; |
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 } |
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 handleTag('*'); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2427 handleTag(element.nodeName.toLowerCase()); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2428 return content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2429 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2430 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2431 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2432 * Converts a HTML dom element to BBCode starting from |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2433 * the innermost element and working backwards |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2434 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2435 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2436 * @param {HTMLElement} element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2437 * @return {string} BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2438 * @memberOf SCEditor.plugins.bbcode.prototype |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2439 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2440 function elementToBbcode(element) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2441 var toBBCode = function (node, vChildren) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2442 var ret = ''; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2443 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2444 dom.traverse(node, function (node) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2445 var content = '', |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2446 nodeType = node.nodeType, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2447 tag = node.nodeName.toLowerCase(), |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2448 vChild = validChildren[tag], |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2449 firstChild = node.firstChild, |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2450 isValidChild = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2451 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2452 if (typeof vChildren === 'object') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2453 isValidChild = vChildren.indexOf(tag) > -1; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2454 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2455 // Emoticons should always be converted |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2456 if (is(node, 'img') && attr(node, EMOTICON_DATA_ATTR)) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2457 isValidChild = true; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2458 } |
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 // 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
|
2461 // then set this tags allowed children to whatever it |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2462 // allows, otherwise set to what the parent allows |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2463 if (!isValidChild) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2464 vChild = vChildren; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2465 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2466 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2467 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2468 // 3 = text and 1 = element |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2469 if (nodeType !== 3 && nodeType !== 1) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2470 return; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2471 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2472 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2473 if (nodeType === 1) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2474 // skip empty nlf elements (new lines automatically |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2475 // added after block level elements like quotes) |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2476 if (is(node, '.sceditor-nlf') && !firstChild) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2477 return; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2478 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2479 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2480 // don't convert iframe contents |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2481 if (tag !== 'iframe') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2482 content = toBBCode(node, vChild); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2483 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2484 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2485 // TODO: isValidChild is no longer needed. Should use |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2486 // valid children bbcodes instead by creating BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2487 // tokens like the parser. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2488 if (isValidChild) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2489 // code tags should skip most styles |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2490 if (tag !== 'code') { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2491 // First parse inline codes |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2492 content = handleTags(node, content, false); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2493 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2494 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2495 content = handleTags(node, content, true); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2496 ret += handleBlockNewlines(node, content); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2497 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2498 ret += content; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2499 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2500 } else { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2501 ret += node.nodeValue; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2502 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2503 }, false, true); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2504 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2505 return ret; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2506 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2507 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2508 return toBBCode(element); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2509 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2510 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2511 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2512 * Initializer |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2513 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2514 */ |
24 | 2515 base.init = function (editor) { |
33 | 2516 base.editor = editor; |
24 | 2517 base.opts = editor.opts; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2518 base.elementToBbcode = elementToBbcode; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2519 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2520 // build the BBCode cache |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2521 buildBbcodeCache(); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2522 |
30
db061869f28f
remove sceditor.command, add options.onCreate
Franklin Schmidt <fschmidt@gmail.com>
parents:
27
diff
changeset
|
2523 editor.commands = extendDeep( |
33 | 2524 {}, editor.commands, defaultCommandsOverrides |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2525 ); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2526 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2527 // Add BBCode helper methods |
24 | 2528 editor.toBBCode = base.toSource; |
2529 editor.fromBBCode = base.toHtml; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2530 }; |
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 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2533 * Converts BBCode into HTML |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2534 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2535 * @param {boolean} asFragment |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2536 * @param {string} source |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2537 * @param {boolean} [legacyAsFragment] Used by fromBBCode() method |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2538 */ |
27 | 2539 function toHtml(asFragment) { |
2540 return function(source, legacyAsFragment) { | |
33 | 2541 var parser = newBBCodeParser(base.editor); |
27 | 2542 var html = parser.toHTML( |
2543 base.opts.bbcodeTrim ? source.trim() : source | |
2544 ); | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2545 |
27 | 2546 return (asFragment || legacyAsFragment) ? |
2547 removeFirstLastDiv(html) : html; | |
2548 }; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2549 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2550 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2551 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2552 * Converts HTML into 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 * @param {boolean} asFragment |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2555 * @param {string} html |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2556 * @param {!Document} [context] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2557 * @param {!HTMLElement} [parent] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2558 * @return {string} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2559 * @private |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2560 */ |
27 | 2561 function toSource(asFragment) { |
2562 return function(html, context, parent) { | |
2563 context = context || document; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2564 |
27 | 2565 var bbcode, elements; |
2566 var containerParent = context.createElement('div'); | |
2567 var container = context.createElement('div'); | |
33 | 2568 var parser = newBBCodeParser(base.editor); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2569 |
27 | 2570 container.innerHTML = html; |
2571 css(containerParent, 'visibility', 'hidden'); | |
2572 containerParent.appendChild(container); | |
2573 context.body.appendChild(containerParent); | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2574 |
27 | 2575 if (asFragment) { |
2576 // Add text before and after so removeWhiteSpace doesn't remove | |
2577 // leading and trailing whitespace | |
2578 containerParent.insertBefore( | |
2579 context.createTextNode('#'), | |
2580 containerParent.firstChild | |
2581 ); | |
2582 containerParent.appendChild(context.createTextNode('#')); | |
2583 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2584 |
27 | 2585 // Match parents white-space handling |
2586 if (parent) { | |
2587 css(container, 'whiteSpace', css(parent, 'whiteSpace')); | |
2588 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2589 |
27 | 2590 // Remove all nodes with sceditor-ignore class |
2591 elements = container.getElementsByClassName('sceditor-ignore'); | |
2592 while (elements.length) { | |
2593 elements[0].parentNode.removeChild(elements[0]); | |
2594 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2595 |
27 | 2596 dom.removeWhiteSpace(containerParent); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2597 |
27 | 2598 bbcode = elementToBbcode(container); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2599 |
27 | 2600 context.body.removeChild(containerParent); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2601 |
27 | 2602 bbcode = parser.toBBCode(bbcode, true); |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2603 |
27 | 2604 if (base.opts.bbcodeTrim) { |
2605 bbcode = bbcode.trim(); | |
2606 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2607 |
27 | 2608 return bbcode; |
2609 }; | |
2610 } | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2611 |
27 | 2612 base.toHtml = toHtml(false); |
2613 base.fragmentToHtml = toHtml(true); | |
2614 base.toSource = toSource(false); | |
2615 base.fragmentToSource = toSource(true); | |
25 | 2616 |
2617 return base; | |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2618 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2619 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2620 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2621 * Gets a BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2622 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2623 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2624 * @return {Object|null} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2625 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2626 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2627 bbcodeFormat.get = function (name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2628 return bbcodeHandlers[name] || null; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2629 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2630 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2631 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2632 * 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
|
2633 * 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
|
2634 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2635 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2636 * @param {Object} bbcode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2637 * @return {this} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2638 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2639 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2640 bbcodeFormat.set = function (name, bbcode) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2641 if (name && bbcode) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2642 // merge any existing command properties |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2643 bbcode = extend(bbcodeHandlers[name] || {}, bbcode); |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2644 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2645 bbcode.remove = function () { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2646 delete bbcodeHandlers[name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2647 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2648 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2649 bbcodeHandlers[name] = bbcode; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2650 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2651 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2652 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2653 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2654 * Renames a BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2655 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2656 * 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
|
2657 * changed manually. |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2658 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2659 * @param {string} name [description] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2660 * @param {string} newName [description] |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2661 * @return {this|false} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2662 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2663 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2664 bbcodeFormat.rename = function (name, newName) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2665 if (name in bbcodeHandlers) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2666 bbcodeHandlers[newName] = bbcodeHandlers[name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2667 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2668 delete bbcodeHandlers[name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2669 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2670 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2671 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2672 /** |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2673 * Removes a BBCode |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2674 * |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2675 * @param {string} name |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2676 * @return {this} |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2677 * @since 2.0.0 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2678 */ |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2679 bbcodeFormat.remove = function (name) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2680 if (name in bbcodeHandlers) { |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2681 delete bbcodeHandlers[name]; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2682 } |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2683 }; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2684 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2685 bbcodeFormat.formatBBCodeString = formatBBCodeString; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2686 |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2687 sceditor.formats.bbcode = bbcodeFormat; |
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2688 sceditor.BBCodeParser = BBCodeParser; |
14
0cb206904499
formats set default format
Franklin Schmidt <fschmidt@gmail.com>
parents:
4
diff
changeset
|
2689 sceditor.defaultOptions.format = 'bbcode'; |
0
4c4fc447baea
start with sceditor-3.1.1
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2690 }(sceditor)); |