增加VE主分类选择功能

master
落雨楓 1 year ago
parent 1643f1bfc1
commit b10e134c14

@ -142,6 +142,35 @@
"isekai-ve-formatdropdown-format-mw-heading6" "isekai-ve-formatdropdown-format-mw-heading6"
] ]
}, },
"ve.ext.isekai.paste": {
"scripts": [
"ve.ext.isekai.paste.js"
],
"targets": [
"desktop",
"mobile"
],
"dependencies": [
"ext.visualEditor.mwcore",
"ext.visualEditor.mwextensions"
]
},
"ve.ext.isekai.mainCategory": {
"scripts": [
"ve.ext.isekai.mainCategory.js"
],
"targets": [
"desktop",
"mobile"
],
"dependencies": [
"ext.visualEditor.mwcore",
"ext.visualEditor.mwextensions"
],
"messages": [
"isekai-ve-dialog-meta-categories-input-maincategorieslabel"
]
},
"ext.isekai.function-btn": { "ext.isekai.function-btn": {
"scripts": [ "scripts": [
"ext.isekai.function-btn.js" "ext.isekai.function-btn.js"
@ -163,7 +192,8 @@
"attributes": { "attributes": {
"VisualEditor": { "VisualEditor": {
"PluginModules": [ "PluginModules": [
"ve.ext.isekai.misc" "ve.ext.isekai.misc",
"ve.ext.isekai.mainCategory"
] ]
} }
}, },
@ -184,6 +214,9 @@
}, },
"IsekaiActivateEditorRequiredWords": { "IsekaiActivateEditorRequiredWords": {
"value": 300 "value": 300
},
"IsekaiMainCategoriesIndexUrl": {
"value": "/index.php?title=Project:MainCategories.json&action=raw"
} }
}, },
"manifest_version": 2 "manifest_version": 2

@ -45,5 +45,7 @@
"isekai-ve-formatdropdown-format-mw-heading3": "Sub-heading 3", "isekai-ve-formatdropdown-format-mw-heading3": "Sub-heading 3",
"isekai-ve-formatdropdown-format-mw-heading4": "Sub-heading 4", "isekai-ve-formatdropdown-format-mw-heading4": "Sub-heading 4",
"isekai-ve-formatdropdown-format-mw-heading5": "Sub-heading 5", "isekai-ve-formatdropdown-format-mw-heading5": "Sub-heading 5",
"isekai-ve-formatdropdown-format-mw-heading6": "Sub-heading 6" "isekai-ve-formatdropdown-format-mw-heading6": "Sub-heading 6",
"isekai-ve-dialog-meta-categories-input-maincategorieslabel": "Main categories"
} }

@ -45,5 +45,7 @@
"isekai-ve-formatdropdown-format-mw-heading3": "三级标题", "isekai-ve-formatdropdown-format-mw-heading3": "三级标题",
"isekai-ve-formatdropdown-format-mw-heading4": "四级标题", "isekai-ve-formatdropdown-format-mw-heading4": "四级标题",
"isekai-ve-formatdropdown-format-mw-heading5": "五级标题", "isekai-ve-formatdropdown-format-mw-heading5": "五级标题",
"isekai-ve-formatdropdown-format-mw-heading6": "六级标题" "isekai-ve-formatdropdown-format-mw-heading6": "六级标题",
"isekai-ve-dialog-meta-categories-input-maincategorieslabel": "主要分类"
} }

@ -45,5 +45,7 @@
"isekai-ve-formatdropdown-format-mw-heading3": "三级標題", "isekai-ve-formatdropdown-format-mw-heading3": "三级標題",
"isekai-ve-formatdropdown-format-mw-heading4": "四级標題", "isekai-ve-formatdropdown-format-mw-heading4": "四级標題",
"isekai-ve-formatdropdown-format-mw-heading5": "五级標題", "isekai-ve-formatdropdown-format-mw-heading5": "五级標題",
"isekai-ve-formatdropdown-format-mw-heading6": "六级標題" "isekai-ve-formatdropdown-format-mw-heading6": "六级標題",
"isekai-ve-dialog-meta-categories-input-maincategorieslabel": "主要分類"
} }

@ -319,6 +319,7 @@ HTML
public static function onResourceLoaderGetConfigVars(array &$vars, string $skin, Config $config){ public static function onResourceLoaderGetConfigVars(array &$vars, string $skin, Config $config){
$vars['wgIsekaiShowAds'] = $config->get('IsekaiShowAds'); $vars['wgIsekaiShowAds'] = $config->get('IsekaiShowAds');
$vars['wgIsekaiMainCategoriesIndexUrl'] = $config->get('IsekaiMainCategoriesIndexUrl');
} }
public static function onGetPreferences(User $user, array &$preferences){ public static function onGetPreferences(User $user, array &$preferences){

@ -0,0 +1,68 @@
var _veUiMWCategoryInputWidgetPopulateLookupMenu = ve.ui.MWCategoryInputWidget.prototype.populateLookupMenu;
ve.ui.MWCategoryInputWidget.prototype.populateLookupMenu = function () {
this.allowSuggestionsWhenEmpty = true;
_veUiMWCategoryInputWidgetPopulateLookupMenu.call(this);
};
ve.ui.MWCategoryInputWidget.prototype.isekaiGetCategoryItemFromData = function (data, indent) {
indent = indent || 0;
var items = [];
data.forEach(function (cInfo) {
var item;
var indentText = ' '.repeat(indent * 2);
if (cInfo.isSection) {
item = new OO.ui.MenuSectionOptionWidget({
data: cInfo.category,
label: indentText + cInfo.label
});
} else {
item = new OO.ui.MenuOptionWidget({
data: cInfo.category,
label: indentText + cInfo.label,
})
}
items.push(item);
if (Array.isArray(cInfo.children)) {
items = items.concat(this.isekaiGetCategoryItemFromData(cInfo.children, indent + 1));
}
}.bind(this));
return items;
};
ve.ui.MWCategoryInputWidget.prototype.getLookupMenuItems = function () {
deferred = $.Deferred();
if (this.value === '') {
if (this.cachedMainCategories) {
return deferred.resolve(this.cachedMainCategories);
}
var mcUrl = mw.config.get('wgIsekaiMainCategoriesIndexUrl');
var itemWidgets = [];
// Section header
itemWidgets.push(
new OO.ui.MenuSectionOptionWidget({
data: 'mainCategories',
label: ve.msg('isekai-ve-dialog-meta-categories-input-maincategorieslabel')
})
);
return $.ajax({
url: mcUrl,
type: 'GET',
dataType: 'json',
}).then(function (data) {
var categoryItems = this.isekaiGetCategoryItemFromData(data);
itemWidgets = itemWidgets.concat(categoryItems);
this.cachedMainCategories = itemWidgets;
return deferred.resolve(itemWidgets);
}.bind(this));
} else {
return this.getRequestData().then(function (data) {
return this.getLookupMenuOptionsFromData(data);
}.bind(this));
}
};

@ -0,0 +1,9 @@
// Paste from office
var _ve_ce_Surface_afterPaste = ve.ce.Surface.prototype.afterPaste;
ve.ce.Surface.prototype.afterPaste = function () {
var beforePasteData = this.beforePasteData || {};
console.log('beforePasteData', beforePasteData);
return _ve_ce_Surface_afterPaste.apply(this, arguments);
}
Loading…
Cancel
Save