Tech, emailconfirmed, Administrators (Semantic MediaWiki), Curators (Semantic MediaWiki), Administrators
12,456
edits
m (Fix VE source mode support) |
Bongolium500 (talk | contribs) No edit summary |
||
(9 intermediate revisions by 3 users not shown) | |||
Line 27: | Line 27: | ||
return; | return; | ||
} | } | ||
console.log('[PreloadTemplates]: version 1. | console.log('[PreloadTemplates]: version 1.06 - 07/2021.'); | ||
// ================= | // ================= | ||
Line 78: | Line 78: | ||
function getPreloadPage(title) { | function getPreloadPage(title) { | ||
// check if subpage is standard or is case by case | // check if subpage is standard or is case by case | ||
var namespace = mwc.wgFormattedNamespaces['10'] | var namespace = (function() { | ||
if (typeof window.preloadTemplates_namespace == 'undefined') return mwc.wgFormattedNamespaces['10']; | |||
if (typeof mwc.wgFormattedNamespaces[window.preloadTemplates_namespace] != 'undefined') return mwc.wgFormattedNamespaces[window.preloadTemplates_namespace]; | |||
for (var key in mwc.wgFormattedNamespaces) { | |||
if (mwc.wgFormattedNamespaces[key] == window.preloadTemplates_namespace) return mwc.wgFormattedNamespaces[key]; | |||
} | |||
return mwc.wgFormattedNamespaces['10']; | |||
})(); | |||
var namespacePagename = (function() { | |||
if (namespace) return namespace + ':'; | |||
return ''; | |||
})(); | |||
var page = config.subpage === 'case-by-case' ? | |||
namespacePagename + title : | |||
namespacePagename + title + '/' + config.subpage; | |||
$.get(mw.util.wikiScript(), { | $.get(mw.util.wikiScript(), { | ||
Line 90: | Line 101: | ||
// Parse some MediaWiki tags | // Parse some MediaWiki tags | ||
var preloadDataParsed = parseMW(preloadData); | var preloadDataParsed = parseMW(preloadData); | ||
// Display error if no useful data is present | // Display error if no useful data is present | ||
if (preloadDataParsed === '') { | if (preloadDataParsed === '') { | ||
Line 99: | Line 109: | ||
// Insert syntax | // Insert syntax | ||
var cke = document.getElementsByClassName('cke_source'), | var cke = document.getElementsByClassName('cke_source'), | ||
textbox = document.getElementById('wpTextbox1'); | textbox = document.getElementById('wpTextbox1'), | ||
cm = $(".CodeMirror").get(0); | |||
if (window.ve && ve.init && ve.init.target && ve.init.target.active) { | if (window.ve && ve.init && ve.init.target && ve.init.target.active) { | ||
// UCP Visual Editor (Source mode) | // UCP Visual Editor (Source mode) | ||
Line 110: | Line 121: | ||
// Visual editor | // Visual editor | ||
insertAtCursor(cke[0], preloadDataParsed); | insertAtCursor(cke[0], preloadDataParsed); | ||
} else if (textbox) { | } else if (cm){ | ||
// text editor with syntex heighting | |||
var cmEditor = cm.CodeMirror; | |||
var cmdDoc = cmEditor.getDoc(); | |||
cmdDoc.replaceRange(preloadDataParsed, cmdDoc.getCursor()); | |||
} | |||
else if(textbox) { | |||
insertAtCursor(textbox, preloadDataParsed); | insertAtCursor(textbox, preloadDataParsed); | ||
} else { | } else { | ||
Line 232: | Line 249: | ||
// Imports | // Imports | ||
// =========== | // =========== | ||
if (!window.dev || !window.dev.i18n) { | /*if (!window.dev || !window.dev.i18n) { | ||
importArticle({ | importArticle({ | ||
type: 'script', | type: 'script', | ||
Line 241: | Line 258: | ||
type: 'style', | type: 'style', | ||
article: 'u:dev:MediaWiki:PreloadTemplates.css' | article: 'u:dev:MediaWiki:PreloadTemplates.css' | ||
}); | });*/ | ||
mw.hook('dev.i18n').add(function(i18no) { | mw.hook('dev.i18n').add(function(i18no) { |
edits