Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
matrix_accessibility.inc
1 <?php
18 global $ROOT_PATH;
19 include_once($ROOT_PATH.'wysiwyg_plugin.inc');
20 require_once dirname(__FILE__).'/../../../../core/include/init.inc';
21 
35 {
36 
44  function matrix_accessibility(&$wysiwyg)
45  {
46  wysiwyg_plugin::wysiwyg_plugin($wysiwyg);
47  $this->_add_button('matrixabbr','MatrixAbbr','Insert Abbreviation','false','64');
48  $this->_add_button('matrixacronym','MatrixAcronym','Insert Acronym','false','66');
49 
50  }//end constructor
51 
60  function paint_generic()
61  {
62  ?>
63  <script type="text/javascript" src="<?php echo sq_web_path('lib').'/js/general.js' ?>"></script>
64  <script type="text/javascript" src="<?php echo sq_web_path('fudge').'/var_serialise/var_serialise.js' ?>"></script>
65 
66  <script type="text/javascript" language="Javascript">
67  var wysiwyg_editing = true; // just so that onclick links don't execute in wysiwyg
68 
69  // Called when the user clicks on "Insert Abbreviation" button
70  HTMLArea.prototype._matrixInsertAbbr = function() {
71  var editor = this; // for nested functions
72 
73  // OK, let's create the current args array that we'll pass to the dialog
74  var currArgs = new Object();
75  currArgs["title"] = "";
76 
77  var sel = this._getSelection();
78  var range = this._createRange(sel);
79  var text_range = false;
80 
81  // OK, so they have a control object selected, let's try and make it a text selection
82  if (sel.type && sel.type.toLowerCase() == "control") {
83  var control_range = this._createRange(sel);
84  var text_range = this._createTextRange(sel);
85  if (text_range != null) {
86  text_range = true;
87  editor.selectNodeContents(control_range(0));
88  } else {
89  alert(js_translate('object_requires_selection'));
90  sel.empty();
91  return;
92  }
93  sel = this._getSelection();
94  range = this._createRange(sel);
95  }// end if a control
96 
97  var inside_html = '';
98  var current_abbr = this.getClosest("abbr");
99  if (current_abbr) {
100  if (HTMLArea.is_ie) {
101  inside_html = current_abbr.innerHTML;
102  } else {
103  this.selectNodeContents(current_abbr);
104  inside_html = editor.getSelectedHTML();
105  }
106  this.selectNodeContents(current_abbr);
107  } else {
108  inside_html = editor.getSelectedHTML();
109  }
110 
111  sel = this._getSelection();
112  range = this._createRange(sel);
113 
114  // Is this aready an abbreviation?
115  if (current_abbr) {
116 
117  var e = '^(<abbr [^>]+>)(.*)</abbr>$';
118  var re = new RegExp(e, "i");
119  var tag_html = editor.getSelectedHTML().replace(re, "$1");
120 
121  var re = new RegExp("\n", "gi");
122  var tag_html = tag_html.replace(re, "");
123 
124  currArgs["title"] = current_abbr.title;
125 
126  re = new RegExp('if \\(!window\\.wysiwyg_editing\\)[\\s]+\\{[\\s]+window\\.open\\([\'"]([^\'"]+)[\'"], [\'"][0-9]+[\'"], [\'"]([^\'"]+)[\'"]\\);', "gi");
127  results = re.exec(tag_html);
128 
129  if (results != null) {
130  currArgs["title"] = results[1];
131  }// end if
132  // else not a link so check for paragraphs
133  } else {
134 
135  // convert all para tags to lowercase
136  var para_html = inside_html.replace(/(<\/?)P/gi, "$1p");
137 
138  // OK so we have some paragraph tags caught up in the mix, let's see what we can do with them
139  // because we don't want our href's going around paragraph tags
140  if (para_html.indexOf("<p") > -1) {
141 
142  // if the position of the first tag is the same as the last then we have only one paragraph
143  // we don't want more than one paragraph because these can start or end from half-way through
144  // a para, which would break the formatting when we go to re-insert the text with the href
145  if (para_html.indexOf("<p") != para_html.lastIndexOf("<p")) {
146  alert(js_translate('select_one_paragraph_at_a_time'));
147  return;
148  }
149 
150  }// end if paragraphs exist
151 
152  }// end if existing link
153 
154  var in_popup = '0';
155  if (this._inPopup == true) { in_popup = '1'; }
156 
157  editor_<?php echo $this->wysiwyg->name?>._object = this;
158  var strPage = "<?php echo $this->get_popup_href('insert_abbr.php')?>?&title=" + escape(currArgs["title"]) + "&abbr=" + escape(inside_html) +"&editor_name=" + escape("<?php echo $this->wysiwyg->name; ?>") + "&in_popup=" + escape(in_popup);
159 
160  var popup_width = 410;
161 
162  // A bit more breathing room for Safari
163  if (HTMLArea.is_safari) popup_width += 15;
164 
165  this._popupDialog("matrixInsertAbbr", strPage, popup_width, 210, true, function(param) {
166  if (!param) {
167  // user must have pressed Cancel
168  return false;
169  }
170 
171  if (param["title"] != "") {
172 
173  if (param["abbr"] != inside_html) { inside_html = param["abbr"]; }
174 
175  var html = '<abbr title="' + param["title"] + '">' + inside_html + '</abbr>';
176 
177  // Update abbreviation if selected, otherwise create a new one
178  if (current_abbr) {
179  current_abbr.title = param["title"];
180  current_abbr.innerHTML = inside_html;
181  } else {
182  if (HTMLArea.is_gecko) {
183  editor.insertHTML(html, range);
184  } else if (HTMLArea.is_ie) {
185  range.pasteHTML(html);
186  }
187  }
188 
189 
190  }// end if param exists
191 
192  }, null);
193 
194  };
195 
196  // Called when the user clicks on "Insert Acronym" button
197  HTMLArea.prototype._matrixInsertAcronym = function() {
198  var editor = this; // for nested functions
199 
200  // OK, let's create the current args array that we'll pass to the dialog
201  var currArgs = new Object();
202  currArgs["title"] = "";
203 
204  var sel = this._getSelection();
205  var range = this._createRange(sel);
206  var text_range = false;
207 
208  // OK, so they have a control object selected, let's try and make it a text selection
209  if (sel.type && sel.type.toLowerCase() == "control") {
210  var control_range = this._createRange(sel);
211  var text_range = this._createTextRange(sel);
212  if (text_range != null) {
213  text_range = true;
214  editor.selectNodeContents(control_range(0));
215  } else {
216  alert(js_translate('object_requires_selection'));
217  sel.empty();
218  return;
219  }
220  sel = this._getSelection();
221  range = this._createRange(sel);
222  }// end if a control
223 
224  var inside_html = '';
225  var current_acronym = this.getClosest("acronym");
226  if (current_acronym) {
227  if (HTMLArea.is_ie) {
228  inside_html = current_acronym.innerHTML;
229  } else {
230  this.selectNodeContents(current_acronym);
231  inside_html = editor.getSelectedHTML();
232  }
233  this.selectNodeContents(current_acronym);
234  } else {
235  inside_html = editor.getSelectedHTML();
236  }
237 
238  sel = this._getSelection();
239  range = this._createRange(sel);
240 
241  // Is this aready an abbreviation?
242  if (current_acronym) {
243 
244  var e = '^(<acronym [^>]+>)(.*)</acronym>$';
245  var re = new RegExp(e, "i");
246  var tag_html = editor.getSelectedHTML().replace(re, "$1");
247 
248  var re = new RegExp("\n", "gi");
249  var tag_html = tag_html.replace(re, "");
250 
251  currArgs["title"] = current_acronym.title;
252 
253  re = new RegExp('if \\(!window\\.wysiwyg_editing\\)[\\s]+\\{[\\s]+window\\.open\\([\'"]([^\'"]+)[\'"], [\'"][0-9]+[\'"], [\'"]([^\'"]+)[\'"]\\);', "gi");
254  results = re.exec(tag_html);
255 
256  if (results != null) {
257  currArgs["title"] = results[1];
258  }// end if
259  // else not a link so check for paragraphs
260  } else {
261 
262  // convert all para tags to lowercase
263  var para_html = inside_html.replace(/(<\/?)P/gi, "$1p");
264 
265  // OK so we have some paragraph tags caught up in the mix, let's see what we can do with them
266  // because we don't want our href's going around paragraph tags
267  if (para_html.indexOf("<p") > -1) {
268 
269  // if the position of the first tag is the same as the last then we have only one paragraph
270  // we don't want more than one paragraph because these can start or end from half-way through
271  // a para, which would break the formatting when we go to re-insert the text with the href
272  if (para_html.indexOf("<p") != para_html.lastIndexOf("<p")) {
273  alert("Please select only one paragraph to link at a time.");
274  return;
275  }
276 
277  }// end if paragraphs exist
278 
279  }// end if existing link
280 
281  var in_popup = '0';
282  if (this._inPopup == true) { in_popup = '1'; }
283 
284  editor_<?php echo $this->wysiwyg->name?>._object = this;
285  var strPage = "<?php echo $this->get_popup_href('insert_acronym.php')?>?&title=" + escape(currArgs["title"]) + "&acronym=" + escape(inside_html) +"&editor_name=" + escape("<?php echo $this->wysiwyg->name; ?>") + "&in_popup=" + escape(in_popup);
286 
287  var popup_width = 410;
288 
289  // A bit more breathing room for Safari
290  if (HTMLArea.is_safari) popup_width += 15;
291 
292  this._popupDialog("matrixInsertAcronym", strPage, popup_width, 210, true, function(param) {
293  if (!param) {
294  // user must have pressed Cancel
295  return false;
296  }
297 
298  if (param["title"] != "") {
299 
300  if (param["acronym"] != inside_html) { inside_html = param["acronym"]; }
301 
302  var html = '<acronym title="' + param["title"] + '">' + inside_html + '</acronym>';
303 
304  // Update acronym if selected, otherwise create a
305  if (current_acronym) {
306  current_acronym.title = param["title"];
307  current_acronym.innerHTML = inside_html;
308  } else {
309  editor.insertHTML(html, range);
310  }
311 
312  }// end if param exists
313 
314  }, null);
315 
316  };
317  </script>
318  <?php
319 
320  }//end paint_generic()
321 
322 
329  function print_plugin_button_click()
330  {
331  ?>
332  case "matrixabbr":
333  this._matrixInsertAbbr();
334  break;
335  case "matrixacronym":
336  this._matrixInsertAcronym();
337  break;
338  <?php
339 
340  }//end print_plugin_button_click()
341 
342 
349  function print_plugin_update_toolbar()
350  {
351  ?>
352  case "matrixabbr":
353  if (allEnabled == null && this._tmp['disable_toolbar'] == true) {
354  this.updateToolbar(false);
355  return;
356  }
357  break;
358  case "matrixacronym":
359  if (allEnabled == null && this._tmp['disable_toolbar'] == true) {
360  this.updateToolbar(false);
361  return;
362  }
363  break;
364  <?php
365 
366  }//end print_plugin_update_toolbar()
367 
368 }//end class
369 
370 ?>