* Fixed bug #7560: Incorrect behaviours of block style in htmlArea RTE
authorStanislas Rolland <typo3@sjbr.ca>
Sun, 17 Feb 2008 03:06:31 +0000 (03:06 +0000)
committerStanislas Rolland <typo3@sjbr.ca>
Sun, 17 Feb 2008 03:06:31 +0000 (03:06 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@3175 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/rtehtmlarea/ChangeLog
typo3/sysext/rtehtmlarea/class.tx_rtehtmlarea_base.php
typo3/sysext/rtehtmlarea/htmlarea/plugins/BlockStyle/block-style.js

index 8c2302e..0a194f5 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-02-16  Stanislas Rolland  <stanislas.rolland@fructifor.ca>
+
+       * Fixed bug #7560: Incorrect behaviours of block style in htmlArea RTE
+
 2008-02-17  Dmitry Dulepov  <dmitry@typo3.org>
 
        * Fixed bug #7558: typolinkCheckRootline is broken in 4.2
index 8c4313c..3b4c3d9 100644 (file)
@@ -1,3 +1,7 @@
+2008-02-16  Stanislas Rolland  <stanislas.rolland@fructifor.ca>
+
+       * Fixed bug #7560: Incorrect behaviours of block style in htmlArea RTE
+
 2008-02-13  Stanislas Rolland  <stanislas.rolland@fructifor.ca>
 
        * Fixed bug #7232: htmlArea RTE: In IE, selecting words with CTRL+SHIFT+Left doesn't activate "link" button
index 369d8ff..7effd02 100644 (file)
@@ -1025,7 +1025,7 @@ class tx_rtehtmlarea_base extends t3lib_rteapi {
        function buildJSClassesConfig($RTEcounter) {
                        // Build JS array of lists of classes
                $classesTagList = 'classesCharacter, classesParagraph, classesImage, classesTable, classesLinks, classesTD';
-               $classesTagConvert = array( 'classesCharacter' => 'span', 'classesParagraph' => 'p', 'classesImage' => 'img', 'classesTable' => 'table', 'classesLinks' => 'a', 'classesTD' => 'td');
+               $classesTagConvert = array( 'classesCharacter' => 'span', 'classesParagraph' => 'div', 'classesImage' => 'img', 'classesTable' => 'table', 'classesLinks' => 'a', 'classesTD' => 'td');
                $classesTagArray = t3lib_div::trimExplode(',' , $classesTagList);
                $configureRTEInJavascriptString = '
                        RTEarea['.$RTEcounter.']["classesTag"] = new Object();';
index 6d09dac..2d98b98 100644 (file)
@@ -1,7 +1,7 @@
 /***************************************************************
 *  Copyright notice
 *
-* (c) 2007 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+* (c) 2007-2008 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -29,7 +29,7 @@
 /*
  * Block Style Plugin for TYPO3 htmlArea RTE
  *
- * TYPO3 CVS ID: $Id$
+ * TYPO3 SVN ID: $Id: block-style.js $
  */
 BlockStyle = HTMLArea.Plugin.extend({
                
@@ -37,7 +37,7 @@ BlockStyle = HTMLArea.Plugin.extend({
                this.base(editor, pluginName);
        },
        
-               /*
+       /*
         * This function gets called by the class constructor
         */
        configurePlugin : function(editor) {
@@ -53,12 +53,12 @@ BlockStyle = HTMLArea.Plugin.extend({
                        this.tags = new Object();
                }
                if (typeof(this.editorConfiguration.classesTag) !== "undefined") {
-                       if (this.editorConfiguration.classesTag.p) {
-                               if (!this.tags.p) {
-                                       this.tags.p = new Object();
+                       if (this.editorConfiguration.classesTag.div) {
+                               if (!this.tags.div) {
+                                       this.tags.div = new Object();
                                }
-                               if (!this.tags.p.allowedClasses) {
-                                       this.tags.p.allowedClasses = this.editorConfiguration.classesTag.p;
+                               if (!this.tags.div.allowedClasses) {
+                                       this.tags.div.allowedClasses = this.editorConfiguration.classesTag.div;
                                }
                        }
                        if (this.editorConfiguration.classesTag.td) {
@@ -84,7 +84,7 @@ BlockStyle = HTMLArea.Plugin.extend({
                
                        /* Registering plugin "About" information */
                var pluginInformation = {
-                       version         : "1.0",
+                       version         : "1.1",
                        developer       : "Stanislas Rolland",
                        developerUrl    : "http://www.fructifor.ca/",
                        copyrightOwner  : "Stanislas Rolland",
@@ -128,21 +128,31 @@ BlockStyle = HTMLArea.Plugin.extend({
                                var tagName = parent.tagName.toLowerCase();
                        }
                        if (parent.tagName.toLowerCase() == tagName) {
-                               if (className == "none") {
-                                       var classNames = parent.className.trim().split(" ");
-                                       for (var i = classNames.length; --i >= 0;) {
-                                               if (!HTMLArea.reservedClassNames.test(classNames[i])) {
-                                                       HTMLArea._removeClass(parent, classNames[i]);
-                                                       break;
-                                               }
-                                       }
-                               } else {
-                                       HTMLArea._addClass(parent, className);
+                               this.applyClassChange(parent, className);
+                       }
+               }
+       },
+       
+       /*
+        * This function applies the class change to the node
+        */
+       applyClassChange : function (node, className) {
+               if (className == "none") {
+                       var classNames = node.className.trim().split(" ");
+                       for (var i = classNames.length; --i >= 0;) {
+                               if (!HTMLArea.reservedClassNames.test(classNames[i])) {
+                                       HTMLArea._removeClass(node, classNames[i]);
+                                       break;
                                }
                        }
+               } else {
+                       HTMLArea._addClass(node, className);
                }
        },
        
+       /*
+        * This function gets the list of selected blocks
+        */
        getSelectedBlocks : function() {
                var block, range, i = 0, blocks = [];
                if (HTMLArea.is_gecko && !HTMLArea.is_safari && !HTMLArea.is_opera) {
@@ -161,6 +171,9 @@ BlockStyle = HTMLArea.Plugin.extend({
                return blocks;
        },
        
+       /*
+        * This function gets called when the editor is generated
+        */
        onGenerate : function() {
                if (HTMLArea.is_gecko) {
                        this.generate(this.editor, "BlockStyle");
@@ -208,6 +221,9 @@ BlockStyle = HTMLArea.Plugin.extend({
                }
        },
        
+       /*
+        * This function updates the current value of the dropdown list
+        */
        updateValue : function(dropDownId) {
                var select = document.getElementById(this.editor._toolbarObjects[dropDownId].elementId);
                while(select.options.length > 0) {
@@ -222,53 +238,13 @@ BlockStyle = HTMLArea.Plugin.extend({
                while (parent && !HTMLArea.isBlockElement(parent) && parent.nodeName.toLowerCase() != "img") {
                        parent = parent.parentNode;
                }
-               
                if (parent) {
                        tagName = parent.nodeName.toLowerCase();
-                       if (parent.className && /\S/.test(parent.className)) {
-                               classNames = parent.className.trim().split(" ");
-                       }
-                       if (HTMLArea.reservedClassNames.test(parent.className)) {
-                               var cleanClassNames = new Array();
-                               var j = -1;
-                               for (var i = 0; i < classNames.length; ++i) {
-                                       if (HTMLArea.reservedClassNames.test(classNames[i])) {
-                                               cleanClassNames[++j] = classNames[i];
-                                       }
-                               }
-                               classNames = cleanClassNames;
-                       }
+                       classNames = this.getClassNames(parent);
                }
                if (tagName && tagName !== "body"){
                        this.buildDropDownOptions(select, tagName);
-                       select.selectedIndex = 0;
-                       if (classNames.length) {
-                               for (var i = select.options.length; --i >= 0;) {
-                                       if (classNames[classNames.length-1] == select.options[i].value) {
-                                               select.options[i].selected = true;
-                                               select.selectedIndex = i;
-                                               select.options[0].text = this.localize("Remove style");
-                                               break;
-                                       }
-                               }
-                               if (select.selectedIndex == 0) {
-                                       select.options[select.options.length] = new Option(this.localize("Unknown style"), classNames[classNames.length-1]);
-                                       select.options[select.options.length-1].selected = true;
-                                       select.selectedIndex = select.options.length-1;
-                               }
-                               for (var i = select.options.length; --i >= 0;) {
-                                       if (("," + classNames.join(",") + ",").indexOf("," + select.options[i].value + ",") !== -1) {
-                                               if (select.selectedIndex != i) {
-                                                       select.options[i] = null;
-                                               }
-                                       }
-                               }
-                       }
-                       if (select.options.length > 1) {
-                               select.disabled = false;
-                       } else {
-                               select.disabled = true;
-                       }
+                       this.setSelectedOption(select, classNames);
                }
                select.className = "";
                if (select.disabled) {
@@ -276,7 +252,31 @@ BlockStyle = HTMLArea.Plugin.extend({
                }
        },
        
-       buildDropDownOptions : function(select, tagName) {
+       /*
+        * This function returns an array containing the class names assigned to the node
+        */
+       getClassNames : function (node) {
+               var classNames = new Array();
+               if (node && node.className && /\S/.test(node.className)) {
+                       classNames = node.className.trim().split(" ");
+               }
+               if (HTMLArea.reservedClassNames.test(node.className)) {
+                       var cleanClassNames = new Array();
+                       var j = -1;
+                       for (var i = 0; i < classNames.length; ++i) {
+                               if (!HTMLArea.reservedClassNames.test(classNames[i])) {
+                                       cleanClassNames[++j] = classNames[i];
+                               }
+                       }
+                       return cleanClassNames;
+               }
+               return classNames;
+       },
+       
+       /*
+        * This function builds the options to be displayed in the select box
+        */
+       buildDropDownOptions : function (select, tagName) {
                var cssArray = new Array();
                while(select.options.length > 0) {
                        select.options[select.length-1] = null;
@@ -347,6 +347,43 @@ BlockStyle = HTMLArea.Plugin.extend({
                }
        },
        
+       /*
+        * This function sets the selected option of the select box
+        */
+       setSelectedOption : function (select, classNames, noUnknown) {
+               select.selectedIndex = 0;
+               if (classNames.length) {
+                       for (var i = select.options.length; --i >= 0;) {
+                               if (classNames[classNames.length-1] == select.options[i].value) {
+                                       select.options[i].selected = true;
+                                       select.selectedIndex = i;
+                                       select.options[0].text = this.localize("Remove style");
+                                       break;
+                               }
+                       }
+                       if (select.selectedIndex == 0 && !noUnknown) {
+                               select.options[select.options.length] = new Option(this.localize("Unknown style"), classNames[classNames.length-1]);
+                               select.options[select.options.length-1].selected = true;
+                               select.selectedIndex = select.options.length-1;
+                       }
+                       for (var i = select.options.length; --i >= 0;) {
+                               if (("," + classNames.join(",") + ",").indexOf("," + select.options[i].value + ",") !== -1) {
+                                       if (select.selectedIndex != i) {
+                                               select.options[i] = null;
+                                       }
+                               }
+                       }
+               }
+               if (select.options.length > 1) {
+                       select.disabled = false;
+               } else {
+                       select.disabled = true;
+               }
+       },
+       
+       /*
+        * This function builds the main array of class selectors
+        */
        buildCssArray : function(editor, dropDownId) {
                this.cssArray = this.parseStyleSheet();
                if (!this.cssLoaded && (this.cssParseCount < 17)) {
@@ -361,6 +398,9 @@ BlockStyle = HTMLArea.Plugin.extend({
                }
        },
        
+       /*
+        * This function parses the stylesheets
+        */
        parseStyleSheet : function() {
                var iframe = this.editor._iframe.contentWindow ? this.editor._iframe.contentWindow.document : this.editor._iframe.contentDocument;
                var newCssArray = new Object();
@@ -389,6 +429,9 @@ BlockStyle = HTMLArea.Plugin.extend({
                return newCssArray;
        },
        
+       /*
+        * This function parses IE import rules
+        */
        parseCssIEImport : function(cssIEImport, cssArray) {
                var newCssArray = new Object();
                newCssArray = cssArray;
@@ -403,6 +446,9 @@ BlockStyle = HTMLArea.Plugin.extend({
                return newCssArray;
        },
        
+       /*
+        * This function parses gecko css rules
+        */
        parseCssRule : function(cssRules, cssArray) {
                var newCssArray = new Object();
                newCssArray = cssArray;
@@ -424,6 +470,9 @@ BlockStyle = HTMLArea.Plugin.extend({
                return newCssArray;
        },
        
+       /*
+        * This function parses each selector rule
+        */
        parseSelectorText : function(selectorText, cssArray) {
                var cssElements = new Array();
                var cssElement = new Array();
@@ -466,6 +515,9 @@ BlockStyle = HTMLArea.Plugin.extend({
                return newCssArray;
        },
        
+       /*
+        * This function sorts the main array of class selectors
+        */
        sortCssArray : function(cssArray) {
                var newCssArray = new Object();
                for (var tagName in cssArray) {