-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to scratchblocks v3.6.1, refactor code (#13)
* Host scratchblocks locally * Use v2 schema * Refactor code
- Loading branch information
Showing
6 changed files
with
62 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,22 @@ | ||
function run_scratchblocks() { | ||
mw.hook('wikipage.content').add(function run_scratchblocks() { | ||
var version = mw.config.get('wgScratchBlocks4BlockVersion'); | ||
var scale = 1; | ||
// Note: the weak equality is intentional to allow '2' and 2 both specify sb2 | ||
if (version == 2 || version[0] == '2') { // to handle '2.0' | ||
version = 'scratch2'; | ||
} else { | ||
version = 'scratch3'; | ||
scale = 0.675; | ||
} | ||
var langs = ['en'].concat(mw.config.get('wgScratchBlocks4Langs')); | ||
scratchblocks.renderMatching('pre.blocks', {languages: langs, style: version}); | ||
scratchblocks.renderMatching('code.blocks', {languages: langs, style: version, inline: true}); | ||
scratchblocks.renderMatching('pre[class^=blocks-3]', {languages: langs, style: 'scratch3'}); | ||
scratchblocks.renderMatching('code[class^=blocks-3]', {languages: langs, style: 'scratch3', inline: true}); | ||
scratchblocks.renderMatching('pre[class^=blocks-2]', {languages: langs, style: 'scratch2'}); | ||
scratchblocks.renderMatching('code[class^=blocks-2]', {languages: langs, style: 'scratch2', inline: true}); | ||
scratchblocks.renderMatching('pre.blocks', { languages: langs, style: version, scale: scale }); | ||
scratchblocks.renderMatching('code.blocks', { languages: langs, style: version, inline: true, scale: scale }); | ||
scratchblocks.renderMatching('pre[class^=blocks-3]', { languages: langs, style: 'scratch3', scale: 0.675 }); | ||
scratchblocks.renderMatching('code[class^=blocks-3]', { languages: langs, style: 'scratch3', inline: true, scale: 0.675 }); | ||
scratchblocks.renderMatching('pre[class^=blocks-2]', { languages: langs, style: 'scratch2' }); | ||
scratchblocks.renderMatching('code[class^=blocks-2]', { languages: langs, style: 'scratch2', inline: true }); | ||
var query = '[class^=blocks-3] .scratchblocks svg'; | ||
if (version === 'scratch3') { | ||
query = '.blocks .scratchblocks svg, ' + query; | ||
} | ||
var items = document.querySelectorAll(query); | ||
var item; | ||
for (var i = items.length; i--;) { | ||
item = items[i]; | ||
item.width.baseVal.value *= 0.675; | ||
item.height.baseVal.value = item.viewBox.baseVal.height * 0.675; | ||
} | ||
} | ||
$.getScript('https://scratchblocks.github.io/js/scratchblocks-v3.6.0-min.js').done(function(){ | ||
$.getScript('https://scratchblocks.github.io/js/translations-all-v3.6.0.js').done(function(){ | ||
mw.hook('wikipage.content').add(run_scratchblocks); | ||
}); | ||
}); |