MediaWiki talk:Common.js/Archive 5
Tooltip for dismiss watchlist linkHow about adding a "title" attribute to the dismiss watchlist link to create a tooltip: ButtonLink.setAttribute( "title", "Hide watchlist message for one week" ); This way, normal users have a chance of seeing that "dismiss" will hide the message for one week, instead of blindly clicking on it (or avoiding it for fear of permanently dismissing the message). What would be really cool would be to make the message dismiss until the text was changed. This would be pretty easy to do if there was a built-in MD5 function or some other sort of hash or checksum derived from the message that could be used as the value of the cookie instead of "yes". That way the code could tell if the message that was dismissed was the same as the current message. Mike Dillon 14:09, 31 March 2007 (UTC)
Query strings{{editprotected}} I have made a querystring function in my morebits.js, wonder if you think it should be included here? →AzaToth 19:45, 1 April 2007 (UTC) Code /** * Maps the querystring to an object * * Functions: * * QueryString.exists(key) * returns true if the particular key is set * QueryString.get(key) * returns the value associated to the key * QueryString.equals(key, value) * returns true if the value associated with given key equals given value * QueryString.toString() * returns the query string as a string * QueryString.create( hash ) * creates an querystring and encodes strings via encodeURIComponent and joins arrays with | * * In static context, the value of location.search.substring(1), else the value given to the constructor is going to be used. The mapped hash is saved in the object. * * Example: * * var value = QueryString.get('key'); * var obj = new QueryString('foo=bar&baz=quux'); * value = obj.get('foo'); */ function QueryString(qString) { this.string = qString; this.params = {}; if( qString.length == 0 ) { return; } qString.replace(/\+/, ' '); var args = qString.split('&'); for( var i in args ) { if( typeof( args[i] ) != 'string' ) { continue; } var pair = args[i].split( '=' ); var key = decodeURIComponent( pair[0] ), value = key; if( pair.length == 2 ) { value = decodeURIComponent( pair[1] ); } this.params[key] = value; } } QueryString.static = null; QueryString.staticInit = function() { if( QueryString.static == null ) { QueryString.static = new QueryString(location.search.substring(1)); } } QueryString.get = function(key) { QueryString.staticInit(); return QueryString.static.get(key); }; QueryString.prototype.get = function(key) { return this.params[key] ? this.params[key] : null; }; QueryString.exists = function(key) { QueryString.staticInit(); return QueryString.static.exists(key); } QueryString.prototype.exists = function(key) { return this.params[key] ? true : false; } QueryString.equals = function(key, value) { QueryString.staticInit(); return QueryString.static.equals(key, value); } QueryString.prototype.equals = function(key, value) { return this.params[key] == value ? true : false; } QueryString.toString = function() { QueryString.staticInit(); return QueryString.static.toString(); } QueryString.prototype.toString = function() { return this.string ? this.string : null; } QueryString.create = function( arr ) { var resarr = Array(); for( var i in arr ) { if( typeof arr[i] == 'object' ){ var v = Array(); for(var j in arr[i] ) { v[j] = encodeURIComponent( arr[i][j] ); } resarr.push( encodeURIComponent( i ) + '=' + v.join('|') ); } else { resarr.push( encodeURIComponent( i ) + '=' + encodeURIComponent( arr[i] ) ); } } return resarr.join('&'); } QueryString.prototype.create = QueryString.create; Looks great, but do we really need it? It's long, and each load is an unnecessary drain on the servers if its relatively unused. —METS501 (talk) 20:03, 1 April 2007 (UTC)
What does it do? At first glance it doesn't seem to have any use outside of other user-scipts (which can just as easily import it themselves.) —Ruud 21:02, 1 April 2007 (UTC)
Code function queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } } return null; } The above is basically from Lupin's popups, no? Or somewhere else before that, given the nature of much javascript code. Now, my opinion really doesn't matter here (not really that professional a javascript coder), but it might be useful to have one standardized function related to query strings, since a lot of scripts need them, and said scripts have their own query functions. So if those scripts are used together, you have (possibly) three or four query string functions altogether, which doesn't strike me as that efficient. Creating and getting query strings sounds useful; the rest, not as much. GracenotesT § 14:29, 2 April 2007 (UTC) As WP:TW is probably the only script as of yet using QueryString (by some freak coincident), the number of calls to QueryString as of yet is 59 times. →AzaToth 14:45, 2 April 2007 (UTC)
As to show you why it's so "complicated", I'm using it for example to create things like this (though I'm usually tries to make it asyncronus, it's syncrone here for the ease of typing): var query = { 'title': 'User talk:' + user, 'action': 'submit' }; xmlhttp = sajax_init_object(); xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), false); xmlhttp.send( null ); form = xmlhttp.responseXML.getElementById('editform'); var postData = { 'wpMinoredit': form.wpMinoredit.checked, 'wpWatchthis': form.wpWatchthis.checked, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': summary, 'wpTextbox1': text }; xmlhttp = sajax_init_object(); xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'POST' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( query ), false); xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); xmlhttp.send( QueryString.create( postData ) ); Another example could be to check if we are "editing" the page: var isEditing = QueryString.equals('action', 'edit'); A third common example of you want to do, is when you want to grab data from a link: var query = new QueryString( node.getAttribute('href').split('?',2) ); var rev = query.get('oldid'); This is just simple examples, and I made it extensive, so it would be easy to parse/create query strings. one good thing is that it takes care of encoding automatically, for example QueryString.create({'foo bar':['a','123!"#åäö']}) becomes "foo%20bar=a|123!%22%23%C3%A5%C3%A4%C3%B6" vice versa→AzaToth 23:32, 7 April 2007 (UTC)
Better search engineAfter requests from WikipediaSearch.net I copied the enhanced search JavaScript from fr:; feel free to revert or alter. David.Monniaux 20:14, 10 April 2007 (UTC)
There is something weird here. I was contacted on IRC by User:DragonflySixtyseven who told me that the matter had been discussed and all was needed was a technical fix, which he didn't feel comfortable doing because he did not know how to hack JavaScript. David.Monniaux 05:10, 11 April 2007 (UTC) I was thinking that the concensus are find on saturday afternoon on IRC, i speak with User:DragonflySixtyseven and he told me that we can modify the page of the namespace 8, I was explain to User:DragonflySixtyseven that the community are very happy to see our engine http://fr.wikipedia.org/wiki/Special:Linksearch/*.wikipediasearch.net Pmartin76 05:32, 11 April 2007 (UTC) It doesn't help that PMartin76's English isn't the best, and that I was feeling sickly all weekend. If this is inappropriate, revert it. DS 13:31, 11 April 2007 (UTC)
SortingI plan to add a bug fix for sorting tables, like I have done on Meta, to allow sorting of numbers with more than one thousands separator, see m:MediaWiki:Common.js. Any comments?--Patrick 13:47, 11 April 2007 (UTC) Compare Help:Sorting#Making_variable-length_numbers_with_thousands_separators_sortable with m:Help:Sorting#Making_variable-length_numbers_with_thousands_separators_sortable.--Patrick 14:06, 11 April 2007 (UTC)
Proposal: Short button captions for collapse tablesCan you add a shorter caption version of the collapse buttons? Maybe [+/-] instead of [show/hide]? Geva Zeichner 12:52, 14 April 2007 (UTC)
Also, why is Button.style.width = "6em" so wide? it takes also a lot of space. Geva Zeichner 13:29, 14 April 2007 (UTC)
|
Portal di Ensiklopedia Dunia