MediaWiki:Script/InputBoxNoPrefix.js: различия между версиями
Перейти к навигации
Перейти к поиску
Andras (обсуждение | вклад) (Новая страница: «//usage: {{Выполнить скрипт|InputBoxNoPrefix}} // <div class=inputbox-no-prefix><inputbox>...</div> function movePrefix(){ //move prefix away from input mw.util.$content.find('div.inputbox-no-prefix') .find('form') .each( function(i, frm){ $(frm).find('span.prefix').remove() //in case user clicked 'back' browser button var ttl = frm.title // same as $(frm).find('input[name=title]') var prefix = /^.+[:\/]/.exec( ttl.defaultValue )...») |
(нет различий)
|
Текущая версия от 16:43, 16 июля 2023
//usage: {{Выполнить скрипт|InputBoxNoPrefix}}
// <div class=inputbox-no-prefix><inputbox>...</div>
function movePrefix(){ //move prefix away from input
mw.util.$content.find('div.inputbox-no-prefix')
.find('form')
.each( function(i, frm){
$(frm).find('span.prefix').remove() //in case user clicked 'back' browser button
var ttl = frm.title // same as $(frm).find('input[name=title]')
var prefix = /^.+[:\/]/.exec( ttl.defaultValue )
if (! prefix ) return
prefix = prefix[0]
$( '<span class=prefix />' ).text( prefix ).insertBefore( ttl )
ttl.value = ttl.value.substring( prefix.length)
ttl.size -= prefix.length
$(frm).submit( restorePrefix )
})
}
function restorePrefix(){
var sp = $(this).find('span.prefix').remove()
if( !sp.length ) return
this.title.value = sp.text() + this.title.value
}
if( mw.config.get('wgNamespaceNumber') != 0 ) $(movePrefix)