मीडियाविकि:Gadget-morebits.js: रिवीजन सभ के बीचा में अंतर
Content deleted Content added
Siddhartha Ghai (वार्ता) द्वारा किए बदलाव 1555707 को पूर्ववत करें |
छो Mayur (Talk) के संपादनों को हटाकर Siddhartha Ghai के आखिरी अवतरण को पूर्ववत किया |
||
लाइन 1:
// <nowiki>
/**
* morebits.js
Line 40 ⟶ 41:
function userIsAnon() {
return mw.config.get( 'wgUserGroups' ).length === 1;
}
Line 187 ⟶ 56:
create: function( name, value, max_age, path ) {
if( Cookies.exists( name ) ) {
throw new Error( "cookie " + name + " already exists" );
}
Cookies.set( name, value, max_age, path );
Line 236 ⟶ 105:
/**
* **************** QuickForm ****************
*
* specific coding.
*
* Index to QuickForm element types:
*
* select A combo box (aka drop-down).
* - Attributes: name, label, multiple, size, list, event
* option An element for a combo box.
* - Attributes: value, label, selected, disabled
* optgroup A group of "option"s.
* - Attributes: label, list
* field A fieldset (aka group box).
* - Attributes: name, label
* checkbox A checkbox. Must use "list" parameter.
* - Attributes: name, list, event
* - Attributes (within list): name, label, value, checked, disabled, event, subgroup
* radio A radio button. Must use "list" parameter.
* - Attributes: name, list, event
* - Attributes (within list): name, label, value, checked, disabled, event, subgroup
* input A text box.
* - Attributes: name, label, value, size, disabled, readonly, maxlength, event
* dyninput A set of text boxes with "Remove" buttons and an "Add" button.
* - Attributes: name, label, min, max, sublabel, value, size, maxlength, event
* hidden An invisible form field.
* - Attributes: name, value
* header A level 5 header.
* - Attributes: label
* div A generic placeholder element or label.
* - Attributes: name, label
* submit A submit button. SimpleWindow moves these to the footer of the dialog.
* - Attributes: name, label, disabled
* button A generic button.
* - Attributes: name, label, disabled, event
* textarea A big, multi-line text box.
* - Attributes: name, label, value, cols, rows, disabled, readonly
*
* Global attributes: id, tooltip, extra, adminonly
*/
Line 681 ⟶ 585:
break;
default:
throw new Error("QuickForm: unknown element type " + data.type.toString());
}
Line 724 ⟶ 627:
* Type is optional and can specify if either radio or checkbox (for the event
* that both checkboxes and radiobuttons have the same name.
*/
Line 767 ⟶ 667:
}
}
}
}
Line 810 ⟶ 694:
return text;
};
Line 1,136 ⟶ 761:
tmp /= Math.pow( 10, Bytes.magnitudes[mag] * 3 );
}
if( parseInt( tmp, 10 ) !== tmp ) {
tmp =
}
return tmp + ' ' + mag + (si?'i':'') +
} else {
// si per default
Line 1,148 ⟶ 773:
}
tmp = this.value / Math.pow( 2, current * 10 );
if( parseInt( tmp, 10 ) !== tmp ) {
tmp =
}
return tmp + ' ' + Bytes.rmagnitudes[current] + ( current > 0 ? 'iB' : 'B' );
}
};
/**
Line 1,160 ⟶ 786:
String.prototype.ltrim = function stringPrototypeLtrim( chars ) {
chars = chars || "\\s
return this.replace( new RegExp("^[" + chars + "]+", "g"), "" );
};
String.prototype.rtrim = function stringPrototypeRtrim( chars ) {
chars = chars || "\\s
return this.replace( new RegExp("[" + chars + "]+$", "g"), "" );
};
Line 1,175 ⟶ 801:
String.prototype.splitWeightedByKeys = function stringPrototypeSplitWeightedByKeys( start, end, skip ) {
if( start.length !== end.length ) {
throw new Error( 'start marker and end marker must be of the same length' );
}
var level = 0;
Line 1,186 ⟶ 812:
skip = [ skip ];
} else {
throw new Error( "non-applicable skip parameter" );
}
}
Line 1,264 ⟶ 890:
};
Array.prototype.chunk = function arrayChunk( size ) {
if( typeof( size ) !== 'number' || size <= 0 ) { // pretty impossible to do anything :)
Line 1,284 ⟶ 909:
/**
* **************** Unbinder ****************
* Used by MediaWiki.commentOutImage
*/
function Unbinder( string ) {
if( typeof( string ) !== 'string' ) {
throw new Error( "not a string" );
}
this.content = string;
Line 1,306 ⟶ 931:
var content = this.content;
content.self = this;
for( var current in this.history ) {
if( this.history.hasOwnProperty( current ) ) {
content = content.replace( current, this.history[current] );
}
}
return content;
},
Line 1,330 ⟶ 957:
/**
* **************** clone() ****************
* REMOVEME - global namespace pollution
* rework the few usages using jQuery.extend
*/
function clone( obj, deep ) {
var objectClone = new obj.constructor();
for ( var property in obj ) {
if ( !deep ) {
objectClone[property] = obj[property];
Line 1,343 ⟶ 971:
objectClone[property] = obj[property];
}
}
return objectClone;
}
Line 1,521 ⟶ 1,118:
'108': 'Book',
'109': 'Book talk'
};
// Analyzes the HTML of the current page (i.e. no AJAX requests) to determine if it
// is a redirect or soft redirect
Wikipedia.isPageRedirect = function wikipediaIsPageRedirect() {
return !!($("span.redirectText").length > 0 || document.getElementById("softredirect"));
};
// we dump all XHR here so they won't loose props
// REMOVEME
Wikipedia.dump = [];
Line 1,570 ⟶ 1,173:
new Status( Wikipedia.actionCompleted.notice, Wikipedia.actionCompleted.postfix, 'info' );
if( Wikipedia.actionCompleted.redirect ) {
// if it isn't
if( !( (/^\w+\:\/\//).test( Wikipedia.actionCompleted.redirect ) ) ) {
Wikipedia.actionCompleted.redirect = mw.
if( Wikipedia.actionCompleted.followRedirect === false ) {
Wikipedia.actionCompleted.redirect += "?redirect=no";
Line 1,585 ⟶ 1,188:
// editCount - REMOVEME when Wikipedia.wiki is gone
Wikipedia.editCount = 10;
Wikipedia.actionCompleted.timeOut = wpActionCompletedTimeOut;
Wikipedia.actionCompleted.redirect = null;
Line 1,828 ⟶ 1,432:
*
* Watchlist notes:
* 1. The MediaWiki API value of 'unwatch',
*
* 2. If both setWatchlist() and setWatchlistFromPreferences() are called,
* the last call takes priority.
Line 2,506 ⟶ 2,110:
// default on success action - display link for edited page
var link = document.createElement('a');
link.setAttribute('href', mw.
link.appendChild(document.createTextNode(ctx.pageName));
ctx.statusElement.info(['completed (', link, ')']);
Line 2,624 ⟶ 2,228:
var moveToken = $(xml).find('page').attr('movetoken');
if (!moveToken) {
ctx.statusElement.error("Failed to retrieve
return;
}
Line 2,766 ⟶ 2,370:
/**
* **************** Wikipedia.wiki ****************
* REMOVEME - but *only* after
*/
Line 2,861 ⟶ 2,463:
} else {
var link = document.createElement( 'a' );
link.setAttribute( 'href', mw.
link.setAttribute( 'title', self.query['title'] );
link.appendChild( document.createTextNode( self.query['title'] ) );
Line 2,956 ⟶ 2,558:
for( var i = start; i < text.length; ++i ) {
var test3 = text.substr( i, 3 );
if( test3 === '
current += '
i += 2;
++level;
continue;
}
if( test3 === '
current += '
i += 2;
--level;
Line 2,969 ⟶ 2,571:
}
var test2 = text.substr( i, 2 );
if( test2 === '
current += test2;
++i;
Line 2,975 ⟶ 2,577:
continue;
}
if( test2 === '
current += test2;
++i;
Line 2,981 ⟶ 2,583:
continue;
}
if( test2 === '
current += test2;
++i;
Line 3,113 ⟶ 2,715:
var first_char = template.substr( 0, 1 );
var template_re_string = "(?:[Tt]emplate:)?\\s*[" + first_char.toUpperCase() + first_char.toLowerCase() + ']' + RegExp.escape( template.substr( 1 ), true );
var links_re = new RegExp( "
var allTemplates = this.text.splitWeightedByKeys( '{
for( var i = 0; i < allTemplates.length; ++i ) {
if( links_re.test( allTemplates[i] ) ) {
Line 3,134 ⟶ 2,736:
function isInNetwork( ipaddress, network ) {
var iparr = ipaddress.split('.');
var ip = (parseInt(iparr[0], 10) << 24) + (parseInt(iparr[1], 10) << 16) + (parseInt(iparr[2], 10) << 8) + (parseInt(iparr[3], 10));
var netmask = 0xffffffff << network.split('/')[1];
var netarr = network.split('/')[0].split('.');
var net = (parseInt(netarr[0], 10) << 24) + (parseInt(netarr[1], 10) << 16) + (parseInt(netarr[2], 10) << 8) + (parseInt(netarr[3], 10));
return (ip & netmask) === net;
Line 3,297 ⟶ 2,899:
this.stat = this.codify(stat);
this.type = type || 'status';
if (type === 'error') {
// hack to force the page not to reload when an error is output - see also update() below
Wikipedia.numberOfActionsLeft = 1000;
// call error callback
if (Status.errorEvent) {
Status.errorEvent();
}
}
this.generate();
Line 3,309 ⟶ 2,915:
Status.init = function( root ) {
if( !( root instanceof Element ) ) {
throw new
}
while( root.hasChildNodes() ) {
Line 3,315 ⟶ 2,921:
}
Status.root = root;
Status.errorEvent = null;
};
Status.root = null;
Status.onError = function( handler ) {
if (typeof handler === "function") {
Status.errorEvent = handler;
} else {
throw "Status.onError: handler is not a function";
}
};
Status.prototype = {
Line 3,358 ⟶ 2,973:
if( type ) {
this.type = type;
if (type === 'error') {
// hack to force the page not to reload when an error is output - see also Status() above
Wikipedia.numberOfActionsLeft = 1000;
// call error callback
if (Status.errorEvent) {
Status.errorEvent();
}
}
}
Line 3,445 ⟶ 3,064:
buttons: { "Placeholder button": function() {} },
dialogClass: 'morebits-dialog',
width: Math.min(parseInt(window.innerWidth, 10), parseInt(width ? width : 800, 10)),
// give jQuery the given height value (which represents the anticipated height of the dialog) here, so
// it can position the dialog appropriately
Line 3,503 ⟶ 3,122:
}
var dialog = $(this.content).dialog("open");
if (window.setupTooltips) { dialog.parent()[0].ranSetupTooltipsAlready = false; setupTooltips(dialog.parent()[0]); } //tie in with NAVPOP
this.setHeight( this.height ); // init height algorithm
},
Line 3,527 ⟶ 3,147:
// note that the given height will exclude the approx. 20px that the jQuery UI chrome has in height in addition to the height
// of an equivalent "classic" SimpleWindow
if (parseInt(getComputedStyle($(this.content).dialog("widget")[0], null).height, 10) > window.innerHeight) {
$(this.content).dialog("option", "height", window.innerHeight - 2).dialog("option", "position", "top");
} else {
$(this.content).dialog("option", "height", "auto");
}
$(this.content).dialog("widget").find(".morebits-dialog-content")[0].style.maxHeight = parseInt(this.height - 30, 10) + "px";
},
// Sets the content of the dialog to the given element node, usually from rendering a QuickForm or QuickForm element.
Line 3,582 ⟶ 3,202:
}
var link = document.createElement("a");
link.setAttribute("href",
link.setAttribute("title", wikiPage);
link.setAttribute("target", "_blank");
Line 3,608 ⟶ 3,228:
};
// Twinkle blacklist was removed per consensus at http://en.wikipedia.org/wiki/Wikipedia:Administrators%27_noticeboard/Archive221#New_Twinkle_blacklist_proposal
// </nowiki>
|