r105978 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105977‎ | r105978 | r105979 >
Date:04:21, 13 December 2011
Author:jeroendedauw
Status:ok
Tags:
Comment:
jquery tweaks
Modified paths:
  • /trunk/extensions/SemanticImageInput/resources/jquery.instantImage.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticImageInput/resources/jquery.instantImage.js
@@ -7,9 +7,16 @@
88 * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
99 */
1010
11 -(function( $, mw ) {
 11+(function( $, mw ) { $.fn.instantImage = function( options ) {
 12+
 13+ var settings = $.extend( {
 14+ 'imagename': 'Beatles',
 15+ 'inputname': '',
 16+ 'apipath': 'https://en.wikipedia.org/w/api.php?callback=?',
 17+ 'imagewidth': 200
 18+ }, options );
1219
13 - $.fn.instantImage = function( opts ) {
 20+ return this.each( function() {
1421
1522 var _this = this;
1623 var $this = $( this );
@@ -18,25 +25,18 @@
1926 this.images = null;
2027 this.raw = null;
2128
22 - this.options = {
23 - 'imagename': 'Beatles',
24 - 'inputname': '',
25 - 'apipath': 'https://en.wikipedia.org/w/api.php?callback=?',
26 - 'imagewidth': 200
27 - };
28 -
2929 this.getMainTitle = function( callback ) {
3030 $.getJSON(
31 - this.options.apipath,
 31+ settings.apipath,
3232 {
3333 'action': 'query',
3434 'format': 'json',
35 - 'titles': this.options.imagename,
 35+ 'titles': settings.imagename,
3636 'redirects': 1
3737 },
3838 function( data ) {
3939 if ( data.query && data.query.redirects ) {
40 - _this.options.imagename = data.query.redirects[0].to;
 40+ settings.imagename = data.query.redirects[0].to;
4141 }
4242
4343 callback();
@@ -46,12 +46,12 @@
4747
4848 this.getImages = function( callback ) {
4949 $.getJSON(
50 - this.options.apipath,
 50+ settings.apipath,
5151 {
5252 'action': 'query',
5353 'format': 'json',
5454 'prop': 'images',
55 - 'titles': this.options.imagename,
 55+ 'titles': settings.imagename,
5656 'redirects': 1,
5757 'imlimit': 500
5858 },
@@ -81,13 +81,13 @@
8282
8383 this.getRaw = function( callback ) {
8484 $.getJSON(
85 - this.options.apipath,
 85+ settings.apipath,
8686 {
8787 'action': 'query',
8888 'format': 'json',
8989 'prop': 'revisions',
9090 'rvprop': 'content',
91 - 'titles': this.options.imagename
 91+ 'titles': settings.imagename
9292 },
9393 function( data ) {
9494 if ( data.query ) {
@@ -133,14 +133,14 @@
134134 }
135135
136136 $.getJSON(
137 - this.options.apipath,
 137+ settings.apipath,
138138 {
139139 'action': 'query',
140140 'format': 'json',
141141 'prop': 'imageinfo',
142142 'iiprop': 'url',
143143 'titles': image,
144 - 'iiurlwidth': this.options.imagewidth
 144+ 'iiurlwidth': settings.imagewidth
145145 },
146146 function( data ) {
147147 if ( data.query && data.query.pages ) {
@@ -150,11 +150,11 @@
151151 var info = pages[p].imageinfo;
152152 for ( i in info ) {
153153 if ( info[i].thumburl.indexOf( '/wikipedia/commons/' ) !== -1 ) {
154 - $( 'input[name="' + _this.options.inputname + '"]' ).val( image );
 154+ $( 'input[name="' + settings.inputname + '"]' ).val( image );
155155
156156 $this.html( $( '<img />' ).attr( {
157157 'src': info[i].thumburl,
158 - 'width': _this.options.imagewidth + 'px'
 158+ 'width': settings.imagewidth + 'px'
159159 } ) );
160160
161161 return;
@@ -180,11 +180,11 @@
181181 this.start = function() {
182182 this.loadedFirstReq = false;
183183
184 - if ( this.options.iteminput ) {
185 - this.options.imagename = this.options.iteminput.val();
 184+ if ( settings.iteminput ) {
 185+ settings.imagename = settings.iteminput.val();
186186 }
187187
188 - if ( this.options.imagename.trim() === '' ) {
 188+ if ( settings.imagename.trim() === '' ) {
189189 $this.html( '' );
190190 }
191191 else {
@@ -196,18 +196,14 @@
197197 };
198198
199199 this.init = function() {
200 - $.extend( this.options, opts );
201 -
202 - if ( this.options.iteminput ) {
203 - this.options.iteminput.change( function() { _this.start(); } );
 200+ if ( settings.iteminput ) {
 201+ settings.iteminput.change( function() { _this.start(); } );
204202 }
205203
206204 this.start();
207205 };
208206
209207 this.init();
210 -
211 - return this;
212 - };
 208+ } );
213209
214 -})( window.jQuery, window.mediaWiki );
 210+}; })( window.jQuery, window.mediaWiki );

Status & tagging log