Index: trunk/extensions/SemanticForms/SemanticForms.php |
— | — | @@ -236,6 +236,9 @@ |
237 | 237 | 'scripts' => 'libs/SF_wikieditor.js', |
238 | 238 | 'styles' => 'skins/SF_wikieditor.css', |
239 | 239 | ), |
| 240 | + 'ext.semanticforms.imagepreview' => $sfgResourceTemplate + array( |
| 241 | + 'scripts' => 'libs/SF_imagePreview.js', |
| 242 | + ), |
240 | 243 | ); |
241 | 244 | } |
242 | 245 | |
Index: trunk/extensions/SemanticForms/specials/SF_UploadWindow2.php |
— | — | @@ -385,11 +385,16 @@ |
386 | 386 | $basename = str_replace( '_', ' ', $basename ); |
387 | 387 | // UTF8-decoding is needed for IE |
388 | 388 | $basename = utf8_decode( $basename ); |
389 | | - $output = ' <script type="text/javascript">' . "\n"; |
| 389 | + |
| 390 | + $output .= <<<END |
| 391 | + <script type="text/javascript"> |
| 392 | + var input = parent.window.jQuery( parent.document.getElementById("{$this->mInputID}") ); |
| 393 | +END; |
| 394 | + |
390 | 395 | if ( $this->mDelimiter == null ) { |
391 | 396 | $output .= <<<END |
392 | | - parent.document.getElementById("{$this->mInputID}").value = '$basename'; |
393 | | - |
| 397 | + input.val( '$basename' ); |
| 398 | + input.change(); |
394 | 399 | END; |
395 | 400 | } else { |
396 | 401 | $output .= <<<END |
— | — | @@ -399,14 +404,18 @@ |
400 | 405 | // both a delimiter and a file name; and add on a delimiter |
401 | 406 | // at the end in any case |
402 | 407 | var cur_value = parent.document.getElementById("{$this->mInputID}").value; |
| 408 | + |
403 | 409 | if (cur_value === '') { |
404 | | - parent.document.getElementById("{$this->mInputID}").value = '$basename' + '{$this->mDelimiter} '; |
| 410 | + input.val( '$basename' + '{$this->mDelimiter} ' ); |
| 411 | + input.change(); |
405 | 412 | } else { |
406 | 413 | var last_char = cur_value.charAt(cur_value.length - 1); |
407 | 414 | if (last_char == '{$this->mDelimiter}' || last_char == ' ') { |
408 | 415 | parent.document.getElementById("{$this->mInputID}").value += '$basename' + '{$this->mDelimiter} '; |
| 416 | + input.change(); |
409 | 417 | } else { |
410 | 418 | parent.document.getElementById("{$this->mInputID}").value += '{$this->mDelimiter} $basename{$this->mDelimiter} '; |
| 419 | + input.change(); |
411 | 420 | } |
412 | 421 | } |
413 | 422 | |
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_TextInput.php |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | return array( '_wpg' ); |
44 | 44 | } |
45 | 45 | |
46 | | - public static function uploadLinkHTML( $input_id, $delimiter = null, $default_filename = null ) { |
| 46 | + public static function uploadableHTML( $input_id, $delimiter = null, $default_filename = null, $cur_value = '', $other_args = array() ) { |
47 | 47 | $upload_window_page = SpecialPage::getPage( 'UploadWindow' ); |
48 | 48 | $query_string = "sfInputID=$input_id"; |
49 | 49 | if ( $delimiter != null ) { |
— | — | @@ -60,13 +60,48 @@ |
61 | 61 | $style = ''; |
62 | 62 | } |
63 | 63 | |
| 64 | + $cssClasses = array( 'sfFancyBox', 'sfUploadable' ); |
| 65 | + |
| 66 | + $showPreview = array_key_exists( 'imagepreview', $other_args ) && trim( $other_args['imagepreview'] == 'on' ); |
| 67 | + |
| 68 | + if ( $showPreview ) { |
| 69 | + $cssClasses[] = 'sfImagePreview'; |
| 70 | + } |
| 71 | + |
64 | 72 | $linkAttrs = array( |
65 | 73 | 'href' => $upload_window_url, |
66 | | - 'class' => 'sfFancyBox', |
| 74 | + 'class' => implode( ' ', $cssClasses ), |
67 | 75 | 'title' => $upload_label, |
68 | | - 'rev' => $style |
| 76 | + 'rev' => $style, |
| 77 | + 'data-input-id' => $input_id |
69 | 78 | ); |
| 79 | + |
70 | 80 | $text = "\t" . Xml::element( 'a', $linkAttrs, $upload_label ) . "\n"; |
| 81 | + |
| 82 | + if ( $showPreview ) { |
| 83 | + $previewImage = null; |
| 84 | + |
| 85 | + if ( $cur_value !== '' ) { |
| 86 | + $imageTitle = Title::newFromText( $cur_value, NS_FILE ); |
| 87 | + |
| 88 | + if ( !is_null( $imageTitle ) && $imageTitle->getNamespace() == NS_FILE && $imageTitle->exists() ) { |
| 89 | + $imagePage = new ImagePage( $imageTitle ); |
| 90 | + $url = $imagePage->getDisplayedFile()->transform( array( 'width' => 200 ) )->getURL(); |
| 91 | + |
| 92 | + $previewImage = Html::element( |
| 93 | + 'img', |
| 94 | + array( 'src' => $url ) |
| 95 | + ); |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + $text .= Html::rawElement( |
| 100 | + 'div', |
| 101 | + array( 'id' => $input_id . '_imagepreview' ), |
| 102 | + $previewImage |
| 103 | + ); |
| 104 | + } |
| 105 | + |
71 | 106 | return $text; |
72 | 107 | } |
73 | 108 | |
— | — | @@ -146,7 +181,8 @@ |
147 | 182 | } else { |
148 | 183 | $default_filename = ''; |
149 | 184 | } |
150 | | - $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename ); |
| 185 | + |
| 186 | + $text .= self::uploadableHTML( $input_id, $delimiter, $default_filename, $cur_value, $other_args ); |
151 | 187 | } |
152 | 188 | $spanClass = 'inputSpan'; |
153 | 189 | if ( $inputType !== '' ) { |
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_TextAreaWithAutocompleteInput.php |
— | — | @@ -139,7 +139,7 @@ |
140 | 140 | } else { |
141 | 141 | $default_filename = ''; |
142 | 142 | } |
143 | | - $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename ); |
| 143 | + $text .= self::uploadableHTML( $input_id, $delimiter, $default_filename, $cur_value, $other_args ); |
144 | 144 | } |
145 | 145 | |
146 | 146 | $spanClass = 'inputSpan'; |
Index: trunk/extensions/SemanticForms/includes/forminputs/SF_TextWithAutocompleteInput.php |
— | — | @@ -184,7 +184,7 @@ |
185 | 185 | } else { |
186 | 186 | $default_filename = ''; |
187 | 187 | } |
188 | | - $text .= self::uploadLinkHTML( $input_id, $delimiter, $default_filename ); |
| 188 | + $text .= self::uploadableHTML( $input_id, $delimiter, $default_filename, $cur_value, $other_args ); |
189 | 189 | } |
190 | 190 | |
191 | 191 | $spanClass = 'inputSpan'; |
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -284,6 +284,7 @@ |
285 | 285 | } |
286 | 286 | $output->addModules( 'ext.semanticforms.main' ); |
287 | 287 | $output->addModules( 'ext.semanticforms.fancybox' ); |
| 288 | + $output->addModules( 'ext.semanticforms.imagepreview' ); |
288 | 289 | $output->addModules( 'ext.semanticforms.autogrow' ); |
289 | 290 | $output->addModules( 'ext.semanticforms.submit' ); |
290 | 291 | $output->addModules( 'ext.smw.tooltips' ); |
— | — | @@ -395,6 +396,7 @@ |
396 | 397 | $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.mouse.min.js"; |
397 | 398 | $scripts[] = "$sfgScriptPath/libs/jquery-ui/jquery.ui.sortable.min.js"; |
398 | 399 | $scripts[] = "$sfgScriptPath/libs/jquery.fancybox.js"; |
| 400 | + $scripts[] = "$sfgScriptPath/libs/SF_imagePreview.js"; |
399 | 401 | $scripts[] = "$sfgScriptPath/libs/SF_autogrow.js"; |
400 | 402 | $scripts[] = "$sfgScriptPath/libs/SF_submit.js"; |
401 | 403 | $scripts[] = "$sfgScriptPath/libs/SemanticForms.js"; |
Index: trunk/extensions/SemanticForms/libs/SF_imagePreview.js |
— | — | @@ -0,0 +1,67 @@ |
| 2 | +/** |
| 3 | + * JavasSript for the Semantic Forms MediaWiki extension. |
| 4 | + * |
| 5 | + * @licence GNU GPL v3+ |
| 6 | + * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
| 7 | + */ |
| 8 | + |
| 9 | +(function( $ ) { |
| 10 | + |
| 11 | + var _this = this; |
| 12 | + |
| 13 | + this.getPreviewImage = function( args, callback ) { |
| 14 | + $.getJSON( |
| 15 | + wgScriptPath + '/api.php', |
| 16 | + { |
| 17 | + 'action': 'query', |
| 18 | + 'format': 'json', |
| 19 | + 'prop': 'imageinfo', |
| 20 | + 'iiprop': 'url', |
| 21 | + 'titles': 'File:' + args.title, |
| 22 | + 'iiurlwidth': args.width |
| 23 | + }, |
| 24 | + function( data ) { |
| 25 | + if ( data.query && data.query.pages ) { |
| 26 | + var pages = data.query.pages; |
| 27 | + |
| 28 | + for ( p in pages ) { |
| 29 | + var info = pages[p].imageinfo; |
| 30 | + for ( i in info ) { |
| 31 | + callback( info[i].thumburl ); |
| 32 | + return; |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + callback( false ); |
| 37 | + } |
| 38 | + ); |
| 39 | + }; |
| 40 | + |
| 41 | + $( document ).ready( function() { |
| 42 | + $( '.sfImagePreview' ).each( function( index, domElement ) { |
| 43 | + var $uploadLink = $( domElement ); |
| 44 | + var inputId = $uploadLink.attr( 'data-input-id' ); |
| 45 | + var $input = $( '#' + inputId ); |
| 46 | + |
| 47 | + $input.change( function() { |
| 48 | + _this.getPreviewImage( |
| 49 | + { |
| 50 | + 'title': $input.val(), |
| 51 | + 'width': 200 |
| 52 | + }, |
| 53 | + function( url ) { |
| 54 | + $previewDiv = $( '#' + inputId + '_imagepreview' ); |
| 55 | + |
| 56 | + if ( url === false ) { |
| 57 | + $previewDiv.html( '' ); |
| 58 | + } |
| 59 | + else { |
| 60 | + $previewDiv.html( $( '<img />' ).attr( { 'src': url } ) ); |
| 61 | + } |
| 62 | + } |
| 63 | + ); |
| 64 | + } ); |
| 65 | + } ); |
| 66 | + } ); |
| 67 | + |
| 68 | +})( window.jQuery ); |
Property changes on: trunk/extensions/SemanticForms/libs/SF_imagePreview.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 69 | + native |