Module:CRTModel: Difference between revisions
Tag: Undo |
No edit summary Tag: Reverted |
||
| Line 196: | Line 196: | ||
-- Documents section | -- Documents section | ||
addSectionRow(container, 'Documents') | addSectionRow(container, 'Documents') | ||
-- Query for document count | -- Query for document count | ||
| Line 292: | Line 279: | ||
docsDiv:node(ul) | docsDiv:node(ul) | ||
-- Add upload link as a button | -- Add upload link as a button with JavaScript UUID generation | ||
local uploadDiv = mw.html.create('div') | local uploadDiv = mw.html.create('div') | ||
uploadDiv:css('margin-top', '0.5em'):css('text-align', 'center') | uploadDiv:css('margin-top', '0.5em'):css('text-align', 'center') | ||
local button = mw.html.create('a') | |||
button:attr('href', '#') | |||
button:attr('data-crt-model', pageName) | |||
button:attr('class', 'everycrt-upload-doc-btn') | |||
button:css('display', 'inline-block') | |||
button:css('padding', '0.5rem 1rem') | |||
button:css('background-color', '#eff6ff') | |||
button:css('color', '#1d4ed8') | |||
button:css('border', '1px solid #bfdbfe') | |||
button:css('border-radius', '0.375rem') | |||
button:css('font-size', '0.875rem') | |||
button:css('font-weight', '500') | |||
button:css('text-decoration', 'none') | |||
button:css('cursor', 'pointer') | |||
button:wikitext('Upload a document') | |||
uploadDiv:node(button) | |||
docsDiv:node(uploadDiv) | docsDiv:node(uploadDiv) | ||
-- Add the JavaScript inline | |||
local scriptTag = mw.html.create('script') | |||
scriptTag:wikitext([[ | |||
(function(){ | |||
var btn = document.querySelector('.everycrt-upload-doc-btn'); | |||
if(btn && !btn.dataset.initialized) { | |||
btn.dataset.initialized = 'true'; | |||
btn.addEventListener('click', function(e){ | |||
e.preventDefault(); | |||
var u = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c){ | |||
var r = Math.random()*16|0, v = c=='x'?r:(r&0x3|0x8); | |||
return v.toString(16); | |||
}); | |||
var model = encodeURIComponent(this.dataset.crtModel); | |||
window.location.href = '/wiki/Special:FormEdit?form=Document&target=Document:' + u + '&Document[crt_models]=' + model; | |||
}); | |||
} | |||
})(); | |||
]]) | |||
docsDiv:node(scriptTag) | |||
else | else | ||
-- Just show the upload link as a button | -- Just show the upload link as a button with JavaScript UUID generation | ||
local uploadDiv = mw.html.create('div') | local uploadDiv = mw.html.create('div') | ||
uploadDiv:css('text-align', 'center') | uploadDiv:css('text-align', 'center') | ||
local button = mw.html.create('a') | |||
button:attr('href', '#') | |||
button:attr('data-crt-model', pageName) | |||
button:attr('class', 'everycrt-upload-doc-btn') | |||
button:css('display', 'inline-block') | |||
button:css('padding', '0.5rem 1rem') | |||
button:css('background-color', '#eff6ff') | |||
button:css('color', '#1d4ed8') | |||
button:css('border', '1px solid #bfdbfe') | |||
button:css('border-radius', '0.375rem') | |||
button:css('font-size', '0.875rem') | |||
button:css('font-weight', '500') | |||
button:css('text-decoration', 'none') | |||
button:css('cursor', 'pointer') | |||
button:wikitext('Upload a document') | |||
uploadDiv:node(button) | |||
docsDiv:node(uploadDiv) | docsDiv:node(uploadDiv) | ||
-- Add the JavaScript inline | |||
local scriptTag = mw.html.create('script') | |||
scriptTag:wikitext([[ | |||
(function(){ | |||
var btn = document.querySelector('.everycrt-upload-doc-btn'); | |||
if(btn && !btn.dataset.initialized) { | |||
btn.dataset.initialized = 'true'; | |||
btn.addEventListener('click', function(e){ | |||
e.preventDefault(); | |||
var u = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c){ | |||
var r = Math.random()*16|0, v = c=='x'?r:(r&0x3|0x8); | |||
return v.toString(16); | |||
}); | |||
var model = encodeURIComponent(this.dataset.crtModel); | |||
window.location.href = '/wiki/Special:FormEdit?form=Document&target=Document:' + u + '&Document[crt_models]=' + model; | |||
}); | |||
} | |||
})(); | |||
]]) | |||
docsDiv:node(scriptTag) | |||
end | end | ||