[+FEATURE] Re-Added term type "Description (tool-tip)" with a pure CSS based tooltip.
authorjocrau <jocrau@735d13b6-9817-0410-8766-e36946ffe9aa>
Fri, 5 Feb 2010 23:52:00 +0000 (23:52 +0000)
committerBastian Bringenberg <spam@bastian-bringenberg.de>
Thu, 4 Dec 2014 23:56:07 +0000 (00:56 +0100)
[+FEATURE] Added support for custom JavaScript libraries.

git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/contagged/trunk@29748 735d13b6-9817-0410-8766-e36946ffe9aa

class.tx_contagged.php
ext_conf_template.txt
javascript/contagged.js [new file with mode: 0644]
static/css/setup.txt
static/setup.txt

index 49cf1bf..6375ccf 100644 (file)
@@ -75,7 +75,7 @@ class tx_contagged extends tslib_pibase {
 
                // exit if the content should be skipped
                if ($this->isContentToSkip()) return $content;          
-
+               
                // get an array of all type configurations
                $this->typesArray = $this->conf['types.'];
 
@@ -115,6 +115,7 @@ class tx_contagged extends tslib_pibase {
                if ($this->conf['updateKeywords'] > 0) {
                        $this->updatePageKeywords();
                }
+               $this->addJavaScript();
 
                return $parsedContent;
        }
@@ -339,10 +340,9 @@ class tx_contagged extends tslib_pibase {
         * @param       int                     $termKey: Internal key of the term
         */
        function registerFields($typeConfigArray,$termKey) {
-               // Replace <p></p> with <br/>; Idea from Markus Timtner. Thank you!
-               // TODO: strip or replace all block-tags
                if ($typeConfigArray['stripBlockTags']>0) {
-                       $this->termsArray[$termKey]['desc_long'] = preg_replace('/<p[^<>]*>(.*?)<\/p\s*>/' . $this->conf['modifier'],'$1<br />',$this->termsArray[$termKey]['desc_long']);
+                       $text = $this->cObj->parseFunc($this->termsArray[$termKey]['desc_long'], array(), '< lib.parseFunc_RTE');
+                       $this->termsArray[$termKey]['desc_long_inline'] = $this->stripBlockTags($text);
                }
 
                $GLOBALS['TSFE']->register['contagged_key'] = $termKey;
@@ -391,6 +391,7 @@ class tx_contagged extends tslib_pibase {
                                        $parameter = array_shift(t3lib_div::trimExplode(',',$this->conf['listPages'],1));
                                }
                        }
+                       $GLOBALS['TSFE']->register['contagged_list_page'] = $parameter;
                        $additionalParams = array(
                                'source' => $termArray['source'],
                                'uid' => $termArray['uid'],
@@ -400,6 +401,7 @@ class tx_contagged extends tslib_pibase {
                        }
                        $typolinkConf['additionalParams'] = t3lib_div::implodeArrayForUrl('tx_contagged', $additionalParams, '', 1);
                        $typolinkConf['parameter'] = $parameter;
+                       $GLOBALS['TSFE']->register['contagged_link_url'] = $this->cObj->typoLink_URL($typolinkConf);
                        $matchedTerm = $this->cObj->typolink($matchedTerm, $typolinkConf);              
                }
                
@@ -529,6 +531,100 @@ class tx_contagged extends tslib_pibase {
 
                return $result;
        }
+       
+       /**
+        * Replaces block elements with inline versions (if possible)
+        * 
+        * @param string $text 
+        * @return string The reformatted text
+        */
+       protected function stripBlockTags($text) {
+               $blockElements = 'address|blockquote|center|del|dir|div|dl|fieldset|form|h[1-6]|hr|ins|isindex|menu|noframes|noscript|ol|p|pre|table|ul|center|dir|isindex|menu|noframes';
+           $text = preg_replace('%' . $this->getOpeningTag('li|dd') . '%xs', '&nbsp;&nbsp;*&nbsp;', $text);
+           $text = preg_replace('%' . $this->getClosingTag('li|dt') . '%xs', '<br />', $text);
+           $text = preg_replace('%' . $this->getClosingTag('ol|ul|dl') . '%xs', '', $text);
+           $text = preg_replace('%' . $this->getOpeningTag($blockElements) . '%xs', '', $text);
+           $text = preg_replace('%' . $this->getClosingTag($blockElements) . '%xs', '<br />', $text);
+           $text = preg_replace('%' . $this->getOpeningTag('br') . '{2,2}%xs', '<br />', $text);
+           return $text;
+       }
+       
+       /**
+        * Returns an opening tag of the allowed elements.
+        *
+        * @param string $allowedElements The allowed elements ("a|b|c")
+        * @return void
+        */
+       protected function getOpeningTag($allowedElements) {
+               $tag = "
+                       (
+                               <(?:" . $allowedElements . ")           # opening tag ('<tag') or closing tag ('</tag')
+                               (?:
+                                       (?:
+                                               \s+\w+                                  # EITHER spaces, followed by word characters (attribute names)
+                                               (?:
+                                                       \s*=?\s*                        # equals
+                                                       (?>
+                                                               \".*?\"                 # attribute values in double-quotes
+                                                               |
+                                                               '.*?'                   # attribute values in single-quotes
+                                                               |
+                                                               [^'\">\s]+              # plain attribute values
+                                                       )
+                                               )?
+                                       )+\s*
+                                       |                                                       # OR only spaces
+                                       \s*
+                               )
+                               /?>                                                             # closing the tag with '>' or '/>'
+                       )";
+               return $tag;            
+       }
+
+       /**
+        * Returns a closing tag of the allowed elements.
+        *
+        * @param string $allowedElements The allowed elements ("a|b|c")
+        * @return void
+        */
+       protected function getClosingTag($allowedElements) {
+               $tag = "
+                       (
+                               </(?:" . $allowedElements . ")          # opening tag ('<tag') or closing tag ('</tag')
+                               (?:
+                                       (?:
+                                               \s+\w+                                  # EITHER spaces, followed by word characters (attribute names)
+                                               (?:
+                                                       \s*=?\s*                        # equals
+                                                       (?>
+                                                               \".*?\"                 # attribute values in double-quotes
+                                                               |
+                                                               '.*?'                   # attribute values in single-quotes
+                                                               |
+                                                               [^'\">\s]+              # plain attribute values
+                                                       )
+                                               )?
+                                       )+\s*
+                                       |                                                       # OR only spaces
+                                       \s*
+                               )
+                               >                                                               # closing the tag with '>' or '/>'
+                       )";
+               return $tag;            
+       }
+       
+       /**
+        * Adds the qTip plugin script (jQuery). You can call this function in you TS setup if necessary.
+        *
+        * @return void
+        */
+       protected function addJavaScript() {
+               $extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['contagged']);
+               $javaScriptPathAndFilename = $extensionConfiguration['javaScriptPathAndFilename'];
+               if (is_string($javaScriptPathAndFilename) && $javaScriptPathAndFilename !== '') {
+                       $GLOBALS['TSFE']->additionalHeaderData['contagged'] .= '<script src="' . $javaScriptPathAndFilename . '" type="text/javascript"></script>';
+               }
+       }
 }
 
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/contagged/class.tx_contagged.php']) {
index 4c4632b..02951a2 100644 (file)
@@ -1,2 +1,5 @@
        # cat=basic//20; type=boolean; label= DAM as image source: Take DAM (digital asset management) as image source.
-       getImagesFromDAM = 0
\ No newline at end of file
+       getImagesFromDAM = 0
+       
+       # cat=basic//30; type=string; label= JavaScript: The Path and filename of the JavaScript to be included on parsed pages (e.g.to display tooltips).
+       javaScriptPathAndFilename = typo3conf/ext/contagged/javascript/contagged.js
\ No newline at end of file
diff --git a/javascript/contagged.js b/javascript/contagged.js
new file mode 100644 (file)
index 0000000..e69de29
index 25c198f..a2de29d 100644 (file)
@@ -18,5 +18,30 @@ plugin.tx_contagged {
                div.tx-contagged-index span {
                        margin: 0;
                }
+               
+               /* position:relative is necessary for correct positioning of inline descriptions */
+               span.tx-contagged-tooltip {
+                       position: relative;
+               }
+
+               /* z-index makes sure the block is the top most element */
+               span.tx-contagged-tooltip span.tx-contagged-tooltip-content {
+                       background: #EEEEEE;
+                       display: none;
+                       position: absolute;
+                       z-index: 9999;
+               }
+
+               span.tx-contagged-tooltip:hover span.tx-contagged-tooltip-content {
+                       display: inline;
+                       position: absolute;
+                       top: -1px;
+                       left: -11px;
+                       width: 300px;
+                       margin-top: -1px;
+                       border: 1px #CCCCCC solid;
+                       padding: 0px 10px 10px 10px;
+               }
+               
        )
 }
\ No newline at end of file
index b53383d..a451e6f 100644 (file)
@@ -109,6 +109,28 @@ plugin.tx_contagged {
                        label.de = Definition
                        tag = dfn
                }
+               
+               tooltip {
+                       label = Definition (tool-tip)
+                       label.de = Definition (Tool-Tip)
+                       tag = span
+                       addCssClassAttribute = 1
+                       cssClass = tooltip
+                       stripBlockTags = 1
+                       stdWrap.innerWrap.cObject = COA
+                       stdWrap.innerWrap.cObject {
+                               10 = TEXT
+                               10.value = | <span id="{register:contagged_key}" class="tx-contagged-tooltip-content"><a href="{register:contagged_link_url}">{register:contagged_matchedTerm}</a>
+                               10.insertData = 1
+                               50 = TEXT
+                               50.value = <br />
+                               60 = TEXT
+                               60.required = 1
+                               60.data = register:contagged_desc_long_inline
+                               70 = TEXT
+                               70.value = </span>
+                       }
+               }
 
                acronym {
                        label = Acronym
@@ -141,7 +163,6 @@ plugin.tx_contagged {
                                term_lang.field = term_lang
                                desc_short.field = desc_short
                                desc_long.field = desc_long
-                               # desc_long.stdWrap.parseFunc < lib.parseFunc_RTE
                                image.field = image
                                imagecaption.field = imagecaption
                                imagealt.field = imagealt