19 include_once($ROOT_PATH.
'wysiwyg_plugin.inc');
41 var $_css_classes = Array();
54 require_once dirname(__FILE__).
'/../../../../core/include/init.inc';
58 if (!empty($classes)) {
59 foreach ($classes as $class_name => $short_name) {
60 $this->_css_classes[$class_name] = $short_name;
65 if (empty($this->_css_classes) && isset($GLOBALS[
'sq_bodycopy_cssids'])) {
66 foreach ($GLOBALS[
'sq_bodycopy_cssids'] as $css_assetid) {
67 $css = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($css_assetid);
68 $css_file = $css->getExistingFile();
70 if (!empty($css_file)) {
71 $stylesheet_src = $css_file[
'path'];
75 if (file_exists($stylesheet_src)) {
76 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
77 $stylesheet = preg_replace(
'%[\r\n]+%',
' ',file_to_string($stylesheet_src));
78 $stylesheet = preg_replace(
'/\/\*.*\*\//sU',
'',$stylesheet);
80 preg_match_all(
'%\s*([^\{]+)\{[^\}]+\}%', $stylesheet, $matches);
81 $class_strings = $matches[1];
86 foreach ($class_strings as $class_string) {
87 $variations = explode(
',', $class_string);
88 foreach ($variations as $class) {
90 list($class) = explode(
':',trim($class));
91 if (substr($class,0,1) ==
'.') $this->_css_classes[trim($class,
'.')] = trim($class,
'.');
96 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($css);
101 $this->_add_button(
'formatblock',
'',
'',
'',
'');
102 if (!empty($this->_css_classes)) $this->_add_button(
'applystyle',
'',
'',
'',
'');
116 this.config.applystyle = {
119 if (!empty($this->_css_classes)) {
120 ?>
"-- select css style --":
"",<?php
122 foreach ($this->_css_classes as $class_name => $cn) echo
'" '.str_replace(
'"',
'\"', $cn).
'": "'.str_replace(
'"',
'\"', $class_name).
'",';
123 ?>
"-- remove css style --":
"no_style"<?php
129 this.config.formatblock = {
137 "Address" :
"address",
156 options = editor.config[txt];
175 var options = this.config[
"applystyle"];
176 var current_span = this.getClosest(
"span");
179 var value = current_span.className;
181 for (var j in options) {
182 if (options[j].toLowerCase() == value) {
183 btn.element.selectedIndex = k;
190 if (!found) { btn.element.selectedIndex = 0; }
199 var value = (
"" + doc.queryCommandValue(cmd)).toLowerCase();
204 btn.element.selectedIndex = 0;
205 var options = this.config[
"formatblock"];
207 for (var j in options) {
209 if ((j.toLowerCase() == value) ||
210 (options[j].substr(0, value.length).toLowerCase() == value)) {
211 btn.element.selectedIndex = k;
236 range = this._createRange(this._getSelection());
238 if (HTMLArea.is_ie) {
243 if (range.boundingWidth == 0) {
249 var parent = range.parentElement();
251 var testRange = range.duplicate();
252 testRange.moveToElementText(parent);
253 if (testRange.inRange(range)) {
256 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() ==
'body')) {
259 parent = parent.parentElement;
261 var selectedHTML = range.htmlText.replace(/^\s+|\s+$/,
'');
263 if (selectedHTML == range.text.replace(/^\s+|\s+$/,
'')) {
265 range.text =
'MYOPENSPAN'+range.text+
'MYCLOSESPAN';
266 }
else if ((parent.innerHTML == selectedHTML) || (parent.outerHTML.replace(/\s/g,
'') == selectedHTML.replace(/\s/g,
''))) {
268 parent.className = value;
271 for (var elt = parent.firstChild; elt != null; elt = elt.nextSibling) {
272 var tempRange = document.body.createTextRange();
273 tempRange.moveToElementText(elt);
275 (range.compareEndPoints(
'StartToEnd', tempRange) <= 0)
276 && (range.compareEndPoints(
'EndToStart', tempRange) >= 0);
278 var endsAfter = (range.compareEndPoints(
'EndToEnd', tempRange) == -1);
279 var startsBefore = (range.compareEndPoints(
'StartToStart', tempRange) == 1);
282 while (range.compareEndPoints(
'StartToStart', tempRange) == 1) {
284 tempRange.moveStart(
'character', 1);
286 tempRange.moveToElementText(elt);
287 var newText = tempRange.text.substring(0, offset)+
"MYOPENSPAN"+tempRange.text.substring(offset, tempRange.text.length)+
"MYCLOSESPAN";
288 if (elt.nodeType == 3) {
290 }
else if ((elt.childNodes.length == 1) && (elt.firstChild.nodeType == 3)) {
291 elt.innerHTML = newText;
293 tempRange.text = newText;
295 }
else if (endsAfter) {
298 while (range.compareEndPoints(
'EndToEnd', tempRange) == -1) {
300 tempRange.moveEnd(
'character', -1);
302 tempRange.moveToElementText(elt);
303 tempRange.text =
"MYOPENSPAN"+tempRange.text.substring(0, tempRange.text.length-offset+1)+
"MYCLOSESPAN"+tempRange.text.substring(tempRange.text.length-offset+1, tempRange.text.length);
307 if (elt.nodeType == 3) {
309 var newSpan = document.createElement(
'SPAN');
310 newSpan.innerHTML = elt.data;
311 newSpan.className = value;
312 elt.parentNode.insertBefore(newSpan, elt);
313 elt.parentNode.removeChild(elt);
315 elt.className = value;
321 parent.innerHTML = (parent.innerHTML.replace(
new RegExp(
"MYOPENSPAN",
"g"),
'<span class="'+value+
'">').replace(
new RegExp(
"MYCLOSESPAN",
"g"),
'</span>'));
326 if (range.collapsed) {
329 if ((range.startContainer.nodeType == 3) && (range.startContainer == range.endContainer)) {
331 if ((range.startOffset == 0) && (range.endOffset == range.endContainer.length)) {
333 range.startContainer.parentNode.className = value;
336 this.surroundHTML(
'<span class="'+value+
'">',
'</span>');
342 var effectiveStartElt = range.startContainer;
343 if ((effectiveStartElt.nodeType == 3)) {
344 effectiveStartElt = effectiveStartElt.parentNode;
346 var effectiveEndElt = range.endContainer;
347 if ((effectiveEndElt.nodeType == 3)) {
348 effectiveEndElt = effectiveEndElt.parentNode;
351 if (range.startContainer == range.endContainer) {
352 if ((range.startOffset != 0) || (range.endOffset != range.childNodes.length)) {
353 effectiveStartElt = range.startContainer.childNodes.item(range.startOffset);
354 effectiveEndElt = range.startContainer.childNodes.item(range.endOffset);
358 var ancestor = range.commonAncestorContainer;
359 if ((ancestor.tagName ==
'UL') || (ancestor.tagName ==
'OL') || (ancestor.tagName ==
'TABLE') || (ancestor.tagName ==
'DL') || (ancestor.tagName ==
'TR')) {
361 var elt = ancestor.firstChild;
362 while (elt != null) {
363 nextElt = elt.nextSibling;
364 if ((elt.nodeType == 3) && (elt.data.replace(/^\s+|\s+$/,
'') ==
'')) {
365 elt.parentNode.removeChild(elt);
371 if ((effectiveStartElt == effectiveStartElt.parentNode.firstChild) && (effectiveEndElt == effectiveStartElt.parentNode.lastChild) && (range.startOffset == 0) && (range.endOffset == 0)) {
373 effectiveStartElt.parentNode.className = value;
378 if (effectiveStartElt.parentNode == effectiveEndElt.parentNode) {
382 if (range.startContainer.nodeType == 3) {
383 if (range.startOffset == 0) {
384 effectiveStartElt.className = value;
387 var newSpan = document.createElement(
'SPAN');
388 newSpan.innerHTML = range.startContainer.data.substring(range.startOffset);
389 newSpan.className = value;
390 if (range.startContainer.nextSibling == null) {
391 range.startContainer.parentNode.appendChild(newSpan);
393 range.startContainer.parentNode.insertBefore(newSpan, range.startContainer.nextSibling);
395 range.startContainer.data = range.startContainer.data.substring(0, range.startOffset);
398 effectiveStartElt.className = value;
402 var tempElt = effectiveStartElt.nextSibling;
403 while ((tempElt != null) && (tempElt != effectiveEndElt)) {
404 if (tempElt.nodeType == 3) {
406 var newSpan = document.createElement(
'SPAN');
407 newSpan.innerHTML = tempElt.data;
408 newSpan.className = value;
409 tempElt.parentNode.insertBefore(newSpan, tempElt);
410 tempElt.parentNode.removeChild(tempElt);
412 tempElt.className = value;
414 tempElt = tempElt.nextSibling;
418 if (range.endContainer.nodeType == 3) {
419 if (range.endOffset >= range.endContainer.data.length-1) {
420 effectiveEndElt.className = value;
423 var newSpan = document.createElement(
'SPAN');
424 newSpan.className = value;
425 newSpan.innerHTML = range.endContainer.data.substring(0, range.endOffset);
426 range.endContainer.parentNode.insertBefore(newSpan, range.endContainer);
427 range.endContainer.data = range.endContainer.data.substring(range.endOffset);
430 effectiveEndElt.className == value;
436 alert(
'Styles cannot be applied to the current selection. Try applying styles to smaller subsections individually');
441 if (HTMLArea.is_ie) {
442 value =
"<" + value +
">";
444 this._execCommand(txt,
false, value);
461 $html = preg_replace(
'|<span[^>]+class\="?no_style"?([^>]+)?>([^<]+)?</span>|i',
'\\2', $html);
462 $html = preg_replace(
'|(<[^>]*?)class\="?no_style"?([^>]*?>)|i',
'$1$2', $html);
476 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
478 if (isset($GLOBALS[
'sq_preview_url']) && !empty($GLOBALS[
'sq_preview_url'])) {
479 $url = $GLOBALS[
'sq_preview_url'];
480 $url = preg_replace(
'|^http[s]?://|',
'', $url);
482 $designid = $am->getValueFromURL($url,
'design::%frontend%', TRUE);
485 $design = $am->getAsset($designid);
486 $classes_list = $design->attr(
'wysiwyg_classes');
487 if (!empty($classes_list)) {
488 foreach ($classes_list as $key => $value) {
489 $classes[$key] = $value;