From 6d0a353d7891faf7f7a5925a23b3131f6b23f896 Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Mon, 26 Feb 2018 16:23:07 +0300 Subject: [PATCH] [Common] refactoring. defined $icon element for a button --- apps/common/main/lib/component/Button.js | 1 + apps/documenteditor/main/app/view/Toolbar.js | 2 - .../main/app/controller/Toolbar.js | 46 ++++------ .../main/app/view/Toolbar.js | 2 - .../main/app/controller/Toolbar.js | 83 ++++++------------- .../main/app/view/Toolbar.js | 1 - 6 files changed, 43 insertions(+), 92 deletions(-) diff --git a/apps/common/main/lib/component/Button.js b/apps/common/main/lib/component/Button.js index 2315c167a..71a4c74f4 100644 --- a/apps/common/main/lib/component/Button.js +++ b/apps/common/main/lib/component/Button.js @@ -350,6 +350,7 @@ define([ me.menu.render(me.cmpEl); parentEl.html(me.cmpEl); + me.$icon = me.$el.find('.icon'); } } diff --git a/apps/documenteditor/main/app/view/Toolbar.js b/apps/documenteditor/main/app/view/Toolbar.js index 93474165f..7dfe2dbf9 100644 --- a/apps/documenteditor/main/app/view/Toolbar.js +++ b/apps/documenteditor/main/app/view/Toolbar.js @@ -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; }, diff --git a/apps/presentationeditor/main/app/controller/Toolbar.js b/apps/presentationeditor/main/app/controller/Toolbar.js index 4099bc566..956aded7f 100644 --- a/apps/presentationeditor/main/app/controller/Toolbar.js +++ b/apps/presentationeditor/main/app/controller/Toolbar.js @@ -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) diff --git a/apps/presentationeditor/main/app/view/Toolbar.js b/apps/presentationeditor/main/app/view/Toolbar.js index 0ad878eaf..84023b454 100644 --- a/apps/presentationeditor/main/app/view/Toolbar.js +++ b/apps/presentationeditor/main/app/view/Toolbar.js @@ -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}); diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index f21ff9169..6c6ed4809 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -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; } } } diff --git a/apps/spreadsheeteditor/main/app/view/Toolbar.js b/apps/spreadsheeteditor/main/app/view/Toolbar.js index 7b0f621d8..537958d85 100644 --- a/apps/spreadsheeteditor/main/app/view/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/view/Toolbar.js @@ -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; },