r70358 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70357‎ | r70358 | r70359 >
Date:21:17, 2 August 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Enabled optionally defining modules needs in PHP, which are then generated into JavaScript output. Loaders are still supported. Also fixed a bug in the loader that made the resolve() method not function properly.
Modified paths:
  • /branches/resourceloader/phase3/includes/ResourceLoader.php (modified) (history)
  • /branches/resourceloader/phase3/resources/Resources.php (modified) (history)
  • /branches/resourceloader/phase3/resources/mediawiki/mediawiki.js (modified) (history)
  • /branches/resourceloader/phase3/resources/test/index.html (modified) (history)
  • /branches/resourceloader/phase3/resources/test/loader.js (deleted) (history)

Diff [purge]

Index: branches/resourceloader/phase3/includes/ResourceLoader.php
@@ -113,6 +113,7 @@
114114 * 'locales' => [array: paths to scripts to include, keyed by locale name, optional],
115115 * 'messages' => [array: message keys, optional],
116116 * 'loader' => [string: path to file, optional],
 117+ * 'needs' => [array: names of modules this module needs, optional - ignored if loader is present],
117118 * 'raw' => [boolean: include directly without any loading support, optional],
118119 * 'debug' => [boolean: include in debug mode only, optional],
119120 * )
@@ -144,6 +145,7 @@
145146 'locales' => array(),
146147 'messages' => array(),
147148 'loader' => null,
 149+ 'needs' => array(),
148150 'raw' => false,
149151 'debug' => false,
150152 ), $options );
@@ -215,9 +217,11 @@
216218 // Use output buffering
217219 ob_start();
218220 // Output raw modules first
 221+ $ready = array();
219222 foreach ( $modules as $module ) {
220223 if ( self::$modules[$module]['raw'] ) {
221224 readfile( self::$modules[$module]['script'] );
 225+ $ready[] = $module;
222226 echo "\n";
223227 }
224228 }
@@ -235,12 +239,19 @@
236240 echo "mw.config.set( " . json_encode( $parameters ) . " );\n";
237241 // Collect all loaders
238242 $loaders = array();
239 - $registers = array();
 243+ $registrations = array();
240244 foreach ( self::$modules as $name => $options ) {
241245 if ( $options['loader'] !== null ) {
242246 $loaders[] = $options['loader'];
243247 } else {
244 - $registers[] = $name;
 248+ if ( empty( $options['needs'] ) && !in_array( $name, $ready ) ) {
 249+ $registrations[$name] = $name;
 250+ } else {
 251+ $registrations[$name] = array( $name, $options['needs'] );
 252+ if ( in_array( $name, $ready ) ) {
 253+ $registrations[$name][] = 'ready';
 254+ }
 255+ }
245256 }
246257 }
247258 // Include loaders
@@ -249,7 +260,7 @@
250261 echo "\n";
251262 }
252263 // Register modules without loaders
253 - echo "mw.loader.register( " . json_encode( array_unique( $registers ) ) . " );\n";
 264+ echo "mw.loader.register( " . json_encode( array_values( $registrations ) ) . " );\n";
254265 }
255266 // Output non-raw modules
256267 $blobs = MessageBlobStore::get( $modules, $parameters['lang'] );
Index: branches/resourceloader/phase3/resources/test/loader.js
@@ -1,6 +0,0 @@
2 -// Registers the modules with the loading system
3 -mw.loader.register( 'test', ['foo'] );
4 -mw.loader.register( 'foo', ['bar'] );
5 -mw.loader.register( 'bar', ['buz'] );
6 -mw.loader.register( 'buz', ['baz'] );
7 -mw.loader.register( 'baz', [] );
\ No newline at end of file
Index: branches/resourceloader/phase3/resources/test/index.html
@@ -8,18 +8,9 @@
99 color: white;
1010 }
1111 </style>
12 - <script type="text/javascript" src="../../load.php?modules=jquery|mediawiki&amp;debug=1&amp;skin=vector&amp;lang=ja"></script>
 12+ <script type="text/javascript" src="../../load.php?modules=jquery|mediawiki&amp;debug=false&amp;skin=vector&amp;lang=ja"></script>
1313 <script type="text/javascript">
1414 mw.config.set( 'wgScriptPath', '../..' );
15 - $(document).ready( function() {
16 - mw.loader.using( ['jquery.ui.core', 'jquery.ui.datepicker'], function() {
17 - $( '#datepicker' ).datepicker();
18 - mw.log( 'datepicker (dynamic)' );
19 - } );
20 - mw.loader.using( 'test', function() {
21 - mw.log( 'test (static with dynamic needs)' );
22 - } );
23 - } );
2415 </script>
2516 </head>
2617 <body>
@@ -31,6 +22,17 @@
3223 <strong>Datepicker....</strong>
3324 <div id="datepicker"></div>
3425 </p>
35 - <script type="text/javascript" src="../../load.php?modules=test&amp;debug=1&amp;skin=vector&amp;lang=ja"></script>
 26+ <script type="text/javascript" >
 27+ mw.loader.load( ['test', 'jquery.ui.core', 'jquery.ui.datepicker'] );
 28+ </script>
 29+ <script type="text/javascript">
 30+ mw.loader.using( 'test', function() {
 31+ mw.log( 'test (static with dynamic needs)' );
 32+ } );
 33+ mw.loader.using( 'jquery.ui.datepicker', function() {
 34+ $( '#datepicker' ).datepicker();
 35+ mw.log( 'datepicker (dynamic)' );
 36+ } );
 37+ </script>
