MediaWiki:Upload.js — различия между версиями
Arhssaarh (обсуждение | вклад) |
|||
| (не показано 6 промежуточных версий 2 участников) | |||
| Строка 2: | Строка 2: | ||
if (window.wgUploadAutoFill){ | if (window.wgUploadAutoFill){ | ||
upForm = document.getElementById('mw-upload-form') | upForm = document.getElementById('mw-upload-form') | ||
| − | |||
} | } | ||
var desc = document.getElementById('wpUploadDescription') | var desc = document.getElementById('wpUploadDescription') | ||
| Строка 48: | Строка 47: | ||
} | } | ||
} | } | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
/* Hide quick insert */ | /* Hide quick insert */ | ||
Текущая версия на 00:38, 10 мая 2013
function uploadPage(){
if (window.wgUploadAutoFill){
upForm = document.getElementById('mw-upload-form')
}
var desc = document.getElementById('wpUploadDescription')
var tmpl = document.getElementById('imageinfo')
if (wgUploadAutoFill && tmpl && desc && !desc.value) desc.value = tmpl.innerHTML
appendCSS('a.insertlink { text-decoration: none; }')
var span = document.getElementById('insertlink-free')
if (!!span) {
var a = document.createElement('a')
a.href = 'javascript:addInfoTemplate("rationale", "imageinfo", 8)'
a.class = 'insertlink'
span.parentNode.insertBefore(a, span)
a.appendChild(span)
}
var span = document.getElementById('insertlink-unfree')
if (!!span) {
var a = document.createElement('a')
a.href = 'javascript:addInfoTemplate("imageinfo", "rationale", 16)'
a.class = 'insertlink'
span.parentNode.insertBefore(a, span)
a.appendChild(span)
}
var c = document.getElementById('commons-link')
var c_a = c.lastChild
c.innerHTML = '<input class="commons-btn" type="button" onclick="window.location.href=\''+c_a.href+'\'" value="'+c_a.text+'"/>'
}
function addInfoTemplate(oldId, newId, rows){
var desc = document.getElementById('wpUploadDescription')
var oldTmpl = document.getElementById(oldId)
var tmpl = document.getElementById(newId)
if (desc && oldTmpl && desc.value == oldTmpl.innerHTML){
desc.value = tmpl.innerHTML
desc.rows = rows
}
else if (desc && tmpl && desc.value.indexOf(tmpl.innerHTML.substring(0,8)) == -1){
desc.value += '\n' + tmpl.innerHTML
desc.rows = 20
}
licList = document.getElementsByTagName('option', document.getElementById('wpLicense'))
if (newId == 'rationale'){
licList[licList.length-1].selected='selected'
}
else {
licList[0].selected='selected'
}
}
/* Hide quick insert */
function uploadHideInsert(){
qIns = document.getElementById('editpage-specialchars')
qInsCover = document.createElement('div')
qInsCover.setAttribute('style', qIns.style.cssText)
if (typeof(qInsCover.style.setAttribute) == 'function') qInsCover.style.setAttribute('style', qIns.style.cssText) // IE
qInsCover.innerHTML = '<small><span style="border-bottom:1px dotted gray; cursor:help" title="Позволяет быстро вставлять символы разметки в поле описания">Быстрая вставка</span> (<a href="javascript:uploadExpandInsert()">раскрыть блок</a>)</small>'
qIns.style.display = 'none'
qIns.parentNode.appendChild(qInsCover)
}
function uploadExpandInsert(){
qInsCover.style.display = 'none'
qIns.style.display = 'block'
}
/* Ajax Preview */
function uploadPreviewRun(){
wpUploadPreview.innerHTML = ''
injectSpinner(wpUploadPreview,'preview')
var aj = sajax_init_object()
aj.onreadystatechange = function(){
if (aj.readyState!=4 || aj.status!=200) return
removeSpinner('preview')
wpUploadPreview.innerHTML = eval('('+aj.responseText+')')['parse']['text']['*']
wpUploadPreview.scrollIntoView()
}
aj.open('GET', '/w/api.php?action=parse&prop=text&pst&format=json&text='
+ encodeURIComponent(wpUploadText.value), true)
aj.send('')
}
function uploadPreviewInit(){
wpUploadText = document.getElementById('wpUploadDescription')
if (!wpUploadText) return
var bt = create('input','wpDestFile'); bt.type='button'
bt.style.cssFloat = bt.style.styleFloat = 'right'
bt.value = 'Предпросмотр'; bt.onclick = uploadPreviewRun
wpUploadPreview = create('div','wpLicense')
function create(type, attachTo){
var el = document.createElement(type)
attachTo = document.getElementById(attachTo) || wpUploadText
attachTo.parentNode.appendChild(el)
return el
}
}
addOnloadHook(uploadPage)
addOnloadHook(uploadHideInsert)
addOnloadHook(uploadPreviewInit)