Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
misc_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 misc_accessibility(&$wysiwyg)
45  {
46  wysiwyg_plugin::wysiwyg_plugin($wysiwyg);
47  $this->_add_button('misccite','MiscCite','Insert Citation','false','58');
48  $this->_add_button('miscdfn','MiscDfn','Insert Definition','false','59');
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 Citation" button
70  HTMLArea.prototype._matrixInsertCite = 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["name"] = "";
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_cite = this.getClosest("cite");
99  if (current_cite) {
100  if (HTMLArea.is_ie) {
101  inside_html = current_cite.innerHTML;
102  } else {
103  this.selectNodeContents(current_cite);
104  inside_html = editor.getSelectedHTML();
105  }
106  this.selectNodeContents(current_cite);
107  } else {
108  inside_html = editor.getSelectedHTML();
109  }
110  sel = this._getSelection();
111  range = this._createRange(sel);
112 
113  // remove nested cite tags in selection
114  var reg = new RegExp("<\/?cite ?[^>]*>", "gi");
115  inside_html = inside_html.replace(reg, "");
116 
117  // if citation exists, remove it
118  if (current_cite) {
119  var text = this._doc.createDocumentFragment();
120  // the following also deletes the selection
121  var div = this._doc.createElement("div");
122  div.innerHTML = inside_html;
123  while (div.firstChild) {
124  text.appendChild(div.firstChild);
125  }
126  current_cite.parentNode.replaceChild(text, current_cite);
127  // else insert the citation
128  } else {
129  if (inside_html != '') {
130  this.insertHTML('<cite>' + inside_html + '</cite>');
131  }
132  }
133  };
134 
135 
136  // Called when the user clicks on "Insert Definition" button
137  HTMLArea.prototype._matrixInsertDfn = function() {
138  var editor = this; // for nested functions
139 
140  // OK, let's create the current args array that we'll pass to the dialog
141  var currArgs = new Object();
142  currArgs["title"] = "";
143 
144  var sel = this._getSelection();
145  var range = this._createRange(sel);
146  var text_range = false;
147 
148  // OK, so they have a control object selected, let's try and make it a text selection
149  if (sel.type && sel.type.toLowerCase() == "control") {
150  var control_range = this._createRange(sel);
151  var text_range = this._createTextRange(sel);
152  if (text_range != null) {
153  text_range = true;
154  editor.selectNodeContents(control_range(0));
155  } else {
156  alert(js_translate('object_requires_selection'));
157  sel.empty();
158  return;
159  }
160  sel = this._getSelection();
161  range = this._createRange(sel);
162  }// end if a control
163 
164  var inside_html = '';
165  var current_dfn = this.getClosest("dfn");
166  if (current_dfn) {
167  if (HTMLArea.is_ie) {
168  inside_html = current_dfn.innerHTML;
169  } else {
170  this.selectNodeContents(current_dfn);
171  inside_html = editor.getSelectedHTML();
172  }
173  this.selectNodeContents(current_dfn);
174  } else {
175  inside_html = editor.getSelectedHTML();
176  }
177 
178  sel = this._getSelection();
179  range = this._createRange(sel);
180 
181  // Is this aready an definition?
182  if (current_dfn) {
183 
184  var e = '^(<dfn [^>]+>)(.*)</dfn>$';
185  var re = new RegExp(e, "i");
186  var tag_html = editor.getSelectedHTML().replace(re, "$1");
187 
188  var re = new RegExp("\n", "gi");
189  var tag_html = tag_html.replace(re, "");
190 
191  currArgs["title"] = current_dfn.title;
192 
193  re = new RegExp('if \\(!window\\.wysiwyg_editing\\)[\\s]+\\{[\\s]+window\\.open\\([\'"]([^\'"]+)[\'"], [\'"][0-9]+[\'"], [\'"]([^\'"]+)[\'"]\\);', "gi");
194  results = re.exec(tag_html);
195 
196  if (results != null) {
197  currArgs["title"] = results[1];
198  }// end if
199  // else not a link so check for paragraphs
200  } else {
201 
202  // convert all para tags to lowercase
203  var para_html = inside_html.replace(/(<\/?)P/gi, "$1p");
204 
205  // OK so we have some paragraph tags caught up in the mix, let's see what we can do with them
206  // because we don't want our href's going around paragraph tags
207  if (para_html.indexOf("<p") > -1) {
208 
209  // if the position of the first tag is the same as the last then we have only one paragraph
210  // we don't want more than one paragraph because these can start or end from half-way through
211  // a para, which would mess up the formatting when we go to re-insert the text with the href
212  if (para_html.indexOf("<p") != para_html.lastIndexOf("<p")) {
213  alert(js_translate('select_one_paragraph_at_a_time'));
214  return;
215  }
216 
217  }// end if paragraphs exist
218 
219  }// end if existing link
220 
221  var in_popup = '0';
222  if (this._inPopup == true) { in_popup = '1'; }
223 
224  editor_<?php echo $this->wysiwyg->name?>._object = this;
225  var strPage = "<?php echo $this->get_popup_href('insert_dfn.php')?>?&title=" + escape(currArgs["title"]) + "&dfn=" + escape(inside_html) +"&editor_name=" + escape("<?php echo $this->wysiwyg->name; ?>") + "&in_popup=" + escape(in_popup);
226 
227  this._popupDialog("matrixInsertDfn", strPage, 420, 270, true, function(param) {
228  if (!param) {
229  // user must have pressed Cancel
230  return false;
231  }
232 
233  if (param["title"] != "") {
234 
235  if (param["dfn"] != inside_html) { inside_html = param["dfn"]; }
236 
237  var html = '<dfn title="' + param["title"] + '">' + inside_html + '</dfn>';
238 
239  // replace with new URL
240  editor.insertHTML(html, range);
241 
242  }// end if param exists
243 
244  }, null);
245 
246  };
247 
248  </script>
249  <?php
250 
251  }//end paint_generic()
252 
253 
261  {
262  ?>
263  case "misccite":
264  this._matrixInsertCite();
265  break;
266  case "miscdfn":
267  this._matrixInsertDfn();
268  break;
269  <?php
270 
271  }//end print_plugin_button_click()
272 
273 
281  {
282  ?>
283  case "misccite":
284  if (allEnabled == null && this._tmp['disable_toolbar'] == true) {
285  this.updateToolbar(false);
286  return;
287  }
288  break;
289  case "miscdfn":
290  if (allEnabled == null && this._tmp['disable_toolbar'] == true) {
291  this.updateToolbar(false);
292  return;
293  }
294  break;
295  <?php
296 
297  }//end print_plugin_update_toolbar()
298 
299 }//end class
300 
301 ?>