bgneal@45
|
1 tinyMCEPopup.requireLangPack();
|
bgneal@45
|
2
|
bgneal@45
|
3 function init() {
|
bgneal@45
|
4 tinyMCEPopup.resizeToInnerSize();
|
bgneal@45
|
5
|
bgneal@45
|
6 document.getElementById('backgroundimagebrowsercontainer').innerHTML = getBrowserHTML('backgroundimagebrowser','backgroundimage','image','table');
|
bgneal@45
|
7 document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor');
|
bgneal@45
|
8
|
bgneal@45
|
9 var inst = tinyMCEPopup.editor;
|
bgneal@45
|
10 var dom = inst.dom;
|
bgneal@45
|
11 var trElm = dom.getParent(inst.selection.getNode(), "tr");
|
bgneal@45
|
12 var formObj = document.forms[0];
|
bgneal@45
|
13 var st = dom.parseStyle(dom.getAttrib(trElm, "style"));
|
bgneal@45
|
14
|
bgneal@45
|
15 // Get table row data
|
bgneal@45
|
16 var rowtype = trElm.parentNode.nodeName.toLowerCase();
|
bgneal@45
|
17 var align = dom.getAttrib(trElm, 'align');
|
bgneal@45
|
18 var valign = dom.getAttrib(trElm, 'valign');
|
bgneal@45
|
19 var height = trimSize(getStyle(trElm, 'height', 'height'));
|
bgneal@45
|
20 var className = dom.getAttrib(trElm, 'class');
|
bgneal@45
|
21 var bgcolor = convertRGBToHex(getStyle(trElm, 'bgcolor', 'backgroundColor'));
|
bgneal@45
|
22 var backgroundimage = getStyle(trElm, 'background', 'backgroundImage').replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");;
|
bgneal@45
|
23 var id = dom.getAttrib(trElm, 'id');
|
bgneal@45
|
24 var lang = dom.getAttrib(trElm, 'lang');
|
bgneal@45
|
25 var dir = dom.getAttrib(trElm, 'dir');
|
bgneal@45
|
26
|
bgneal@45
|
27 // Setup form
|
bgneal@45
|
28 addClassesToList('class', 'table_row_styles');
|
bgneal@45
|
29 TinyMCE_EditableSelects.init();
|
bgneal@45
|
30
|
bgneal@45
|
31 formObj.bgcolor.value = bgcolor;
|
bgneal@45
|
32 formObj.backgroundimage.value = backgroundimage;
|
bgneal@45
|
33 formObj.height.value = height;
|
bgneal@45
|
34 formObj.id.value = id;
|
bgneal@45
|
35 formObj.lang.value = lang;
|
bgneal@45
|
36 formObj.style.value = dom.serializeStyle(st);
|
bgneal@45
|
37 selectByValue(formObj, 'align', align);
|
bgneal@45
|
38 selectByValue(formObj, 'valign', valign);
|
bgneal@45
|
39 selectByValue(formObj, 'class', className, true, true);
|
bgneal@45
|
40 selectByValue(formObj, 'rowtype', rowtype);
|
bgneal@45
|
41 selectByValue(formObj, 'dir', dir);
|
bgneal@45
|
42
|
bgneal@45
|
43 // Resize some elements
|
bgneal@45
|
44 if (isVisible('backgroundimagebrowser'))
|
bgneal@45
|
45 document.getElementById('backgroundimage').style.width = '180px';
|
bgneal@45
|
46
|
bgneal@45
|
47 updateColor('bgcolor_pick', 'bgcolor');
|
bgneal@45
|
48 }
|
bgneal@45
|
49
|
bgneal@45
|
50 function updateAction() {
|
bgneal@45
|
51 var inst = tinyMCEPopup.editor, dom = inst.dom, trElm, tableElm, formObj = document.forms[0];
|
bgneal@45
|
52 var action = getSelectValue(formObj, 'action');
|
bgneal@45
|
53
|
bgneal@45
|
54 tinyMCEPopup.restoreSelection();
|
bgneal@45
|
55 trElm = dom.getParent(inst.selection.getNode(), "tr");
|
bgneal@45
|
56 tableElm = dom.getParent(inst.selection.getNode(), "table");
|
bgneal@45
|
57
|
bgneal@45
|
58 inst.execCommand('mceBeginUndoLevel');
|
bgneal@45
|
59
|
bgneal@45
|
60 switch (action) {
|
bgneal@45
|
61 case "row":
|
bgneal@45
|
62 updateRow(trElm);
|
bgneal@45
|
63 break;
|
bgneal@45
|
64
|
bgneal@45
|
65 case "all":
|
bgneal@45
|
66 var rows = tableElm.getElementsByTagName("tr");
|
bgneal@45
|
67
|
bgneal@45
|
68 for (var i=0; i<rows.length; i++)
|
bgneal@45
|
69 updateRow(rows[i], true);
|
bgneal@45
|
70
|
bgneal@45
|
71 break;
|
bgneal@45
|
72
|
bgneal@45
|
73 case "odd":
|
bgneal@45
|
74 case "even":
|
bgneal@45
|
75 var rows = tableElm.getElementsByTagName("tr");
|
bgneal@45
|
76
|
bgneal@45
|
77 for (var i=0; i<rows.length; i++) {
|
bgneal@45
|
78 if ((i % 2 == 0 && action == "odd") || (i % 2 != 0 && action == "even"))
|
bgneal@45
|
79 updateRow(rows[i], true, true);
|
bgneal@45
|
80 }
|
bgneal@45
|
81
|
bgneal@45
|
82 break;
|
bgneal@45
|
83 }
|
bgneal@45
|
84
|
bgneal@45
|
85 inst.addVisual();
|
bgneal@45
|
86 inst.nodeChanged();
|
bgneal@45
|
87 inst.execCommand('mceEndUndoLevel');
|
bgneal@45
|
88 tinyMCEPopup.close();
|
bgneal@45
|
89 }
|
bgneal@45
|
90
|
bgneal@45
|
91 function updateRow(tr_elm, skip_id, skip_parent) {
|
bgneal@45
|
92 var inst = tinyMCEPopup.editor;
|
bgneal@45
|
93 var formObj = document.forms[0];
|
bgneal@45
|
94 var dom = inst.dom;
|
bgneal@45
|
95 var curRowType = tr_elm.parentNode.nodeName.toLowerCase();
|
bgneal@45
|
96 var rowtype = getSelectValue(formObj, 'rowtype');
|
bgneal@45
|
97 var doc = inst.getDoc();
|
bgneal@45
|
98
|
bgneal@45
|
99 // Update row element
|
bgneal@45
|
100 if (!skip_id)
|
bgneal@45
|
101 tr_elm.setAttribute('id', formObj.id.value);
|
bgneal@45
|
102
|
bgneal@45
|
103 tr_elm.setAttribute('align', getSelectValue(formObj, 'align'));
|
bgneal@45
|
104 tr_elm.setAttribute('vAlign', getSelectValue(formObj, 'valign'));
|
bgneal@45
|
105 tr_elm.setAttribute('lang', formObj.lang.value);
|
bgneal@45
|
106 tr_elm.setAttribute('dir', getSelectValue(formObj, 'dir'));
|
bgneal@45
|
107 tr_elm.setAttribute('style', dom.serializeStyle(dom.parseStyle(formObj.style.value)));
|
bgneal@45
|
108 dom.setAttrib(tr_elm, 'class', getSelectValue(formObj, 'class'));
|
bgneal@45
|
109
|
bgneal@45
|
110 // Clear deprecated attributes
|
bgneal@45
|
111 tr_elm.setAttribute('background', '');
|
bgneal@45
|
112 tr_elm.setAttribute('bgColor', '');
|
bgneal@45
|
113 tr_elm.setAttribute('height', '');
|
bgneal@45
|
114
|
bgneal@45
|
115 // Set styles
|
bgneal@45
|
116 tr_elm.style.height = getCSSSize(formObj.height.value);
|
bgneal@45
|
117 tr_elm.style.backgroundColor = formObj.bgcolor.value;
|
bgneal@45
|
118
|
bgneal@45
|
119 if (formObj.backgroundimage.value != "")
|
bgneal@45
|
120 tr_elm.style.backgroundImage = "url('" + formObj.backgroundimage.value + "')";
|
bgneal@45
|
121 else
|
bgneal@45
|
122 tr_elm.style.backgroundImage = '';
|
bgneal@45
|
123
|
bgneal@45
|
124 // Setup new rowtype
|
bgneal@45
|
125 if (curRowType != rowtype && !skip_parent) {
|
bgneal@45
|
126 // first, clone the node we are working on
|
bgneal@45
|
127 var newRow = tr_elm.cloneNode(1);
|
bgneal@45
|
128
|
bgneal@45
|
129 // next, find the parent of its new destination (creating it if necessary)
|
bgneal@45
|
130 var theTable = dom.getParent(tr_elm, "table");
|
bgneal@45
|
131 var dest = rowtype;
|
bgneal@45
|
132 var newParent = null;
|
bgneal@45
|
133 for (var i = 0; i < theTable.childNodes.length; i++) {
|
bgneal@45
|
134 if (theTable.childNodes[i].nodeName.toLowerCase() == dest)
|
bgneal@45
|
135 newParent = theTable.childNodes[i];
|
bgneal@45
|
136 }
|
bgneal@45
|
137
|
bgneal@45
|
138 if (newParent == null) {
|
bgneal@45
|
139 newParent = doc.createElement(dest);
|
bgneal@45
|
140
|
bgneal@45
|
141 if (dest == "thead") {
|
bgneal@45
|
142 if (theTable.firstChild.nodeName == 'CAPTION')
|
bgneal@45
|
143 inst.dom.insertAfter(newParent, theTable.firstChild);
|
bgneal@45
|
144 else
|
bgneal@45
|
145 theTable.insertBefore(newParent, theTable.firstChild);
|
bgneal@45
|
146 } else
|
bgneal@45
|
147 theTable.appendChild(newParent);
|
bgneal@45
|
148 }
|
bgneal@45
|
149
|
bgneal@45
|
150 // append the row to the new parent
|
bgneal@45
|
151 newParent.appendChild(newRow);
|
bgneal@45
|
152
|
bgneal@45
|
153 // remove the original
|
bgneal@45
|
154 tr_elm.parentNode.removeChild(tr_elm);
|
bgneal@45
|
155
|
bgneal@45
|
156 // set tr_elm to the new node
|
bgneal@45
|
157 tr_elm = newRow;
|
bgneal@45
|
158 }
|
bgneal@45
|
159
|
bgneal@45
|
160 dom.setAttrib(tr_elm, 'style', dom.serializeStyle(dom.parseStyle(tr_elm.style.cssText)));
|
bgneal@45
|
161 }
|
bgneal@45
|
162
|
bgneal@45
|
163 function changedBackgroundImage() {
|
bgneal@45
|
164 var formObj = document.forms[0], dom = tinyMCEPopup.editor.dom;
|
bgneal@45
|
165 var st = dom.parseStyle(formObj.style.value);
|
bgneal@45
|
166
|
bgneal@45
|
167 st['background-image'] = "url('" + formObj.backgroundimage.value + "')";
|
bgneal@45
|
168
|
bgneal@45
|
169 formObj.style.value = dom.serializeStyle(st);
|
bgneal@45
|
170 }
|
bgneal@45
|
171
|
bgneal@45
|
172 function changedStyle() {
|
bgneal@45
|
173 var formObj = document.forms[0], dom = tinyMCEPopup.editor.dom;
|
bgneal@45
|
174 var st = dom.parseStyle(formObj.style.value);
|
bgneal@45
|
175
|
bgneal@45
|
176 if (st['background-image'])
|
bgneal@45
|
177 formObj.backgroundimage.value = st['background-image'].replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");
|
bgneal@45
|
178 else
|
bgneal@45
|
179 formObj.backgroundimage.value = '';
|
bgneal@45
|
180
|
bgneal@45
|
181 if (st['height'])
|
bgneal@45
|
182 formObj.height.value = trimSize(st['height']);
|
bgneal@45
|
183
|
bgneal@45
|
184 if (st['background-color']) {
|
bgneal@45
|
185 formObj.bgcolor.value = st['background-color'];
|
bgneal@45
|
186 updateColor('bgcolor_pick','bgcolor');
|
bgneal@45
|
187 }
|
bgneal@45
|
188 }
|
bgneal@45
|
189
|
bgneal@45
|
190 function changedSize() {
|
bgneal@45
|
191 var formObj = document.forms[0], dom = tinyMCEPopup.editor.dom;
|
bgneal@45
|
192 var st = dom.parseStyle(formObj.style.value);
|
bgneal@45
|
193
|
bgneal@45
|
194 var height = formObj.height.value;
|
bgneal@45
|
195 if (height != "")
|
bgneal@45
|
196 st['height'] = getCSSSize(height);
|
bgneal@45
|
197 else
|
bgneal@45
|
198 st['height'] = "";
|
bgneal@45
|
199
|
bgneal@45
|
200 formObj.style.value = dom.serializeStyle(st);
|
bgneal@45
|
201 }
|
bgneal@45
|
202
|
bgneal@45
|
203 function changedColor() {
|
bgneal@45
|
204 var formObj = document.forms[0], dom = tinyMCEPopup.editor.dom;
|
bgneal@45
|
205 var st = dom.parseStyle(formObj.style.value);
|
bgneal@45
|
206
|
bgneal@45
|
207 st['background-color'] = formObj.bgcolor.value;
|
bgneal@45
|
208
|
bgneal@45
|
209 formObj.style.value = dom.serializeStyle(st);
|
bgneal@45
|
210 }
|
bgneal@45
|
211
|
bgneal@45
|
212 tinyMCEPopup.onInit.add(init);
|