Merge pull request 'feature/btn-borders' (#314) from feature/btn-borders into develop

This commit is contained in:
Julia Radzhabova
2025-02-24 11:58:08 +00:00
11 changed files with 411 additions and 2 deletions

View File

@ -369,6 +369,14 @@ define([
toolbar.btnParagraphColor.on('color:select', _.bind(this.onParagraphColorPickerSelect, this));
toolbar.btnParagraphColor.on('eyedropper:start', _.bind(this.onEyedropperStart, this));
toolbar.btnParagraphColor.on('eyedropper:end', _.bind(this.onEyedropperEnd, this));
toolbar.btnBorders.on('click', _.bind(this.onBorders, this));
if (toolbar.btnBorders.rendered) {
toolbar.btnBorders.menu.on('item:click', _.bind(this.onBordersMenu, this));
toolbar.mnuBorderWidth.on('item:toggle', _.bind(this.onBordersWidth, this));
toolbar.mnuBorderColorPicker.on('select', _.bind(this.onBordersColor, this));
$('#id-toolbar-menu-auto-bordercolor').on('click', _.bind(this.onAutoBorderColor, this));
}
$('#id-toolbar-menu-new-bordercolor').on('click', _.bind(this.onNewBorderColor, this));
this.mode.isEdit && Common.NotificationCenter.on('eyedropper:start', _.bind(this.eyedropperStart, this));
toolbar.mnuHighlightColorPicker.on('select', _.bind(this.onSelectHighlightColor, this));
toolbar.mnuHighlightTransparent.on('click', _.bind(this.onHighlightTransparentClick, this));
@ -882,7 +890,7 @@ define([
toolbar.btnAlignLeft, toolbar.btnAlignCenter, toolbar.btnAlignRight, toolbar.btnAlignJust,
toolbar.btnMarkers, toolbar.btnNumbers, toolbar.btnMultilevels,
toolbar.btnDecLeftOffset, toolbar.btnIncLeftOffset,
toolbar.btnLineSpace
toolbar.btnLineSpace, toolbar.btnBorders
]});
this.toolbar.lockToolbar(Common.enumLock.controlPlain, control_plain, {array: [toolbar.btnInsertTable, toolbar.btnInsertImage, toolbar.btnInsertChart, toolbar.btnInsertText, toolbar.btnInsertTextArt,
toolbar.btnInsertShape, toolbar.btnInsertSmartArt, toolbar.btnInsertEquation, toolbar.btnDropCap, toolbar.btnColumns, toolbar.mnuInsertPageNum ]});
@ -924,7 +932,7 @@ define([
this.toolbar.lockToolbar(Common.enumLock.chartLock, in_chart && image_locked, {array: [toolbar.btnInsertChart]});
this.toolbar.lockToolbar(Common.enumLock.cantAddEquation, !can_add_image&&!in_equation, {array: [toolbar.btnInsertEquation]});
this.toolbar.lockToolbar(Common.enumLock.noParagraphSelected, !in_para, {array: [toolbar.btnInsertSymbol, toolbar.btnInsDateTime, toolbar.btnLineSpace, toolbar.btnInsField]});
this.toolbar.lockToolbar(Common.enumLock.noParagraphSelected, !in_para, {array: [toolbar.btnInsertSymbol, toolbar.btnInsDateTime, toolbar.btnLineSpace, toolbar.btnInsField, toolbar.btnBorders]});
this.toolbar.lockToolbar(Common.enumLock.inImage, in_image, {array: [toolbar.btnColumns]});
this.toolbar.lockToolbar(Common.enumLock.inImagePara, in_image && in_para, {array: [toolbar.btnLineNumbers]});
@ -2942,6 +2950,198 @@ define([
Common.component.Analytics.trackEvent('ToolBar', 'Page Color');
},
onNewBorderColor: function(picker, color) {
this.toolbar.btnBorders.menu.hide();
this.toolbar.btnBorders.toggle(false, true);
this.toolbar.mnuBorderColorPicker.addNewColor();
},
onBorders: function(btn) {
var menuItem;
_.each(btn.menu.getItems(true), function(item) {
if (btn.options.borderId == item.options.borderId) {
menuItem = item;
return false;
}
});
if (menuItem) {
this.onBordersMenu(btn.menu, menuItem);
}
},
onBordersMenu: function(menu, item) {
var me = this;
if (me.api && !_.isUndefined(item.options.borderId)) {
var btnBorders = me.toolbar.btnBorders,
bordersWidth = btnBorders.options.borderswidth || 0.5,
bordersColor = btnBorders.options.borderscolor;
if ( btnBorders.rendered ) {
btnBorders.$icon.removeClass(btnBorders.options.icls).addClass(item.options.icls);
btnBorders.options.icls = item.options.icls;
}
btnBorders.options.borderId = item.options.borderId;
var props;
if (me.api){
var selectedElements = me.api.getSelectedElements(),
selectedElementsLenght = selectedElements.length;
if (selectedElements && _.isArray(selectedElements)){
for (var i = 0; i < selectedElementsLenght; i++) {
if (selectedElements[i].get_ObjectType() == Asc.c_oAscTypeSelectElement.Paragraph) {
props = selectedElements[i].get_ObjectValue();
break;
}
}
}
}
var paragraphProps = new Asc.asc_CParagraphProperty();
var borders = new Asc.asc_CParagraphBorders(props.get_Borders());
var borderStyle = new Asc.asc_CTextBorder();
var currentBorder = {};
borderStyle.asc_putColor(bordersColor);
borderStyle.asc_putSize(bordersWidth * 25.4 / 72);
['Left', 'Top', 'Right', 'Bottom', 'Between'].forEach(side => {
var border = borders[`get_${side}`]();
if (border) {
var currentSize = (border.asc_getValue() === -1) ? 0 : border.asc_getSize();
var sizePts = currentSize * 72 / 25.4;
currentBorder[side] = {
width: sizePts,
color: border.asc_getColor(),
value: border.asc_getValue()
};
}
});
var borderSide = {
left: ['Left'],
top: ['Top'],
right: ['Right'],
bottom: ['Bottom'],
all: ['Left', 'Top', 'Right', 'Bottom', 'Between'],
outer: ['Left', 'Top', 'Right', 'Bottom'],
inner: ['Between'],
none: ['Left', 'Top', 'Right', 'Bottom', 'Between']
};
function toleranceError(a, b, t) {
t = 0.01;
return Math.abs(a - b) < t;
}
function compareColors(colorA, colorB) {
if (!colorA || !colorB) return false;
return colorA.get_r() === colorB.get_r() &&
colorA.get_g() === colorB.get_g() &&
colorA.get_b() === colorB.get_b();
}
var targetBorder = borderSide[item.options.borderId],
brd = new Asc.asc_CTextBorder();
if (item.options.borderId === 'none') {
targetBorder.forEach(side => {
brd.put_Color(new Asc.asc_CColor());
brd.put_Value(0);
borders[`put_${side}`](brd);
});
} else if (item.options.borderId === 'all') {
targetBorder.forEach(side => {
brd.put_Color(bordersColor);
brd.put_Size(bordersWidth * 25.4 / 72);
brd.put_Value(1);
borders[`put_${side}`](brd);
});
} else if (item.options.borderId === 'outer') {
var outerSame = targetBorder.every(side =>
toleranceError(currentBorder[side].width, bordersWidth) &&
compareColors(currentBorder[side].color, bordersColor) && currentBorder[side].value === borderStyle.asc_getValue());
if (outerSame) {
targetBorder.forEach(side => {
brd.put_Color(new Asc.asc_CColor());
brd.put_Value(0);
borders[`put_${side}`](brd);
});
} else {
targetBorder.forEach(side => {
brd.put_Color(bordersColor);
brd.put_Size(bordersWidth * 25.4 / 72);
brd.put_Value(1);
borders[`put_${side}`](brd);
});
}
} else {
targetBorder.forEach(side => {
var same = toleranceError(currentBorder[side].width, bordersWidth) &&
compareColors(currentBorder[side].color, bordersColor) && currentBorder[side].value === borderStyle.asc_getValue()
if (same) {
brd.put_Color(new Asc.asc_CColor());
brd.put_Value(0);
borders[`put_${side}`](brd);
} else {
brd.put_Color(bordersColor);
brd.put_Size(bordersWidth * 25.4 / 72);
brd.put_Value(1);
borders[`put_${side}`](brd);
}
});
}
paragraphProps.put_Borders(borders);
if (me.api) {
me.api.paraApply(paragraphProps);
}
Common.NotificationCenter.trigger('edit:complete', me.toolbar);
Common.component.Analytics.trackEvent('ToolBar', 'Borders');
}
},
onBordersWidth: function(menu, item, state) {
if (state) {
this.toolbar.btnBorders.options.borderswidth = item.value;
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
Common.component.Analytics.trackEvent('ToolBar', 'Border Width');
}
},
onBordersColor: function(picker, color) {
$('#id-toolbar-mnu-item-border-color > a .menu-item-icon').css('border-color', '#' + ((typeof(color) == 'object') ? color.color : color));
this.toolbar.mnuBorderColor.onUnHoverItem();
this.toolbar.btnBorders.options.borderscolor = Common.Utils.ThemeColor.getRgbColor(color);
this.toolbar.mnuBorderColorPicker.currentColor = color;
var clr_item = this.toolbar.btnBorders.menu.$el.find('#id-toolbar-menu-auto-bordercolor > a');
clr_item.hasClass('selected') && clr_item.removeClass('selected');
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
Common.component.Analytics.trackEvent('ToolBar', 'Border Color');
},
onAutoBorderColor: function(e) {
$('#id-toolbar-mnu-item-border-color > a .menu-item-icon').css('border-color', '#000');
this.toolbar.mnuBorderColor.onUnHoverItem();
var color = new Asc.asc_CColor();
color.put_auto(true);
this.toolbar.btnBorders.options.borderscolor = color;
this.toolbar.mnuBorderColorPicker.clearSelection();
this.toolbar.mnuBorderColorPicker.currentColor = {color: color, isAuto: true};
var clr_item = this.toolbar.btnBorders.menu.$el.find('#id-toolbar-menu-auto-bordercolor > a');
!clr_item.hasClass('selected') && clr_item.addClass('selected');
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
Common.component.Analytics.trackEvent('ToolBar', 'Border Color');
},
eyedropperStart: function () {
if (this.toolbar.btnCopyStyle.pressed) {
this.toolbar.btnCopyStyle.toggle(false, true);
@ -3372,6 +3572,17 @@ define([
this._state.clrshd_asccolor = undefined;
updateColors(this.toolbar.mnuPageColorPicker, 1);
if (this.toolbar.mnuBorderColorPicker) {
updateColors(this.toolbar.mnuBorderColorPicker, { color: Common.Utils.ThemeColor.getRgbColor('#000000'), isAuto: true });
var currentColor = { color: Common.Utils.ThemeColor.getRgbColor('#000000'), isAuto: true };
if (currentColor.isAuto) {
var clr_item = this.toolbar.btnBorders.menu.$el.find('#id-toolbar-menu-auto-bordercolor > a');
!clr_item.hasClass('selected') && clr_item.addClass('selected');
}
this.toolbar.btnBorders.options.borderscolor = currentColor.color;
$('#id-toolbar-mnu-item-border-color > a .menu-item-icon').css('border-color', '#' + this.toolbar.btnBorders.options.borderscolor);
}
},
_onInitEditorStyles: function(styles) {

View File

@ -75,6 +75,7 @@
<span class="btn-slot split" id="slot-btn-align-just"></span>
<span class="btn-slot split" id="slot-btn-hidenchars"></span>
<span class="btn-slot split" id="slot-btn-paracolor"></span>
<span class="btn-slot split" id="slot-btn-borders"></span>
</div>
</div>
<div class="separator long invisible"></div>

View File

@ -435,6 +435,21 @@ define([
this.paragraphControls.push(this.btnParagraphColor);
this.textOnlyControls.push(this.btnParagraphColor);
this.btnBorders = new Common.UI.Button({
id: 'id-toolbar-btn-borders',
cls: 'btn-toolbar',
iconCls: 'toolbar__icon btn-border-out',
icls: 'btn-border-out',
borderId: 'outer',
lock: [_set.noParagraphSelected, _set.fixedForm, _set.paragraphLock, _set.headerLock, _set.richEditLock, _set.plainEditLock, _set.previewReviewMode, _set.viewFormMode, _set.lostConnect, _set.disableOnStart, _set.docLockView, _set.docLockForms, _set.docLockComments, _set.viewMode],
split: true,
menu: true,
dataHint: '1',
dataHintDirection: 'bottom',
dataHintOffset: '0, -16'
})
this.paragraphControls.push(this.btnBorders);
this.btnChangeCase = new Common.UI.Button({
id: 'id-toolbar-btn-case',
cls: 'btn-toolbar',
@ -2144,6 +2159,7 @@ define([
_injectComponent('#slot-btn-copystyle', this.btnCopyStyle);
_injectComponent('#slot-btn-colorschemas', this.btnColorSchemas);
_injectComponent('#slot-btn-paracolor', this.btnParagraphColor);
_injectComponent('#slot-btn-borders', this.btnBorders);
_injectComponent('#slot-field-styles', this.listStyles);
_injectComponent('#slot-img-align', this.btnImgAlign);
_injectComponent('#slot-img-group', this.btnImgGroup);
@ -2583,6 +2599,7 @@ define([
this.btnHighlightColor.updateHint(this.tipHighlightColor);
this.btnFontColor.updateHint(this.tipFontColor);
this.btnParagraphColor.updateHint(this.tipPrColor);
this.btnBorders.updateHint(this.tipBorders);
this.btnChangeCase.updateHint(this.tipChangeCase);
this.btnAlignLeft.updateHint(this.tipAlignLeft + Common.Utils.String.platformKey('Ctrl+L'));
this.btnAlignCenter.updateHint(this.tipAlignCenter + Common.Utils.String.platformKey('Ctrl+E'));
@ -2798,6 +2815,127 @@ define([
items: []
}));
if (this.btnBorders && this.btnBorders.rendered) {
this.btnBorders.setMenu(new Common.UI.Menu({
cls: 'shifted-right',
items:[
{
caption: this.textBottomBorders,
iconCls: 'menu__icon btn-border-bottom',
icls: 'btn-border-bottom',
borderId: 'bottom',
},
{
caption: this.textTopBorders,
iconCls: 'menu__icon btn-border-top',
icls: 'btn-border-top',
borderId: 'top',
},
{
caption: this.textLeftBorders,
iconCls: 'menu__icon btn-border-left',
icls: 'btn-border-left',
borderId: 'left',
},
{
caption: this.textRightBorders,
iconCls: 'menu__icon btn-border-right',
icls: 'btn-border-right',
borderId: 'right',
},
{ caption: '--' },
{
caption: this.textNoBorders,
iconCls: 'menu__icon btn-border-no',
icls: 'btn-border-no',
borderId: 'none',
},
{
caption: this.textAllBorders,
iconCls: 'menu__icon btn-border-all',
icls: 'btn-border-all',
borderId: 'all',
},
{
caption: this.textOutBorders,
iconCls: 'menu__icon btn-border-out',
icls: 'btn-border-out',
borderId: 'outer',
},
{
caption: this.textInsideBorders,
iconCls: 'menu__icon btn-border-inside',
icls: 'btn-border-inside',
borderId: 'inner',
},
{ caption: '--' },
{
id: 'id-toolbar-menu-item-border-width',
caption: this.textBordersStyle,
iconCls: 'menu__icon btn-border-style',
menu: (function () {
var txtPt = ' ' + Common.Utils.Metric.getMetricName(Common.Utils.Metric.c_MetricUnits.pt);
var itemTemplate = _.template(
'<a id="<%= id %>" tabindex="-1" type="menuitem">' +
'<div class="border-size-item">' +
'<span class="border-size-text"><%= options.displayValue %></span>' +
'<svg><use xlink:href="#<%= options.imgId %>"></use></svg>' +
'</div>' +
'</a>'
);
me.mnuBorderWidth = new Common.UI.Menu({
style: 'min-width: 100px;',
cls: 'shifted-right',
menuAlign: 'tl-tr',
id: 'toolbar-menu-borders-width',
items: [
{ template: itemTemplate, stopPropagation: true, checkable: true, toggleGroup: 'border-width', displayValue: '0.5' + txtPt, value: 0.5, pxValue: 0.5, imgId: 'half-pt', checked:true},
{ template: itemTemplate, stopPropagation: true, checkable: true, toggleGroup: 'border-width', displayValue: '1 ' + txtPt, value: 1, pxValue: 1, imgId: 'one-pt' },
{ template: itemTemplate, stopPropagation: true, checkable: true, toggleGroup: 'border-width', displayValue: '1.5 ' + txtPt, value: 1.5, pxValue: 2, imgId: 'one-and-half-pt' },
{ template: itemTemplate, stopPropagation: true, checkable: true, toggleGroup: 'border-width', displayValue: '2.25 ' + txtPt, value: 2.25, pxValue: 3, imgId: 'two-and-quarter-pt' },
{ template: itemTemplate, stopPropagation: true, checkable: true, toggleGroup: 'border-width', displayValue: '3 ' + txtPt, value: 3, pxValue: 4, imgId: 'three-pt' },
{ template: itemTemplate, stopPropagation: true, checkable: true, toggleGroup: 'border-width', displayValue: '4.5 ' + txtPt, value: 4.5, pxValue: 6, imgId: 'four-and-half-pt' },
{ template: itemTemplate, stopPropagation: true, checkable: true, toggleGroup: 'border-width', displayValue: '6 ' + txtPt, value: 6, pxValue: 8, imgId: 'six-pt' },
]
});
return me.mnuBorderWidth;
})()
},
this.mnuBorderColor = new Common.UI.MenuItem({
id: 'id-toolbar-mnu-item-border-color',
caption: this.textBordersColor,
iconCls: 'mnu-icon-item mnu-border-color',
template : _.template('<a id="<%= id %>"tabindex="-1" type="menuitem"><span class="menu-item-icon"></span><%= caption %></a>'),
menu: new Common.UI.Menu({
menuAlign: 'tl-tr',
cls: 'shifted-left',
items: [
{
id: 'id-toolbar-menu-auto-bordercolor',
caption: this.textAutoColor,
template: _.template('<a tabindex="-1" type="menuitem"><span class="menu-item-icon color-auto"></span><%= caption %></a>'),
stopPropagation: true
},
{ caption: '--' },
{ template: _.template('<div id="id-toolbar-menu-bordercolor" style="width: 164px;display: inline-block;"></div>'), stopPropagation: true },
{ caption: '--' },
{
id: "id-toolbar-menu-new-bordercolor",
template: _.template('<a tabindex="-1" type="menuitem">' + this.textNewColor + '</a>'),
stopPropagation: true
}
]
})
})
]
}))
this.mnuBorderColorPicker = new Common.UI.ThemeColorPalette({
el: $('#id-toolbar-menu-bordercolor'),
outerMenu: {menu: this.mnuBorderColor.menu, index: 2},
});
this.mnuBorderColor.menu.setInnerMenu([{menu: this.mnuBorderColorPicker, index: 2}]);
}
var onShowBeforeSmartArt = function (menu) { // + <% if(typeof imageUrl === "undefined" || imageUrl===null || imageUrl==="") { %> style="visibility: hidden;" <% } %>/>',
var smartArtData = Common.define.smartArt.getSmartArtData();
smartArtData.forEach(function (item, index) {

View File

@ -3556,6 +3556,17 @@
"DE.Views.Toolbar.textTradeMark": "Trade Mark Sign",
"DE.Views.Toolbar.textUnderline": "Underline",
"DE.Views.Toolbar.textYen": "Yen Sign",
"DE.Views.Toolbar.textBottomBorders": "Bottom borders",
"DE.Views.Toolbar.textTopBorders": "Top borders",
"DE.Views.Toolbar.textLeftBorders": "Left borders",
"DE.Views.Toolbar.textRightBorders": "Right borders",
"DE.Views.Toolbar.textNoBorders": "No borders",
"DE.Views.Toolbar.textAllBorders": "All borders",
"DE.Views.Toolbar.textOutBorders": "Outside borders",
"DE.Views.Toolbar.textInsideBorders": "Inside borders",
"DE.Views.Toolbar.textBordersColor": "Border color",
"DE.Views.Toolbar.textBordersStyle": "Border style",
"DE.Views.Toolbar.tipBorders": "Borders",
"DE.Views.Toolbar.tipAlignCenter": "Align center",
"DE.Views.Toolbar.tipAlignJust": "Justified",
"DE.Views.Toolbar.tipAlignLeft": "Align left",

View File

@ -322,3 +322,51 @@
}
}
}
#id-toolbar-menu-item-border-width,
#format-rules-borders-border-width {
.border-size-item {
display: flex;
justify-content: space-between;
align-items: center;
.border-size-text {
margin-right: 8px;
}
svg {
width: 60px;
height: 8px;
fill: var(--text-normal);
shape-rendering: crispEdges;
}
}
}
#id-toolbar-mnu-item-border-color {
> span {
background-image: none;
width: 12px;
height: 12px;
margin: 2px 8px 0 -20px;
border-style: solid;
border-width: 3px;
border-color: #000;
.rtl & {
margin: 2px -20px 0 8px;
}
}
}
#id-toolbar-menu-auto-bordercolor {
.color-auto {
background-image: none;
width: 12px;
height: 12px;
margin: 1px 7px 0 1px;
background-color: #000;
.rtl & {
margin: 1px 1px 0 7px;
}
}
}