Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
indenting.inc
1 <?php
18 global $ROOT_PATH;
19 include_once($ROOT_PATH.'wysiwyg_plugin.inc');
20 
35 {
36 
44  function indenting()
45  {
46  $this->_add_button('outdent','Outdent','Decrease Indent','false','28');
47  $this->_add_button('indent','Indent','Increase Indent','false','29');
48  }
49 
50 
59  function paint_generic()
60  {
61  ?>
62  <script type="text/javascript">
63  // Called when the user clicks on "Insert Blockquote" button
64  HTMLArea.prototype._changeIndent = function(direction) {
65 
66  if (HTMLArea.is_ie) {
67 
68  // IE - we need to override some stuff
69  var blockElts = "|applet|div|embed|fieldset|form|h1|h2|h3|h4|h5|h6|iframe|ilayer|img|object|p|pre|quote|table|textarea|ul|ol|";
70  var sel = this._getSelection();
71  var range = this._createRange(sel);
72  range.expand();
73  range.select();
74  if (direction == 'right') {
75 
76  // First get the browser to do its thing
77  this._execCommand('indent', false, '');
78 
79  // Second, remove the blockquote element if necessary
80  var sel = this._getSelection();
81  var range = this._createRange(sel);
82  range.expand();
83  var parent = range.parentElement();
84  if (parent.tagName.toLowerCase() == 'p') {
85  parent = parent.parentNode;
86  }
87  if (parent.tagName == 'BLOCKQUOTE') {
88  var subElt = parent.firstChild;
89  while (subElt != null) {
90  newElt = subElt.nextSibling;
91  if (subElt.tagName) {
92  if (blockElts.indexOf('|'+subElt.tagName.toLowerCase()+'|') != -1) {
93  this._setLeftMargin(direction, subElt);
94  }
95  parent.removeChild(subElt);
96  parent.parentNode.insertBefore(subElt, parent);
97  }
98  subElt = newElt;
99  }
100  parent.parentNode.removeChild(parent);
101  }
102  } else {
103 
104  // First, try to trim off left margin ourselves
105  var tRange = this._doc.selection.createRange()
106  if (tRange.parentElement().tagName.toLowerCase() == 'p') {
107  tRange.moveToElementText(tRange.parentElement());
108  }
109  tRange.moveStart('character', -1);
110  tRange.moveEnd('character', 1);
111  var parent = this.getParentElement();
112  if (parent.tagName.toLowerCase() == 'p') {
113  parent = parent.parentNode;
114  }
115  var subElt = parent.firstChild;
116  var success = false;
117  var foundFirst = false;
118  while (subElt != null) {
119  var nextElt = subElt.nextSibling;
120  if (subElt.tagName) {
121  var nodeRange = tRange.duplicate();
122  nodeRange.moveToElementText(subElt);
123  nodeRange.expand();
124  if (tRange.inRange(nodeRange)) {
125  if (blockElts.indexOf('|'+subElt.tagName.toLowerCase()+'|') != -1) {
126  success = this._setLeftMargin(direction, subElt) || success;
127  }
128  }
129  }
130  subElt = nextElt;
131  }
132 
133  // If we didn't catch anything, send it to the browser for handling
134  if (!success) {
135  this._doc.execCommand('outdent', false, '');
136  }
137  }
138 
139  } else {
140 
141  // NOT IE - browser default behaviour is fine
142  this._doc.execCommand((direction == 'left') ? 'outdent' : 'indent', false, '');
143 
144  }
145  }
146 
147  // Set the left margin value of the element's style
148  HTMLArea.prototype._setLeftMargin = function(direction, el) {
149  if (el.style.marginLeft == "" || el.style.marginLeft == "0pt"|| el.style.marginLeft == "0px") {
150  if (direction == "right") {
151  el.style.marginLeft = "40px";
152  } else {
153  return false; // could not outdent
154  }
155  } else {
156  var new_px;
157  var result = el.style.marginLeft.match(/(\d)+px/g);
158  var current_indent = parseInt(result[0]);
159  if (direction == "right") {
160  new_px = current_indent + 40;
161  } else if (direction == "left") {
162  if (current_indent > 40) {
163  new_px = current_indent - 40;
164  } else if (current_indent == 40) {
165  new_px = 0;
166  } else {
167  return false; // could not outdent
168  }
169  }
170  el.style.marginLeft = new_px.toString();
171  }
172  return true;
173  };
174 
175  </script>
176  <?php
177  }
178 
179 
187  {
188  ?>
189  case "outdent":
190  this._changeIndent("left");
191  break;
192  case "indent":
193  this._changeIndent("right");
194  break;
195  <?php
196 
197  }//end print_plugin_button_click()
198 
199 }
200 
201 ?>