미디어위키:Gadget-CreatePageUw.js: 두 판 사이의 차이
식물 vs 좀비 위키
편집 요약 없음 |
편집 요약 없음 |
||
| 9번째 줄: | 9번째 줄: | ||
} | } | ||
function | function createNativeInput( originalInput ) { | ||
var | var fieldLayout; | ||
var | var fieldContainer; | ||
var nativeInput; | |||
if ( | if ( | ||
return; | originalInput.classList.contains( | ||
'pvz-createpage-input' | |||
) | |||
) { | |||
originalInput.placeholder = | |||
'새로 재배할 문서의 제목을 입력하세요'; | |||
return originalInput; | |||
} | } | ||
fieldLayout = originalInput.closest( | |||
' | '.oo-ui-fieldLayout' | ||
); | ); | ||
fieldContainer = originalInput.closest( | |||
'.oo-ui-fieldLayout-field' | |||
); | |||
if ( !fieldContainer ) { | |||
return originalInput; | |||
} | |||
/* | |||
* 기존 input의 이름·ID·필수값·최대 길이 등은 유지하되, | |||
* OOUI 클래스와 인라인 디자인은 모두 제거한다. | |||
*/ | |||
nativeInput = originalInput.cloneNode( false ); | |||
nativeInput.value = originalInput.value; | |||
nativeInput.className = | |||
'input' | 'pvz-createpage-input'; | ||
) | |||
nativeInput.removeAttribute( 'style' ); | |||
nativeInput.removeAttribute( 'role' ); | |||
nativeInput.removeAttribute( 'aria-invalid' ); | |||
nativeInput.placeholder = | |||
'새로 재배할 문서의 제목을 입력하세요'; | |||
nativeInput.setAttribute( | |||
'aria-label', | |||
'새로 재배할 문서의 제목을 입력하세요' | |||
); | |||
/* | |||
* OOUI 입력창 래퍼 전체를 삭제하고 | |||
* 일반 입력창 하나만 남긴다. | |||
*/ | |||
fieldContainer.replaceChildren( | |||
nativeInput | |||
); | ); | ||
if ( | if ( fieldLayout ) { | ||
fieldLayout.classList.add( | |||
'pvz-createpage- | 'pvz-createpage-input-layout' | ||
); | ); | ||
} | |||
return nativeInput; | |||
' | } | ||
function createNativeSubmitButton( | |||
form, | |||
originalButton | |||
) { | |||
var fieldLayout; | |||
var fieldContainer; | |||
var nativeButton; | |||
var attributes; | |||
if ( !originalButton ) { | |||
return; | |||
} | |||
if ( | |||
originalButton.classList.contains( | |||
'pvz-createpage-submit-button' | |||
) | |||
) { | |||
originalButton.textContent = '제출'; | |||
originalButton.setAttribute( | |||
'aria-label', | |||
'제출' | |||
); | ); | ||
return; | |||
} | } | ||
fieldLayout = originalButton.closest( | |||
'.oo-ui-fieldLayout' | |||
); | |||
fieldContainer = originalButton.closest( | |||
' | '.oo-ui-fieldLayout-field' | ||
); | ); | ||
if ( ! | if ( !fieldContainer ) { | ||
return; | return; | ||
} | } | ||
nativeButton = | |||
' | document.createElement( 'button' ); | ||
nativeButton.type = 'submit'; | |||
nativeButton.className = | |||
'pvz-createpage-submit-button'; | |||
nativeButton.textContent = '제출'; | |||
nativeButton.setAttribute( | |||
'aria-label', | 'aria-label', | ||
' | '제출' | ||
); | ); | ||
/* | |||
* 기존 버튼의 제출 관련 속성을 유지한다. | |||
); | */ | ||
attributes = [ | |||
'id', | |||
'name', | |||
'value', | |||
'title', | |||
'formaction', | |||
'formmethod', | |||
'formenctype', | |||
'formtarget' | |||
]; | |||
attributes.forEach( function ( attribute ) { | |||
if ( | |||
originalButton.hasAttribute( | |||
attribute | |||
) | |||
) { | |||
nativeButton.setAttribute( | |||
attribute, | |||
originalButton.getAttribute( | |||
attribute | |||
) | |||
); | |||
} | |||
} ); | |||
if ( originalButton.disabled ) { | |||
nativeButton.disabled = true; | |||
} | |||
if ( | |||
originalButton.hasAttribute( | |||
'formnovalidate' | |||
) | |||
) { | |||
nativeButton.setAttribute( | |||
'formnovalidate', | |||
'' | |||
); | |||
} | |||
/* | |||
* OOUI 버튼 래퍼 전체를 삭제하고 | |||
* 일반 제출 버튼 하나만 남긴다. | |||
*/ | |||
fieldContainer.replaceChildren( | |||
nativeButton | |||
); | ); | ||
if ( | if ( fieldLayout ) { | ||
fieldLayout.classList.add( | |||
'pvz-createpage- | 'pvz-createpage-submit-layout' | ||
); | ); | ||
} | } | ||
} | |||
function insertSproutImage( | |||
input, | |||
fieldLayout | |||
) { | |||
var imageBox; | |||
var image; | |||
var insertionTarget; | |||
if ( | if ( | ||
document.querySelector( | |||
'.pvz-createpage-sprout' | '.pvz-createpage-sprout' | ||
) | ) | ||
) { | ) { | ||
imageBox = | return; | ||
} | |||
imageBox = | |||
document.createElement( 'div' ); | |||
imageBox.className = | |||
'pvz-createpage-sprout'; | |||
image = | |||
document.createElement( 'img' ); | |||
image.src = mw.util.getUrl( | |||
'Special:Redirect/file/' + | |||
'Sprout_PvZ2.png' | |||
); | |||
image.alt = ''; | |||
image.className = | |||
'pvz-design-critical'; | |||
imageBox.appendChild( image ); | |||
insertionTarget = | |||
fieldLayout || | |||
input.parentElement; | |||
if ( | |||
insertionTarget && | |||
insertionTarget.parentNode | |||
) { | |||
insertionTarget.parentNode.insertBefore( | |||
imageBox, | |||
insertionTarget | |||
); | ); | ||
} | |||
} | |||
function initializeCreatePageUw() { | |||
var originalInput; | |||
var inputFieldLayout; | |||
var input; | |||
var form; | |||
var originalButton; | |||
originalInput = document.getElementById( | |||
'mw-input-wptitle' | |||
); | |||
if ( !originalInput ) { | |||
return; | |||
} | |||
inputFieldLayout = originalInput.closest( | |||
'.oo-ui-fieldLayout' | |||
); | |||
input = createNativeInput( | |||
originalInput | |||
); | |||
insertSproutImage( | |||
input, | |||
inputFieldLayout | |||
); | |||
form = input.closest( 'form' ); | form = input.closest( 'form' ); | ||
| 155번째 줄: | 272번째 줄: | ||
} | } | ||
originalButton = form.querySelector( | |||
'.pvz-createpage-submit-button, ' + | |||
'button[type="submit"], ' + | 'button[type="submit"], ' + | ||
'input[type="submit"], ' + | 'input[type="submit"], ' + | ||
| 162번째 줄: | 280번째 줄: | ||
); | ); | ||
createNativeSubmitButton( | |||
form, | |||
originalButton | |||
); | |||
} | } | ||
