User:KokoroSenshi/common.js: Difference between revisions
Jump to navigation
Jump to search
KokoroSenshi (talk | contribs) m (→Autocomplete/Dropdown list: Added code to add css of counter the effect of `body` having a margin-top and position:relative) |
KokoroSenshi (talk | contribs) m (→Autocomplete/Dropdown list: typo) |
||
Line 6: | Line 6: | ||
//https://api.jquery.com/jQuery.getScript/#success-callback | //https://api.jquery.com/jQuery.getScript/#success-callback | ||
$.getScript( "https:// | $.getScript( "https://unpkg.com/textcomplete@0.13.1/dist/textcomplete.min.js", function( data, textStatus, jqxhr ) { | ||
console.log( data ); // Data returned | console.log( data ); // Data returned | ||
console.log( textStatus ); // Success | console.log( textStatus ); // Success |
Revision as of 04:40, 19 January 2018
/* Autocomplete/Dropdown list */
// Won't work with CodeEditor, but that's fine since CodeEditor won't be used for wikitext
//mw.loader.load('https://unpkg.com/textcomplete@0.13.1/dist/textcomplete.min.js');
//^Doesn't wait for it to load nor excecute
//https://api.jquery.com/jQuery.getScript/#success-callback
$.getScript( "https://unpkg.com/textcomplete@0.13.1/dist/textcomplete.min.js", function( data, textStatus, jqxhr ) {
console.log( data ); // Data returned
console.log( textStatus ); // Success
console.log( jqxhr.status ); // 200
console.log( "Load was performed. (Script has been loaded but not necessarily executed)" );
wikiAutocomplete();
});
function wikiAutocomplete() {
Textarea = Textcomplete.editors.Textarea;
//A negative margin on the dropdown list to offset the shift down caused by the position:relative and margin-top of the `body`
var bodyMarginTop = $('body').css("margin-top");
var TextcompleteCss = mw.util.addCSS(
'.dropdown-menu { margin-top: -'+bodyMarginTop+'; }'
);
// A 'strategy' for Template:Guide
guides = {
"TLoZ|publisher":'',
"SS|publisher":'',
"BotW|Test":'',
"Botw|Prima":''
};
window.guideStrategy = {
id: 'guide',
match: /(){{Guide\|([a-z0-9+\-\_}]*)$/, //https://regexr.com/
search: function (term, callback) {
callback(Object.keys(guides).filter(function (name) {
return name.startsWith(term);
}));
},
template: function (name) {
return name;
},
replace: function (name) {
return '$1{{Guide|' + name + '}}';
}
};
var editor = new Textarea(document.getElementById('wpTextbox1'));
var textcomplete = new Textcomplete(editor);
textcomplete.register([guideStrategy]);
}