Fix document title width

This commit is contained in:
Julia Radzhabova 2022-04-28 21:36:08 +03:00
parent ecda48303b
commit 1ddc70848d
2 changed files with 16 additions and 11 deletions

View file

@ -204,7 +204,7 @@ define([
} }
function onAppShowed(config) { function onAppShowed(config) {
//config.isCrypted =true; //delete fore merge! // config.isCrypted =true; //delete fore merge!
if ( this.labelDocName ) { if ( this.labelDocName ) {
if ( config.isCrypted ) { if ( config.isCrypted ) {
this.labelDocName.before( this.labelDocName.before(
@ -212,7 +212,6 @@ define([
'<svg class="icon"><use xlink:href="#svg-icon-crypted"></use></svg>' + '<svg class="icon"><use xlink:href="#svg-icon-crypted"></use></svg>' +
'</div>'); '</div>');
this.imgCrypted = this.labelDocName.parent().find('.crypted'); this.imgCrypted = this.labelDocName.parent().find('.crypted');
this.titleAlign = 'left';
} }
if (!config.isEdit || !config.customization || !config.customization.compactHeader) { if (!config.isEdit || !config.customization || !config.customization.compactHeader) {
@ -726,6 +725,7 @@ define([
'focus': onFocusDocName.bind(this), 'focus': onFocusDocName.bind(this),
'blur': function (e) { 'blur': function (e) {
me.imgCrypted && me.imgCrypted.attr('hidden', false); me.imgCrypted && me.imgCrypted.attr('hidden', false);
label[0].selectionStart = label[0].selectionEnd = 0;
if(!me.isSaveDocName) { if(!me.isSaveDocName) {
me.withoutExt = false; me.withoutExt = false;
me.setDocTile(me.documentCaption); me.setDocTile(me.documentCaption);
@ -757,22 +757,26 @@ define([
return (name.substring(idx) == this.fileExtention) ? name.substring(0, idx) : name ; return (name.substring(idx) == this.fileExtention) ? name.substring(0, idx) : name ;
}, },
setDocTile: function(name){ setDocTile: function(name){
if(name) if(name)
this.labelDocName.val(name); this.labelDocName.val(name);
else else
name = this.labelDocName.val(); name = this.labelDocName.val();
var font ="12.5px Arial, Helvetica, \"Helvetica Neue\", sans-serif"; var width = this.getTextWidth(name);
var align = (this.titleAlign)?'text-align: ' + this.titleAlign + '; margin-left: 1px; ':''; (width>=0) && this.labelDocName.width(width);
this.labelDocName.attr('style', align + 'width:'+this.getTextWidth(name,font)+'px');
}, },
getTextWidth: function(text, font) { getTextWidth: function(text) {
(!this.canvas) && (this.canvas = document.createElement("canvas")); if (!this._testCanvas ) {
var ctx = this.canvas.getContext('2d'); var font = (this.labelDocName.css('font-size') + ' ' + this.labelDocName.css('font-family')).trim();
ctx.font = font; if (font) {
var w = Math.ceil(ctx.measureText(text).width); var canvas = document.createElement("canvas");
return (w < 100) ? Math.ceil(w*1.3) : w; this._testCanvas = canvas.getContext('2d');
this._testCanvas.font = font;
}
}
return this._testCanvas ? this._testCanvas.measureText(text).width : -1;
}, },
setUserName: function(name) { setUserName: function(name) {

View file

@ -497,6 +497,7 @@
text-align: center; text-align: center;
font-size: 12px; font-size: 12px;
line-height: 24px; line-height: 24px;
padding: 1px 5px;
background-color: transparent; background-color: transparent;
border: 0 none; border: 0 none;
cursor: default; cursor: default;