r63309 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63308‎ | r63309 | r63310 >
Date:13:18, 6 March 2010
Author:ialex
Status:deferred
Tags:
Comment:
* Moved script and style to own file
* Use ParserFirstCallInit hook
* Some coding style fixes
Modified paths:
  • /trunk/extensions/Tooltip/Tooltip.css (added) (history)
  • /trunk/extensions/Tooltip/Tooltip.js (added) (history)
  • /trunk/extensions/Tooltip/Tooltip.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Tooltip/Tooltip.php
@@ -1,7 +1,5 @@
22 <?php
33
4 -$wgExtensionFunctions[] = "wfToolTipExtension";
5 -$wgHooks['LanguageGetMagic'][] = 'wfTooltipParserFunction_Magic';
64 $wgExtensionCredits['parserhook'][] = array(
75 'path' => __FILE__,
86 'name' => 'ToolTip',
@@ -10,84 +8,17 @@
119 'version' => '0.5.2',
1210 );
1311
14 -$dir = dirname(__FILE__) . '/';
 12+$dir = dirname( __FILE__ ) . '/';
1513 $wgExtensionMessagesFiles['Tooltip'] = $dir . 'Tooltip.i18n.php';
1614
17 -function wfToolTipExtension() {
18 - global $wgParser;
19 - global $wgOut;
20 - global $wgScriptPath;
21 -
22 - $output = <<< END
23 -<style type="text/css">
24 - .xstooltip{
25 - visibility: hidden;
26 - position: absolute;
27 - top: 0;
28 - left: 0;
29 - z-index: 2;
30 - font: normal 8pt sans-serif;
31 - color: white;
32 - padding: 3px;
33 - border: solid 1px;
34 - background-repeat: repeat;
35 - background-image: url($wgScriptPath/images/ttbg.png);
36 - }
37 - .xstooltip_body{
38 - color: green;
39 - }
40 -</style>
41 -<script type= "text/javascript">
42 - function xstooltip_findPosX(obj) {
43 - var curleft = 0;
44 - if (obj.offsetParent) {
45 - while (obj.offsetParent){
46 - curleft += obj.offsetLeft;
47 - obj = obj.offsetParent;
48 - }
49 - } else if (obj.x)
50 - curleft += obj.x;
51 - return curleft - 200;
52 - }
53 - function xstooltip_findPosY(obj) {
54 - var curtop = 0;
55 - if (obj.offsetParent) {
56 - while (obj.offsetParent) {
57 - curtop += obj.offsetTop;
58 - obj = obj.offsetParent;
59 - }
60 - } else if (obj.y)
61 - curtop+= obj.y;
62 - return curtop - 25
63 - }
64 - function xstooltip_show(tooltipId, parentId, posX, posY) {
65 - it = document.getElementById(tooltipId);
66 - if (it.style.top == '' || it.style.top == 0) {
67 - if (it.style.left == '' || it.style.left == 0) {
68 - it.style.width = it.offsetWidth + 'px';
69 - it.style.height = it.offsetHeight + 'px';
70 - img = document.getElementById(parentId);
71 - x = xstooltip_findPosX(img) + posX;
72 - y = xstooltip_findPosY(img) + posY;
73 - if (x < 0 )
74 - x = 0;
75 - if (x + it.offsetWidth > img.offsetParent.offsetWidth )
76 - x = img.offsetParent.offsetWidth - it.offsetWidth - 1;
77 - it.style.top = y + 'px';
78 - it.style.left = x + 'px';
79 - }
80 - }
81 - it.style.visibility = 'visible';
82 - }
83 - function xstooltip_hide(id) {
84 - it = document.getElementById(id);
85 - it.style.visibility = 'hidden';
86 - }
87 -</script>
88 -END;
89 - $wgOut->addScript($output);
90 - $wgParser->setHook( "tooltip", "renderToolTip" );
91 - $wgParser->setFunctionHook( 'tooltip', 'wfTooltipParserFunction_Render' );
 15+$wgHooks['ParserFirstCallInit'][] = 'wfToolTipRegisterParserHooks';
 16+$wgHooks['LanguageGetMagic'][] = 'wfTooltipParserFunction_Magic';
 17+$wgHooks['BeforePageDisplay'][] = 'wfTooltipBeforePageDisplay';
 18+
 19+function wfToolTipRegisterParserHooks( $parser ) {
 20+ $parser->setHook( 'tooltip', 'renderToolTip' );
 21+ $parser->setFunctionHook( 'tooltip', 'wfTooltipParserFunction_Render' );
 22+ return true;
9223 }
9324
9425 function wfTooltipParserFunction_Magic( &$magicWords, $langCode ) {
@@ -99,6 +30,14 @@
10031 return true;
10132 }
10233
 34+function wfTooltipBeforePageDisplay( $out ) {
 35+ global $wgExtensionAssetsPath;
 36+
 37+ $out->addScriptFile( "$wgExtensionAssetsPath/Tooltip/Tooltip.js" );
 38+ $out->addExtensionStyle( "$wgExtensionAssetsPath/Tooltip/Tooltip.css" );
 39+ return true;
 40+}
 41+
10342 function wfTooltipParserFunction_Render( $parser, $basetext = '', $tooltiptext = '', $x = 0, $y = 0) {
10443 $output = renderToolTip($tooltiptext, array('text'=>$basetext, 'x'=>$x, 'y'=>$y), $parser);
10544 return array($output, 'nowiki' => false, 'noparse' => true, 'isHTML' => false);
@@ -128,8 +67,8 @@
12968 $output = '';
13069
13170 if ($input != '') {
132 - $tooltipid = uniqid('tooltipid');
133 - $parentid = uniqid('parentid');
 71+ $tooltipid = uniqid( 'tooltipid' );
 72+ $parentid = uniqid( 'parentid' );
13473 $output .= "<span id='$tooltipid' class='xstooltip'>" . $parser->unstrip($parser->recursiveTagParse($input),$parser->mStripState) . "</span>";
13574 $output .= "<span id='$parentid' class='xstooltip_body' onmouseover=\"xstooltip_show('$tooltipid', '$parentid', $xoffset, $yoffset);\" onmouseout=\"xstooltip_hide('$tooltipid');\">" . $parser->unstrip($parser->recursiveTagParse($text),$parser->mStripState) . "</span>";
13675 }
@@ -137,4 +76,3 @@
13877 return $output;
13978 }
14079
141 -?>
Index: trunk/extensions/Tooltip/Tooltip.css
@@ -0,0 +1,17 @@
 2+.xstooltip {
 3+ visibility: hidden;
 4+ position: absolute;
 5+ top: 0;
 6+ left: 0;
 7+ z-index: 2;
 8+ font: normal 8pt sans-serif;
 9+ color: white;
 10+ padding: 3px;
 11+ border: solid 1px;
 12+ background-repeat: repeat;
 13+ /*background-image: url($wgScriptPath/images/ttbg.png);*/
 14+}
 15+
 16+.xstooltip_body {
 17+ color: green;
 18+}
\ No newline at end of file
Property changes on: trunk/extensions/Tooltip/Tooltip.css
___________________________________________________________________
Name: svn:eol-style
119 + native
Index: trunk/extensions/Tooltip/Tooltip.js
@@ -0,0 +1,48 @@
 2+function xstooltip_findPosX(obj) {
 3+ var curleft = 0;
 4+ if (obj.offsetParent) {
 5+ while (obj.offsetParent){
 6+ curleft += obj.offsetLeft;
 7+ obj = obj.offsetParent;
 8+ }
 9+ } else if (obj.x)
 10+ curleft += obj.x;
 11+ return curleft - 200;
 12+}
 13+
 14+function xstooltip_findPosY(obj) {
 15+ var curtop = 0;
 16+ if (obj.offsetParent) {
 17+ while (obj.offsetParent) {
 18+ curtop += obj.offsetTop;
 19+ obj = obj.offsetParent;
 20+ }
 21+ } else if (obj.y)
 22+ curtop+= obj.y;
 23+ return curtop - 25
 24+}
 25+
 26+function xstooltip_show(tooltipId, parentId, posX, posY) {
 27+ it = document.getElementById(tooltipId);
 28+ if (it.style.top == '' || it.style.top == 0) {
 29+ if (it.style.left == '' || it.style.left == 0) {
 30+ it.style.width = it.offsetWidth + 'px';
 31+ it.style.height = it.offsetHeight + 'px';
 32+ img = document.getElementById(parentId);
 33+ x = xstooltip_findPosX(img) + posX;
 34+ y = xstooltip_findPosY(img) + posY;
 35+ if (x < 0 )
 36+ x = 0;
 37+ if (x + it.offsetWidth > img.offsetParent.offsetWidth )
 38+ x = img.offsetParent.offsetWidth - it.offsetWidth - 1;
 39+ it.style.top = y + 'px';
 40+ it.style.left = x + 'px';
 41+ }
 42+ }
 43+ it.style.visibility = 'visible';
 44+}
 45+
 46+function xstooltip_hide(id) {
 47+ it = document.getElementById(id);
 48+ it.style.visibility = 'hidden';
 49+}
\ No newline at end of file
Property changes on: trunk/extensions/Tooltip/Tooltip.js
___________________________________________________________________
Name: svn:eol-style
150 + native

Status & tagging log