Difference between revisions of "Extension:Javascript"
m |
m |
||
Line 9: | Line 9: | ||
define('JAVASCRIPT_VERSION','0.0.0, 2007-06-25'); | define('JAVASCRIPT_VERSION','0.0.0, 2007-06-25'); | ||
− | $ | + | $wgJavascriptPaths = array(); |
− | $ | + | $wgJavascriptFiles = array(); |
$wgExtensionFunctions[] = 'wfSetupJavascript'; | $wgExtensionFunctions[] = 'wfSetupJavascript'; | ||
# Build list of files from list, no duplicate names | # Build list of files from list, no duplicate names | ||
− | foreach ($ | + | foreach ($wgJavascriptPaths as $path) { |
if (is_file($path)) $wgJavascriptFiles[$path] = true; | if (is_file($path)) $wgJavascriptFiles[$path] = true; | ||
elseif (is_dir($path)) { | elseif (is_dir($path)) { | ||
Line 40: | Line 40: | ||
function wfSetupJavascript() { | function wfSetupJavascript() { | ||
global $wgOut,$wgJavascriptFiles; | global $wgOut,$wgJavascriptFiles; | ||
− | foreach (array_keys($wgJavascriptFiles) as $ | + | foreach (array_keys($wgJavascriptFiles) as $file) |
− | $wgOut->addScript("<script type=\"text/javascript\" src=\"$ | + | $wgOut->addScript("<script type=\"text/javascript\" src=\"$file\"></script>\n"); |
} | } | ||
?> | ?> |
Revision as of 01:14, 25 June 2007
<?php
- Extension:JavascriptTemplate:Php
- - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
- - Author: http://www.organicdesign.co.nz/nad
- - Started: 2007-06-25, see article history
if (!defined('MEDIAWIKI')) die('Not an entry point.');
define('JAVASCRIPT_VERSION','0.0.0, 2007-06-25');
$wgJavascriptPaths = array(); $wgJavascriptFiles = array();
$wgExtensionFunctions[] = 'wfSetupJavascript';
- Build list of files from list, no duplicate names
foreach ($wgJavascriptPaths as $path) { if (is_file($path)) $wgJavascriptFiles[$path] = true; elseif (is_dir($path)) { if ($dir = opendir($path)) { while (false !== ($file = readdir($dir))) $wgJavascriptFiles[$file] = true; closedir($dir); } } }
$wgExtensionCredits['other'][] = array( 'name' => 'Javascript', 'author' => 'User:Nad', 'description' => 'Handles the loading of Javascript files. Scripts loaded: '.join(', ',$wgJavascriptFiles), 'url' => 'http://www.mediawiki.org/wiki/Extension:Javascript', 'version' => JAVASCRIPT_VERSION );
- Notes:
- Load all dirs/files in $wgJavascriptPaths into $wgJavascriptScripts using filename as key
- Other extensions can add to the list if they need to
- After all extenions are loaded and $wgOut is established, add all the script
function wfSetupJavascript() { global $wgOut,$wgJavascriptFiles; foreach (array_keys($wgJavascriptFiles) as $file) $wgOut->addScript("<script type=\"text/javascript\" src=\"$file\"></script>\n"); }
?>