Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
quotation.inc
1 <?php
18 global $ROOT_PATH;
19 include_once($ROOT_PATH.'wysiwyg_plugin.inc');
20 
33 class Quotation extends WYSIWYG_Plugin
34 {
35 
36 
44  function Quotation(&$wysiwyg)
45  {
46  wysiwyg_plugin::wysiwyg_plugin($wysiwyg);
47  $this->_add_button('quotation','Quotation','Quotation','false','60');
48 
49  }//end constructor
50 
51 
58  function paint_generic()
59  {
60  ?>
61  <script type="text/javascript" language="Javascript">
62  // Called when the user clicks on "Insert Blockquote" button
63  HTMLArea.prototype._insertBlockquote = function() {
64  var editor = this; // for nested functions
65 
66  var selection = this.getSelectedHTML();
67  var parent = this.getParentElement();
68 
69  // Is the selected text is inside blockquote?
70  var inside_blockquote = false;
71  var ancestors = this.getAllAncestors();
72  for (var i = ancestors.length; --i >= 0;) {
73  var el = ancestors[i];
74 
75  // If the selected text is wrapped by "blockquote", toggle it off
76  if (el && el.tagName == "BLOCKQUOTE") {
77  var pattern = new RegExp("<blockquote>\r?\n?"+el.innerHTML+"\r?\n?<\/blockquote>", "i");
78  el.parentNode.innerHTML = el.parentNode.innerHTML.replace(pattern, el.innerHTML);
79  inside_blockquote = true;
80  break;
81  }
82  }
83 
84  // Remove all the "blockquotes" in select area
85  var pattern = /(<blockquote>\r?\n?.*?\r?\n?<\/blockquote>)|(\r?\n?<blockquote \/>)/i;
86  if (pattern.test(selection)) {
87  inside_blockquote = true;
88  var nodeContent;
89  for (var i = parent.childNodes.length; --i >= 0;) {
90  if (parent.childNodes[i].tagName == "BLOCKQUOTE") {
91  nodeContent = parent.childNodes[i].innerHTML;
92 
93  pattern = new RegExp("<blockquote>\r?\n?"+nodeContent+"\r?\n?<\/blockquote>", "i");
94  parent.childNodes[i].parentNode.innerHTML = parent.childNodes[i].parentNode.innerHTML.replace(pattern, nodeContent);
95  }//end if
96  }//end for
97  }//end if hasBlockquotes
98 
99  if (!inside_blockquote) {
100 
101  if (parent.tagName == "P") {
102  var parent_html = parent.innerHTML;
103  parent_html = parent_html.replace(/^\s*/, "").replace(/\s*$/, "");//trim whitespace
104 
105  // Remove surrounding paragraph tag from selected HTML for comparison
106  if (HTMLArea.is_ie) {
107  // Remove newlines from paragraph HTML so we can perform a meaningful comparison
108  e = '\r\n';
109  re = new RegExp(e, "i");
110  selection = selection.replace(re, "");
111  // Remove paragraph start and end
112  var e = '^<p[^>]*>';
113  var re = new RegExp(e, "i");
114  selection = selection.replace(re, "");
115  e = '</p>$';
116  re = new RegExp(e, "i");
117  selection = selection.replace(re, "");
118  }
119  selection = selection.replace(/^\s*/, "").replace(/\s*$/, "");//trim whitespace
120 
121  if (parent_html == selection) {
122  // the whole paragraph is selected, now wrap it with
123  // blockquote tags
124  var blockquote = this._doc.createElement("blockquote");
125  var paragraph = this._doc.createElement("p");
126  paragraph.innerHTML = selection;
127  blockquote.appendChild(paragraph);
128 
129  var parent_parent = parent.parentNode;
130  parent_parent.insertBefore(blockquote, parent);
131  parent_parent.removeChild(parent);
132  } else {
133  alert("<BLOCKQUOTE> tags cannot be added to partial text within a paragraph.");
134  }
135 
136  } else {
137  // the selected text is not in p tag, just wrap it with blockquote
138  this.surroundHTML('<blockquote>', '</blockquote>');
139  }
140  }
141 
142  };
143  </script>
144  <?php
145  }
146 
147 
155  {
156  ?>
157  case "quotation":
158  this._insertBlockquote();
159  break;
160  <?php
161 
162  }//end print_plugin_button_click()
163 
164 
165 }//end class
166 
167 ?>