]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/debian/missing-sources/framework/Web/Javascripts/source/tinymce-405/plugins/paste/classes/Quirks.js
baculum: Add missing-sources directory in debian metadata structure
[bacula/bacula] / gui / baculum / debian / missing-sources / framework / Web / Javascripts / source / tinymce-405 / plugins / paste / classes / Quirks.js
1 /**
2  * Quirks.js
3  *
4  * Copyright, Moxiecode Systems AB
5  * Released under LGPL License.
6  *
7  * License: http://www.tinymce.com/license
8  * Contributing: http://www.tinymce.com/contributing
9  */
10
11 /**
12  * This class contains various fixes for browsers. These issues can not be feature
13  * detected since we have no direct control over the clipboard. However we might be able
14  * to remove some of these fixes once the browsers gets updated/fixed.
15  *
16  * @class tinymce.pasteplugin.Quirks
17  * @private
18  */
19 define("tinymce/pasteplugin/Quirks", [
20         "tinymce/Env",
21         "tinymce/util/Tools"
22 ], function(Env, Tools) {
23         "use strict";
24
25         return function(editor) {
26                 var explorerBlocksRegExp;
27
28                 function addPreProcessFilter(filterFunc) {
29                         editor.on('PastePreProcess', function(e) {
30                                 e.content = filterFunc(e.content);
31                         });
32                 }
33
34                 function process(content, items) {
35                         Tools.each(items, function(v) {
36                                 if (v.constructor == RegExp) {
37                                         content = content.replace(v, '');
38                                 } else {
39                                         content = content.replace(v[0], v[1]);
40                                 }
41                         });
42
43                         return content;
44                 }
45
46                 /**
47                  * Removes WebKit fragment comments and converted-space spans.
48                  *
49                  * This:
50                  *   <!--StartFragment-->a<span class="Apple-converted-space">&nbsp;</span>b<!--EndFragment-->
51                  *
52                  * Becomes:
53                  *   a&nbsp;b
54                  */
55                 function removeWebKitFragments(html) {
56                         html = process(html, [
57                                 /^[\s\S]*<!--StartFragment-->|<!--EndFragment-->[\s\S]*$/g,        // WebKit fragment
58                                 [/<span class="Apple-converted-space">\u00a0<\/span>/g, '\u00a0'], // WebKit &nbsp;
59                                 /<br>$/                                                                                                                    // Traling BR elements
60                         ]);
61
62                         return html;
63                 }
64
65                 /**
66                  * Removes BR elements after block elements. IE9 has a nasty bug where it puts a BR element after each
67                  * block element when pasting from word. This removes those elements.
68                  *
69                  * This:
70                  *  <p>a</p><br><p>b</p>
71                  *
72                  * Becomes:
73                  *  <p>a</p><p>b</p>
74                  */
75                 function removeExplorerBrElementsAfterBlocks(html) {
76                         // Produce block regexp based on the block elements in schema
77                         if (!explorerBlocksRegExp) {
78                                 var blockElements = [];
79
80                                 Tools.each(editor.schema.getBlockElements(), function(block, blockName) {
81                                         blockElements.push(blockName);
82                                 });
83
84                                 explorerBlocksRegExp = new RegExp(
85                                         '(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*(<\\/?(' + blockElements.join('|') + ')[^>]*>)(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*',
86                                         'g'
87                                 );
88                         }
89
90                         // Remove BR:s from: <BLOCK>X</BLOCK><BR>
91                         html = process(html, [
92                                 [explorerBlocksRegExp, '$1']
93                         ]);
94
95                         // IE9 also adds an extra BR element for each soft-linefeed and it also adds a BR for each word wrap break
96                         html = process(html, [
97                                 [/<br><br>/g, '<BR><BR>'], // Replace multiple BR elements with uppercase BR to keep them intact
98                                 [/<br>/g, ' '],            // Replace single br elements with space since they are word wrap BR:s
99                                 [/<BR><BR>/g, '<br>']      // Replace back the double brs but into a single BR
100                         ]);
101
102                         return html;
103                 }
104
105                 // Sniff browsers and apply fixes since we can't feature detect
106                 if (Env.webkit) {
107                         addPreProcessFilter(removeWebKitFragments);
108                 }
109
110                 if (Env.ie) {
111                         addPreProcessFilter(removeExplorerBrElementsAfterBlocks);
112                 }
113         };
114 });