2017-04-22 12:40:46 +00:00
/ *
*
2019-01-17 13:05:03 +00:00
* ( c ) Copyright Ascensio System SIA 2010 - 2019
2017-04-22 12:40:46 +00:00
*
* This program is a free software product . You can redistribute it and / or
* modify it under the terms of the GNU Affero General Public License ( AGPL )
* version 3 as published by the Free Software Foundation . In accordance with
* Section 7 ( a ) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non - infringement
* of any third - party rights .
*
* This program is distributed WITHOUT ANY WARRANTY ; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . For
* details , see the GNU AGPL at : http : //www.gnu.org/licenses/agpl-3.0.html
*
2019-01-17 13:00:34 +00:00
* You can contact Ascensio System SIA at 20 A - 12 Ernesta Birznieka - Upisha
* street , Riga , Latvia , EU , LV - 1050.
2017-04-22 12:40:46 +00:00
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices , as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7 ( b ) of the License you must retain the original Product
* logo when distributing the program . Pursuant to Section 7 ( e ) we decline to
* grant you any rights under trademark law for use of our trademarks .
*
* All the Product ' s GUI elements , including illustrations and icon sets , as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution - ShareAlike 4.0 International . See the License
* terms at http : //creativecommons.org/licenses/by-sa/4.0/legalcode
*
* /
/ * *
* Mixtbar . js
*
* Combined component for toolbar 's and header' s elements
*
*
* Created by Maxim . Kadushkin on 4 / 11 / 2017.
2018-03-01 12:16:38 +00:00
* Copyright ( c ) 2018 Ascensio System SIA . All rights reserved .
2017-04-22 12:40:46 +00:00
*
* /
define ( [
2019-02-05 09:25:57 +00:00
'backbone' ,
'common/main/lib/component/BaseView'
2017-04-22 12:40:46 +00:00
] , function ( Backbone ) {
'use strict' ;
Common . UI . Mixtbar = Common . UI . BaseView . extend ( ( function ( ) {
var $boxTabs ;
var $scrollL ;
var optsFold = { timeout : 2000 } ;
var config = { } ;
2021-12-15 09:19:41 +00:00
var btnsMore = [ ] ;
2017-04-22 12:40:46 +00:00
var onScrollTabs = function ( opts , e ) {
var sv = $boxTabs . scrollLeft ( ) ;
if ( sv || opts == 'right' ) {
$boxTabs . animate ( { scrollLeft : opts == 'left' ? sv - 100 : sv + 100 } , 200 ) ;
}
2017-11-22 08:41:47 +00:00
} ;
2017-04-22 12:40:46 +00:00
function onTabDblclick ( e ) {
2020-08-18 16:02:46 +00:00
var tab = $ ( e . currentTarget ) . find ( '> a[data-tab]' ) . data ( 'tab' ) ;
2020-08-19 14:06:45 +00:00
if ( this . dblclick _el == tab ) {
2020-03-02 08:04:05 +00:00
this . fireEvent ( 'change:compact' , [ tab ] ) ;
2020-08-19 14:06:45 +00:00
this . dblclick _el = undefined ;
}
2017-04-22 12:40:46 +00:00
}
function onShowFullviewPanel ( state ) {
if ( state )
optsFold . $bar . addClass ( 'cover' ) ; else
optsFold . $bar . removeClass ( 'cover' ) ;
}
function onClickDocument ( e ) {
if ( this . isFolded ) {
2018-05-07 14:17:41 +00:00
if ( $ ( e . target ) . parents ( '.toolbar, #file-menu-panel' ) . length ) {
2017-04-22 12:40:46 +00:00
} else {
2019-12-05 10:46:03 +00:00
optsFold . $bar && optsFold . $bar . hasClass ( 'expanded' ) && this . collapse ( ) ;
2017-04-22 12:40:46 +00:00
}
}
}
return {
$tabs : undefined ,
$panels : undefined ,
isFolded : false ,
initialize : function ( options ) {
Common . UI . BaseView . prototype . initialize . call ( this , options ) ;
2018-05-16 14:41:47 +00:00
var _template _tabs =
'<section class="tabs">' +
2021-08-17 13:55:46 +00:00
'<a class="scroll left" data-hint="0" data-hint-direction="bottom" data-hint-offset="-7, 0" data-hint-title="V"></a>' +
2018-05-16 14:41:47 +00:00
'<ul>' +
'<% for(var i in items) { %>' +
2020-07-09 11:53:22 +00:00
'<% if (typeof items[i] == "object") { %>' +
2018-05-16 14:41:47 +00:00
'<li class="ribtab' +
'<% if (items[i].haspanel===false) print(" x-lone") %>' +
2021-10-07 08:43:31 +00:00
'<% if (items[i].extcls) print(\' \' + items[i].extcls) %>"' +
'<% if (typeof items[i].layoutname == "string") print(" data-layout-name=" + \' \' + items[i].layoutname) + \' \' %>>' +
2021-11-11 18:00:38 +00:00
'<a data-tab="<%= items[i].action %>" data-title="<%= items[i].caption %>" data-hint="0" data-hint-direction="bottom" data-hint-offset="small" <% if (typeof items[i].dataHintTitle !== "undefined") { %> data-hint-title="<%= items[i].dataHintTitle %>" <% } %>><%= items[i].caption %></a>' +
2018-05-16 14:41:47 +00:00
'</li>' +
2020-07-09 11:53:22 +00:00
'<% } %>' +
2018-05-16 14:41:47 +00:00
'<% } %>' +
'</ul>' +
2021-08-17 13:55:46 +00:00
'<a class="scroll right" data-hint="0" data-hint-direction="bottom" data-hint-offset="-7, 0" data-hint-title="R"></a>' +
2018-05-16 14:41:47 +00:00
'</section>' ;
2017-04-22 12:40:46 +00:00
this . $layout = $ ( options . template ( {
2018-05-16 14:41:47 +00:00
tabsmarkup : _ . template ( _template _tabs ) ( { items : options . tabs } )
2017-04-22 12:40:46 +00:00
} ) ) ;
config . tabs = options . tabs ;
$ ( document . body ) . on ( 'click' , onClickDocument . bind ( this ) ) ;
2017-10-12 14:25:47 +00:00
Common . NotificationCenter . on ( 'tab:visible' , _ . bind ( function ( action , visible ) {
2018-05-15 12:37:26 +00:00
this . setVisible ( action , visible ) ;
2017-10-12 14:25:47 +00:00
} , this ) ) ;
2017-04-22 12:40:46 +00:00
} ,
afterRender : function ( ) {
var me = this ;
$boxTabs = me . $ ( '.tabs > ul' ) ;
me . $tabs = $boxTabs . find ( '> li' ) ;
2021-12-15 09:19:41 +00:00
me . $boxpanels = me . $ ( '.box-panels' ) ;
me . $panels = me . $boxpanels . find ( '> .panel' ) ;
2017-05-01 11:30:44 +00:00
optsFold . $bar = me . $ ( '.toolbar' ) ;
2017-04-22 12:40:46 +00:00
var $scrollR = me . $ ( '.tabs .scroll.right' ) ;
$scrollL = me . $ ( '.tabs .scroll.left' ) ;
$scrollL . on ( 'click' , onScrollTabs . bind ( this , 'left' ) ) ;
$scrollR . on ( 'click' , onScrollTabs . bind ( this , 'right' ) ) ;
2017-06-16 09:24:00 +00:00
$boxTabs . on ( 'dblclick' , '> .ribtab' , onTabDblclick . bind ( this ) ) ;
2017-08-30 12:23:22 +00:00
$boxTabs . on ( 'click' , '> .ribtab' , me . onTabClick . bind ( this ) ) ;
2017-04-22 12:40:46 +00:00
} ,
isTabActive : function ( tag ) {
var t = this . $tabs . filter ( '.active' ) . find ( '> a' ) ;
return t . length && t . data ( 'tab' ) == tag ;
} ,
2018-05-17 10:44:46 +00:00
setFolded : function ( value ) {
2017-04-22 12:40:46 +00:00
this . isFolded = value ;
var me = this ;
if ( this . isFolded ) {
if ( ! optsFold . $box ) optsFold . $box = me . $el . find ( '.box-controls' ) ;
2018-05-03 16:02:09 +00:00
optsFold . $bar . addClass ( 'folded z-clear' ) . toggleClass ( 'expanded' , false ) ;
2017-08-01 11:39:31 +00:00
optsFold . $bar . find ( '.tabs .ribtab' ) . removeClass ( 'active' ) ;
2018-05-03 16:02:09 +00:00
optsFold . $bar . on ( $ . support . transition . end , function ( e ) {
if ( optsFold . $bar . hasClass ( 'folded' ) && ! optsFold . $bar . hasClass ( 'expanded' ) )
optsFold . $bar . toggleClass ( 'z-clear' , true ) ;
} ) ;
2017-04-22 12:40:46 +00:00
optsFold . $box . on ( {
mouseleave : function ( e ) {
2017-08-01 10:17:29 +00:00
// optsFold.timer = setTimeout( function(e) {
// clearTimeout(optsFold.timer);
// me.collapse();
// }, optsFold.timeout);
2017-04-22 12:40:46 +00:00
} ,
mouseenter : function ( e ) {
2017-08-01 10:17:29 +00:00
// clearTimeout(optsFold.timer);
2017-04-22 12:40:46 +00:00
}
} ) ;
// $(document.body).on('focus', 'input, textarea', function(e) {
// });
//
// $(document.body).on('blur', 'input, textarea', function(e) {
// });
//
// Common.NotificationCenter.on({
// 'modal:show': function(){
// },
// 'modal:close': function(dlg) {
// },
// 'modal:hide': function(dlg) {
// },
// 'dataview:focus': function(e){
// },
// 'dataview:blur': function(e){
// },
// 'menu:show': function(e){
// },
// 'menu:hide': function(e){
// },
// 'edit:complete': _.bind(me.onEditComplete, me)
// });
} else {
2017-08-01 10:17:29 +00:00
// clearTimeout(optsFold.timer);
2018-05-03 16:02:09 +00:00
optsFold . $bar . removeClass ( 'folded z-clear' ) ;
2017-04-22 12:40:46 +00:00
optsFold . $box . off ( ) ;
2017-08-30 12:23:22 +00:00
var active _panel = optsFold . $box . find ( '.panel.active' ) ;
if ( active _panel . length ) {
var tab = active _panel . data ( 'tab' ) ;
me . $tabs . find ( '> a[data-tab=' + tab + ']' ) . parent ( ) . toggleClass ( 'active' , true ) ;
2018-05-16 14:41:47 +00:00
} else {
2019-03-14 08:10:14 +00:00
tab = me . $tabs . siblings ( ':not(.x-lone):visible' ) . first ( ) . find ( '> a[data-tab]' ) . data ( 'tab' ) ;
2018-05-17 10:44:46 +00:00
me . setTab ( tab ) ;
2017-08-30 12:23:22 +00:00
}
2017-04-22 12:40:46 +00:00
}
} ,
2017-07-10 15:32:33 +00:00
collapse : function ( ) {
2017-08-01 10:17:29 +00:00
Common . UI . Menu . Manager . hideAll ( ) ;
// clearTimeout(optsFold.timer);
2017-06-28 08:43:50 +00:00
if ( this . isFolded && optsFold . $bar ) {
2017-06-16 09:25:36 +00:00
optsFold . $bar . removeClass ( 'expanded' ) ;
optsFold . $bar . find ( '.tabs .ribtab' ) . removeClass ( 'active' ) ;
}
2017-04-22 12:40:46 +00:00
} ,
2017-07-10 15:32:33 +00:00
expand : function ( ) {
2017-08-01 10:17:29 +00:00
// clearTimeout(optsFold.timer);
2017-04-22 12:40:46 +00:00
2018-05-03 16:02:09 +00:00
optsFold . $bar . removeClass ( 'z-clear' ) ;
2017-04-22 12:40:46 +00:00
optsFold . $bar . addClass ( 'expanded' ) ;
2017-08-01 10:17:29 +00:00
// optsFold.timer = setTimeout(this.collapse, optsFold.timeout);
2017-04-22 12:40:46 +00:00
} ,
onResize : function ( e ) {
if ( this . hasTabInvisible ( ) ) {
if ( ! $boxTabs . parent ( ) . hasClass ( 'short' ) )
$boxTabs . parent ( ) . addClass ( 'short' ) ;
} else
if ( $boxTabs . parent ( ) . hasClass ( 'short' ) ) {
$boxTabs . parent ( ) . removeClass ( 'short' ) ;
}
2018-12-12 11:56:08 +00:00
this . processPanelVisible ( ) ;
2021-12-15 09:19:41 +00:00
// this.resizeToolbar();
2017-04-22 12:40:46 +00:00
} ,
2017-08-30 12:23:22 +00:00
onTabClick : function ( e ) {
2018-05-16 14:41:47 +00:00
var me = this ;
var $target = $ ( e . currentTarget ) ;
var tab = $target . find ( '> a[data-tab]' ) . data ( 'tab' ) ;
2020-08-19 14:06:45 +00:00
if ( $target . hasClass ( 'x-lone' ) ) {
me . isFolded && me . collapse ( ) ;
} else {
2018-05-16 14:41:47 +00:00
if ( $target . hasClass ( 'active' ) ) {
2020-08-19 14:06:45 +00:00
if ( ! me . _timerSetTab ) {
me . dblclick _el = tab ;
if ( me . isFolded ) {
me . collapse ( ) ;
setTimeout ( function ( ) {
me . dblclick _el = undefined ;
} , 500 ) ;
}
}
2018-05-16 14:41:47 +00:00
} else {
2020-08-18 16:02:46 +00:00
me . _timerSetTab = true ;
setTimeout ( function ( ) {
me . _timerSetTab = false ;
} , 500 ) ;
2018-05-16 14:41:47 +00:00
me . setTab ( tab ) ;
2021-12-16 13:50:25 +00:00
// me.processPanelVisible(null, true);
2020-08-19 14:06:45 +00:00
if ( ! me . isFolded ) {
if ( me . dblclick _timer ) clearTimeout ( me . dblclick _timer ) ;
me . dblclick _timer = setTimeout ( function ( ) {
me . dblclick _el = tab ;
delete me . dblclick _timer ;
} , 500 ) ;
2020-11-26 19:46:05 +00:00
} else
me . dblclick _el = tab ;
2018-05-16 14:41:47 +00:00
}
2017-08-30 12:23:22 +00:00
}
} ,
2017-04-22 12:40:46 +00:00
setTab : function ( tab ) {
2018-05-16 14:41:47 +00:00
var me = this ;
2017-04-27 15:40:27 +00:00
if ( ! tab ) {
2018-05-16 14:41:47 +00:00
// onShowFullviewPanel.call(this, false);
2017-05-01 11:30:44 +00:00
2017-07-10 15:34:10 +00:00
if ( this . isFolded ) { this . collapse ( ) ; }
2017-04-22 12:40:46 +00:00
else tab = this . lastPanel ;
}
if ( tab ) {
2018-05-16 14:41:47 +00:00
me . $tabs . removeClass ( 'active' ) ;
me . $panels . removeClass ( 'active' ) ;
2021-12-15 09:19:41 +00:00
me . hideMoreBtns ( ) ;
2017-04-22 12:40:46 +00:00
var panel = this . $panels . filter ( '[data-tab=' + tab + ']' ) ;
if ( panel . length ) {
this . lastPanel = tab ;
panel . addClass ( 'active' ) ;
2021-12-15 09:19:41 +00:00
me . setMoreButton ( tab , panel ) ;
2021-12-16 13:50:25 +00:00
me . processPanelVisible ( null , true , true ) ;
2017-04-22 12:40:46 +00:00
}
2017-05-01 11:30:44 +00:00
if ( panel . length ) {
2018-05-16 14:41:47 +00:00
if ( me . isFolded ) me . expand ( ) ;
2017-05-01 11:30:44 +00:00
} else {
2018-05-16 14:41:47 +00:00
// onShowFullviewPanel.call(this, true);
if ( me . isFolded ) me . collapse ( ) ;
2017-07-10 15:32:33 +00:00
}
2017-07-10 15:34:10 +00:00
var $tp = this . $tabs . find ( '> a[data-tab=' + tab + ']' ) . parent ( ) ;
if ( $tp . length ) {
$tp . addClass ( 'active' ) ;
2017-04-22 12:40:46 +00:00
}
2020-03-02 08:04:05 +00:00
2019-08-12 11:48:20 +00:00
this . fireEvent ( 'tab:active' , [ tab ] ) ;
2017-04-22 12:40:46 +00:00
}
} ,
addTab : function ( tab , panel , after ) {
function _get _tab _action ( index ) {
if ( ! config . tabs [ index ] )
return _get _tab _action ( -- index ) ;
return config . tabs [ index ] . action ;
}
2021-11-19 12:34:25 +00:00
var _tabTemplate = _ . template ( '<li class="ribtab" style="display: none;" <% if (typeof layoutname == "string") print(" data-layout-name=" + \' \' + layoutname) + \' \' %>><a data-tab="<%= action %>" data-title="<%= caption %>" data-hint="0" data-hint-direction="bottom" data-hint-offset="small" <% if (typeof dataHintTitle !== "undefined") { %> data-hint-title="<%= dataHintTitle %>" <% } %> ><%= caption %></a></li>' ) ;
2017-04-22 12:40:46 +00:00
config . tabs [ after + 1 ] = tab ;
var _after _action = _get _tab _action ( after ) ;
var _elements = this . $tabs || this . $layout . find ( '.tabs' ) ;
var $target = _elements . find ( 'a[data-tab=' + _after _action + ']' ) ;
if ( $target . length ) {
$target . parent ( ) . after ( _tabTemplate ( tab ) ) ;
if ( panel ) {
_elements = this . $panels || this . $layout . find ( '.box-panels > .panel' ) ;
$target = _elements . filter ( '[data-tab=' + _after _action + ']' ) ;
if ( $target . length ) {
$target . after ( panel ) ;
2018-05-15 12:37:26 +00:00
} else {
panel . appendTo ( this . $layout . find ( '.box-panels' ) ) ;
2017-04-22 12:40:46 +00:00
}
}
// synchronize matched elements
this . $tabs && ( this . $tabs = $boxTabs . find ( '> li' ) ) ;
this . $panels && ( this . $panels = this . $el . find ( '.box-panels > .panel' ) ) ;
}
} ,
isCompact : function ( ) {
return this . isFolded ;
} ,
hasTabInvisible : function ( ) {
2017-08-03 14:43:43 +00:00
if ( $boxTabs . length < 1 ) return false ;
2017-04-27 08:58:37 +00:00
var _left _bound _ = Math . round ( $boxTabs . offset ( ) . left ) ,
_right _bound _ = Math . round ( _left _bound _ + $boxTabs . width ( ) ) ;
2017-04-22 12:40:46 +00:00
2017-10-18 14:03:49 +00:00
var tab = this . $tabs . filter ( ':visible:first' ) . get ( 0 ) ;
2017-07-21 14:56:05 +00:00
if ( ! tab ) return false ;
2017-04-22 12:40:46 +00:00
var rect = tab . getBoundingClientRect ( ) ;
2017-04-27 08:58:37 +00:00
if ( ! ( Math . round ( rect . left ) < _left _bound _ ) ) {
2017-10-18 14:03:49 +00:00
tab = this . $tabs . filter ( ':visible:last' ) . get ( 0 ) ;
2017-04-22 12:40:46 +00:00
rect = tab . getBoundingClientRect ( ) ;
2017-04-27 08:58:37 +00:00
if ( ! ( Math . round ( rect . right ) > _right _bound _ ) )
2017-04-22 12:40:46 +00:00
return false ;
}
return true ;
} ,
2018-12-12 11:56:08 +00:00
/ * *
* in case panel partly visible .
* hide button ' s caption to decrease panel width
* # # adopt - panel - width
* * /
2021-12-16 13:50:25 +00:00
processPanelVisible : function ( panel , now , force ) {
2018-12-12 11:56:08 +00:00
var me = this ;
if ( me . _timer _id ) clearTimeout ( me . _timer _id ) ;
function _fc ( ) {
2019-01-18 13:43:56 +00:00
var $active = panel || me . $panels . filter ( '.active' ) ;
2018-12-17 13:50:51 +00:00
if ( $active && $active . length ) {
2018-12-12 11:56:08 +00:00
var _maxright = $active . parents ( '.box-controls' ) . width ( ) ;
var data = $active . data ( ) ,
2020-04-13 14:45:30 +00:00
_rightedge = data . rightedge ,
_btns = data . buttons ,
_flex = data . flex ;
2021-12-16 13:50:25 +00:00
var more _section = $active . find ( '.more-box' ) ;
2018-12-12 11:56:08 +00:00
if ( ! _rightedge ) {
_rightedge = $active . get ( 0 ) . getBoundingClientRect ( ) . right ;
}
2020-04-13 14:45:30 +00:00
if ( ! _btns ) {
_btns = [ ] ;
_ . each ( $active . find ( '.btn-slot .x-huge' ) , function ( item ) {
_btns . push ( $ ( item ) . closest ( '.btn-slot' ) ) ;
} ) ;
data . buttons = _btns ;
}
if ( ! _flex ) {
_flex = [ ] ;
_ . each ( $active . find ( '.group.flex' ) , function ( item ) {
2020-08-03 11:05:35 +00:00
var el = $ ( item ) ;
_flex . push ( { el : el , width : el . attr ( 'data-group-width' ) || el . attr ( 'max-width' ) } ) ; //save flex element and it's initial width
2020-04-13 14:45:30 +00:00
} ) ;
data . flex = _flex ;
}
2018-12-12 11:56:08 +00:00
2021-12-16 13:50:25 +00:00
if ( ( _rightedge > _maxright ) ) {
if ( ! more _section . is ( ':visible' ) ) {
if ( _flex . length > 0 ) {
for ( var i = 0 ; i < _flex . length ; i ++ ) {
var item = _flex [ i ] . el ;
2021-12-21 21:27:30 +00:00
_rightedge = $active . get ( 0 ) . getBoundingClientRect ( ) . right ;
if ( item . outerWidth ( ) > parseInt ( item . css ( 'min-width' ) ) ) {
data . rightedge = _rightedge ;
2021-12-16 13:50:25 +00:00
return ;
2021-12-21 21:27:30 +00:00
} else
2021-12-16 13:50:25 +00:00
item . css ( 'width' , item . css ( 'min-width' ) ) ;
}
2020-04-13 14:45:30 +00:00
}
2021-12-16 13:50:25 +00:00
for ( var i = _btns . length - 1 ; i >= 0 ; i -- ) {
var btn = _btns [ i ] ;
if ( ! btn . hasClass ( 'compactwidth' ) && ! btn . hasClass ( 'slot-btn-more' ) ) {
btn . addClass ( 'compactwidth' ) ;
_rightedge = $active . get ( 0 ) . getBoundingClientRect ( ) . right ;
if ( _rightedge <= _maxright )
break ;
}
2020-04-13 14:45:30 +00:00
}
2021-12-16 13:50:25 +00:00
data . rightedge = _rightedge ;
2020-04-13 14:45:30 +00:00
}
2021-12-16 13:50:25 +00:00
me . resizeToolbar ( force ) ;
2018-12-12 11:56:08 +00:00
} else {
2021-12-16 13:50:25 +00:00
more _section . is ( ':visible' ) && me . resizeToolbar ( force ) ;
if ( ! more _section . is ( ':visible' ) ) {
for ( var i = 0 ; i < _btns . length ; i ++ ) {
var btn = _btns [ i ] ;
if ( btn . hasClass ( 'compactwidth' ) ) {
btn . removeClass ( 'compactwidth' ) ;
2020-04-13 14:45:30 +00:00
_rightedge = $active . get ( 0 ) . getBoundingClientRect ( ) . right ;
2021-12-16 13:50:25 +00:00
if ( _rightedge > _maxright ) {
btn . addClass ( 'compactwidth' ) ;
_rightedge = $active . get ( 0 ) . getBoundingClientRect ( ) . right ;
break ;
}
2020-04-13 14:45:30 +00:00
}
}
2021-12-16 13:50:25 +00:00
data . rightedge = _rightedge ;
if ( _flex . length > 0 && $active . find ( '.btn-slot.compactwidth' ) . length < 1 ) {
for ( var i = 0 ; i < _flex . length ; i ++ ) {
var item = _flex [ i ] ;
item . el . css ( 'width' , item . width ) ;
2021-12-21 21:27:30 +00:00
data . rightedge = $active . get ( 0 ) . getBoundingClientRect ( ) . right ;
2021-12-16 13:50:25 +00:00
}
2020-04-13 14:45:30 +00:00
}
2018-12-12 11:56:08 +00:00
}
}
}
} ;
2018-12-17 13:50:51 +00:00
if ( now === true ) _fc ( ) ; else
2018-12-12 11:56:08 +00:00
me . _timer _id = setTimeout ( function ( ) {
delete me . _timer _id ;
_fc ( ) ;
} , 100 ) ;
} ,
/**/
2017-04-22 12:40:46 +00:00
setExtra : function ( place , el ) {
2017-05-04 12:36:42 +00:00
if ( ! ! el ) {
if ( this . $tabs ) {
} else {
if ( place == 'right' ) {
this . $layout . find ( '.extra.right' ) . html ( el ) ;
} else if ( place == 'left' ) {
this . $layout . find ( '.extra.left' ) . html ( el ) ;
}
2017-04-22 12:40:46 +00:00
}
}
2017-10-12 14:25:47 +00:00
} ,
setVisible : function ( tab , visible ) {
2020-07-29 17:58:25 +00:00
if ( tab && this . $tabs ) {
2017-10-12 14:25:47 +00:00
this . $tabs . find ( '> a[data-tab=' + tab + ']' ) . parent ( ) . css ( 'display' , visible ? '' : 'none' ) ;
2020-07-29 17:58:25 +00:00
this . onResize ( ) ;
}
2021-12-15 09:19:41 +00:00
} ,
setMoreButton : function ( tab , panel ) {
if ( ! btnsMore [ tab ] ) {
2021-12-16 16:49:24 +00:00
var box = $ ( '<div class="more-box" style="position: absolute;right: 0; padding-left: 12px;padding-right: 6px;display: none;">' +
2021-12-15 09:19:41 +00:00
'<div class="separator long" style="position: relative;display: table-cell;"></div>' +
'<div class="group" style=""><span class="btn-slot text x-huge slot-btn-more"></span></div>' +
'</div>' ) ;
panel . append ( box ) ;
btnsMore [ tab ] = new Common . UI . Button ( {
cls : 'btn-toolbar x-huge icon-top dropdown-manual' ,
caption : 'More' ,
2021-12-16 13:50:25 +00:00
iconCls : 'toolbar__icon btn-insertchart' ,
2021-12-15 09:19:41 +00:00
enableToggle : true
} ) ;
btnsMore [ tab ] . render ( box . find ( '.slot-btn-more' ) ) ;
btnsMore [ tab ] . on ( 'toggle' , function ( btn , state , e ) {
Common . NotificationCenter . trigger ( 'more:toggle' , btn , state ) ;
} ) ;
2021-12-16 16:49:24 +00:00
var moreContainer = $ ( '<div class="dropdown-menu more-container"><div style="display: inline;"></div></div>' ) ;
2021-12-15 09:19:41 +00:00
optsFold . $bar . append ( moreContainer ) ;
btnsMore [ tab ] . panel = moreContainer . find ( 'div' ) ;
}
this . $moreBar = btnsMore [ tab ] . panel ;
2021-12-16 13:50:25 +00:00
} ,
resizeToolbar : function ( reset ) {
var activePanel = this . $panels . filter ( '.active' ) ,
more _section = activePanel . find ( '.more-box' ) ,
more _section _width = parseInt ( more _section . css ( 'width' ) ) || 0 ,
boxpanels _offset = this . $boxpanels . offset ( ) ,
2021-12-21 21:27:30 +00:00
boxpanels _outer _width = this . $boxpanels . outerWidth ( ) ,
boxpanels _inner _width = this . $boxpanels . width ( ) ,
boxpanels _width = more _section . is ( ':visible' ) ? boxpanels _outer _width - more _section _width : boxpanels _inner _width , // more section has absolute position -> use outer width
delta = ( this . _prevBoxWidth ) ? ( boxpanels _inner _width - this . _prevBoxWidth ) : - 1 ;
this . _prevBoxWidth = boxpanels _inner _width ;
2021-12-16 13:50:25 +00:00
var boxpanels _right = boxpanels _offset . left + boxpanels _width ;
if ( this . $moreBar && this . $moreBar . parent ( ) . is ( ':visible' ) ) {
this . $moreBar . parent ( ) . css ( 'max-width' , Common . Utils . innerWidth ( ) ) ;
}
2021-12-21 21:27:30 +00:00
if ( ( reset || delta < 0 ) && activePanel . outerWidth ( ) > boxpanels _width ) { // from toolbar to more section
2021-12-16 13:50:25 +00:00
if ( ! more _section . is ( ':visible' ) ) {
more _section . css ( 'display' , "" ) ;
2021-12-21 21:27:30 +00:00
boxpanels _width = boxpanels _outer _width - parseInt ( more _section . css ( 'width' ) ) ; // more section has absolute position -> use outer width
2021-12-16 13:50:25 +00:00
boxpanels _right = boxpanels _offset . left + boxpanels _width ;
}
var last _separator = null ,
last _group = null ,
prevchild = this . $moreBar . children ( ) ;
if ( prevchild . length > 0 ) {
prevchild = $ ( prevchild [ 0 ] ) ;
if ( prevchild . hasClass ( 'separator' ) )
last _separator = prevchild ;
if ( prevchild . hasClass ( 'group' ) && prevchild . attr ( 'group-state' ) == 'open' )
last _group = prevchild ;
}
var items = activePanel . find ( '> div:not(.more-box)' ) ;
var need _break = false ;
for ( var i = items . length - 1 ; i >= 0 ; i -- ) {
2021-12-21 21:27:30 +00:00
var item = $ ( items [ i ] ) ;
2021-12-16 13:50:25 +00:00
if ( item . hasClass ( 'group' ) ) {
var offset = item . offset ( ) ,
item _width = item . outerWidth ( ) ,
children = item . children ( ) ;
if ( ! item . attr ( 'inner-width' ) && item . attr ( 'group-state' ) !== 'open' ) {
item . attr ( 'inner-width' , item _width ) ;
for ( var j = children . length - 1 ; j >= 0 ; j -- ) {
var child = $ ( children [ j ] ) ;
child . attr ( 'inner-width' , child . outerWidth ( ) ) ;
}
}
if ( ( offset . left > boxpanels _right || children . length == 1 ) && item . attr ( 'group-state' ) != 'open' ) {
// move group
this . $moreBar . prepend ( item ) ;
if ( last _separator ) {
last _separator . css ( 'display' , '' ) ;
}
} else if ( offset . left + item _width > boxpanels _right ) {
// move buttons from group
for ( var j = children . length - 1 ; j >= 0 ; j -- ) {
var child = $ ( children [ j ] ) ;
if ( child . hasClass ( 'elset' ) ) {
this . $moreBar . prepend ( item ) ;
if ( last _separator ) {
last _separator . css ( 'display' , '' ) ;
}
break ;
} else {
var child _offset = child . offset ( ) ,
child _width = child . outerWidth ( ) ;
if ( child _offset . left + child _width > boxpanels _right ) {
if ( ! last _group ) {
2021-12-16 16:49:24 +00:00
last _group = $ ( '<div></div>' ) ;
2021-12-21 21:27:30 +00:00
last _group . addClass ( items [ i ] . className ) ;
var attrs = items [ i ] . attributes ;
for ( var k = 0 ; k < attrs . length ; k ++ ) {
last _group . attr ( attrs [ k ] . name , attrs [ k ] . value ) ;
}
2021-12-16 13:50:25 +00:00
this . $moreBar . prepend ( last _group ) ;
if ( last _separator ) {
last _separator . css ( 'display' , '' ) ;
}
}
last _group . prepend ( child ) ;
} else {
need _break = true ;
break ;
}
}
}
if ( item . children ( ) . length < 1 ) { // all buttons are moved
item . remove ( ) ;
last _group && last _group . removeAttr ( 'group-state' ) . attr ( 'inner-width' , item . attr ( 'inner-width' ) ) ;
last _group = null ;
} else {
last _group && last _group . attr ( 'group-state' , 'open' ) && item . attr ( 'group-state' , 'open' ) ;
}
if ( need _break )
break ;
} else {
break ;
}
last _separator = null ;
} else if ( item . hasClass ( 'separator' ) ) {
this . $moreBar . prepend ( item ) ;
item . css ( 'display' , 'none' ) ;
last _separator = item ;
}
}
2021-12-15 09:19:41 +00:00
} else if ( ( reset || delta > 0 ) && more _section . is ( ':visible' ) ) {
var last _separator = null ,
last _group = null ,
prevchild = activePanel . find ( '> div:not(.more-box)' ) ;
var last _width = 0 ;
if ( prevchild . length > 0 ) {
prevchild = $ ( prevchild [ prevchild . length - 1 ] ) ;
if ( prevchild . hasClass ( 'separator' ) ) {
last _separator = prevchild ;
2021-12-21 21:27:30 +00:00
last _width = parseInt ( last _separator . css ( 'margin-left' ) ) + parseInt ( last _separator . css ( 'margin-right' ) ) + 1 ;
2021-12-15 09:19:41 +00:00
}
if ( prevchild . hasClass ( 'group' ) && prevchild . attr ( 'group-state' ) == 'open' )
last _group = prevchild ;
}
var items = this . $moreBar . children ( ) ;
2021-12-16 16:49:24 +00:00
var active _width = activePanel . outerWidth ( ) ;
2021-12-15 09:19:41 +00:00
if ( items . length > 0 ) {
// from more panel to toolbar
for ( var i = 0 ; i < items . length ; i ++ ) {
2021-12-21 21:27:30 +00:00
var item = $ ( items [ i ] ) ;
2021-12-16 16:49:24 +00:00
active _width = activePanel . outerWidth ( ) ;
2021-12-15 09:19:41 +00:00
if ( item . hasClass ( 'group' ) ) {
var islast = false ;
if ( this . $moreBar . children ( ) . filter ( '.group' ) . length == 1 ) {
2021-12-21 21:27:30 +00:00
boxpanels _width = boxpanels _inner _width ; // try to move last group
2021-12-15 09:19:41 +00:00
islast = true ;
}
var item _width = parseInt ( item . attr ( 'inner-width' ) || 0 ) ;
2021-12-21 21:27:30 +00:00
var children = item . children ( ) ;
2021-12-15 09:19:41 +00:00
if ( active _width + last _width + item _width < boxpanels _width && item . attr ( 'group-state' ) != 'open' ) {
// move group
more _section . before ( item ) ;
if ( last _separator ) {
last _separator . css ( 'display' , '' ) ;
}
if ( this . $moreBar . children ( ) . filter ( '.group' ) . length == 0 ) {
this . hideMoreBtns ( ) ;
more _section . css ( 'display' , "none" ) ;
}
2021-12-21 21:27:30 +00:00
} else if ( active _width + last _width < boxpanels _width && children . length > 1 ) { // if only one child in group - don't move child. try to move whole group
2021-12-15 09:19:41 +00:00
// move buttons from group
2021-12-21 21:27:30 +00:00
boxpanels _width = boxpanels _outer _width - more _section _width ;
2021-12-15 09:19:41 +00:00
for ( var j = 0 ; j < children . length ; j ++ ) {
if ( islast && j == children . length - 1 )
2021-12-21 21:27:30 +00:00
boxpanels _width = boxpanels _inner _width ; // try to move last item from last group
2021-12-16 16:49:24 +00:00
active _width = activePanel . outerWidth ( ) ;
2021-12-15 09:19:41 +00:00
var child = $ ( children [ j ] ) ;
2021-12-16 13:50:25 +00:00
if ( child . hasClass ( 'elset' ) ) { // don't add group - no enough space
2021-12-16 16:49:24 +00:00
need _break = true ;
2021-12-15 09:19:41 +00:00
break ;
} else {
2021-12-16 16:49:24 +00:00
var child _width = parseInt ( child . attr ( 'inner-width' ) || 0 ) + ( ! last _group ? 6 : 0 ) ;
2021-12-15 09:19:41 +00:00
if ( active _width + last _width + child _width < boxpanels _width ) {
if ( ! last _group ) {
2021-12-16 16:49:24 +00:00
last _group = $ ( '<div></div>' ) ;
2021-12-21 21:27:30 +00:00
last _group . addClass ( items [ i ] . className ) ;
var attrs = items [ i ] . attributes ;
for ( var k = 0 ; k < attrs . length ; k ++ ) {
last _group . attr ( attrs [ k ] . name , attrs [ k ] . value ) ;
}
if ( last _group . hasClass ( 'flex' ) ) { // need to update flex groups list
activePanel . data ( ) . flex = null ;
}
2021-12-15 09:19:41 +00:00
more _section . before ( last _group ) ;
if ( last _separator ) {
last _separator . css ( 'display' , '' ) ;
}
}
last _group . append ( child ) ;
} else {
need _break = true ;
break ;
}
}
}
if ( item . children ( ) . length < 1 ) { // all buttons are moved
item . remove ( ) ;
last _group && last _group . removeAttr ( 'group-state' ) . attr ( 'inner-width' , item . attr ( 'inner-width' ) ) ;
last _group = null ;
if ( this . $moreBar . children ( ) . filter ( '.group' ) . length == 0 ) {
this . hideMoreBtns ( ) ;
more _section . css ( 'display' , "none" ) ;
}
} else {
last _group && last _group . attr ( 'group-state' , 'open' ) && item . attr ( 'group-state' , 'open' ) ;
}
if ( need _break )
break ;
} else {
break ;
}
last _separator = null ; last _width = 0 ;
} else if ( item . hasClass ( 'separator' ) ) {
more _section . before ( item ) ;
item . css ( 'display' , 'none' ) ;
last _separator = item ;
2021-12-21 21:27:30 +00:00
last _width = parseInt ( last _separator . css ( 'margin-left' ) ) + parseInt ( last _separator . css ( 'margin-right' ) ) + 1 ;
2021-12-15 09:19:41 +00:00
}
}
} else {
this . hideMoreBtns ( ) ;
more _section . css ( 'display' , "none" ) ;
}
}
} ,
hideMoreBtns : function ( ) {
for ( var btn in btnsMore ) {
btnsMore [ btn ] && btnsMore [ btn ] . toggle ( false ) ;
}
2017-04-22 12:40:46 +00:00
}
} ;
} ( ) ) ) ;
} ) ;