]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/debian/missing-sources/framework/Web/Javascripts/source/tinymce-405/plugins/table/classes/CellSelection.js
baculum: Add missing-sources directory in debian metadata structure
[bacula/bacula] / gui / baculum / debian / missing-sources / framework / Web / Javascripts / source / tinymce-405 / plugins / table / classes / CellSelection.js
1 /**
2  * CellSelection.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 handles table cell selection by faking it using a css class that gets applied
13  * to cells when dragging the mouse from one cell to another.
14  *
15  * @class tinymce.tableplugin.CellSelection
16  * @private
17  */
18 define("tinymce/tableplugin/CellSelection", [
19         "tinymce/tableplugin/TableGrid",
20         "tinymce/dom/TreeWalker",
21         "tinymce/util/Tools"
22 ], function(TableGrid, TreeWalker, Tools) {
23         return function(editor) {
24                 var dom = editor.dom, tableGrid, startCell, startTable, hasCellSelection = true;
25
26                 function clear() {
27                         // Restore selection possibilities
28                         editor.getBody().style.webkitUserSelect = '';
29
30                         if (hasCellSelection) {
31                                 editor.dom.removeClass(
32                                         editor.dom.select('td.mce-item-selected,th.mce-item-selected'),
33                                         'mce-item-selected'
34                                 );
35
36                                 hasCellSelection = false;
37                         }
38                 }
39
40                 // Add cell selection logic
41                 editor.on('MouseDown', function(e) {
42                         if (e.button != 2) {
43                                 clear();
44
45                                 startCell = dom.getParent(e.target, 'td,th');
46                                 startTable = dom.getParent(startCell, 'table');
47                         }
48                 });
49
50                 dom.bind(editor.getDoc(), 'mouseover', function(e) {
51                         var sel, table, target = e.target;
52
53                         if (startCell && (tableGrid || target != startCell) && (target.nodeName == 'TD' || target.nodeName == 'TH')) {
54                                 table = dom.getParent(target, 'table');
55                                 if (table == startTable) {
56                                         if (!tableGrid) {
57                                                 tableGrid = new TableGrid(editor, table);
58                                                 tableGrid.setStartCell(startCell);
59
60                                                 editor.getBody().style.webkitUserSelect = 'none';
61                                         }
62
63                                         tableGrid.setEndCell(target);
64                                         hasCellSelection = true;
65                                 }
66
67                                 // Remove current selection
68                                 sel = editor.selection.getSel();
69
70                                 try {
71                                         if (sel.removeAllRanges) {
72                                                 sel.removeAllRanges();
73                                         } else {
74                                                 sel.empty();
75                                         }
76                                 } catch (ex) {
77                                         // IE9 might throw errors here
78                                 }
79
80                                 e.preventDefault();
81                         }
82                 });
83
84                 editor.on('MouseUp', function() {
85                         var rng, sel = editor.selection, selectedCells, walker, node, lastNode, endNode;
86
87                         function setPoint(node, start) {
88                                 var walker = new TreeWalker(node, node);
89
90                                 do {
91                                         // Text node
92                                         if (node.nodeType == 3 && Tools.trim(node.nodeValue).length !== 0) {
93                                                 if (start) {
94                                                         rng.setStart(node, 0);
95                                                 } else {
96                                                         rng.setEnd(node, node.nodeValue.length);
97                                                 }
98
99                                                 return;
100                                         }
101
102                                         // BR element
103                                         if (node.nodeName == 'BR') {
104                                                 if (start) {
105                                                         rng.setStartBefore(node);
106                                                 } else {
107                                                         rng.setEndBefore(node);
108                                                 }
109
110                                                 return;
111                                         }
112                                 } while ((node = (start ? walker.next() : walker.prev())));
113                         }
114
115                         // Move selection to startCell
116                         if (startCell) {
117                                 if (tableGrid) {
118                                         editor.getBody().style.webkitUserSelect = '';
119                                 }
120
121                                 // Try to expand text selection as much as we can only Gecko supports cell selection
122                                 selectedCells = dom.select('td.mce-item-selected,th.mce-item-selected');
123                                 if (selectedCells.length > 0) {
124                                         rng = dom.createRng();
125                                         node = selectedCells[0];
126                                         endNode = selectedCells[selectedCells.length - 1];
127                                         rng.setStartBefore(node);
128                                         rng.setEndAfter(node);
129
130                                         setPoint(node, 1);
131                                         walker = new TreeWalker(node, dom.getParent(selectedCells[0], 'table'));
132
133                                         do {
134                                                 if (node.nodeName == 'TD' || node.nodeName == 'TH') {
135                                                         if (!dom.hasClass(node, 'mce-item-selected')) {
136                                                                 break;
137                                                         }
138
139                                                         lastNode = node;
140                                                 }
141                                         } while ((node = walker.next()));
142
143                                         setPoint(lastNode);
144
145                                         sel.setRng(rng);
146                                 }
147
148                                 editor.nodeChanged();
149                                 startCell = tableGrid = startTable = null;
150                         }
151                 });
152
153                 editor.on('KeyUp', function() {
154                         clear();
155                 });
156
157                 return {
158                         clear: clear
159                 };
160         };
161 });