增加VE主分类选择功能
parent
1643f1bfc1
commit
b10e134c14
@ -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…
Reference in New Issue