MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 109: | Line 109: | ||
}() ); | }() ); | ||
function openCreateDialog() { | function openCreateDialog() { | ||
| Line 137: | Line 116: | ||
overlay.innerHTML = ` | overlay.innerHTML = ` | ||
<div class="grantha-modal-box"> | <div class="grantha-modal-box"> | ||
<div class="gm-title">Create | |||
<input type="text" id="gm-input" placeholder=" | <div class="gm-header"> | ||
<div class="gm-title">New document</div> | |||
<div class="gm-sub">Create a new text</div> | |||
</div> | |||
<input | |||
type="text" | |||
id="gm-input" | |||
placeholder="Untitled document" | |||
autofocus | |||
/> | |||
<div class="gm-actions"> | <div class="gm-actions"> | ||
<button | <button class="gm-btn gm-cancel">Cancel</button> | ||
<button | <button class="gm-btn gm-create">Create</button> | ||
</div> | </div> | ||
</div> | </div> | ||
`; | `; | ||
| Line 148: | Line 139: | ||
document.body.appendChild(overlay); | document.body.appendChild(overlay); | ||
var input = overlay.querySelector('#gm-input'); | |||
input.focus(); | |||
// Cancel | |||
overlay.querySelector('.gm-cancel').onclick = function () { | |||
overlay.remove(); | overlay.remove(); | ||
}; | }; | ||
// Create | |||
var name = | overlay.querySelector('.gm-create').onclick = function () { | ||
var name = input.value.trim(); | |||
if (!name) return; | if (!name) return; | ||
| Line 159: | Line 155: | ||
window.location.href = mw.util.getUrl(name, { action: 'edit' }); | window.location.href = mw.util.getUrl(name, { action: 'edit' }); | ||
}; | |||
// Enter key support | |||
input.addEventListener('keydown', function (e) { | |||
if (e.key === 'Enter') { | |||
overlay.querySelector('.gm-create').click(); | |||
} | |||
}); | |||
// Click outside to close | |||
overlay.onclick = function (e) { | |||
if (e.target === overlay) overlay.remove(); | |||
}; | }; | ||
} | } | ||