Index: trunk/extensions/TreeAndMenu/TreeAndMenu.i18n.magic.php |
— | — | @@ -8,4 +8,5 @@ |
9 | 9 | $magicWords['en'] = array( |
10 | 10 | 'menu' => array( 0, 'menu' ), |
11 | 11 | 'tree' => array( 0, 'tree' ), |
| 12 | + 'star' => array( 0, 'star' ), |
12 | 13 | ); |
Index: trunk/extensions/TreeAndMenu/TreeAndMenu.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | |
16 | 16 | if( !defined( 'MEDIAWIKI' ) ) die( 'Not an entry point.' ); |
17 | 17 | |
18 | | -define( 'TREEANDMENU_VERSION','1.3.0, 2012-01-19' ); |
| 18 | +define( 'TREEANDMENU_VERSION','2.0.0, 2012-01-28' ); |
19 | 19 | |
20 | 20 | // Set any unset images to default titles |
21 | 21 | if( !isset( $wgTreeViewImages ) || !is_array( $wgTreeViewImages ) ) $wgTreeViewImages = array(); |
— | — | @@ -48,31 +48,29 @@ |
49 | 49 | var $images = ''; // internal JS to update dTree images |
50 | 50 | var $useLines = true; // internal variable determining whether to render connector lines |
51 | 51 | var $args = array(); // args for each tree |
52 | | - var $js = 0; |
53 | 52 | |
54 | 53 | /** |
55 | 54 | * Constructor |
56 | 55 | */ |
57 | 56 | function __construct() { |
58 | | - global $wgOut, $wgHooks, $wgParser, $wgScriptPath, $wgJsMimeType, |
59 | | - $wgTreeViewImages, $wgTreeViewShowLines, $wgTreeViewBaseDir, $wgTreeViewBaseUrl; |
| 57 | + global $wgOut, $wgHooks, $wgParser, $wgJsMimeType, $wgExtensionAssetsPath, $wgResourceModules, $wgTreeViewImages, $wgTreeViewShowLines; |
60 | 58 | |
61 | 59 | // Add hooks |
62 | | - $wgParser->setFunctionHook( 'tree', array( $this,'expandTree' ) ); |
63 | | - $wgParser->setFunctionHook( 'menu', array( $this,'expandMenu' ) ); |
| 60 | + $wgParser->setFunctionHook( 'tree', array( $this, 'expandTree' ) ); |
| 61 | + $wgParser->setFunctionHook( 'menu', array( $this, 'expandMenu' ) ); |
| 62 | + $wgParser->setFunctionHook( 'star', array( $this, 'expandStar' ) ); |
64 | 63 | $wgHooks['ParserAfterTidy'][] = array( $this, 'renderTreeAndMenu' ); |
65 | 64 | |
66 | 65 | // Update general tree paths and properties |
67 | | - $this->baseDir = isset( $wgTreeViewBaseDir ) ? $wgTreeViewBaseDir : dirname( __FILE__ ); |
68 | | - $this->baseUrl = isset( $wgTreeViewBaseUrl ) ? $wgTreeViewBaseUrl : preg_replace( '|^.+(?=/ext)|', $wgScriptPath, $this->baseDir ); |
| 66 | + $this->baseDir = dirname( __FILE__ ); |
| 67 | + $this->baseUrl = $wgExtensionAssetsPath . '/' . basename( dirname( __FILE__ ) ); |
69 | 68 | $this->useLines = $wgTreeViewShowLines ? 'true' : 'false'; |
70 | 69 | $this->uniq = uniqid( $this->uniqname ); |
71 | 70 | |
72 | 71 | // Convert image titles to file paths and store as JS to update dTree |
73 | 72 | foreach( $wgTreeViewImages as $k => $v ) { |
74 | | - $title = Title::newFromText( $v, NS_IMAGE ); |
75 | | - $image = wfFindFile( $title ); |
76 | | - $v = $image && $image->exists() ? $image->getURL() : $wgTreeViewImages[$k]; |
| 73 | + $image = wfLocalFile( $v ); |
| 74 | + $v = ( is_object( $image ) && $image->exists() ) ? $image->getURL() : $wgTreeViewImages[$k]; |
77 | 75 | $this->images .= "tree.icon['$k'] = '$v';"; |
78 | 76 | } |
79 | 77 | } |
— | — | @@ -94,6 +92,14 @@ |
95 | 93 | } |
96 | 94 | |
97 | 95 | /** |
| 96 | + * Expand #star parser-functions |
| 97 | + */ |
| 98 | + public function expandStar() { |
| 99 | + $args = func_get_args(); |
| 100 | + return 'star menus coming soon!'; |
| 101 | + } |
| 102 | + |
| 103 | + /** |
98 | 104 | * Expand either kind of parser-function (reformats tree rows for matching later) and store args |
99 | 105 | */ |
100 | 106 | private function expandTreeAndMenu( $magic, $args ) { |
— | — | @@ -212,6 +218,13 @@ |
213 | 219 | $class = isset( $args['class'] ) ? $args['class'] : "d$type"; |
214 | 220 | if( $type == 'tree' ) { |
215 | 221 | |
| 222 | + // Load the dTree script if not loaded already |
| 223 | + static $dtree = false; |
| 224 | + if( !$dtree ) { |
| 225 | + $wgOut->addScriptFile( $this->baseUrl . '/dtree.js' ); |
| 226 | + $dtree = true; |
| 227 | + } |
| 228 | + |
216 | 229 | // Finalise a tree |
217 | 230 | $add = isset( $args['root'] ) ? "tree.add(0,-1,'".$args['root']."');" : ''; |
218 | 231 | $top = $bottom = $root = $opennodesjs = ''; |
— | — | @@ -222,41 +235,33 @@ |
223 | 236 | if( $top ) $top = "<p> $top</p>"; |
224 | 237 | if( $bottom ) $bottom = "<p> $bottom</p>"; |
225 | 238 | |
226 | | - // Add the dTRee script if not loaded yet |
227 | | - $dTreeScript = $this->js++ ? "" : "<script type=\"$wgJsMimeType\" src=\"{$this->baseUrl}/dtree.js\"></script>"; |
228 | | - |
229 | 239 | // Define the script to build this tree |
230 | | - $script = "tree = new dTree('$objid'); |
231 | | - for (i in tree.icon) tree.icon[i] = '{$this->baseUrl}/'+tree.icon[i];{$this->images} |
232 | | - tree.config.useLines = {$this->useLines}; |
233 | | - $add |
234 | | - $objid = tree; |
235 | | - $nodes |
236 | | - document.getElementById('$id').innerHTML = $objid.toString(); |
237 | | - $opennodesjs"; |
238 | | - |
239 | | - // Embed the script into the output |
240 | | - $html = "$top<div class='$class' id='$id'>$dTreeScript<script type=\"$wgJsMimeType\">/*<![CDATA[*/ |
241 | | - // TreeAndMenu-{$this->version} |
242 | | - $script |
243 | | - /*]]>*/</script></div>$bottom"; |
| 240 | + $script = "// TreeAndMenu-{$this->version}\ntree = new dTree('$objid'); |
| 241 | + for (i in tree.icon) tree.icon[i] = '{$this->baseUrl}/'+tree.icon[i];{$this->images} |
| 242 | + tree.config.useLines = {$this->useLines}; |
| 243 | + $add |
| 244 | + $objid = tree; |
| 245 | + $nodes |
| 246 | + document.getElementById('$id').innerHTML = $objid.toString(); |
| 247 | + $opennodesjs |
| 248 | + for(i in window.tamOnload_$objid) { window.tamOnload_{$objid}[i](); }"; |
| 249 | + $wgOut->addScript( "<script type=\"$wgJsMimeType\">$(function(){\n$script\n});</script>" ); |
| 250 | + $html = "$top<div class='$class' id='$id'></div>$bottom"; |
| 251 | + $html .= "<script type=\"$wgJsMimeType\">window.tamOnload_$objid=[]</script>"; |
244 | 252 | } else { |
245 | 253 | |
246 | 254 | // Finalise a menu |
247 | 255 | if( $depth > 0 ) $nodes .= str_repeat( '</ul></li>', $depth ); |
248 | 256 | $nodes = preg_replace( "/<(a.*? )title=\".+?\".*?>/", "<$1>", $nodes ); // IE has problems with title attribute in suckerfish menus |
249 | | - $html = " |
250 | | - <ul class='$class' id='$id'>\n$nodes</ul> |
251 | | - <script type=\"$wgJsMimeType\">/*<![CDATA[*/ |
252 | | - if (window.attachEvent) { |
| 257 | + $html = "<ul class='$class' id='$id'>\n$nodes</ul><div style=\"clear:both\"></div>"; |
| 258 | + $script = "if (window.attachEvent) { |
253 | 259 | var sfEls = document.getElementById('$id').getElementsByTagName('li'); |
254 | 260 | for (var i=0; i<sfEls.length; i++) { |
255 | 261 | sfEls[i].onmouseover=function() { this.className+=' sfhover'; } |
256 | 262 | sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(' sfhover *'),''); } |
257 | 263 | } |
258 | | - } |
259 | | - /*]]>*/</script> |
260 | | - "; |
| 264 | + }"; |
| 265 | + $wgOut->addScript( "<script type=\"$wgJsMimeType\">$(function(){\n$script\n});</script>" ); |
261 | 266 | } |
262 | 267 | |
263 | 268 | $text = preg_replace( "/\x7f1$u\x7f$id\x7f.+?$/m", $html, $text, 1 ); // replace first occurence of this trees root-id |