Follow-up for feature #7970: fontstyle and fontsize should not use deprecated font tag
authorStanislas Rolland <typo3@sjbr.ca>
Sun, 8 Mar 2009 05:07:16 +0000 (05:07 +0000)
committerStanislas Rolland <typo3@sjbr.ca>
Sun, 8 Mar 2009 05:07:16 +0000 (05:07 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5140 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/rtehtmlarea/ChangeLog
typo3/sysext/rtehtmlarea/doc/manual.sxw
typo3/sysext/rtehtmlarea/extensions/SelectFont/class.tx_rtehtmlarea_selectfont.php
typo3/sysext/rtehtmlarea/extensions/SelectFont/locallang.xml
typo3/sysext/rtehtmlarea/htmlarea/plugins/SelectFont/select-font.js

index 0440396..f2e23fa 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,10 @@
+2009-03-07  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Follow-up for feature #7970: fontstyle and fontsize should not use deprecated font tag
+
 2009-03-07  Benjamin Mack  <benni@typo3.org>
 
        * Cleanup #10601: Move static dyntabmenu code in external file
-Description
        * #10565: Speedup / Cleanup t3lib_match_condition - make use of trimExplode
 
 2009-03-07  Ingo Renner  <ingo@typo3.org>
index 2152211..0659914 100644 (file)
@@ -1,3 +1,7 @@
+2009-03-07  Stanislas Rolland  <typo3@sjbr.ca>
+
+       * Follow-up for feature #7970: fontstyle and fontsize should not use deprecated font tag
+
 2009-03-06  Stanislas Rolland  <typo3@sjbr.ca>
 
        * Fixed bug #10610: htmlArea RTE: Two errors in class.tx_rtehtmlarea_acronym.php (Thanks to Ursula Renziehausen).
index 107f0f4..d67c4a5 100644 (file)
Binary files a/typo3/sysext/rtehtmlarea/doc/manual.sxw and b/typo3/sysext/rtehtmlarea/doc/manual.sxw differ
index 6a8c7ec..f298004 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2008 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  (c) 2008-2009 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the Typo3 project. The Typo3 project is
@@ -62,13 +62,13 @@ class tx_rtehtmlarea_selectfont extends tx_rtehtmlareaapi {
                        'Wingdings'             => 'Wingdings',
                        ),
                'fontsize' => array(
-                       'Extra small'   =>      'xx-small',
-                       'Very small'    =>      'x-small',
-                       'Small'         =>      'small',
-                       'Medium'        =>      'medium',
-                       'Large'         =>      'large',
-                       'Very large'    =>      'x-large',
-                       'Extra large'   =>      'xx-large',
+                       'Extra small'   =>      '8px',
+                       'Very small'    =>      '9px',
+                       'Small'         =>      '10px',
+                       'Medium'        =>      '12px',
+                       'Large'         =>      '16px',
+                       'Very large'    =>      '24px',
+                       'Extra large'   =>      '32px',
                        ),
                );
 
@@ -121,42 +121,42 @@ class tx_rtehtmlarea_selectfont extends tx_rtehtmlareaapi {
 
                        // Getting removal and addition configuration
                $hideItems = $this->htmlAreaRTE->cleanList($this->thisConfig['hideFont' .  (($buttonId == 'fontstyle') ? 'Faces' : 'Sizes')]);
-               $addItems = $this->htmlAreaRTE->cleanList($this->thisConfig[($buttonId == 'fontstyle') ? 'fontFace' : 'fontSize']);
-               if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.'][$buttonId])) {
-                       if ($this->thisConfig['buttons.'][$buttonId]['removeItems']) {
-                               $hideItems = $this->thisConfig['buttons.'][$buttonId]['removeItems'];
+               $addItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig[($buttonId == 'fontstyle') ? 'fontFace' : 'fontSize']), 1);
+               if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.'][$buttonId . '.'])) {
+                       if ($this->thisConfig['buttons.'][$buttonId . '.']['removeItems']) {
+                               $hideItems = $this->thisConfig['buttons.'][$buttonId . '.']['removeItems'];
                        }
