Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
table_editing.inc
1 <?php
18 global $ROOT_PATH;
19 include_once($ROOT_PATH.'wysiwyg_plugin.inc');
20 
34 class Table_Editing extends WYSIWYG_Plugin
35 {
36 
37 
45  function Table_Editing(&$wysiwyg)
46  {
47  wysiwyg_plugin::wysiwyg_plugin($wysiwyg);
48  $this->_add_button('inserttable','InsertTable','Insert Table','false','35');
49  $this->_add_button('tableproperties','TableProperties','Table Properties','false','36','table');
50 
51  }//end constructor
52 
53 
60  function print_plugin_vars()
61  {
62  ?>
63  this.config._showborders = true;
64  <?php
65 
66  }//end print_plugin_vars()
67 
68 
75  function paint_generic()
76  {
77  ?>
78  <script type="text/javascript">
79  //<![CDATA[
80  //global for holding table data. Used to workaround 4096 byte limit
81  //IE imposes on dialogArguments.
82  var table_structure;
83  // helper function that clears the content in a table row
84  HTMLArea.prototype.clearRow = function(tr) {
85  var mozbr = HTMLArea.is_gecko ? "<br />" : "";
86  var tds = tr.getElementsByTagName("td");
87  for (var i = tds.length; --i >= 0;) {
88  var td = tds[i];
89  td.rowSpan = 1;
90  td.innerHTML = mozbr;
91  }
92  };
93 
94 
95  HTMLArea.prototype.selectNextNode = function(el) {
96  var node = el.nextSibling;
97  while (node && node.nodeType != 1) {
98  node = node.nextSibling;
99  }
100  if (!node) {
101  node = el.previousSibling;
102  while (node && node.nodeType != 1) {
103  node = node.previousSibling;
104  }
105  }
106  if (!node) {
107  node = el.parentNode;
108  }
109  this.selectNodeContents(node);
110  };
111 
112 
113  // Called when the user clicks the Insert Table button
114  HTMLArea.prototype._insertTable = function() {
115  var editor = this; // for nested functions
116 
117  // set focus in case we havnt selected anything
118  if (HTMLArea.is_ie) {
119  this._docContent.focus();
120  } else if (HTMLArea.is_gecko) {
121  this.focusEditor();
122  }
123  var sel = this._getSelection();
124  var range = this._createRange(sel);
125  this._popupDialog
126  ("insertTable", "<?php echo $this->get_popup_href('insert_table.html')?>", 400, 500, true, function(param) {
127  if (!param) { // user must have pressed Cancel
128  return false;
129  }
130  var doc = editor._doc;
131  // create the table element
132  var table = doc.createElement("table");
133 
134  var row_header = param["f_headerRow"];
135  var col_header = param["f_headerCol"];
136 
137  // assign the given arguments
138  for (var field in param) {
139  var value = param[field];
140  //alert("value="+value+"\nfield="+field);
141  if (!value) {
142  continue;
143  }
144  switch (field) {
145  case "f_class":
146  if (value != "") {
147  table.className = value;
148  }
149  break;
150 
151  case "f_width":
152  table.style.width = value + param["f_widthUnit"];
153  break;
154 
155  case "f_border":
156  table.border = parseInt(value);
157  break;
158 
159  case "f_spacing":
160  table.cellSpacing = parseInt(value);
161  break;
162 
163  case "f_padding":
164  table.cellPadding = parseInt(value);
165  break;
166 
167  case "f_summary":
168  if (value != "") {
169  table.setAttribute("summary", value);
170  }
171  break;
172  }
173  }
174 
175  var tbody = doc.createElement("tbody");
176  table.appendChild(tbody);
177  for (var i = 0; i < param["f_rows"]; ++i) {
178  var tr = doc.createElement("tr");
179  tbody.appendChild(tr);
180  for (var j = 0; j < param["f_cols"]; ++j) {
181  var td = null;
182  // create a table header
183  if ((col_header && j == 0)
184  || (row_header && i == 0)) {
185  td = doc.createElement("th");
186  } else {
187  td = doc.createElement("td");
188  }
189  tr.appendChild(td);
190  if (HTMLArea.is_gecko) {
191  // Mozilla likes to see something
192  // inside the cell.
193  td.appendChild(doc.createElement("br"));
194  } else if (HTMLArea.is_ie) {
195  // to overcome that IE will not close with </th> tag for empty content
196  td.appendChild(doc.createTextNode(''));
197  }
198  }
199  }
200 
201  if (HTMLArea.is_ie) {
202  range.pasteHTML(HTMLArea.getHTML(table, true));
203  } else {
204  // insert the table
205  editor.insertNodeAtSelection(table);
206  }
207  return true;
208  }, null);
209  };
210 
211 
212  // this function requires the file PopupDiv/PopupWin to be loaded from browser
213  HTMLArea.prototype._editTableProperties = function() {
214  var editor = this; // for nested functions
215 
216  // retrieve existing values
217  var table = this.getClosest("table");
218  if (HTMLArea.is_ie) {
219  //workaround against stupid IE behaviour. We will use native MS functions
220  var tablekeeper = table.outerHTML;
221  } else {
222  var div = document.createElement("DIV");
223  div.appendChild(table.cloneNode(true));
224  var tablekeeper = div.innerHTML;
225  }
226  table_structure = tablekeeper;
227  strPage = "<?php echo $this->get_popup_href('edit_table.php')?>";
228  var width = 835;
229  var height = 730;
230  table_structure = this.make_absolute_urls(table_structure);
231  this._popupDialog("editTableProperties", strPage, width, height, true, function(params) {
232  if (!params) {
233  // user must have pressed Cancel
234  return false;
235  }
236  var div = document.createElement("DIV");
237  div.innerHTML = params;
238  var table = div.getElementsByTagName("TABLE")[0];
239  var old_table = editor.getClosest("TABLE");
240  if (HTMLArea.is_ie) {
241  old_table.outerHTML = table.outerHTML;
242  } else {
243  old_table.parentNode.replaceChild(table, old_table);
244  }
245  // various workarounds to refresh the table display (Gecko,
246  // what's going on?! do not disappoint me!)
247  editor.forceRedraw();
248  editor.focusEditor();
249  editor.updateToolbar();
250  var save_collapse = table.style.borderCollapse;
251  table.style.borderCollapse = "collapse";
252  table.style.borderCollapse = "separate";
253  table.style.borderCollapse = save_collapse;
254  }, window);
255  //above: window is passed, so that tableStructure can be accessed by the called dialog. avoids dialogArguments limit
256  };
257 
258  //Functions for showing the table borders
259  HTMLArea.prototype.storedBorders = Array();
260 
261  this.clonedBorder = function() {
262 
263  this.cloneSaveBorder = function(border) {
264  for (i in border) {
265  this[i] = border[i];
266  }
267  }
268 
269  }
270 
271  HTMLArea._restoreBorder = function(elt, stored)
272  {
273  if (stored.borderLeft) {
274  elt.style.borderLeft = stored.borderLeft;
275  }
276  if (stored.borderRight) {
277  elt.style.borderRight = stored.borderRight;
278  }
279  if (stored.borderTop) {
280  elt.style.borderTop = stored.borderTop;
281  }
282  if (stored.borderBottom) {
283  elt.style.borderBottom = stored.borderBottom;
284  }
285  }
286  //]]>
287  </script>
288  <?php
289 
290  }//end paint_generic()
291 
292 
300  {
301  ?>
302  case "inserttable":
303  this._insertTable();
304  if (this.config._showborders){
305  if (HTMLArea.is_ie) {
306  var doco = this._docContent;
307  } else {
308  var doco = this._iframe.contentWindow;
309  }
310  this.config._showborders = true;
311  }
312  break;
313 
314  case "tableproperties":
315  this._editTableProperties();
316  break;
317  <?php
318 
319  }//end print_plugin_button_click()
320 
321 
329  {
330 
331  }//end print_plugin_update_toolbar()
332 
333 
342  {
343  ?>
344  retVal = retVal.replace(/class=""/gi, '');
345  <?php
346  return;
347 
348  }//end print_plugin_get_html()
349 
350 
351 }//end class
352 
353 ?>