3638 </body>
3739 </html>
\ No newline at end of file
Index: branches/resourceloader/phase3/resources/Resources.php
@@ -14,9 +14,6 @@
1515 /* jQuery UI */
1616
1717 // Components
18 - 'jquery.ui.accordion' => array( 'script' => 'resources/jquery/ui/jquery.ui.accordion.js' ),
19 - 'jquery.ui.autocomplete' => array( 'script' => 'resources/jquery/ui/jquery.ui.autocomplete.js' ),
20 - 'jquery.ui.button' => array( 'script' => 'resources/jquery/ui/jquery.ui.button.js' ),
2118 'jquery.ui.core' => array(
2219 'script' => 'resources/jquery/ui/jquery.ui.core.js',
2320 'style' => 'resources/jquery/ui/themes/base/jquery.ui.theme.css',
@@ -25,9 +22,23 @@
2623 'vector' => 'resources/jquery/ui/themes/vector/jquery.ui.theme.css',
2724 'monobook' => 'resources/jquery/ui/themes/monobook/jquery.ui.theme.css',
2825 ),
 26+ 'needs' => array( 'jquery' ),
2927 ),
 28+ 'jquery.ui.accordion' => array(
 29+ 'script' => 'resources/jquery/ui/jquery.ui.accordion.js',
 30+ 'needs' => array( 'jquery.ui.core' ),
 31+ ),
 32+ 'jquery.ui.autocomplete' => array(
 33+ 'script' => 'resources/jquery/ui/jquery.ui.autocomplete.js',
 34+ 'needs' => array( 'jquery.ui.core' ),
 35+ ),
 36+ 'jquery.ui.button' => array(
 37+ 'script' => 'resources/jquery/ui/jquery.ui.button.js',
 38+ 'needs' => array( 'jquery.ui.core' ),
 39+ ),
3040 'jquery.ui.datepicker' => array(
3141 'script' => 'resources/jquery/ui/jquery.ui.datepicker.js',
 42+ 'needs' => array( 'jquery.ui.core' ),
3243 'style' => 'resources/jquery/ui/themes/base/jquery.ui.datepicker.css',
3344 'themes' => array(
3445 'default' => 'resources/jquery/ui/themes/default/jquery.ui.datepicker.css',
@@ -89,147 +100,438 @@
90101 'zh-tw' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-zh-TW.js'
91102 ),
92103 ),
93 - 'jquery.ui.dialog' => array( 'script' => 'resources/jquery/ui/jquery.ui.dialog.js' ),
94 - 'jquery.ui.draggable' => array( 'script' => 'resources/jquery/ui/jquery.ui.draggable.js' ),
95 - 'jquery.ui.droppable' => array( 'script' => 'resources/jquery/ui/jquery.ui.droppable.js' ),
96 - 'jquery.ui.mouse' => array( 'script' => 'resources/jquery/ui/jquery.ui.mouse.js' ),
97 - 'jquery.ui.position' => array( 'script' => 'resources/jquery/ui/jquery.ui.position.js' ),
98 - 'jquery.ui.progressbar' => array( 'script' => 'resources/jquery/ui/jquery.ui.progressbar.js' ),
99 - 'jquery.ui.resizable' => array( 'script' => 'resources/jquery/ui/jquery.ui.resizable.js' ),
100 - 'jquery.ui.selectable' => array( 'script' => 'resources/jquery/ui/jquery.ui.selectable.js' ),
101 - 'jquery.ui.slider' => array( 'script' => 'resources/jquery/ui/jquery.ui.slider.js' ),
102 - 'jquery.ui.sortable' => array( 'script' => 'resources/jquery/ui/jquery.ui.sortable.js' ),
103 - 'jquery.ui.tabs' => array( 'script' => 'resources/jquery/ui/jquery.ui.tabs.js' ),
104 - 'jquery.ui.widget' => array( 'script' => 'resources/jquery/ui/jquery.ui.widget.js' ),
 104+ 'jquery.ui.dialog' => array(
 105+ 'script' => 'resources/jquery/ui/jquery.ui.dialog.js',
 106+ 'needs' => array( 'jquery.ui.core' ),
 107+ ),
 108+ 'jquery.ui.draggable' => array(
 109+ 'script' => 'resources/jquery/ui/jquery.ui.draggable.js',
 110+ 'needs' => array( 'jquery.ui.core' ),
 111+ ),
 112+ 'jquery.ui.droppable' => array(
 113+ 'script' => 'resources/jquery/ui/jquery.ui.droppable.js',
 114+ 'needs' => array( 'jquery.ui.core' ),
 115+ ),
 116+ 'jquery.ui.mouse' => array(
 117+ 'script' => 'resources/jquery/ui/jquery.ui.mouse.js',
 118+ 'needs' => array( 'jquery.ui.core' ),
 119+ ),
 120+ 'jquery.ui.position' => array(
 121+ 'script' => 'resources/jquery/ui/jquery.ui.position.js',
 122+ 'needs' => array( 'jquery.ui.core' ),
 123+ ),
 124+ 'jquery.ui.progressbar' => array(
 125+ 'script' => 'resources/jquery/ui/jquery.ui.progressbar.js',
 126+ 'needs' => array( 'jquery.ui.core' ),
 127+ ),
 128+ 'jquery.ui.resizable' => array(
 129+ 'script' => 'resources/jquery/ui/jquery.ui.resizable.js',
 130+ 'needs' => array( 'jquery.ui.core' ),
 131+ ),
 132+ 'jquery.ui.selectable' => array(
 133+ 'script' => 'resources/jquery/ui/jquery.ui.selectable.js',
 134+ 'needs' => array( 'jquery.ui.core' ),
 135+ ),
 136+ 'jquery.ui.slider' => array(
 137+ 'script' => 'resources/jquery/ui/jquery.ui.slider.js',
 138+ 'needs' => array( 'jquery.ui.core' ),
 139+ ),
 140+ 'jquery.ui.sortable' => array(
 141+ 'script' => 'resources/jquery/ui/jquery.ui.sortable.js',
 142+ 'needs' => array( 'jquery.ui.core' ),
 143+ ),
 144+ 'jquery.ui.tabs' => array(
 145+ 'script' => 'resources/jquery/ui/jquery.ui.tabs.js',
 146+ 'needs' => array( 'jquery.ui.core' ),
 147+ ),
 148+ 'jquery.ui.widget' => array(
 149+ 'script' => 'resources/jquery/ui/jquery.ui.widget.js',
 150+ 'needs' => array( 'jquery.ui.core' ),
 151+ ),
