Index: trunk/extensions/Tooltip/Tooltip.php |
— | — | @@ -1,7 +1,5 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -$wgExtensionFunctions[] = "wfToolTipExtension"; |
5 | | -$wgHooks['LanguageGetMagic'][] = 'wfTooltipParserFunction_Magic'; |
6 | 4 | $wgExtensionCredits['parserhook'][] = array( |
7 | 5 | 'path' => __FILE__, |
8 | 6 | 'name' => 'ToolTip', |
— | — | @@ -10,84 +8,17 @@ |
11 | 9 | 'version' => '0.5.2', |
12 | 10 | ); |
13 | 11 | |
14 | | -$dir = dirname(__FILE__) . '/'; |
| 12 | +$dir = dirname( __FILE__ ) . '/'; |
15 | 13 | $wgExtensionMessagesFiles['Tooltip'] = $dir . 'Tooltip.i18n.php'; |
16 | 14 | |
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; |
92 | 23 | } |
93 | 24 | |
94 | 25 | function wfTooltipParserFunction_Magic( &$magicWords, $langCode ) { |
— | — | @@ -99,6 +30,14 @@ |
100 | 31 | return true; |
101 | 32 | } |
102 | 33 | |
| 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 | + |
103 | 42 | function wfTooltipParserFunction_Render( $parser, $basetext = '', $tooltiptext = '', $x = 0, $y = 0) { |
104 | 43 | $output = renderToolTip($tooltiptext, array('text'=>$basetext, 'x'=>$x, 'y'=>$y), $parser); |
105 | 44 | return array($output, 'nowiki' => false, 'noparse' => true, 'isHTML' => false); |
— | — | @@ -128,8 +67,8 @@ |
129 | 68 | $output = ''; |
130 | 69 | |
131 | 70 | if ($input != '') { |
132 | | - $tooltipid = uniqid('tooltipid'); |
133 | | - $parentid = uniqid('parentid'); |
| 71 | + $tooltipid = uniqid( 'tooltipid' ); |
| 72 | + $parentid = uniqid( 'parentid' ); |
134 | 73 | $output .= "<span id='$tooltipid' class='xstooltip'>" . $parser->unstrip($parser->recursiveTagParse($input),$parser->mStripState) . "</span>"; |
135 | 74 | $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>"; |
136 | 75 | } |
— | — | @@ -137,4 +76,3 @@ |
138 | 77 | return $output; |
139 | 78 | } |
140 | 79 | |
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 |
1 | 19 | + 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 |
1 | 50 | + native |