-                       if ($this->thisConfig['buttons.'][$buttonId]['addItems']) {
-                               $addItems = $this->thisConfig['buttons.'][$buttonId]['addItems'];
+                       if ($this->thisConfig['buttons.'][$buttonId . '.']['addItems']) {
+                               $addItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig['buttons.'][$buttonId . '.']['addItems']), 1);
                        }
                }
                        // Initializing the items array
                $items = array();
                if ($this->htmlAreaRTE->is_FE()) {
                        $items['none'] = '
-                       "' . $GLOBALS['TSFE']->getLLL((($buttonId == 'fontstyle') ? 'No font' : 'No size'), $this->LOCAL_LANG) . '" : ""';
+                       "' . $GLOBALS['TSFE']->getLLL((($buttonId == 'fontstyle') ? 'Default font' : 'Default size'), $this->LOCAL_LANG) . '" : ""';
                } else {
                        $items['none'] = '
                        "' . ($this->htmlAreaRTE->TCEform->inline->isAjaxCall 
-                                       ? $GLOBALS['LANG']->csConvObj->utf8_encode($GLOBALS['LANG']->getLL(($buttonId == 'fontstyle') ? 'No font' : 'No size'), $GLOBALS['LANG']->charSet) 
-                                       : $GLOBALS['LANG']->getLL(($buttonId == 'fontstyle') ? 'No font' : 'No size')) . '" : ""';
+                                       ? $GLOBALS['LANG']->csConvObj->utf8_encode($GLOBALS['LANG']->getLL(($buttonId == 'fontstyle') ? 'Default font' : 'Default size'), $GLOBALS['LANG']->charSet) 
+                                       : $GLOBALS['LANG']->getLL(($buttonId == 'fontstyle') ? 'Default font' : 'Default size')) . '" : ""';
                }
