[Common] refactoring. defined $icon element for a button

This commit is contained in:
Maxim Kadushkin 2018-02-26 16:23:07 +03:00
parent fc6c6c2cb8
commit 6d0a353d78
6 changed files with 43 additions and 92 deletions

View file

@ -350,6 +350,7 @@ define([
me.menu.render(me.cmpEl);
parentEl.html(me.cmpEl);
me.$icon = me.$el.find('.icon');
}
}

View file

@ -1323,8 +1323,6 @@ define([
Array.prototype.push.apply(me.paragraphControls, me.btnsPageBreak);
}.call(this);
this.btnSave.$icon = $('.icon', this.btnSave.cmpEl);
this.btnHorizontalAlign.$icon = $('.icon', this.btnHorizontalAlign.cmpEl);
return $host;
},

View file

@ -514,14 +514,9 @@ define([
btnHorizontalAlign.menu.clearAll();
}
if (btnHorizontalAlign.rendered) {
var iconEl = $('.icon', btnHorizontalAlign.cmpEl);
if (iconEl) {
iconEl.removeClass(btnHorizontalAlign.options.icls);
btnHorizontalAlign.options.icls = align;
iconEl.addClass(btnHorizontalAlign.options.icls);
}
if ( btnHorizontalAlign.rendered && btnHorizontalAlign.$icon ) {
btnHorizontalAlign.$icon.removeClass(btnHorizontalAlign.options.icls).addClass(align);
btnHorizontalAlign.options.icls = align;
}
}
},
@ -547,14 +542,9 @@ define([
btnVerticalAlign.menu.clearAll();
}
if (btnVerticalAlign.rendered) {
var iconEl = $('.icon', btnVerticalAlign.cmpEl);
if (iconEl) {
iconEl.removeClass(btnVerticalAlign.options.icls);
btnVerticalAlign.options.icls = align;
iconEl.addClass(btnVerticalAlign.options.icls);
}
if ( btnVerticalAlign.rendered && btnVerticalAlign.$icon ) {
btnVerticalAlign.$icon.removeClass(btnVerticalAlign.options.icls).addClass(align);
btnVerticalAlign.options.icls = align;
}
}
},
@ -912,7 +902,7 @@ define([
var toolbar = this.toolbar;
if (this.api && this.api.asc_isDocumentCanSave) {
var isModified = this.api.asc_isDocumentCanSave();
var isSyncButton = $('.icon', this.toolbar.btnSave.cmpEl).hasClass('btn-synch');
var isSyncButton = this.toolbar.btnSave.$icon.hasClass('btn-synch');
if (!isModified && !isSyncButton && !this.toolbar.mode.forcesave)
return;
@ -1046,14 +1036,11 @@ define([
onMenuHorizontalAlignSelect: function(menu, item) {
this._state.pralign = undefined;
var btnHorizontalAlign = this.toolbar.btnHorizontalAlign,
iconEl = $('.icon', btnHorizontalAlign.cmpEl);
var btnHorizontalAlign = this.toolbar.btnHorizontalAlign;
if (iconEl) {
iconEl.removeClass(btnHorizontalAlign.options.icls);
btnHorizontalAlign.options.icls = !item.checked ? 'btn-align-left' : item.options.icls;
iconEl.addClass(btnHorizontalAlign.options.icls);
}
btnHorizontalAlign.$icon.removeClass(btnHorizontalAlign.options.icls);
btnHorizontalAlign.options.icls = !item.checked ? 'btn-align-left' : item.options.icls;
btnHorizontalAlign.$icon.addClass(btnHorizontalAlign.options.icls);
if (this.api && item.checked)
this.api.put_PrAlign(item.value);
@ -1063,14 +1050,11 @@ define([
},
onMenuVerticalAlignSelect: function(menu, item) {
var btnVerticalAlign = this.toolbar.btnVerticalAlign,
iconEl = $('.icon', btnVerticalAlign.cmpEl);
var btnVerticalAlign = this.toolbar.btnVerticalAlign;
if (iconEl) {
iconEl.removeClass(btnVerticalAlign.options.icls);
btnVerticalAlign.options.icls = !item.checked ? 'btn-align-middle' : item.options.icls;
iconEl.addClass(btnVerticalAlign.options.icls);
}
btnVerticalAlign.$icon.removeClass(btnVerticalAlign.options.icls);
btnVerticalAlign.options.icls = !item.checked ? 'btn-align-middle' : item.options.icls;
btnVerticalAlign.$icon.addClass(btnVerticalAlign.options.icls);
this._state.vtextalign = undefined;
if (this.api && item.checked)

View file

@ -1012,8 +1012,6 @@ define([
}
});
me.btnSave.$icon = $('.icon', me.btnSave.cmpEl);
var created = me.btnsInsertImage.concat(me.btnsInsertText, me.btnsInsertShape, me.btnsAddSlide);
this.lockToolbar(PE.enumLock.disableOnStart, true, {array: created});

View file

@ -495,8 +495,7 @@ define([
},
onSubscriptMenu: function(menu, item) {
var btnSubscript = this.toolbar.btnSubscript,
iconEl = $('.icon', btnSubscript.cmpEl);
var btnSubscript = this.toolbar.btnSubscript;
if (item.value == 'sub') {
this._state.subscript = undefined;
@ -506,9 +505,8 @@ define([
this.api.asc_setCellSuperscript(item.checked);
}
if (item.checked) {
iconEl.removeClass(btnSubscript.options.icls);
btnSubscript.$icon.removeClass(btnSubscript.options.icls).addClass(item.options.icls);
btnSubscript.options.icls = item.options.icls;
iconEl.addClass(btnSubscript.options.icls);
}
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
@ -612,14 +610,9 @@ define([
bordersWidth = btnBorders.options.borderswidth,
bordersColor = btnBorders.options.borderscolor;
if (btnBorders.rendered) {
var iconEl = $('.icon', btnBorders.cmpEl);
if (iconEl) {
iconEl.removeClass(btnBorders.options.icls);
btnBorders.options.icls = item.options.icls;
iconEl.addClass(btnBorders.options.icls);
}
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;
@ -681,14 +674,11 @@ define([
},
onHorizontalAlignMenu: function(menu, item) {
var btnHorizontalAlign = this.toolbar.btnHorizontalAlign,
iconEl = $('.icon', btnHorizontalAlign.cmpEl);
var btnHorizontalAlign = this.toolbar.btnHorizontalAlign;
if (iconEl) {
iconEl.removeClass(btnHorizontalAlign.options.icls);
btnHorizontalAlign.options.icls = !item.checked ? 'btn-align-left' : item.options.icls;
iconEl.addClass(btnHorizontalAlign.options.icls);
}
btnHorizontalAlign.$icon.removeClass(btnHorizontalAlign.options.icls);
btnHorizontalAlign.options.icls = !item.checked ? 'btn-align-left' : item.options.icls;
btnHorizontalAlign.$icon.addClass(btnHorizontalAlign.options.icls);
this._state.pralign = undefined;
if (this.api)
@ -701,14 +691,11 @@ define([
},
onVerticalAlignMenu: function(menu, item) {
var btnVerticalAlign = this.toolbar.btnVerticalAlign,
iconEl = $('.icon', btnVerticalAlign.cmpEl);
var btnVerticalAlign = this.toolbar.btnVerticalAlign;
if (iconEl) {
iconEl.removeClass(btnVerticalAlign.options.icls);
btnVerticalAlign.options.icls = !item.checked ? 'btn-valign-bottom' : item.options.icls;
iconEl.addClass(btnVerticalAlign.options.icls);
}
btnVerticalAlign.$icon.removeClass(btnVerticalAlign.options.icls);
btnVerticalAlign.options.icls = !item.checked ? 'btn-valign-bottom' : item.options.icls;
btnVerticalAlign.$icon.addClass(btnVerticalAlign.options.icls);
this._state.valign = undefined;
if (this.api)
@ -1792,13 +1779,10 @@ define([
btnSubscript.menu.clearAll();
} else {
btnSubscript.menu.items[index].setChecked(true);
if (btnSubscript.rendered) {
var iconEl = $('.icon', btnSubscript.cmpEl);
if (iconEl) {
iconEl.removeClass(btnSubscript.options.icls);
btnSubscript.options.icls = btnSubscript.menu.items[index].options.icls;
iconEl.addClass(btnSubscript.options.icls);
}
if ( btnSubscript.rendered && btnSubscript.$icon ) {
btnSubscript.$icon.removeClass(btnSubscript.options.icls);
btnSubscript.options.icls = btnSubscript.menu.items[index].options.icls;
btnSubscript.$icon.addClass(btnSubscript.options.icls);
}
}
@ -1933,13 +1917,10 @@ define([
btnSubscript.menu.clearAll();
} else {
btnSubscript.menu.items[index].setChecked(true);
if (btnSubscript.rendered) {
var iconEl = $('.icon', btnSubscript.cmpEl);
if (iconEl) {
iconEl.removeClass(btnSubscript.options.icls);
btnSubscript.options.icls = btnSubscript.menu.items[index].options.icls;
iconEl.addClass(btnSubscript.options.icls);
}
if ( btnSubscript.rendered ) {
btnSubscript.$icon.removeClass(btnSubscript.options.icls);
btnSubscript.options.icls = btnSubscript.menu.items[index].options.icls;
btnSubscript.$icon.addClass(btnSubscript.options.icls);
}
}
@ -2068,14 +2049,9 @@ define([
}
var btnHorizontalAlign = this.toolbar.btnHorizontalAlign;
if (btnHorizontalAlign.rendered) {
var hIconEl = $('.icon', btnHorizontalAlign.cmpEl);
if (hIconEl) {
hIconEl.removeClass(btnHorizontalAlign.options.icls);
btnHorizontalAlign.options.icls = align;
hIconEl.addClass(btnHorizontalAlign.options.icls);
}
if ( btnHorizontalAlign.rendered ) {
btnHorizontalAlign.$icon.removeClass(btnHorizontalAlign.options.icls).addClass(align);
btnHorizontalAlign.options.icls = align;
}
}
@ -2103,14 +2079,9 @@ define([
toolbar.btnVerticalAlign.menu.items[index].setChecked(true, false);
var btnVerticalAlign = this.toolbar.btnVerticalAlign;
if (btnVerticalAlign.rendered) {
var vIconEl = $('.icon', btnVerticalAlign.cmpEl);
if (vIconEl) {
vIconEl.removeClass(btnVerticalAlign.options.icls);
btnVerticalAlign.options.icls = align;
vIconEl.addClass(btnVerticalAlign.options.icls);
}
if ( btnVerticalAlign.rendered ) {
btnVerticalAlign.$icon.removeClass(btnVerticalAlign.options.icls).addClass(align);
btnVerticalAlign.options.icls = align;
}
}
}

View file

@ -1388,7 +1388,6 @@ define([
// replacePlacholder('#id-toolbar-short-placeholder-btn-valign', this.btnVerticalAlign);
// replacePlacholder('#id-toolbar-short-placeholder-btn-filter', this.btnAutofilter);
this.btnSave.$icon = $('.icon', this.btnSave.cmpEl);
return $host;
},