MediaWiki:Editpage.js — различия между версиями
Материал из GS
м (Отмена правки 53575, сделанной участником StereoMaster (обс.)) |
м |
||
| Строка 1: | Строка 1: | ||
| − | + | importMW('Wikificator') | |
| + | mwCustomEditButtons['wikif'] = [function(){Wikify()}, 'commons/0/06/Wikify-toolbutton.png', 'Викификатор — автоматический обработчик текста'] | ||
| + | |||
| + | |||
| + | if( mw.user.options.get('usebetatoolbar') ){ | ||
| + | var gTlbLoc = '#wikiEditor-ui-toolbar' | ||
| + | mw.util.addCSS('#gadget-toolbar {height:26px; border-right:1px solid #ddd; margin:3px; padding-right:6px} #gadget-toolbar img {padding:2px}') | ||
| + | $('#wpTextbox1').bind('wikiEditor-toolbar-buildSection-main', function(e, sec){ | ||
| + | sec.groups.insert.tools.file.action.options.post = '|thumb]]' | ||
| + | }) | ||
| + | }else if( document.getElementById('toolbar') ){ | ||
| + | var gTlbLoc = '#toolbar' | ||
| + | mwCustomEditButtons['wikif'][1] = 'commons/3/38/Button_wikify.png' | ||
| + | importMW('ToolbarOld') | ||
| + | }else{ | ||
| + | var gTlbLoc = '#editform' | ||
| + | importMW('ToolbarNone') | ||
| + | } | ||
| + | |||
| + | |||
| + | $(function(){ | ||
| + | gToolbar() | ||
| + | setTimeout(gToolbar, 2000) | ||
| + | setTimeout(gToolbar, 6000) | ||
| + | }) | ||
| + | |||
| + | |||
| + | |||
| + | function gToolbar(){ | ||
| + | |||
| + | if( !document.getElementById('gadget-toolbar') ){ | ||
| + | var where = $(gTlbLoc) | ||
| + | if( !where.length ) return //beta toolbar not ready yet | ||
| + | $('<div id=gadget-toolbar style="float:left" />').prependTo(where) | ||
| + | } | ||
| + | |||
| + | for( var id in mwCustomEditButtons ){ | ||
| + | var b = mwCustomEditButtons[id] | ||
| + | if( ! b.length ) continue | ||
| + | createFuncBtn(id, b[0], b[1], b[2]) | ||
| + | delete mwCustomEditButtons[id] | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | function createFuncBtn(id, func, img, tip){ | ||
| + | $('<img id="'+id+'" src="'+wgImg(img)+'" style="cursor:pointer" ' | ||
| + | +'title="'+tip+'" alt="'+tip.substr(0,3)+'" />') | ||
| + | .appendTo('#gadget-toolbar') | ||
| + | .click(func) | ||
| + | } | ||
| + | |||
| + | |||
function wgImg(img){ | function wgImg(img){ | ||
| − | return | + | return '//upload.wikimedia.org/wikipedia/' + img |
| − | } | + | } |
| − | + | ||
| + | |||
| + | //for userscripts | ||
| + | function addFuncBtn(id, func, img, tip){ | ||
| + | if( document.getElementById('gadget-toolbar') ) | ||
| + | createFuncBtn(id, func, img, tip) | ||
| + | else | ||
| + | mwCustomEditButtons[id] = [func, img, tip] | ||
| + | } | ||
//Summary buttons | //Summary buttons | ||
Версия 21:04, 1 июля 2012
importMW('Wikificator')
mwCustomEditButtons['wikif'] = [function(){Wikify()}, 'commons/0/06/Wikify-toolbutton.png', 'Викификатор — автоматический обработчик текста']
if( mw.user.options.get('usebetatoolbar') ){
var gTlbLoc = '#wikiEditor-ui-toolbar'
mw.util.addCSS('#gadget-toolbar {height:26px; border-right:1px solid #ddd; margin:3px; padding-right:6px} #gadget-toolbar img {padding:2px}')
$('#wpTextbox1').bind('wikiEditor-toolbar-buildSection-main', function(e, sec){
sec.groups.insert.tools.file.action.options.post = '|thumb]]'
})
}else if( document.getElementById('toolbar') ){
var gTlbLoc = '#toolbar'
mwCustomEditButtons['wikif'][1] = 'commons/3/38/Button_wikify.png'
importMW('ToolbarOld')
}else{
var gTlbLoc = '#editform'
importMW('ToolbarNone')
}
$(function(){
gToolbar()
setTimeout(gToolbar, 2000)
setTimeout(gToolbar, 6000)
})
function gToolbar(){
if( !document.getElementById('gadget-toolbar') ){
var where = $(gTlbLoc)
if( !where.length ) return //beta toolbar not ready yet
$('<div id=gadget-toolbar style="float:left" />').prependTo(where)
}
for( var id in mwCustomEditButtons ){
var b = mwCustomEditButtons[id]
if( ! b.length ) continue
createFuncBtn(id, b[0], b[1], b[2])
delete mwCustomEditButtons[id]
}
}
function createFuncBtn(id, func, img, tip){
$('<img id="'+id+'" src="'+wgImg(img)+'" style="cursor:pointer" '
+'title="'+tip+'" alt="'+tip.substr(0,3)+'" />')
.appendTo('#gadget-toolbar')
.click(func)
}
function wgImg(img){
return '//upload.wikimedia.org/wikipedia/' + img
}
//for userscripts
function addFuncBtn(id, func, img, tip){
if( document.getElementById('gadget-toolbar') )
createFuncBtn(id, func, img, tip)
else
mwCustomEditButtons[id] = [func, img, tip]
}
//Summary buttons
function SummaryButtons(){
var sum = document.getElementById('wpSummary')
if (!sum || (sum.form.wpSection && sum.form.wpSection.value == 'new')) return
var sp = document.createElement('span'); sp.id = 'userSummaryButtonsA'
sum.parentNode.insertBefore(sp, sum.nextSibling)
sum.parentNode.insertBefore(document.createElement('br'), sum.nextSibling)
addSumButton('викификация','викификация')
addSumButton('форматирование','форматирование')
addSumButton('унификация','унификация')
addSumButton('стиль','стилевые правки')
addSumButton('орфография','орфография')
addSumButton('пунктуация','пунктуация')
addSumButton('дополнение','дополнение')
addSumButton('иллюстрации','иллюстрации')
addSumButton('категории','категории')
addSumButton('обновление','обновление данных')
addSumButton('шаблон','шаблон')
}
function addSumButton(name, text, title) {
var btn = document.createElement('a')
btn.appendChild(document.createTextNode(name))
btn.title = title || text
btn.onclick = function(){insertSummary(text)}
document.getElementById('userSummaryButtonsA').appendChild(btn)
}
function insertSummary(text) {
var sum = document.getElementById('wpSummary')
if (sum.value.indexOf(text) != -1) return
if (sum.value.match(/[^,; \/]$/)) sum.value += ','
if (sum.value.match(/[^ ]$/)) sum.value += ' '
sum.value += text
}
addOnloadHook(SummaryButtons)