-               $defaultItems = 'none,';
-
                        // Inserting and localizing default items
                if ($hideItems != '*') {
                        $index = 0;
                        foreach ($this->defaultFont[$buttonId] as $name => $value) {
-                               if (!t3lib_div::inList($hideItems, $index+1)) {
+                               if (!t3lib_div::inList($hideItems, strval($index+1))) {
                                        if ($this->htmlAreaRTE->is_FE()) {
                                                $label = $GLOBALS['TSFE']->getLLL($name,$this->LOCAL_LANG);
                                        } else {
                                                $label = $GLOBALS['LANG']->getLL($name);
+                                               if (!$label) {
+                                                       $label = $name;
+                                               }
                                                $label = $this->htmlAreaRTE->TCEform->inline->isAjaxCall ? $GLOBALS['LANG']->csConvObj->utf8_encode($label, $GLOBALS['LANG']->charSet) : $label;
                                        }
                                        $items[$name] = '
                                "' . $label . '" : "' . $this->htmlAreaRTE->cleanList($value) . '"';
-                                       $defaultItems .= $name . ',';
                                }
                                $index++;
                        }
@@ -165,18 +165,24 @@ class tx_rtehtmlarea_selectfont extends tx_rtehtmlareaapi {
                if (is_array($this->RTEProperties[($buttonId == 'fontstyle') ? 'fonts.' : 'fontSizes.'])) {
                        foreach ($this->RTEProperties[($buttonId == 'fontstyle') ? 'fonts.' : 'fontSizes.'] as $name => $conf) {
                                $name = substr($name,0,-1);
-                               $label = $this->htmlAreaRTE->getPageConfigLabel($conf['name'],0);
-                               $label = (!$this->htmlAreaRTE->is_FE() && $this->htmlAreaRTE->TCEform->inline->isAjaxCall) ? $GLOBALS['LANG']->csConvObj->utf8_encode($label, $GLOBALS['LANG']->charSet) : $label;
-                               $items[$name] = '
+                               if (in_array($name, $addItems)) {
+                                       $label = $this->htmlAreaRTE->getPageConfigLabel($conf['name'],0);
+                                       $label = (!$this->htmlAreaRTE->is_FE() && $this->htmlAreaRTE->TCEform->inline->isAjaxCall) ? $GLOBALS['LANG']->csConvObj->utf8_encode($label, $GLOBALS['LANG']->charSet) : $label;
+                                       $items[$name] = '
                                "' . $label . '" : "' . $this->htmlAreaRTE->cleanList($conf['value']) . '"';
+                               }
                        }
                }
+                       // Seting default item
+               if ($this->thisConfig['buttons.'][$buttonId . '.']['defaultItem'] && $items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']]) {
+                       $items['none'] = $items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']];
+                       unset($items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']]);
+               }
                        // Setting the JS list of options
                $JSOptions = '';
-               $configuredItems = t3lib_div::trimExplode(',' , $this->htmlAreaRTE->cleanList($defaultItems . ',' . $addItems));
                $index = 0;
-               foreach ($configuredItems as $name) {
-                       $JSOptions .= ($index ? ',' : '') . $items[$name];
+               foreach ($items as $option) {
+                       $JSOptions .= ($index ? ',' : '') . $option;
                        $index++;
                }
                $JSOptions = '{'
@@ -184,7 +190,7 @@ class tx_rtehtmlarea_selectfont extends tx_rtehtmlareaapi {
                };';
 
                        // Adding to button JS configuration
-               if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$buttonId.'.'])) {
+               if (!is_array( $this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][$buttonId . '.'])) {
                        $configureRTEInJavascriptString .= '
                        RTEarea['.$RTEcounter.'].buttons.'. $buttonId .' = new Object();';
                }
index 0812c4e..172a486 100644 (file)
@@ -9,6 +9,8 @@
                <languageKey index="default" type="array">
                        <label index="No font">No font</label>
                        <label index="No size">No font size</label>
+                       <label index="Default font">Default font</label>
+                       <label index="Default size">Default size</label>
                        <label index="Extra small">Extra small</label>
                        <label index="Very small">Very small</label>
                        <label index="Small">Small</label>
index cb7c646..e9d2ee8 100644 (file)
@@ -1,7 +1,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2008 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  (c) 2008-2009 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -39,25 +39,36 @@ SelectFont = HTMLArea.Plugin.extend({
         * This function gets called by the class constructor
         */
        configurePlugin : function (editor) {
-               
+
                this.options = new Object();
-               this.options.FontName = this.editorConfiguration.buttons.fontstyle ? this.editorConfiguration.buttons.fontstyle.options : null;
-               this.options.FontSize = this.editorConfiguration.buttons.fontsize ? this.editorConfiguration.buttons.fontsize.options : null;
+               this.defaultValue = new Object();
+               if (this.editorConfiguration.buttons.fontstyle) {
+                       this.options.FontName = this.editorConfiguration.buttons.fontstyle.options;
+                       if (this.editorConfiguration.buttons.fontstyle.defaultItem) {
+                               this.defaultValue.FontName = this.editorConfiguration.buttons.fontstyle.options[this.editorConfiguration.buttons.fontstyle.defaultItem];
+                       }
+               }
+               if (this.editorConfiguration.buttons.fontsize) {
+                       this.options.FontSize = this.editorConfiguration.buttons.fontsize.options;
+                       if (this.editorConfiguration.buttons.fontsize.defaultItem) {
+                               this.defaultValue.FontSize = this.editorConfiguration.buttons.fontsize.options[this.editorConfiguration.buttons.fontsize.defaultItem];
+                       }
+               }
                this.disablePCexamples = this.editorConfiguration.disablePCexamples;
 
                        // Font formating will use the style attribute
-               if (this.editor.plugins.TextStyle && this.editor.plugins.TextStyle.instance) {
-                       this.editor.plugins.TextStyle.instance.addAllowedAttribute("style");
-                       this.allowedAttributes = this.editor.plugins.TextStyle.instance.allowedAttributes;
-               }                       
-               if (this.editor.plugins.InlineElements && this.editor.plugins.InlineElements.instance) {
-                       this.editor.plugins.InlineElements.instance.addAllowedAttribute("style");
+               if (this.editor.getPluginInstance("TextStyle")) {
+                       this.editor.getPluginInstance("TextStyle").addAllowedAttribute("style");
+                       this.allowedAttributes = this.editor.getPluginInstance("TextStyle").allowedAttributes;
+               }
+               if (this.editor.getPluginInstance("InlineElements")) {
+                       this.editor.getPluginInstance("InlineElements").addAllowedAttribute("style");
                        if (!this.allowedAllowedAttributes) {
-                               this.allowedAttributes = this.editor.plugins.InlineElements.instance.allowedAttributes;
+                               this.allowedAttributes = this.editor.getPluginInstance("InlineElements").allowedAttributes;
                        }
                }
-               if (this.editor.plugins.BlockElements && this.editor.plugins.BlockElements.instance) {
-                       this.editor.plugins.BlockElements.instance.addAllowedAttribute("style");
+               if (this.editor.getPluginInstance("BlockElements")) {
+                       this.editor.getPluginInstance("BlockElements").addAllowedAttribute("style");
                }
                if (!this.allowedAttributes) {
                        this.allowedAttributes = new Array("id", "title", "lang", "xml:lang", "dir", (HTMLArea.is_gecko?"class":"className"), "style");
@@ -111,6 +122,14 @@ SelectFont = HTMLArea.Plugin.extend({
                FontName        : "fontFamily",
                FontSize        : "fontSize"
        },
+       
+       /*
+        * Conversion object: button name to corresponding css property name
+        */
+       cssProperty : {
+               FontName        : "font-family",
+               FontSize        : "font-size"
+       },
         
        /*
         * This function gets called when some font style or font size was selected from the dropdown lists
@@ -118,13 +137,13 @@ SelectFont = HTMLArea.Plugin.extend({
        onChange : function (editor, buttonId) {
                var select = document.getElementById(this.editor._toolbarObjects[buttonId].elementId),
                        param = select.value;
-               if (param == 'none') {
+               if (!select.selectedIndex) {
                        param = "";
                }
                editor.focusEditor();
                var selection = editor._getSelection(),
                        range = editor._createRange(selection),
-                       statusBarSelection = editor.getPluginInstance("StatusBar") ? editor.getPluginInstance("StatusBar").getSelection() : null;
+                       statusBarSelection = editor.getPluginInstance("StatusBar") ? editor.getPluginInstance("StatusBar").getSelection() : null,
                        element;
                if (editor._selectionEmpty(selection)) {
                        element = editor.getParentElement(selection, range);
@@ -197,6 +216,15 @@ SelectFont = HTMLArea.Plugin.extend({
                                if (this.isButtonInToolbar(buttonId)) {
                                        var select = document.getElementById(editor._toolbarObjects[buttonId].elementId);
                                        value = parentElement.style[this.styleProperty[buttonId]];
+                                       if (!value) {
+                                               if (HTMLArea.is_gecko) {
+                                                       if (editor._doc.defaultView.getComputedStyle(parentElement, null)) {
+                                                               value = editor._doc.defaultView.getComputedStyle(parentElement, null).getPropertyValue(this.cssProperty[buttonId]);
+                                                       }
+                                               } else {
+                                                       value = parentElement.currentStyle[this.styleProperty[buttonId]];
+                                               }
+                                       }
                                        select.selectedIndex = 0;
                                        if (value) {
                                                var options = this.options[buttonId];