105152 // i18n
106 - 'jquery.ui.datepicker-af' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-af.js' ),
107 - 'jquery.ui.datepicker-ar' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ar.js' ),
108 - 'jquery.ui.datepicker-az' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-az.js' ),
109 - 'jquery.ui.datepicker-bg' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-bg.js' ),
110 - 'jquery.ui.datepicker-bs' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-bs.js' ),
111 - 'jquery.ui.datepicker-ca' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ca.js' ),
112 - 'jquery.ui.datepicker-cs' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-cs.js' ),
113 - 'jquery.ui.datepicker-da' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-da.js' ),
114 - 'jquery.ui.datepicker-de' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-de.js' ),
115 - 'jquery.ui.datepicker-el' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-el.js' ),
116 - 'jquery.ui.datepicker-en-GB' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-en-GB.js' ),
117 - 'jquery.ui.datepicker-eo' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-eo.js' ),
118 - 'jquery.ui.datepicker-es' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-es.js' ),
119 - 'jquery.ui.datepicker-et' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-et.js' ),
120 - 'jquery.ui.datepicker-eu' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-eu.js' ),
121 - 'jquery.ui.datepicker-fa' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-fa.js' ),
122 - 'jquery.ui.datepicker-fi' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-fi.js' ),
123 - 'jquery.ui.datepicker-fo' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-fo.js' ),
124 - 'jquery.ui.datepicker-fr-CH' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-fr-CH.js' ),
125 - 'jquery.ui.datepicker-fr' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-fr.js' ),
126 - 'jquery.ui.datepicker-he' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-he.js' ),
127 - 'jquery.ui.datepicker-hr' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-hr.js' ),
128 - 'jquery.ui.datepicker-hu' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-hu.js' ),
129 - 'jquery.ui.datepicker-hy' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-hy.js' ),
130 - 'jquery.ui.datepicker-id' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-id.js' ),
131 - 'jquery.ui.datepicker-is' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-is.js' ),
132 - 'jquery.ui.datepicker-it' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-it.js' ),
133 - 'jquery.ui.datepicker-ja' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ja.js' ),
134 - 'jquery.ui.datepicker-ko' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ko.js' ),
135 - 'jquery.ui.datepicker-lt' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-lt.js' ),
136 - 'jquery.ui.datepicker-lv' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-lv.js' ),
137 - 'jquery.ui.datepicker-ms' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ms.js' ),
138 - 'jquery.ui.datepicker-nl' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-nl.js' ),
139 - 'jquery.ui.datepicker-no' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-no.js' ),
140 - 'jquery.ui.datepicker-pl' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-pl.js' ),
141 - 'jquery.ui.datepicker-pt-BR' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-pt-BR.js' ),
142 - 'jquery.ui.datepicker-ro' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ro.js' ),
143 - 'jquery.ui.datepicker-ru' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ru.js' ),
144 - 'jquery.ui.datepicker-sk' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sk.js' ),
145 - 'jquery.ui.datepicker-sl' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sl.js' ),
146 - 'jquery.ui.datepicker-sq' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sq.js' ),
147 - 'jquery.ui.datepicker-sr-SR' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sr-SR.js' ),
148 - 'jquery.ui.datepicker-sr' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sr.js' ),
149 - 'jquery.ui.datepicker-sv' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sv.js' ),
150 - 'jquery.ui.datepicker-ta' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ta.js' ),
151 - 'jquery.ui.datepicker-th' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-th.js' ),
152 - 'jquery.ui.datepicker-tr' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-tr.js' ),
153 - 'jquery.ui.datepicker-uk' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-uk.js' ),
154 - 'jquery.ui.datepicker-vi' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-vi.js' ),
155 - 'jquery.ui.datepicker-zh-CN' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-zh-CN.js' ),
156 - 'jquery.ui.datepicker-zh-HK' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-zh-HK.js' ),
157 - 'jquery.ui.datepicker-zh-TW' => array( 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-zh-TW.js' ),
 153+ 'jquery.ui.datepicker-af' => array(
 154+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-af.js',
 155+ 'needs' => array( 'jquery.ui.datepicker' ),
 156+ ),
 157+ 'jquery.ui.datepicker-ar' => array(
 158+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ar.js',
 159+ 'needs' => array( 'jquery.ui.datepicker' ),
 160+ ),
 161+ 'jquery.ui.datepicker-az' => array(
 162+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-az.js',
 163+ 'needs' => array( 'jquery.ui.datepicker' ),
 164+ ),
 165+ 'jquery.ui.datepicker-bg' => array(
 166+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-bg.js',
 167+ 'needs' => array( 'jquery.ui.datepicker' ),
 168+ ),
 169+ 'jquery.ui.datepicker-bs' => array(
 170+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-bs.js',
 171+ 'needs' => array( 'jquery.ui.datepicker' ),
 172+ ),
 173+ 'jquery.ui.datepicker-ca' => array(
 174+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ca.js',
 175+ 'needs' => array( 'jquery.ui.datepicker' ),
 176+ ),
 177+ 'jquery.ui.datepicker-cs' => array(
 178+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-cs.js',
 179+ 'needs' => array( 'jquery.ui.datepicker' ),
 180+ ),
 181+ 'jquery.ui.datepicker-da' => array(
 182+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-da.js',
 183+ 'needs' => array( 'jquery.ui.datepicker' ),
 184+ ),
 185+ 'jquery.ui.datepicker-de' => array(
 186+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-de.js',
 187+ 'needs' => array( 'jquery.ui.datepicker' ),
 188+ ),
 189+ 'jquery.ui.datepicker-el' => array(
 190+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-el.js',
 191+ 'needs' => array( 'jquery.ui.datepicker' ),
 192+ ),
 193+ 'jquery.ui.datepicker-en-GB' => array(
 194+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-en-GB.js',
 195+ 'needs' => array( 'jquery.ui.datepicker' ),
 196+ ),
 197+ 'jquery.ui.datepicker-eo' => array(
 198+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-eo.js',
 199+ 'needs' => array( 'jquery.ui.datepicker' ),
 200+ ),
 201+ 'jquery.ui.datepicker-es' => array(
 202+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-es.js',
 203+ 'needs' => array( 'jquery.ui.datepicker' ),
 204+ ),
 205+ 'jquery.ui.datepicker-et' => array(
 206+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-et.js',
 207+ 'needs' => array( 'jquery.ui.datepicker' ),
 208+ ),
 209+ 'jquery.ui.datepicker-eu' => array(
 210+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-eu.js',
 211+ 'needs' => array( 'jquery.ui.datepicker' ),
 212+ ),
 213+ 'jquery.ui.datepicker-fa' => array(
 214+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-fa.js',
 215+ 'needs' => array( 'jquery.ui.datepicker' ),
 216+ ),
 217+ 'jquery.ui.datepicker-fi' => array(
 218+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-fi.js',
 219+ 'needs' => array( 'jquery.ui.datepicker' ),
 220+ ),
 221+ 'jquery.ui.datepicker-fo' => array(
 222+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-fo.js',
 223+ 'needs' => array( 'jquery.ui.datepicker' ),
 224+ ),
 225+ 'jquery.ui.datepicker-fr-CH' => array(
 226+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-fr-CH.js',
 227+ 'needs' => array( 'jquery.ui.datepicker' ),
 228+ ),
 229+ 'jquery.ui.datepicker-fr' => array(
 230+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-fr.js',
 231+ 'needs' => array( 'jquery.ui.datepicker' ),
 232+ ),
 233+ 'jquery.ui.datepicker-he' => array(
 234+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-he.js',
 235+ 'needs' => array( 'jquery.ui.datepicker' ),
 236+ ),
 237+ 'jquery.ui.datepicker-hr' => array(
 238+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-hr.js',
 239+ 'needs' => array( 'jquery.ui.datepicker' ),
 240+ ),
 241+ 'jquery.ui.datepicker-hu' => array(
 242+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-hu.js',
 243+ 'needs' => array( 'jquery.ui.datepicker' ),
 244+ ),
 245+ 'jquery.ui.datepicker-hy' => array(
 246+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-hy.js',
 247+ 'needs' => array( 'jquery.ui.datepicker' ),
 248+ ),
 249+ 'jquery.ui.datepicker-id' => array(
 250+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-id.js',
 251+ 'needs' => array( 'jquery.ui.datepicker' ),
 252+ ),
 253+ 'jquery.ui.datepicker-is' => array(
 254+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-is.js',
 255+ 'needs' => array( 'jquery.ui.datepicker' ),
 256+ ),
 257+ 'jquery.ui.datepicker-it' => array(
 258+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-it.js',
 259+ 'needs' => array( 'jquery.ui.datepicker' ),
 260+ ),
 261+ 'jquery.ui.datepicker-ja' => array(
 262+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ja.js',
 263+ 'needs' => array( 'jquery.ui.datepicker' ),
 264+ ),
 265+ 'jquery.ui.datepicker-ko' => array(
 266+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ko.js',
 267+ 'needs' => array( 'jquery.ui.datepicker' ),
 268+ ),
 269+ 'jquery.ui.datepicker-lt' => array(
 270+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-lt.js',
 271+ 'needs' => array( 'jquery.ui.datepicker' ),
 272+ ),
 273+ 'jquery.ui.datepicker-lv' => array(
 274+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-lv.js',
 275+ 'needs' => array( 'jquery.ui.datepicker' ),
 276+ ),
 277+ 'jquery.ui.datepicker-ms' => array(
 278+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ms.js',
 279+ 'needs' => array( 'jquery.ui.datepicker' ),
 280+ ),
 281+ 'jquery.ui.datepicker-nl' => array(
 282+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-nl.js',
 283+ 'needs' => array( 'jquery.ui.datepicker' ),
 284+ ),
 285+ 'jquery.ui.datepicker-no' => array(
 286+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-no.js',
 287+ 'needs' => array( 'jquery.ui.datepicker' ),
 288+ ),
 289+ 'jquery.ui.datepicker-pl' => array(
 290+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-pl.js',
 291+ 'needs' => array( 'jquery.ui.datepicker' ),
 292+ ),
 293+ 'jquery.ui.datepicker-pt-BR' => array(
 294+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-pt-BR.js',
 295+ 'needs' => array( 'jquery.ui.datepicker' ),
 296+ ),
 297+ 'jquery.ui.datepicker-ro' => array(
 298+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ro.js',
 299+ 'needs' => array( 'jquery.ui.datepicker' ),
 300+ ),
 301+ 'jquery.ui.datepicker-ru' => array(
 302+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ru.js',
 303+ 'needs' => array( 'jquery.ui.datepicker' ),
 304+ ),
 305+ 'jquery.ui.datepicker-sk' => array(
 306+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sk.js',
 307+ 'needs' => array( 'jquery.ui.datepicker' ),
 308+ ),
 309+ 'jquery.ui.datepicker-sl' => array(
 310+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sl.js',
 311+ 'needs' => array( 'jquery.ui.datepicker' ),
 312+ ),
 313+ 'jquery.ui.datepicker-sq' => array(
 314+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sq.js',
 315+ 'needs' => array( 'jquery.ui.datepicker' ),
 316+ ),
 317+ 'jquery.ui.datepicker-sr-SR' => array(
 318+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sr-SR.js',
 319+ 'needs' => array( 'jquery.ui.datepicker' ),
 320+ ),
 321+ 'jquery.ui.datepicker-sr' => array(
 322+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sr.js',
 323+ 'needs' => array( 'jquery.ui.datepicker' ),
 324+ ),
 325+ 'jquery.ui.datepicker-sv' => array(
 326+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-sv.js',
 327+ 'needs' => array( 'jquery.ui.datepicker' ),
 328+ ),
 329+ 'jquery.ui.datepicker-ta' => array(
 330+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-ta.js',
 331+ 'needs' => array( 'jquery.ui.datepicker' ),
 332+ ),
 333+ 'jquery.ui.datepicker-th' => array(
 334+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-th.js',
 335+ 'needs' => array( 'jquery.ui.datepicker' ),
 336+ ),
 337+ 'jquery.ui.datepicker-tr' => array(
 338+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-tr.js',
 339+ 'needs' => array( 'jquery.ui.datepicker' ),
 340+ ),
 341+ 'jquery.ui.datepicker-uk' => array(
 342+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-uk.js',
 343+ 'needs' => array( 'jquery.ui.datepicker' ),
 344+ ),
 345+ 'jquery.ui.datepicker-vi' => array(
 346+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-vi.js',
 347+ 'needs' => array( 'jquery.ui.datepicker' ),
 348+ ),
 349+ 'jquery.ui.datepicker-zh-CN' => array(
 350+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-zh-CN.js',
 351+ 'needs' => array( 'jquery.ui.datepicker' ),
 352+ ),
 353+ 'jquery.ui.datepicker-zh-HK' => array(
 354+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-zh-HK.js',
 355+ 'needs' => array( 'jquery.ui.datepicker' ),
 356+ ),
 357+ 'jquery.ui.datepicker-zh-TW' => array(
 358+ 'script' => 'resources/jquery/ui/i18n/jquery.ui.datepicker-zh-TW.js',
 359+ 'needs' => array( 'jquery.ui.datepicker' ),
 360+ ),
158361 // Effects
159 - 'jquery.effects.blind' => array( 'script' => 'resources/jquery/effects/jquery.effects.blind.js' ),
160 - 'jquery.effects.bounce' => array( 'script' => 'resources/jquery/effects/jquery.effects.bounce.js' ),
161 - 'jquery.effects.clip' => array( 'script' => 'resources/jquery/effects/jquery.effects.clip.js' ),
162 - 'jquery.effects.core' => array( 'script' => 'resources/jquery/effects/jquery.effects.core.js' ),
163 - 'jquery.effects.drop' => array( 'script' => 'resources/jquery/effects/jquery.effects.drop.js' ),
164 - 'jquery.effects.explode' => array( 'script' => 'resources/jquery/effects/jquery.effects.explode.js' ),
165 - 'jquery.effects.fold' => array( 'script' => 'resources/jquery/effects/jquery.effects.fold.js' ),
166 - 'jquery.effects.highlight' => array( 'script' => 'resources/jquery/effects/jquery.effects.highlight.js' ),
167 - 'jquery.effects.pulsate' => array( 'script' => 'resources/jquery/effects/jquery.effects.pulsate.js' ),
168 - 'jquery.effects.scale' => array( 'script' => 'resources/jquery/effects/jquery.effects.scale.js' ),
169 - 'jquery.effects.shake' => array( 'script' => 'resources/jquery/effects/jquery.effects.shake.js' ),
170 - 'jquery.effects.slide' => array( 'script' => 'resources/jquery/effects/jquery.effects.slide.js' ),
171 - 'jquery.effects.transfer' => array( 'script' => 'resources/jquery/effects/jquery.effects.transfer.js' ),
 362+ 'jquery.effects.blind' => array(
 363+ 'script' => 'resources/jquery/effects/jquery.effects.blind.js',
 364+ 'needs' => array( 'jquery' ),
 365+ ),
 366+ 'jquery.effects.bounce' => array(
 367+ 'script' => 'resources/jquery/effects/jquery.effects.bounce.js',
 368+ 'needs' => array( 'jquery' ),
 369+ ),
 370+ 'jquery.effects.clip' => array(
 371+ 'script' => 'resources/jquery/effects/jquery.effects.clip.js',
 372+ 'needs' => array( 'jquery' ),
 373+ ),
 374+ 'jquery.effects.core' => array(
 375+ 'script' => 'resources/jquery/effects/jquery.effects.core.js',
 376+ 'needs' => array( 'jquery' ),
 377+ ),
 378+ 'jquery.effects.drop' => array(
 379+ 'script' => 'resources/jquery/effects/jquery.effects.drop.js',
 380+ 'needs' => array( 'jquery' ),
 381+ ),
 382+ 'jquery.effects.explode' => array(
 383+ 'script' => 'resources/jquery/effects/jquery.effects.explode.js',
 384+ 'needs' => array( 'jquery' ),
 385+ ),
 386+ 'jquery.effects.fold' => array(
 387+ 'script' => 'resources/jquery/effects/jquery.effects.fold.js',
 388+ 'needs' => array( 'jquery' ),
 389+ ),
 390+ 'jquery.effects.highlight' => array(
 391+ 'script' => 'resources/jquery/effects/jquery.effects.highlight.js',
 392+ 'needs' => array( 'jquery' ),
 393+ ),
 394+ 'jquery.effects.pulsate' => array(
 395+ 'script' => 'resources/jquery/effects/jquery.effects.pulsate.js',
 396+ 'needs' => array( 'jquery' ),
 397+ ),
 398+ 'jquery.effects.scale' => array(
 399+ 'script' => 'resources/jquery/effects/jquery.effects.scale.js',
 400+ 'needs' => array( 'jquery' ),
 401+ ),
 402+ 'jquery.effects.shake' => array(
 403+ 'script' => 'resources/jquery/effects/jquery.effects.shake.js',
 404+ 'needs' => array( 'jquery' ),
 405+ ),
 406+ 'jquery.effects.slide' => array(
 407+ 'script' => 'resources/jquery/effects/jquery.effects.slide.js',
 408+ 'needs' => array( 'jquery' ),
 409+ ),
 410+ 'jquery.effects.transfer' => array(
 411+ 'script' => 'resources/jquery/effects/jquery.effects.transfer.js',
 412+ 'needs' => array( 'jquery' ),
 413+ ),
172414
173415 /* MediaWiki */
174416
175 - 'mediawiki' => array( 'script' => 'resources/mediawiki/mediawiki.js', 'raw' => true ),
 417+ 'mediawiki' => array(
 418+ 'script' => 'resources/mediawiki/mediawiki.js', 'raw' => true ),
176419
177420 /* MediaWiki Legacy */
178421
179 - 'mediawiki.legacy.ajax' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.ajax.js' ),
180 - 'mediawiki.legacy.ajaxwatch' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.ajaxwatch.js' ),
181 - 'mediawiki.legacy.block' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.block.js' ),
182 - 'mediawiki.legacy.changepassword' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.changepassword.js' ),
183 - 'mediawiki.legacy.edit' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.edit.js' ),
184 - 'mediawiki.legacy.enhancedchanges' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.enhancedchanges.js' ),
185 - 'mediawiki.legacy.history' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.history.js' ),
186 - 'mediawiki.legacy.htmlform' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.htmlform.js' ),
187 - 'mediawiki.legacy.IEFixes' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.IEFixes.js' ),
188 - 'mediawiki.legacy.metadata' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.metadata.js' ),
189 - 'mediawiki.legacy.mwsuggest' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.mwsuggest.js' ),
190 - 'mediawiki.legacy.prefs' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.prefs.js' ),
191 - 'mediawiki.legacy.preview' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.preview.js' ),
192 - 'mediawiki.legacy.protect' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.protect.js' ),
193 - 'mediawiki.legacy.rightclickedit' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.rightclickedit.js' ),
194 - 'mediawiki.legacy.search' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.search.js' ),
195 - 'mediawiki.legacy.upload' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.upload.js' ),
196 - 'mediawiki.legacy.wikibits' => array( 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.wikibits.js' ),
 422+ 'mediawiki.legacy.ajax' => array(
 423+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.ajax.js',
 424+ 'needs' => array( 'mediawiki' ),
 425+ ),
 426+ 'mediawiki.legacy.ajaxwatch' => array(
 427+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.ajaxwatch.js',
 428+ 'needs' => array( 'mediawiki' ),
 429+ ),
 430+ 'mediawiki.legacy.block' => array(
 431+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.block.js',
 432+ 'needs' => array( 'mediawiki' ),
 433+ ),
 434+ 'mediawiki.legacy.changepassword' => array(
 435+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.changepassword.js',
 436+ 'needs' => array( 'mediawiki' ),
 437+ ),
 438+ 'mediawiki.legacy.edit' => array(
 439+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.edit.js',
 440+ 'needs' => array( 'mediawiki' ),
 441+ ),
 442+ 'mediawiki.legacy.enhancedchanges' => array(
 443+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.enhancedchanges.js',
 444+ 'needs' => array( 'mediawiki' ),
 445+ ),
 446+ 'mediawiki.legacy.history' => array(
 447+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.history.js',
 448+ 'needs' => array( 'mediawiki' ),
 449+ ),
 450+ 'mediawiki.legacy.htmlform' => array(
 451+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.htmlform.js',
 452+ 'needs' => array( 'mediawiki' ),
 453+ ),
 454+ 'mediawiki.legacy.IEFixes' => array(
 455+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.IEFixes.js',
 456+ 'needs' => array( 'mediawiki' ),
 457+ ),
 458+ 'mediawiki.legacy.metadata' => array(
 459+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.metadata.js',
 460+ 'needs' => array( 'mediawiki' ),
 461+ ),
 462+ 'mediawiki.legacy.mwsuggest' => array(
 463+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.mwsuggest.js',
 464+ 'needs' => array( 'mediawiki' ),
 465+ ),
 466+ 'mediawiki.legacy.prefs' => array(
 467+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.prefs.js',
 468+ 'needs' => array( 'mediawiki' ),
 469+ ),
 470+ 'mediawiki.legacy.preview' => array(
 471+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.preview.js',
 472+ 'needs' => array( 'mediawiki' ),
 473+ ),
 474+ 'mediawiki.legacy.protect' => array(
 475+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.protect.js',
 476+ 'needs' => array( 'mediawiki' ),
 477+ ),
 478+ 'mediawiki.legacy.rightclickedit' => array(
 479+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.rightclickedit.js',
 480+ 'needs' => array( 'mediawiki' ),
 481+ ),
 482+ 'mediawiki.legacy.search' => array(
 483+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.search.js',
 484+ 'needs' => array( 'mediawiki' ),
 485+ ),
 486+ 'mediawiki.legacy.upload' => array(
 487+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.upload.js',
 488+ 'needs' => array( 'mediawiki' ),
 489+ ),
 490+ 'mediawiki.legacy.wikibits' => array(
 491+ 'script' => 'resources/mediawiki/legacy/mediawiki.legacy.wikibits.js',
 492+ 'needs' => array( 'mediawiki' ),
 493+ ),
197494
198495 /* MediaWiki Utilities */
199496
200 - 'mediawiki.utilities.client' => array( 'script' => 'resources/mediawiki/utilities/mediawiki.utilities.client.js' ),
 497+ 'mediawiki.utilities.client' => array(
 498+ 'script' => 'resources/mediawiki/utilities/mediawiki.utilities.client.js',
 499+ ),
201500
202501 /* MediaWiki Views */
203502
204 - 'mediawiki.views.diff' => array( 'script' => 'resources/mediawiki/views/mediawiki.views.diff.js' ),
205 - 'mediawiki.views.install' => array( 'script' => 'resources/mediawiki/views/mediawiki.views.install.js' ),
 503+ 'mediawiki.views.diff' => array(
 504+ 'script' => 'resources/mediawiki/views/mediawiki.views.diff.js',
 505+ ),
 506+ 'mediawiki.views.install' => array(
 507+ 'script' => 'resources/mediawiki/views/mediawiki.views.install.js',
 508+ ),
206509
207510 /* Test */
208511
209512 'test' => array(
210513 'script' => 'resources/test/test.js',
211 - 'loader' => 'resources/test/loader.js',
 514+ 'needs' => array( 'foo' ),
212515 'style' => 'resources/test/test.css',
213516 ),
214517 'foo' => array(
215518 'script' => 'resources/test/foo.js',
216 - 'loader' => 'resources/test/loader.js',
 519+ 'needs' => array( 'bar' ),
217520 'style' => 'resources/test/foo.css',
218521 'messages' => array( 'january', 'february', 'march', 'april', 'may', 'june' ),
219522 ),
220523 'bar' => array(
221524 'script' => 'resources/test/bar.js',
222 - 'loader' => 'resources/test/loader.js',
 525+ 'needs' => array( 'buz' ),
223526 'style' => 'resources/test/bar.css',
224527 'messages' => array( 'july', 'august', 'september', 'october', 'november', 'december' ),
225528 ),
226529 'buz' => array(
227530 'script' => 'resources/test/buz.js',
228 - 'loader' => 'resources/test/loader.js',
 531+ 'needs' => array( 'baz' ),
229532 'style' => 'resources/test/buz.css',
230533 ),
231534 'baz' => array(
232535 'script' => 'resources/test/baz.js',
233 - 'loader' => 'resources/test/loader.js',
234536 'style' => 'resources/test/baz.css',
235537 ),
236538 ) );
\ No newline at end of file
Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js
@@ -232,6 +232,24 @@
233233 /* Private Methods */
234234
235235 /**
 236+ * Recursively resolves dependencies and detects circular references
 237+ */
 238+ function recurse( module, resolved, unresolved ) {
 239+ unresolved[unresolved.length] = module;
 240+ for ( var n = 0; n < registry[module].needs.length; n++ ) {
 241+ if ( resolved.indexOf( registry[module].needs[n] ) === -1 ) {
 242+ if ( unresolved.indexOf( registry[module].needs[n] ) !== -1 ) {
 243+ throw new Error(
 244+ 'Circular reference detected: ' + module + ' -> ' + registry[module].needs[n]
 245+ );
 246+ }
 247+ recurse( registry[module].needs[n], resolved, unresolved );
 248+ }
 249+ }
 250+ resolved[resolved.length] = module;
 251+ unresolved.splice( unresolved.indexOf( module ), 1 );
 252+ }
 253+ /**
236254 * Gets a list of modules names that a module needs in their proper dependency order
237255 *
238256 * @param mixed string module name or array of string module names
@@ -254,22 +272,6 @@
255273 if ( !( module in registry ) ) {
256274 return [];
257275 }
258 - // Recursively resolves dependencies and detects circular references
259 - function recurse( module, resolved, unresolved ) {
260 - unresolved[unresolved.length] = module;
261 - for ( var n = 0; n < registry[module].needs; n++ ) {
262 - if ( resolved.indexOf( registry[module].needs[n] ) === -1 ) {
263 - if ( unresolved.indexOf( registry[module].needs[n] ) !== -1 ) {
264 - throw new Error(
265 - 'Circular reference detected: ' + module + ' -> ' + registry[module].needs[n]
266 - );
267 - }
268 - recurse( registry[module].needs[n], resolved, unresolved );
269 - }
270 - }
271 - resolved[resolved.length] = module;
272 - unresolved.splice( unresolved.indexOf( module ), 1 );
273 - }
274276 var resolved = [];
275277 recurse( module, resolved, [] );
276278 return resolved;
@@ -465,47 +467,47 @@
466468 * Registers a module, letting the system know about it and it's dependencies. loader.js files contain calls
467469 * to this function.
468470 */
469 - this.register = function( name, needs ) {
 471+ this.register = function( module, needs, status ) {
470472 // Allow multiple registration
471 - if ( typeof name === 'object' ) {
472 - for ( var n = 0; n < name.length; n++ ) {
473 - if ( typeof name[n] === 'string' ) {
474 - that.register( name[n] );
475 - } else if ( typeof name[n] === 'object' && name[n].length == 2 ) {
476 - that.register( name[n][0], name[n][1] );
 473+ if ( typeof module === 'object' ) {
 474+ for ( var n = 0; n < module.length; n++ ) {
 475+ if ( typeof module[n] === 'string' ) {
 476+ that.register( module[n] );
 477+ } else if ( typeof module[n] === 'object' ) {
 478+ that.register.apply( that, module[n] );
477479 }
478480 }
479481 return;
480482 }
481483 // Validate input
482 - if ( typeof name !== 'string' ) {
483 - throw new Error( 'name must be a string, not a ' + typeof name );
 484+ if ( typeof module !== 'string' ) {
 485+ throw new Error( 'module must be a string, not a ' + typeof module );
484486 }
485 - if ( typeof registry[name] !== 'undefined' ) {
486 - throw new Error( 'module already implemeneted: ' + name );
 487+ if ( typeof registry[module] !== 'undefined' && typeof status === 'undefined' ) {
 488+ throw new Error( 'module already implemeneted: ' + module );
487489 }
488490 // List the module as registered
489 - registry[name] = { 'state': 'registered', 'needs': [] };
 491+ registry[module] = { 'state': typeof status === 'string' ? status : 'registered', 'needs': [] };
490492 // Allow needs to be given as a function which returns a string or array
491493 if ( typeof needs === 'function' ) {
492494 needs = needs();
493495 }
494496 if ( typeof needs === 'string' ) {
495 - // Allow needs to be given as a single module name
496 - registry[name].needs = [needs];
 497+ // Allow needs to be given as a single module module
 498+ registry[module].needs = [needs];
497499 } else if ( typeof needs === 'object' ) {
498 - // Allow needs to be given as an array of module names
499 - registry[name].needs = needs;
 500+ // Allow needs to be given as an array of module modules
 501+ registry[module].needs = needs;
500502 }
501503 };
502504 /**
503505 * Implements a module, giving the system a course of action to take upon loading. Results of a request for
504506 * one or more modules contain calls to this function.
505507 */
506 - this.implement = function( name, script, style, localization ) {
 508+ this.implement = function( module, script, style, localization ) {
507509 // Automaically register module
508 - if ( typeof registry[name] === 'undefined' ) {
509 - that.register( name );
 510+ if ( typeof registry[module] === 'undefined' ) {
 511+ that.register( module );
510512 }
511513 // Validate input
512514 if ( typeof script !== 'function' ) {
@@ -517,24 +519,24 @@
518520 if ( typeof localization !== 'undefined' && typeof localization !== 'object' ) {
519521 throw new Error( 'localization must be an object, not a ' + typeof localization );
520522 }
521 - if ( typeof registry[name] !== 'undefined' && typeof registry[name].script !== 'undefined' ) {
522 - throw new Error( 'module already implemeneted: ' + name );
 523+ if ( typeof registry[module] !== 'undefined' && typeof registry[module].script !== 'undefined' ) {
 524+ throw new Error( 'module already implemeneted: ' + module );
523525 }
524526 // Mark module as loaded
525 - registry[name].state = 'loaded';
 527+ registry[module].state = 'loaded';
526528 // Attach components
527 - registry[name].script = script;
 529+ registry[module].script = script;
528530 if ( typeof style === 'string' ) {
529 - registry[name].style = style;
 531+ registry[module].style = style;
530532 }
531533 if ( typeof messages === 'object' ) {
532 - registry[name].messages = messages;
 534+ registry[module].messages = messages;
533535 }
534536 // Execute or queue callback
535 - if ( filter( ['ready'], registry[name].needs ).compare( registry[name].needs ) ) {
536 - execute( name );
 537+ if ( filter( ['ready'], registry[module].needs ).compare( registry[module].needs ) ) {
 538+ execute( module );
537539 } else {
538 - request( name );
 540+ request( module );
539541 }
540542 };
541543 /**
@@ -572,6 +574,34 @@
573575 request( needs, ready, error );
574576 }
575577 };
 578+ /**
 579+ * Loads one or more modules for future use
 580+ */
 581+ this.load = function( modules ) {
 582+ // Validate input
 583+ if ( typeof modules !== 'object' && typeof modules !== 'string' ) {
 584+ throw new Error( 'needs must be a string or an array, not a ' + typeof needs )
 585+ }
 586+ // Allow calling with a single need as a string
 587+ if ( typeof modules === 'string' ) {
 588+ modules = [needs];
 589+ }
 590+ // Resolve entire dependency map
 591+ modules = resolve( modules );
 592+ // If all modules are ready, nothing need be done
 593+ if ( filter( ['ready'], modules ).compare( modules ) ) {
 594+ return true;
 595+ }
 596+ // If any modules have errors return false
 597+ else if ( filter( ['error'], modules ).length ) {
 598+ return false;
 599+ }
 600+ // Since some modules are not yet ready, queue up a request
 601+ else {
 602+ request( modules );
 603+ return true;
 604+ }
 605+ };
576606
577607 /* Event Bindings */
578608

Follow-up revisions

RevisionCommit summaryAuthorDate
r70467Fixed mixed use of spaces and tabs for indentation. Resolves indentation mist...tparscal17:36, 4 August 2010

Comments

#Comment by Nikerabbit (talk | contribs)   14:09, 3 August 2010
+'Circular reference detected: ' + module + ' -> ' + registry[module].needs[n]

Isn't that circular dependency?

#Comment by Catrope (talk | contribs)   14:27, 4 August 2010
		function recurse( module, resolved, unresolved ) {
+			unresolved[unresolved.length] = module;
+		    for ( var n = 0; n < registry[module].needs.length; n++ ) {
+		        if ( resolved.indexOf( registry[module].needs[n] ) === -1 ) {
+		            if ( unresolved.indexOf( registry[module].needs[n] ) !== -1 ) {
+		                throw new Error(
+		                	'Circular reference detected: ' + module + ' -> ' + registry[module].needs[n]
+		                );
+		            }
+		            recurse( registry[module].needs[n], resolved, unresolved );
+		        }
+		    }
+		    resolved[resolved.length] = module;
+		    unresolved.splice( unresolved.indexOf( module ), 1 );
+		}

This function is misindented.

#Comment by Trevor Parscal (WMF) (talk | contribs)   17:38, 4 August 2010

Hmm, there were a bunch of spaces being used... Fixed in r70467

Status & tagging log