User:Holek/cite-gen.js

/** * Citation templates generator in editor * * @author Mike "Hołek" Połtyn */ if (false && // T35837 ( wgAction == 'edit' || wgAction == 'submit' ) )

{	if (wgNamespaceNumber > -1) {		importScript('User:Holek/cite-gen/i18n.js'); $.extend({URLEncode:function(c){var o=;var x=0;c=c.toString;var r=/(^[a-zA-Z0-9_.]*)/;		while(x1 && m[1]!=){o+=m[1];x+=m[1].length;		  }else{if(c[x]==' ')o+='+';else{var d=c.charCodeAt(x);var h=d.toString(16);		  o+='%'+(h.length<2?'0':)+h.toUpperCase;}x++;}}return o;},		URLDecode:function(s){var o=s;var binVal,t;var r=/(%[^%]{2})/;		while((m=r.exec(o))!=null && m.length>1 && m[1]!=){b=parseInt(m[1].substr(1),16);		t=String.fromCharCode(b);o=o.replace(m[1],t);}return o;}		}); var citeGen = new Object; citeGen.showHide = function (context) { $('#citeGenToolbar').slideToggle('fast', function {				context.fn.trigger( 'resize' );			}); }		citeGen.passInfo = function (e) { var button = $(e.target).attr("disabled","disabled"); $.ajax({				url: 'http://toolserver.org/~citegen/index.php?citelang='+wgContentLanguage+'&s[add-references]=on&template=json&input='+$.URLEncode($('#citeGenInput').val),				dataType: 'jsonp',				jsonp: 'uid',				success: function (json) {					$('#citeGenResult').slideDown('fast', function { ($.wikiEditor.modules.toolbar.evt.resize)($( 'textarea#wpTextbox1' ).data( 'wikiEditor-context' )); });					if (json.response.length > 0) {						var resp = json.response[0].book;					} else {						var resp = wgCiteGenLang['no-results'];					}					$('#citeGenResultOutput').val(resp);					button.prop('disabled', false);				}			}); e.preventDefault; }		if ( typeof $ != 'undefined' && typeof $.fn.wikiEditor != 'undefined' ) {			hookEvent( 'load', function{				var citeGenDescDiv = $(' ').append(wgCiteGenLang['cite-gen-description']),					citeGenInputBox = $(' ').attr({'type':'text','size':'30','id':'citeGenInput'}),					citeGenSubmit = $(' ').attr({'type':'button','value':wgCiteGenLang['generate-template']}).click(citeGen.passInfo),					citeGenForm = $(' ')									.append(citeGenDescDiv)									.append(citeGenInputBox)									.append(citeGenSubmit)									.submit(function {citeGenSubmit.click;return false;}),					citeGenOutputBox = $(' ').attr({'type':'text','size':'60','id':'citeGenResultOutput'}),					citeGenResultBox = $(' ').attr({'id':'citeGenResult','style':'display:none;'}).append(wgCiteGenLang['generated-template']+' ').append(citeGenOutputBox),					citeGenFormSection = $(' ').append(citeGenForm).append(citeGenResultBox);				$('.section-advanced').append(citeGenFormSection);				$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', { 'section': 'advanced', 'group': 'insert', 'tools': { 'cite-gen': { label: wgCiteGenLang['cite-gen-label'], type: 'button', icon: 'http://upload.wikimedia.org/wikipedia/commons/8/81/Wikieditor-reference.png', action: { type: 'callback', execute: citeGen.showHide }						}					}				} );			} );		}	} }