Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -102,12 +102,86 @@ |
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
| 106 | + * Defines all the ResourceLoader modules needed for SF Javascript |
| 107 | + * and CSS |
| 108 | + */ |
| 109 | + static function registerModules( $resourceLoader ) { |
| 110 | + global $sfgPartialPath, $smwgScriptPath; |
| 111 | + |
| 112 | + $resourceLoader->register( |
| 113 | + array( |
| 114 | + 'semanticforms.main' => |
| 115 | + new ResourceLoaderFileModule( |
| 116 | + array( |
| 117 | + 'scripts' => |
| 118 | + "$sfgPartialPath/libs/SemanticForms.js", |
| 119 | + 'styles' => |
| 120 | + array( |
| 121 | + "$sfgPartialPath/skins/SemanticForms.css", |
| 122 | + "$sfgPartialPath/skins/SF_jquery_ui_overrides.css", |
| 123 | + ), |
| 124 | + ) |
| 125 | + ), |
| 126 | + 'semanticforms.fancybox' => |
| 127 | + new ResourceLoaderFileModule( |
| 128 | + array( |
| 129 | + 'scripts' => |
| 130 | + "$sfgPartialPath/libs/jquery.fancybox-1.3.1.js", |
| 131 | + 'styles' => |
| 132 | + "$sfgPartialPath/skins/jquery.fancybox-1.3.1.css", |
| 133 | + ) |
| 134 | + ), |
| 135 | + 'semanticforms.autogrow' => |
| 136 | + new ResourceLoaderFileModule( |
| 137 | + array( |
| 138 | + 'scripts' => |
| 139 | + "$sfgPartialPath/libs/SF_autogrow.js", |
| 140 | + ) |
| 141 | + ), |
| 142 | + 'semanticforms.smw_utilities' => |
| 143 | + new ResourceLoaderFileModule( |
| 144 | + array( |
| 145 | + 'scripts' => |
| 146 | + // no $smwgPartialPath variable exists yet |
| 147 | + "/extensions/SemanticMediaWiki/skins/SMW_tooltip.js", |
| 148 | + "/extension/SemanticMediaWiki/skins/SMW_sorttable.js", |
| 149 | + ) |
| 150 | + ), |
| 151 | + ) |
| 152 | + ); |
| 153 | + |
| 154 | + return true; |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Uses the ResourceLoader (available with MediaWiki 1.17 and higher) |
| 159 | + * to load all the necessary JS and CSS files for Semantic Forms. |
| 160 | + */ |
| 161 | + static function loadJavascriptAndCSS() { |
| 162 | + global $wgOut; |
| 163 | + $wgOut->addModules( 'jquery' ); |
| 164 | + $wgOut->addModules( 'jquery.ui.autocomplete' ); |
| 165 | + $wgOut->addModules( 'jquery.ui.button' ); |
| 166 | + $wgOut->addModules( 'semanticforms.main' ); |
| 167 | + $wgOut->addModules( 'semanticforms.fancybox' ); |
| 168 | + $wgOut->addModules( 'semanticforms.autogrow' ); |
| 169 | + $wgOut->addModules( 'semanticforms.smw_utilities' ); |
| 170 | + global $sfgFancyBoxIncluded; |
| 171 | + $sfgFancyBoxIncluded = true; |
| 172 | + } |
| 173 | + |
| 174 | + /** |
106 | 175 | * Includes the necessary Javascript and CSS files for the form |
107 | 176 | * to display and work correctly |
108 | 177 | * |
109 | 178 | * Accepts an optional Parser instance, or uses $wgOut if omitted. |
110 | 179 | */ |
111 | 180 | static function addJavascriptAndCSS( $parser = NULL ) { |
| 181 | + // MW 1.17 + |
| 182 | + if ( class_exists( 'ResourceLoader' ) ) { |
| 183 | + self::loadJavascriptAndCSS(); |
| 184 | + return; |
| 185 | + } |
112 | 186 | global $wgOut, $sfgScriptPath, $smwgScriptPath, $wgScriptPath, $wgFCKEditorDir, $wgJsMimeType, $sfgUseFormEditPage; |
113 | 187 | global $smwgJQueryIncluded, $smwgJQUIAutoIncluded; |
114 | 188 | // jQuery and jQuery UI are used so often in forms, we might as |
— | — | @@ -134,7 +208,6 @@ |
135 | 209 | else |
136 | 210 | $wgOut->addLink( $link ); |
137 | 211 | } |
138 | | - $wgOut->addStyle( "$sfgScriptPath/skins/SF_IEfixes.css", 'screen', 'IE' ); |
139 | 212 | |
140 | 213 | $scripts = array(); |
141 | 214 | if ( !$sfgUseFormEditPage ) |
— | — | @@ -160,6 +233,7 @@ |
161 | 234 | $script = "<script type=\"$wgJsMimeType\" src=\"$js\"></script>\n"; |
162 | 235 | $parser->getOutput()->addHeadItem( $script ); |
163 | 236 | } else { |
| 237 | + global $wgOut; |
164 | 238 | $wgOut->addScriptFile( $js ); |
165 | 239 | } |
166 | 240 | } |