From 4142f6289592e3ac59f27f5f016cb6f6a02536c8 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 17 May 2022 15:29:01 +0300 Subject: [PATCH] [PE] DocumentHolder: separate view/controller --- .../main/app/controller/DocumentHolder.js | 2 - .../main/app/controller/DocumentHolder.js | 1311 +++++++- .../main/app/controller/Main.js | 18 +- .../main/app/view/DocumentHolder.js | 2788 +++++------------ 4 files changed, 2112 insertions(+), 2007 deletions(-) diff --git a/apps/documenteditor/main/app/controller/DocumentHolder.js b/apps/documenteditor/main/app/controller/DocumentHolder.js index ea48c24f9..758f4c855 100644 --- a/apps/documenteditor/main/app/controller/DocumentHolder.js +++ b/apps/documenteditor/main/app/controller/DocumentHolder.js @@ -1689,7 +1689,6 @@ define([ } }, - /** coauthoring begin **/ addComment: function(item, e, eOpt){ if (this.api && this.mode.canCoAuthoring && this.mode.canComments) { this.documentHolder.suppressEditComplete = true; @@ -1700,7 +1699,6 @@ define([ } } }, - /** coauthoring end **/ onCutCopyPaste: function(item, e) { var me = this; diff --git a/apps/presentationeditor/main/app/controller/DocumentHolder.js b/apps/presentationeditor/main/app/controller/DocumentHolder.js index f6be16df6..a710d39f3 100644 --- a/apps/presentationeditor/main/app/controller/DocumentHolder.js +++ b/apps/presentationeditor/main/app/controller/DocumentHolder.js @@ -90,21 +90,216 @@ define([ ], initialize: function() { - // + this.addListeners({ + 'DocumentHolder': { + 'createdelayedelements': this.createDelayedElements, + 'equation:callback': this.equationCallback + } + }); + + var me = this; + me.usertips = []; + me._TtHeight = 20; + me.fastcoauthtips = []; + me._state = {}; + me.mode = {}; + me._isDisabled = false; + + me.screenTip = { + toolTip: new Common.UI.Tooltip({ + owner: this, + html: true, + title: '
Press Ctrl and click link' +// style: 'word-wrap: break-word;' + }), + strTip: '', + isHidden: true, + isVisible: false + }; + + me.userTooltip = true; + me.wrapEvents = { + userTipMousover: _.bind(me.userTipMousover, me), + userTipMousout: _.bind(me.userTipMousout, me) + }; + + // Hotkeys + // --------------------- + var keymap = {}; + me.hkComments = 'alt+h'; + keymap[me.hkComments] = function() { + if (me.api.can_AddQuotedComment()!==false && me.documentHolder.slidesCount>0) { + me.addComment(); + } + }; + + me.hkPreview = 'command+f5,ctrl+f5'; + keymap[me.hkPreview] = function(e) { + var isResized = false; + e.preventDefault(); + e.stopPropagation(); + if (me.documentHolder.slidesCount>0) { + Common.NotificationCenter.trigger('preview:start', 0); + } + }; + Common.util.Shortcuts.delegateShortcuts({shortcuts:keymap}); }, onLaunch: function() { this.documentHolder = this.createView('DocumentHolder').render(); this.documentHolder.el.tabIndex = -1; + this.onAfterRender(); + + var me = this; + Common.NotificationCenter.on({ + 'window:show': function(e){ + me.screenTip.toolTip.hide(); + me.screenTip.isVisible = false; + /** coauthoring begin **/ + me.userTipHide(); + /** coauthoring end **/ + me.mode && me.mode.isDesktopApp && me.api && me.api.asc_onShowPopupWindow(); + }, + 'modal:show': function(e){ + me.hideTips(); + }, + 'layout:changed': function(e){ + me.screenTip.toolTip.hide(); + me.screenTip.isVisible = false; + /** coauthoring begin **/ + me.userTipHide(); + /** coauthoring end **/ + me.hideTips(); + me.onDocumentHolderResize(); + }, + 'preview:show': function(e){ + me.isPreviewVisible = true; + me.screenTip && (me.screenTip.tipLength = -1); // redraw link tip + }, + 'preview:hide': function(e){ + me.isPreviewVisible = false; + me.screenTip && (me.screenTip.tipLength = -1); // redraw link tip + } + }); }, setApi: function(api) { this.api = api; + + var me = this; + if (me.api) { + me.api.asc_registerCallback('asc_onContextMenu', _.bind(me.onContextMenu, me)); + me.api.asc_registerCallback('asc_onMouseMoveStart', _.bind(me.onMouseMoveStart, me)); + me.api.asc_registerCallback('asc_onMouseMoveEnd', _.bind(me.onMouseMoveEnd, me)); + me.api.asc_registerCallback('asc_onPaintSlideNum', _.bind(me.onPaintSlideNum, me)); + me.api.asc_registerCallback('asc_onEndPaintSlideNum', _.bind(me.onEndPaintSlideNum, me)); + me.api.asc_registerCallback('asc_onCountPages', _.bind(me.onApiCountPages, me)); + me.api.asc_registerCallback('asc_onCurrentPage', _.bind(me.onApiCurrentPages, me)); + me.documentHolder.slidesCount = me.api.getCountPages(); + + //hyperlink + me.api.asc_registerCallback('asc_onHyperlinkClick', _.bind(me.onHyperlinkClick, me)); + me.api.asc_registerCallback('asc_onMouseMove', _.bind(me.onMouseMove, me)); + + if (me.mode.isEdit===true) { + me.api.asc_registerCallback('asc_onDialogAddHyperlink', _.bind(me.onDialogAddHyperlink, me)); + me.api.asc_registerCallback('asc_doubleClickOnChart', _.bind(me.editChartClick, me)); + me.api.asc_registerCallback('asc_doubleClickOnTableOleObject', _.bind(me.onDoubleClickOnTableOleObject, me)); + me.api.asc_registerCallback('asc_onSpellCheckVariantsFound', _.bind(me.onSpellCheckVariantsFound, me)); + me.api.asc_registerCallback('asc_onShowSpecialPasteOptions', _.bind(me.onShowSpecialPasteOptions, me)); + me.api.asc_registerCallback('asc_onHideSpecialPasteOptions', _.bind(me.onHideSpecialPasteOptions, me)); + me.api.asc_registerCallback('asc_ChangeCropState', _.bind(me.onChangeCropState, me)); + me.api.asc_registerCallback('asc_onHidePlaceholderActions', _.bind(me.onHidePlaceholderActions, me)); + me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Image, _.bind(me.onInsertImage, me, true)); + me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.ImageUrl, _.bind(me.onInsertImageUrl, me, true)); + me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Chart, _.bind(me.onClickPlaceholderChart, me)); + me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Table, _.bind(me.onClickPlaceholderTable, me)); + me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Video, _.bind(me.onClickPlaceholder, me, AscCommon.PlaceholderButtonType.Video)); + me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Audio, _.bind(me.onClickPlaceholder, me, AscCommon.PlaceholderButtonType.Audio)); + } + me.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(me.onCoAuthoringDisconnect, me)); + Common.NotificationCenter.on('api:disconnect', _.bind(me.onCoAuthoringDisconnect, me)); + me.api.asc_registerCallback('asc_onTextLanguage', _.bind(me.onTextLanguage, me)); + + me.api.asc_registerCallback('asc_onShowForeignCursorLabel', _.bind(me.onShowForeignCursorLabel, me)); + me.api.asc_registerCallback('asc_onHideForeignCursorLabel', _.bind(me.onHideForeignCursorLabel, me)); + me.api.asc_registerCallback('asc_onFocusObject', _.bind(me.onFocusObject, me)); + me.api.asc_registerCallback('asc_onUpdateThemeIndex', _.bind(me.onApiUpdateThemeIndex, me)); + me.api.asc_registerCallback('asc_onLockDocumentTheme', _.bind(me.onApiLockDocumentTheme, me)); + me.api.asc_registerCallback('asc_onUnLockDocumentTheme', _.bind(me.onApiUnLockDocumentTheme, me)); + me.api.asc_registerCallback('asc_onStartDemonstration', _.bind(me.onApiStartDemonstration)); + + me.documentHolder.setApi(me.api); + } + + return me; }, - createDelayedElements: function() { - var diagramEditor = this.getApplication().getController('Common.Controllers.ExternalDiagramEditor').getView('Common.Views.ExternalDiagramEditor'); + setMode: function(mode) { + var me = this; + me.mode = mode; + /** coauthoring begin **/ + !(me.mode.canCoAuthoring && me.mode.canComments) + ? Common.util.Shortcuts.suspendEvents(me.hkComments) + : Common.util.Shortcuts.resumeEvents(me.hkComments); + /** coauthoring end **/ + me.editorConfig = {user: mode.user}; + me.documentHolder.setMode(mode); + }, + + onAfterRender: function(ct){ + var me = this; + var meEl = me.documentHolder.cmpEl; + if (meEl) { + meEl.on('contextmenu', function(e) { + e.preventDefault(); + e.stopPropagation(); + return false; + }); + meEl.on('click', function(e){ + if (e.target.localName == 'canvas') { + if (me._preventClick) + me._preventClick = false; + else + meEl.focus(); + } + }); + meEl.on('mousedown', function(e){ + if (e.target.localName == 'canvas') + Common.UI.Menu.Manager.hideAll(); + }); + + //NOTE: set mouse wheel handler + + var addEvent = function( elem, type, fn ) { + elem.addEventListener ? elem.addEventListener( type, fn, false ) : elem.attachEvent( "on" + type, fn ); + }; + + var eventname=(/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel'; + addEvent(me.documentHolder.el, eventname, _.bind(me.handleDocumentWheel, me)); + } + + !Common.Utils.isChrome ? $(document).on('mousewheel', _.bind(me.handleDocumentWheel, me)) : + document.addEventListener('mousewheel', _.bind(me.handleDocumentWheel, me), {passive: false}); + $(document).on('keydown', _.bind(me.handleDocumentKeyDown, me)); + $(window).on('resize', _.bind(me.onDocumentHolderResize, me)); + var viewport = me.getApplication().getController('Viewport').getView('Viewport'); + viewport.hlayout.on('layout:resizedrag', _.bind(me.onDocumentHolderResize, me)); + }, + + createDelayedElements: function(view, type) { + var me = this, + view = me.documentHolder; + + if (type=='view') { + view.menuViewCopy.on('click', _.bind(me.onCutCopyPaste, me)); + view.menuViewAddComment.on('click', _.bind(me.addComment, me)); + + return; + } + + var diagramEditor = this.getApplication().getController('Common.Controllers.ExternalDiagramEditor').getView('Common.Views.ExternalDiagramEditor'); if (diagramEditor) { diagramEditor.on('internalmessage', _.bind(function(cmp, message) { var command = message.data.command; @@ -147,6 +342,1116 @@ define([ }, 10); }, this)); } + + view.menuSlidePaste.on('click', _.bind(me.onCutCopyPaste, me)); + view.menuParaCopy.on('click', _.bind(me.onCutCopyPaste, me)); + view.menuParaPaste.on('click', _.bind(me.onCutCopyPaste, me)); + view.menuParaCut.on('click', _.bind(me.onCutCopyPaste, me)); + view.menuImgCopy.on('click', _.bind(me.onCutCopyPaste, me)); + view.menuImgPaste.on('click', _.bind(me.onCutCopyPaste, me)); + view.menuImgCut.on('click', _.bind(me.onCutCopyPaste, me)); + view.menuTableCopy.on('click', _.bind(me.onCutCopyPaste, me)); + view.menuTablePaste.on('click', _.bind(me.onCutCopyPaste, me)); + view.menuTableCut.on('click', _.bind(me.onCutCopyPaste, me)); + view.menuAddHyperlinkPara.on('click', _.bind(me.addHyperlink, me)); + view.menuAddHyperlinkTable.on('click', _.bind(me.addHyperlink, me)); + view.menuEditHyperlinkPara.on('click', _.bind(me.editHyperlink, me)); + view.menuEditHyperlinkTable.on('click', _.bind(me.editHyperlink, me)); + view.menuChartEdit.on('click', _.bind(me.editChartClick, me, undefined)); + view.menuAddCommentPara.on('click', _.bind(me.addComment, me)); + view.menuAddCommentTable.on('click', _.bind(me.addComment, me)); + view.menuAddCommentImg.on('click', _.bind(me.addComment, me)); + view.menuAddToLayoutImg.on('click', _.bind(me.addToLayout, me)); + view.menuAddToLayoutTable.on('click', _.bind(me.addToLayout, me)); + view.menuImgReplace.menu.on('item:click', _.bind(me.onImgReplace, me)); + + }, + + getView: function (name) { + return !name ? + this.documentHolder : Backbone.Controller.prototype.getView.call() + }, + + showPopupMenu: function(menu, value, event, docElement, eOpts){ + var me = this; + if (!_.isUndefined(menu) && menu !== null){ + Common.UI.Menu.Manager.hideAll(); + + var showPoint = [event.get_X(), event.get_Y()], + menuContainer = $(me.documentHolder.el).find(Common.Utils.String.format('#menu-container-{0}', menu.id)); + + if (event.get_Type() == Asc.c_oAscContextMenuTypes.Thumbnails) { + showPoint[0] -= 3; + showPoint[1] -= 3; + } + + if (!menu.rendered) { + // Prepare menu container + if (menuContainer.length < 1) { + menuContainer = $(Common.Utils.String.format('', menu.id)); + $(me.documentHolder.el).append(menuContainer); + } + + menu.render(menuContainer); + menu.cmpEl.attr({tabindex: "-1"}); + } + + menuContainer.css({ + left: showPoint[0], + top : showPoint[1] + }); + + menu.show(); + + if (_.isFunction(menu.options.initMenu)) { + menu.options.initMenu(value); + menu.alignPosition(); + } + _.delay(function() { + menu.cmpEl.focus(); + }, 10); + + me.documentHolder.currentMenu = menu; + } + }, + + fillMenuProps: function(selectedElements) { + if (!selectedElements || !_.isArray(selectedElements)) return; + var me = this, + documentHolder = this.documentHolder; + var menu_props = {}, + menu_to_show = null; + _.each(selectedElements, function(element, index) { + var elType = element.get_ObjectType(), + elValue = element.get_ObjectValue(); + + if (Asc.c_oAscTypeSelectElement.Image == elType) { + menu_to_show = documentHolder.pictureMenu; + menu_props.imgProps = {}; + menu_props.imgProps.value = elValue; + menu_props.imgProps.locked = (elValue) ? elValue.get_Locked() : false; + } else if (Asc.c_oAscTypeSelectElement.Table == elType) + { + menu_to_show = documentHolder.tableMenu; + menu_props.tableProps = {}; + menu_props.tableProps.value = elValue; + menu_props.tableProps.locked = (elValue) ? elValue.get_Locked() : false; + } else if (Asc.c_oAscTypeSelectElement.Hyperlink == elType) { + menu_props.hyperProps = {}; + menu_props.hyperProps.value = elValue; + } else if (Asc.c_oAscTypeSelectElement.Shape == elType) { // shape + menu_to_show = documentHolder.pictureMenu; + menu_props.shapeProps = {}; + menu_props.shapeProps.value = elValue; + menu_props.shapeProps.locked = (elValue) ? elValue.get_Locked() : false; + if (elValue.get_FromChart()) + menu_props.shapeProps.isChart = true; + } + else if (Asc.c_oAscTypeSelectElement.Chart == elType) { + menu_to_show = documentHolder.pictureMenu; + menu_props.chartProps = {}; + menu_props.chartProps.value = elValue; + menu_props.chartProps.locked = (elValue) ? elValue.get_Locked() : false; + } + else if (Asc.c_oAscTypeSelectElement.Slide == elType) { + menu_props.slideProps = {}; + menu_props.slideProps.value = elValue; + menu_props.slideProps.locked = (elValue) ? elValue.get_LockDelete() : false; + } else if (Asc.c_oAscTypeSelectElement.Paragraph == elType) { + menu_props.paraProps = {}; + menu_props.paraProps.value = elValue; + menu_props.paraProps.locked = (elValue) ? elValue.get_Locked() : false; + if ( (menu_props.shapeProps && menu_props.shapeProps.value || menu_props.chartProps && menu_props.chartProps.value)&& // text in shape, need to show paragraph menu with vertical align + _.isUndefined(menu_props.tableProps)) + menu_to_show = documentHolder.textMenu; + } else if (Asc.c_oAscTypeSelectElement.SpellCheck == elType) { + menu_props.spellProps = {}; + menu_props.spellProps.value = elValue; + documentHolder._currentSpellObj = elValue; + } else if (Asc.c_oAscTypeSelectElement.Math == elType) { + menu_props.mathProps = {}; + menu_props.mathProps.value = elValue; + documentHolder._currentMathObj = elValue; + } + }); + if (menu_to_show === null) { + if (!_.isUndefined(menu_props.paraProps)) + menu_to_show = documentHolder.textMenu; + else if (!_.isUndefined(menu_props.slideProps)) { + menu_to_show = documentHolder.slideMenu; + } + } + + return {menu_to_show: menu_to_show, menu_props: menu_props}; + }, + + fillViewMenuProps: function(selectedElements) { + if (!selectedElements || !_.isArray(selectedElements)) return; + + var me = this, + documentHolder = this.documentHolder; + if (!documentHolder.viewModeMenu) + documentHolder.createDelayedElementsViewer(); + + var menu_props = {}, + menu_to_show = null; + _.each(selectedElements, function(element, index) { + var elType = element.get_ObjectType(), + elValue = element.get_ObjectValue(); + + if (Asc.c_oAscTypeSelectElement.Image == elType || Asc.c_oAscTypeSelectElement.Table == elType || Asc.c_oAscTypeSelectElement.Shape == elType || + Asc.c_oAscTypeSelectElement.Chart == elType || Asc.c_oAscTypeSelectElement.Paragraph == elType) { + menu_to_show = documentHolder.viewModeMenu; + menu_props.locked = menu_props.locked || ((elValue) ? elValue.get_Locked() : false); + if (Asc.c_oAscTypeSelectElement.Chart == elType) + menu_props.isChart = true; + } + else if (Asc.c_oAscTypeSelectElement.Slide == elType) { + menu_props.locked = menu_props.locked || ((elValue) ? elValue.get_LockDelete() : false); + } + }); + + return (menu_to_show) ? {menu_to_show: menu_to_show, menu_props: menu_props} : null; + }, + + showObjectMenu: function(event, docElement, eOpts){ + var me = this; + if (me.api){ + var obj = (me.mode.isEdit && !me._isDisabled) ? me.fillMenuProps(me.api.getSelectedElements()) : me.fillViewMenuProps(me.api.getSelectedElements()); + if (obj) me.showPopupMenu(obj.menu_to_show, obj.menu_props, event, docElement, eOpts); + } + }, + + onContextMenu: function(event){ + if (Common.UI.HintManager.isHintVisible()) + Common.UI.HintManager.clearHints(); + var me = this; + _.delay(function(){ + if (event.get_Type() == Asc.c_oAscContextMenuTypes.Thumbnails) { + me.showPopupMenu.call(me, (me.mode.isEdit && !me._isDisabled) ? me.documentHolder.slideMenu : me.documentHolder.viewModeMenuSlide, {isSlideSelect: event.get_IsSlideSelect(), isSlideHidden: event.get_IsSlideHidden(), fromThumbs: true}, event); + } else { + me.showObjectMenu.call(me, event); + } + },10); + }, + + onFocusObject: function(selectedElements) { + var me = this, + currentMenu = me.documentHolder.currentMenu; + if (currentMenu && currentMenu.isVisible()){ + if (me.api.asc_getCurrentFocusObject() === 0 ){ // thumbnails + if (me.documentHolder.slideMenu===currentMenu && !me._isDisabled) { + var isHidden = false; + _.each(selectedElements, function(element, index) { + if (Asc.c_oAscTypeSelectElement.Slide == element.get_ObjectType()) { + isHidden = element.get_ObjectValue().get_IsHidden(); + } + }); + + currentMenu.options.initMenu({isSlideSelect: me.documentHolder.slideMenu.items[2].isVisible(), isSlideHidden: isHidden, fromThumbs: true}); + currentMenu.alignPosition(); + } + } else { + var obj = (me.mode.isEdit && !me._isDisabled) ? me.fillMenuProps(selectedElements) : me.fillViewMenuProps(selectedElements); + if (obj) { + if (obj.menu_to_show===currentMenu) { + currentMenu.options.initMenu(obj.menu_props); + currentMenu.alignPosition(); + } + } + } + } + }, + + handleDocumentWheel: function(event){ + var me = this; + if (me.api) { + var delta = (_.isUndefined(event.originalEvent)) ? event.wheelDelta : event.originalEvent.wheelDelta; + if (_.isUndefined(delta)) { + delta = event.deltaY; + } + + if ((event.ctrlKey || event.metaKey) && !event.altKey){ + if (delta < 0) + me.api.zoomOut(); + else if (delta > 0) + me.api.zoomIn(); + + event.preventDefault(); + event.stopPropagation(); + } + } + }, + + handleDocumentKeyDown: function(event){ + var me = this; + if (me.api){ + var key = event.keyCode; + if ((event.ctrlKey || event.metaKey) && !event.shiftKey && !event.altKey){ + if (key === Common.UI.Keys.NUM_PLUS || key === Common.UI.Keys.EQUALITY || (Common.Utils.isGecko && key === Common.UI.Keys.EQUALITY_FF) || (Common.Utils.isOpera && key == 43)){ + me.api.zoomIn(); + event.preventDefault(); + event.stopPropagation(); + return false; + } + else if (key === Common.UI.Keys.NUM_MINUS || key === Common.UI.Keys.MINUS || (Common.Utils.isGecko && key === Common.UI.Keys.MINUS_FF) || (Common.Utils.isOpera && key == 45)){ + me.api.zoomOut(); + event.preventDefault(); + event.stopPropagation(); + return false; + } else if (key === 48 || key === 96) {// 0 + me.api.zoomFitToPage(); + event.preventDefault(); + event.stopPropagation(); + return false; + } + } + if (me.documentHolder.currentMenu && me.documentHolder.currentMenu.isVisible()) { + if (key == Common.UI.Keys.UP || + key == Common.UI.Keys.DOWN) { + $('ul.dropdown-menu', me.documentHolder.currentMenu.el).focus(); + } + } + if (key == Common.UI.Keys.ESC) { + Common.UI.Menu.Manager.hideAll(); + if (!Common.UI.HintManager.isHintVisible()) + Common.NotificationCenter.trigger('leftmenu:change', 'hide'); + } + } + }, + + onDocumentHolderResize: function(){ + var me = this; + me._Height = me.documentHolder.cmpEl.height(); + me._Width = me.documentHolder.cmpEl.width(); + me._BodyWidth = $('body').width(); + me._XY = undefined; + + if (me.slideNumDiv) { + me.slideNumDiv.remove(); + me.slideNumDiv = undefined; + } + }, + + getUserName: function(id){ + var usersStore = PE.getCollection('Common.Collections.Users'); + if (usersStore){ + var rec = usersStore.findUser(id); + if (rec) + return AscCommon.UserInfoParser.getParsedName(rec.get('username')); + } + return this.documentHolder.guestText; + }, + + isUserVisible: function(id){ + var usersStore = PE.getCollection('Common.Collections.Users'); + if (usersStore){ + var rec = usersStore.findUser(id); + if (rec) + return !rec.get('hidden'); + } + return true; + }, + + userTipMousover: function (evt, el, opt) { + var me = this; + if (me.userTooltip===true) { + me.userTooltip = new Common.UI.Tooltip({ + owner: evt.currentTarget, + title: me.documentHolder.tipIsLocked + }); + + me.userTooltip.show(); + } + }, + + userTipHide: function () { + var me = this; + if (typeof me.userTooltip == 'object') { + me.userTooltip.hide(); + me.userTooltip = undefined; + + for (var i=0; i0) + window.open(url); + else + Common.UI.warning({ + msg: me.documentHolder.txtWarnUrl, + buttons: ['yes', 'no'], + primary: 'yes', + callback: function(btn) { + (btn == 'yes') && window.open(url); + } + }); + } + }, + + onMouseMoveStart: function() { + var me = this; + me.screenTip.isHidden = true; + /** coauthoring begin **/ + if (me.usertips.length>0) { + if (typeof me.userTooltip == 'object') { + me.userTooltip.hide(); + me.userTooltip = true; + } + _.each(me.usertips, function(item) { + item.remove(); + }); + } + me.usertips = []; + me.usertipcount = 0; + /** coauthoring end **/ + }, + + onMouseMoveEnd: function() { + if (this.screenTip.isHidden && this.screenTip.isVisible) { + this.screenTip.isVisible = false; + this.screenTip.toolTip.hide(); + } + }, + + onMouseMove: function(moveData) { + var me = this, + cmpEl = me.documentHolder.cmpEl, + screenTip = me.screenTip; + if (_.isUndefined(me._XY)) { + me._XY = [ + cmpEl.offset().left - $(window).scrollLeft(), + cmpEl.offset().top - $(window).scrollTop() + ]; + me._Width = cmpEl.width(); + me._Height = cmpEl.height(); + me._BodyWidth = $('body').width(); + } + + if (moveData) { + var showPoint, ToolTip; + + if (moveData.get_Type()==1) { // 1 - hyperlink + var hyperProps = moveData.get_Hyperlink(); + var recalc = false; + if (hyperProps) { + screenTip.isHidden = false; + + ToolTip = (_.isEmpty(hyperProps.get_ToolTip())) ? hyperProps.get_Value() : hyperProps.get_ToolTip(); + ToolTip = Common.Utils.String.htmlEncode(ToolTip); + if (ToolTip.length>256) + ToolTip = ToolTip.substr(0, 256) + '...'; + + if (screenTip.tipLength !== ToolTip.length || screenTip.strTip.indexOf(ToolTip)<0 ) { + screenTip.toolTip.setTitle(ToolTip + (me.isPreviewVisible ? '' : '
' + me.documentHolder.txtPressLink + '')); + screenTip.tipLength = ToolTip.length; + screenTip.strTip = ToolTip; + recalc = true; + } + + showPoint = [moveData.get_X(), moveData.get_Y()]; + showPoint[1] += ((me.isPreviewVisible ? 0 : me._XY[1])-15); + showPoint[0] += ((me.isPreviewVisible ? 0 : me._XY[0])+5); + + if (!screenTip.isVisible || recalc) { + screenTip.isVisible = true; + screenTip.toolTip.show([-10000, -10000]); + } + + if ( recalc ) { + screenTip.tipHeight = screenTip.toolTip.getBSTip().$tip.height(); + screenTip.tipWidth = screenTip.toolTip.getBSTip().$tip.width(); + } + showPoint[1] -= screenTip.tipHeight; + if (showPoint[1]<0) + showPoint[1] = 0; + if (showPoint[0] + screenTip.tipWidth > me._BodyWidth ) + showPoint[0] = me._BodyWidth - screenTip.tipWidth; + screenTip.toolTip.getBSTip().$tip.css({top: showPoint[1] + 'px', left: showPoint[0] + 'px'}); + } + } + /** coauthoring begin **/ + else if (moveData.get_Type()==2 && me.mode.isEdit && isUserVisible(moveData.get_UserId())) { // 2 - locked object + var src; + if (me.usertipcount >= me.usertips.length) { + src = $(document.createElement("div")); + src.addClass('username-tip'); + src.css({height: me._TtHeight + 'px', position: 'absolute', zIndex: '900', visibility: 'visible'}); + $(document.body).append(src); + if (userTooltip) { + src.on('mouseover', me.wrapEvents.userTipMousover); + src.on('mouseout', me.wrapEvents.userTipMousout); + } + + me.usertips.push(src); + } + src = me.usertips[me.usertipcount]; + me.usertipcount++; + + ToolTip = me.getUserName(moveData.get_UserId()); + + showPoint = [moveData.get_X()+me._XY[0], moveData.get_Y()+me._XY[1]]; + var maxwidth = showPoint[0]; + showPoint[0] = me._BodyWidth - showPoint[0]; + showPoint[1] -= ((moveData.get_LockedObjectType()==2) ? me._TtHeight : 0); + + if (showPoint[1] > me._XY[1] && showPoint[1]+me._TtHeight < me._XY[1]+me._Height) { + src.text(ToolTip); + src.css({visibility: 'visible', top: showPoint[1] + 'px', right: showPoint[0] + 'px', 'max-width': maxwidth + 'px'}); + } + } + /** coauthoring end **/ + } + }, + + onShowForeignCursorLabel: function(UserId, X, Y, color) { + if (!this.isUserVisible(UserId)) return; + + /** coauthoring begin **/ + var me = this; + var src; + for (var i=0; i0) { + Common.NotificationCenter.trigger('preview:start', 0, null, true); + } + }, + + onApiCountPages: function(count) { + this.documentHolder.slidesCount = count; + }, + + onApiCurrentPages: function(number) { + var me = this; + if (me.documentHolder.currentMenu && me.documentHolder.currentMenu.isVisible() && me._isFromSlideMenu !== true && me._isFromSlideMenu !== number) + setTimeout(function() { + me.documentHolder.currentMenu && me.documentHolder.currentMenu.hide(); + }, 1); + + me._isFromSlideMenu = number; + }, + + onApiUpdateThemeIndex: function(v) { + this._state.themeId = v; + }, + + onApiLockDocumentTheme: function() { + this.documentHolder && (this.documentHolder._state.themeLock = true); + }, + + onApiUnLockDocumentTheme: function() { + this.documentHolder && (this.documentHolder._state.themeLock = false); + }, + + onShowSpecialPasteOptions: function(specialPasteShowOptions) { + var me = this, + documentHolder = me.documentHolder; + var coord = specialPasteShowOptions.asc_getCellCoord(), + pasteContainer = documentHolder.cmpEl.find('#special-paste-container'), + pasteItems = specialPasteShowOptions.asc_getOptions(); + if (!pasteItems) return; + + // Prepare menu container + if (pasteContainer.length < 1) { + me._arrSpecialPaste = []; + me._arrSpecialPaste[Asc.c_oSpecialPasteProps.paste] = documentHolder.textPaste; + me._arrSpecialPaste[Asc.c_oSpecialPasteProps.keepTextOnly] = documentHolder.txtKeepTextOnly; + me._arrSpecialPaste[Asc.c_oSpecialPasteProps.picture] = documentHolder.txtPastePicture; + me._arrSpecialPaste[Asc.c_oSpecialPasteProps.sourceformatting] = documentHolder.txtPasteSourceFormat; + me._arrSpecialPaste[Asc.c_oSpecialPasteProps.destinationFormatting] = documentHolder.txtPasteDestFormat; + + + pasteContainer = $('
'); + documentHolder.cmpEl.append(pasteContainer); + + me.btnSpecialPaste = new Common.UI.Button({ + parentEl: $('#id-document-holder-btn-special-paste'), + cls : 'btn-toolbar', + iconCls : 'toolbar__icon btn-paste', + menu : new Common.UI.Menu({items: []}) + }); + } + + if (pasteItems.length>0) { + var menu = me.btnSpecialPaste.menu; + for (var i = 0; i < menu.items.length; i++) { + menu.removeItem(menu.items[i]); + i--; + } + + var group_prev = -1; + _.each(pasteItems, function(menuItem, index) { + var mnu = new Common.UI.MenuItem({ + caption: me._arrSpecialPaste[menuItem], + value: menuItem, + checkable: true, + toggleGroup : 'specialPasteGroup' + }).on('click', function(item, e) { + me.api.asc_SpecialPaste(item.value); + setTimeout(function(){menu.hide();}, 100); + }); + menu.addItem(mnu); + }); + (menu.items.length>0) && menu.items[0].setChecked(true, true); + } + if (coord.asc_getX()<0 || coord.asc_getY()<0) { + if (pasteContainer.is(':visible')) pasteContainer.hide(); + } else { + var showPoint = [coord.asc_getX() + coord.asc_getWidth() + 3, coord.asc_getY() + coord.asc_getHeight() + 3]; + pasteContainer.css({left: showPoint[0], top : showPoint[1]}); + pasteContainer.show(); + } + }, + + onHideSpecialPasteOptions: function() { + var pasteContainer = this.documentHolder.cmpEl.find('#special-paste-container'); + if (pasteContainer.is(':visible')) + pasteContainer.hide(); + }, + + onChangeCropState: function(state) { + this.documentHolder.menuImgCrop.menu.items[0].setChecked(state, true); + }, + + onDoubleClickOnTableOleObject: function(chart) { + if (this.mode.isEdit && !this._isDisabled) { + var oleEditor = PE.getController('Common.Controllers.ExternalOleEditor').getView('Common.Views.ExternalOleEditor'); + if (oleEditor && chart) { + oleEditor.setEditMode(true); + oleEditor.show(); + oleEditor.setOleData(Asc.asc_putBinaryDataToFrameFromTableOleObject(chart)); + } + } + }, + + addHyperlink: function(item){ + var win, me = this; + if (me.api) { + var _arr = []; + for (var i=0; i')} + ] + }); + // Prepare menu container + menuContainer = $(Common.Utils.String.format('', menu.id)); + this.documentHolder.cmpEl.append(menuContainer); + menu.render(menuContainer); + menu.cmpEl.attr({tabindex: "-1"}); + menu.on('hide:after', function(){ + if (!me._fromShowPlaceholder) + me.api.asc_uncheckPlaceholders(); + }); + + var picker = new Common.UI.DataView({ + el: $('#id-placeholder-menu-chart'), + parentMenu: menu, + showLast: false, + // restoreHeight: 421, + groups: new Common.UI.DataViewGroupStore(Common.define.chartData.getChartGroupData()), + store: new Common.UI.DataViewStore(Common.define.chartData.getChartData()), + itemTemplate: _.template('
\">
') + }); + picker.on('item:click', function (picker, item, record, e) { + me.editChartClick(record.get('type'), me._state.placeholderObj); + }); + } + menuContainer.css({left: x, top : y}); + menuContainer.attr('data-value', 'prevent-canvas-click'); + this._preventClick = true; + menu.show(); + + menu.alignPosition(); + _.delay(function() { + menu.cmpEl.find('.dataview').focus(); + }, 10); + this._fromShowPlaceholder = false; + }, + + onClickPlaceholderTable: function(obj, x, y) { + if (!this.api) return; + + this._state.placeholderObj = obj; + var menu = this.placeholderMenuTable, + menuContainer = menu ? this.documentHolder.cmpEl.find(Common.Utils.String.format('#menu-container-{0}', menu.id)) : null, + me = this; + this._fromShowPlaceholder = true; + Common.UI.Menu.Manager.hideAll(); + + if (!menu) { + this.placeholderMenuTable = menu = new Common.UI.Menu({ + cls: 'shifted-left', + items: [ + {template: _.template('
')}, + {caption: me.mniCustomTable, value: 'custom'} + ] + }); + // Prepare menu container + menuContainer = $(Common.Utils.String.format('', menu.id)); + this.documentHolder.cmpEl.append(menuContainer); + menu.render(menuContainer); + menu.cmpEl.attr({tabindex: "-1"}); + menu.on('hide:after', function(){ + if (!me._fromShowPlaceholder) + me.api.asc_uncheckPlaceholders(); + }); + + var picker = new Common.UI.DimensionPicker({ + el: $('#id-placeholder-menu-tablepicker'), + minRows: 8, + minColumns: 10, + maxRows: 8, + maxColumns: 10 + }); + picker.on('select', function(picker, columns, rows){ + me.api.put_Table(columns, rows, me._state.placeholderObj); + me.fireEvent('editcomplete', me); + }); + menu.on('item:click', function(menu, item, e){ + if (item.value === 'custom') { + (new Common.Views.InsertTableDialog({ + handler: function(result, value) { + if (result == 'ok') + me.api.put_Table(value.columns, value.rows, me._state.placeholderObj); + me.fireEvent('editcomplete', me); + } + })).show(); + } + }); + } + menuContainer.css({left: x, top : y}); + menuContainer.attr('data-value', 'prevent-canvas-click'); + this._preventClick = true; + menu.show(); + + menu.alignPosition(); + _.delay(function() { + menu.cmpEl.focus(); + }, 10); + this._fromShowPlaceholder = false; + }, + + onHidePlaceholderActions: function() { + this.placeholderMenuChart && this.placeholderMenuChart.hide(); + this.placeholderMenuTable && this.placeholderMenuTable.hide(); + }, + + onClickPlaceholder: function(type, obj, x, y) { + if (!this.api) return; + if (type == AscCommon.PlaceholderButtonType.Video) { + this.api.asc_AddVideo(obj); + } else if (type == AscCommon.PlaceholderButtonType.Audio) { + this.api.asc_AddAudio(obj); + } + this.fireEvent('editcomplete', this); + }, + + onImgReplace: function(menu, item, e) { + var me = this; + if (item.value==1) { + me.onInsertImageUrl(false); + } else if (item.value==2) { + Common.NotificationCenter.trigger('storage:image-load', 'change'); + } else { + setTimeout(function(){ + me.onInsertImage(); + }, 10); + } + }, + + editComplete: function() { + this.documentHolder && this.documentHolder.fireEvent('editcomplete', this.documentHolder); } }); }); \ No newline at end of file diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 9f12663c8..62072fa3d 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -586,7 +586,7 @@ define([ toolbarView.btnHighlightColor.toggle(false, false); } - application.getController('DocumentHolder').getView('DocumentHolder').focus(); + application.getController('DocumentHolder').getView().focus(); if (this.api && this.appOptions.isEdit && this.api.asc_isDocumentCanSave) { var cansave = this.api.asc_isDocumentCanSave(), forcesave = this.appOptions.forcesave, @@ -875,7 +875,7 @@ define([ pluginsController.setApi(me.api); documentHolderController.setApi(me.api); - documentHolderController.createDelayedElements(); + // documentHolderController.createDelayedElements(); statusbarController.createDelayedElements(); leftmenuController.getView('LeftMenu').disableMenu('all',false); @@ -883,7 +883,7 @@ define([ if (me.appOptions.canBranding) me.getApplication().getController('LeftMenu').leftMenu.getMenu('about').setLicInfo(me.editorConfig.customization); - documentHolderController.getView('DocumentHolder').setApi(me.api).on('editcomplete', _.bind(me.onEditComplete, me)); + documentHolderController.getView().on('editcomplete', _.bind(me.onEditComplete, me)); // if (me.isThumbnailsShow) me.getMainMenu().onThumbnailsShow(me.isThumbnailsShow); application.getController('Viewport').getView('DocumentPreview').setApi(me.api).setMode(me.appOptions).on('editcomplete', _.bind(me.onEditComplete, me)); @@ -909,7 +909,7 @@ define([ toolbarController.createDelayedElements(); - documentHolderController.getView('DocumentHolder').createDelayedElements(); + documentHolderController.getView().createDelayedElements(); me.setLanguages(); me.api.asc_registerCallback('asc_onUpdateLayout', _.bind(me.fillLayoutsStore, me)); // slide layouts loading @@ -931,7 +931,7 @@ define([ } }, 50); } else { - documentHolderController.getView('DocumentHolder').createDelayedElementsViewer(); + documentHolderController.getView().createDelayedElementsViewer(); Common.NotificationCenter.trigger('document:ready', 'main'); me.applyLicense(); } @@ -1079,7 +1079,7 @@ define([ app.getController('Toolbar').DisableToolbar(disable, options.viewMode); } if (options.documentHolder) { - app.getController('DocumentHolder').getView('DocumentHolder').SetDisabled(disable); + app.getController('DocumentHolder').SetDisabled(disable); } if (options.leftMenu) { if (options.leftMenu.disable) @@ -1282,7 +1282,7 @@ define([ var app = this.getApplication(), viewport = app.getController('Viewport').getView('Viewport'), statusbarView = app.getController('Statusbar').getView('Statusbar'), - documentHolder = app.getController('DocumentHolder').getView('DocumentHolder'), + documentHolder = app.getController('DocumentHolder'), toolbarController = app.getController('Toolbar'); viewport && viewport.setMode(this.appOptions, true); @@ -1854,7 +1854,7 @@ define([ synchronizeChanges: function() { this.getApplication().getController('Statusbar').setStatusCaption(''); - this.getApplication().getController('DocumentHolder').getView('DocumentHolder').hideTips(); + this.getApplication().getController('DocumentHolder').hideTips(); /** coauthoring begin **/ this.getApplication().getController('Toolbar').getView('Toolbar').synchronizeChanges(); /** coauthoring end **/ @@ -2072,7 +2072,7 @@ define([ this.loadLanguages([]); } if (this.languages && this.languages.length>0) { - this.getApplication().getController('DocumentHolder').getView('DocumentHolder').setLanguages(this.languages); + this.getApplication().getController('DocumentHolder').getView().setLanguages(this.languages); this.getApplication().getController('Statusbar').setLanguages(this.languages); this.getApplication().getController('Common.Controllers.ReviewChanges').setLanguages(this.languages); } diff --git a/apps/presentationeditor/main/app/view/DocumentHolder.js b/apps/presentationeditor/main/app/view/DocumentHolder.js index 35d8ee7be..ec9e7f97e 100644 --- a/apps/presentationeditor/main/app/view/DocumentHolder.js +++ b/apps/presentationeditor/main/app/view/DocumentHolder.js @@ -58,1614 +58,13 @@ define([ initialize: function () { var me = this; - me.usertips = []; - me._TtHeight = 20; me.slidesCount = 0; - me.fastcoauthtips = []; me._currentMathObj = undefined; me._currentParaObjDisabled = false; me._currentSpellObj = undefined; me._currLang = {}; me._state = {}; me._isDisabled = false; - - /** coauthoring begin **/ - var usersStore = PE.getCollection('Common.Collections.Users'); - /** coauthoring end **/ - - var showPopupMenu = function(menu, value, event, docElement, eOpts){ - if (!_.isUndefined(menu) && menu !== null){ - Common.UI.Menu.Manager.hideAll(); - - var showPoint = [event.get_X(), event.get_Y()], - menuContainer = $(me.el).find(Common.Utils.String.format('#menu-container-{0}', menu.id)); - - if (event.get_Type() == Asc.c_oAscContextMenuTypes.Thumbnails) { - showPoint[0] -= 3; - showPoint[1] -= 3; - } - - if (!menu.rendered) { - // Prepare menu container - if (menuContainer.length < 1) { - menuContainer = $(Common.Utils.String.format('', menu.id)); - $(me.el).append(menuContainer); - } - - menu.render(menuContainer); - menu.cmpEl.attr({tabindex: "-1"}); - } - - menuContainer.css({ - left: showPoint[0], - top : showPoint[1] - }); - - menu.show(); - - if (_.isFunction(menu.options.initMenu)) { - menu.options.initMenu(value); - menu.alignPosition(); - } - _.delay(function() { - menu.cmpEl.focus(); - }, 10); - - me.currentMenu = menu; - } - }; - - var fillMenuProps = function(selectedElements) { - if (!selectedElements || !_.isArray(selectedElements)) return; - - var menu_props = {}, - menu_to_show = null; - _.each(selectedElements, function(element, index) { - var elType = element.get_ObjectType(), - elValue = element.get_ObjectValue(); - - if (Asc.c_oAscTypeSelectElement.Image == elType) { - menu_to_show = me.pictureMenu; - menu_props.imgProps = {}; - menu_props.imgProps.value = elValue; - menu_props.imgProps.locked = (elValue) ? elValue.get_Locked() : false; - } else if (Asc.c_oAscTypeSelectElement.Table == elType) - { - menu_to_show = me.tableMenu; - menu_props.tableProps = {}; - menu_props.tableProps.value = elValue; - menu_props.tableProps.locked = (elValue) ? elValue.get_Locked() : false; - } else if (Asc.c_oAscTypeSelectElement.Hyperlink == elType) { - menu_props.hyperProps = {}; - menu_props.hyperProps.value = elValue; - } else if (Asc.c_oAscTypeSelectElement.Shape == elType) { // shape - menu_to_show = me.pictureMenu; - menu_props.shapeProps = {}; - menu_props.shapeProps.value = elValue; - menu_props.shapeProps.locked = (elValue) ? elValue.get_Locked() : false; - if (elValue.get_FromChart()) - menu_props.shapeProps.isChart = true; - } - else if (Asc.c_oAscTypeSelectElement.Chart == elType) { - menu_to_show = me.pictureMenu; - menu_props.chartProps = {}; - menu_props.chartProps.value = elValue; - menu_props.chartProps.locked = (elValue) ? elValue.get_Locked() : false; - } - else if (Asc.c_oAscTypeSelectElement.Slide == elType) { - menu_props.slideProps = {}; - menu_props.slideProps.value = elValue; - menu_props.slideProps.locked = (elValue) ? elValue.get_LockDelete() : false; - } else if (Asc.c_oAscTypeSelectElement.Paragraph == elType) { - menu_props.paraProps = {}; - menu_props.paraProps.value = elValue; - menu_props.paraProps.locked = (elValue) ? elValue.get_Locked() : false; - if ( (menu_props.shapeProps && menu_props.shapeProps.value || menu_props.chartProps && menu_props.chartProps.value)&& // text in shape, need to show paragraph menu with vertical align - _.isUndefined(menu_props.tableProps)) - menu_to_show = me.textMenu; - } else if (Asc.c_oAscTypeSelectElement.SpellCheck == elType) { - menu_props.spellProps = {}; - menu_props.spellProps.value = elValue; - me._currentSpellObj = elValue; - } else if (Asc.c_oAscTypeSelectElement.Math == elType) { - menu_props.mathProps = {}; - menu_props.mathProps.value = elValue; - me._currentMathObj = elValue; - } - }); - if (menu_to_show === null) { - if (!_.isUndefined(menu_props.paraProps)) - menu_to_show = me.textMenu; - else if (!_.isUndefined(menu_props.slideProps)) { - menu_to_show = me.slideMenu; - } - } - - return {menu_to_show: menu_to_show, menu_props: menu_props}; - }; - - var fillViewMenuProps = function(selectedElements) { - if (!selectedElements || !_.isArray(selectedElements)) return; - - if (!me.viewModeMenu) - me.createDelayedElementsViewer(); - - var menu_props = {}, - menu_to_show = null; - _.each(selectedElements, function(element, index) { - var elType = element.get_ObjectType(), - elValue = element.get_ObjectValue(); - - if (Asc.c_oAscTypeSelectElement.Image == elType || Asc.c_oAscTypeSelectElement.Table == elType || Asc.c_oAscTypeSelectElement.Shape == elType || - Asc.c_oAscTypeSelectElement.Chart == elType || Asc.c_oAscTypeSelectElement.Paragraph == elType) { - menu_to_show = me.viewModeMenu; - menu_props.locked = menu_props.locked || ((elValue) ? elValue.get_Locked() : false); - if (Asc.c_oAscTypeSelectElement.Chart == elType) - menu_props.isChart = true; - } - else if (Asc.c_oAscTypeSelectElement.Slide == elType) { - menu_props.locked = menu_props.locked || ((elValue) ? elValue.get_LockDelete() : false); - } - }); - - return (menu_to_show) ? {menu_to_show: menu_to_show, menu_props: menu_props} : null; - }; - - var showObjectMenu = function(event, docElement, eOpts){ - if (me.api){ - var obj = (me.mode.isEdit && !me._isDisabled) ? fillMenuProps(me.api.getSelectedElements()) : fillViewMenuProps(me.api.getSelectedElements()); - if (obj) showPopupMenu(obj.menu_to_show, obj.menu_props, event, docElement, eOpts); - } - }; - - var onContextMenu = function(event){ - if (Common.UI.HintManager.isHintVisible()) - Common.UI.HintManager.clearHints(); - _.delay(function(){ - if (event.get_Type() == Asc.c_oAscContextMenuTypes.Thumbnails) { - showPopupMenu.call(me, (me.mode.isEdit && !me._isDisabled) ? me.slideMenu : me.viewModeMenuSlide, {isSlideSelect: event.get_IsSlideSelect(), isSlideHidden: event.get_IsSlideHidden(), fromThumbs: true}, event); - } else { - showObjectMenu.call(me, event); - } - },10); - }; - - var onFocusObject = function(selectedElements) { - if (me.currentMenu && me.currentMenu.isVisible()){ - if (me.api.asc_getCurrentFocusObject() === 0 ){ // thumbnails - if (me.slideMenu===me.currentMenu && !me._isDisabled) { - var isHidden = false; - _.each(selectedElements, function(element, index) { - if (Asc.c_oAscTypeSelectElement.Slide == element.get_ObjectType()) { - isHidden = element.get_ObjectValue().get_IsHidden(); - } - }); - - me.currentMenu.options.initMenu({isSlideSelect: me.slideMenu.items[2].isVisible(), isSlideHidden: isHidden, fromThumbs: true}); - me.currentMenu.alignPosition(); - } - } else { - var obj = (me.mode.isEdit && !me._isDisabled) ? fillMenuProps(selectedElements) : fillViewMenuProps(selectedElements); - if (obj) { - if (obj.menu_to_show===me.currentMenu) { - me.currentMenu.options.initMenu(obj.menu_props); - me.currentMenu.alignPosition(); - } - } - } - } - }; - - var handleDocumentWheel = function(event){ - if (me.api) { - var delta = (_.isUndefined(event.originalEvent)) ? event.wheelDelta : event.originalEvent.wheelDelta; - if (_.isUndefined(delta)) { - delta = event.deltaY; - } - - if ((event.ctrlKey || event.metaKey) && !event.altKey){ - if (delta < 0) - me.api.zoomOut(); - else if (delta > 0) - me.api.zoomIn(); - - event.preventDefault(); - event.stopPropagation(); - } - } - }; - - var handleDocumentKeyDown = function(event){ - if (me.api){ - var key = event.keyCode; - if ((event.ctrlKey || event.metaKey) && !event.shiftKey && !event.altKey){ - if (key === Common.UI.Keys.NUM_PLUS || key === Common.UI.Keys.EQUALITY || (Common.Utils.isGecko && key === Common.UI.Keys.EQUALITY_FF) || (Common.Utils.isOpera && key == 43)){ - me.api.zoomIn(); - event.preventDefault(); - event.stopPropagation(); - return false; - } - else if (key === Common.UI.Keys.NUM_MINUS || key === Common.UI.Keys.MINUS || (Common.Utils.isGecko && key === Common.UI.Keys.MINUS_FF) || (Common.Utils.isOpera && key == 45)){ - me.api.zoomOut(); - event.preventDefault(); - event.stopPropagation(); - return false; - } else if (key === 48 || key === 96) {// 0 - me.api.zoomFitToPage(); - event.preventDefault(); - event.stopPropagation(); - return false; - } - } - if (me.currentMenu && me.currentMenu.isVisible()) { - if (key == Common.UI.Keys.UP || - key == Common.UI.Keys.DOWN) { - $('ul.dropdown-menu', me.currentMenu.el).focus(); - } - } - if (key == Common.UI.Keys.ESC) { - Common.UI.Menu.Manager.hideAll(); - if (!Common.UI.HintManager.isHintVisible()) - Common.NotificationCenter.trigger('leftmenu:change', 'hide'); - } - } - }; - - var onDocumentHolderResize = function(){ - me._Height = me.cmpEl.height(); - me._Width = me.cmpEl.width(); - me._BodyWidth = $('body').width(); - me._XY = undefined; - - if (me.slideNumDiv) { - me.slideNumDiv.remove(); - me.slideNumDiv = undefined; - } - }; - - var onAfterRender = function(ct){ - var meEl = me.cmpEl; - if (meEl) { - meEl.on('contextmenu', function(e) { - e.preventDefault(); - e.stopPropagation(); - return false; - }); - meEl.on('click', function(e){ - if (e.target.localName == 'canvas') { - if (me._preventClick) - me._preventClick = false; - else - meEl.focus(); - } - }); - meEl.on('mousedown', function(e){ - if (e.target.localName == 'canvas') - Common.UI.Menu.Manager.hideAll(); - }); - - //NOTE: set mouse wheel handler - - var addEvent = function( elem, type, fn ) { - elem.addEventListener ? elem.addEventListener( type, fn, false ) : elem.attachEvent( "on" + type, fn ); - }; - - var eventname=(/Firefox/i.test(navigator.userAgent))? 'DOMMouseScroll' : 'mousewheel'; - addEvent(me.el, eventname, handleDocumentWheel); - } - - !Common.Utils.isChrome ? $(document).on('mousewheel', handleDocumentWheel) : - document.addEventListener('mousewheel', handleDocumentWheel, {passive: false}); - $(document).on('keydown', handleDocumentKeyDown); - $(window).on('resize', onDocumentHolderResize); - var viewport = PE.getController('Viewport').getView('Viewport'); - viewport.hlayout.on('layout:resizedrag', onDocumentHolderResize); - }; - - /** coauthoring begin **/ - var getUserName = function(id){ - if (usersStore){ - var rec = usersStore.findUser(id); - if (rec) - return AscCommon.UserInfoParser.getParsedName(rec.get('username')); - } - return me.guestText; - }; - var isUserVisible = function(id){ - if (usersStore){ - var rec = usersStore.findUser(id); - if (rec) - return !rec.get('hidden'); - } - return true; - }; - /** coauthoring end **/ - - var screenTip = { - toolTip: new Common.UI.Tooltip({ - owner: this, - html: true, - title: '
Press Ctrl and click link' -// style: 'word-wrap: break-word;' - }), - strTip: '', - isHidden: true, - isVisible: false - }; - - /** coauthoring begin **/ - var userTooltip = true; - - var userTipMousover = function (evt, el, opt) { - if (userTooltip===true) { - userTooltip = new Common.UI.Tooltip({ - owner: evt.currentTarget, - title: me.tipIsLocked - }); - - userTooltip.show(); - } - }; - - var userTipHide = function () { - if (typeof userTooltip == 'object') { - userTooltip.hide(); - userTooltip = undefined; - - for (var i=0; i0) - window.open(url); - else - Common.UI.warning({ - msg: me.txtWarnUrl, - buttons: ['yes', 'no'], - primary: 'yes', - callback: function(btn) { - (btn == 'yes') && window.open(url); - } - }); - } - }; - - var onMouseMoveStart = function() { - screenTip.isHidden = true; - /** coauthoring begin **/ - if (me.usertips.length>0) { - if (typeof userTooltip == 'object') { - userTooltip.hide(); - userTooltip = true; - } - _.each(me.usertips, function(item) { - item.remove(); - }); - } - me.usertips = []; - me.usertipcount = 0; - /** coauthoring end **/ - }; - - var onMouseMoveEnd = function() { - if (screenTip.isHidden && screenTip.isVisible) { - screenTip.isVisible = false; - screenTip.toolTip.hide(); - } - }; - - var onMouseMove = function(moveData) { - if (_.isUndefined(me._XY)) { - me._XY = [ - me.cmpEl.offset().left - $(window).scrollLeft(), - me.cmpEl.offset().top - $(window).scrollTop() - ]; - me._Width = me.cmpEl.width(); - me._Height = me.cmpEl.height(); - me._BodyWidth = $('body').width(); - } - - if (moveData) { - var showPoint, ToolTip; - - if (moveData.get_Type()==1) { // 1 - hyperlink - var hyperProps = moveData.get_Hyperlink(); - var recalc = false; - if (hyperProps) { - screenTip.isHidden = false; - - ToolTip = (_.isEmpty(hyperProps.get_ToolTip())) ? hyperProps.get_Value() : hyperProps.get_ToolTip(); - ToolTip = Common.Utils.String.htmlEncode(ToolTip); - if (ToolTip.length>256) - ToolTip = ToolTip.substr(0, 256) + '...'; - - if (screenTip.tipLength !== ToolTip.length || screenTip.strTip.indexOf(ToolTip)<0 ) { - screenTip.toolTip.setTitle(ToolTip + (me.isPreviewVisible ? '' : '
' + me.txtPressLink + '')); - screenTip.tipLength = ToolTip.length; - screenTip.strTip = ToolTip; - recalc = true; - } - - showPoint = [moveData.get_X(), moveData.get_Y()]; - showPoint[1] += ((me.isPreviewVisible ? 0 : me._XY[1])-15); - showPoint[0] += ((me.isPreviewVisible ? 0 : me._XY[0])+5); - - if (!screenTip.isVisible || recalc) { - screenTip.isVisible = true; - screenTip.toolTip.show([-10000, -10000]); - } - - if ( recalc ) { - screenTip.tipHeight = screenTip.toolTip.getBSTip().$tip.height(); - screenTip.tipWidth = screenTip.toolTip.getBSTip().$tip.width(); - } - showPoint[1] -= screenTip.tipHeight; - if (showPoint[1]<0) - showPoint[1] = 0; - if (showPoint[0] + screenTip.tipWidth > me._BodyWidth ) - showPoint[0] = me._BodyWidth - screenTip.tipWidth; - screenTip.toolTip.getBSTip().$tip.css({top: showPoint[1] + 'px', left: showPoint[0] + 'px'}); - } - } - /** coauthoring begin **/ - else if (moveData.get_Type()==2 && me.mode.isEdit && isUserVisible(moveData.get_UserId())) { // 2 - locked object - var src; - if (me.usertipcount >= me.usertips.length) { - src = $(document.createElement("div")); - src.addClass('username-tip'); - src.css({height: me._TtHeight + 'px', position: 'absolute', zIndex: '900', visibility: 'visible'}); - $(document.body).append(src); - if (userTooltip) { - src.on('mouseover', userTipMousover); - src.on('mouseout', userTipMousout); - } - - me.usertips.push(src); - } - src = me.usertips[me.usertipcount]; - me.usertipcount++; - - ToolTip = getUserName(moveData.get_UserId()); - - showPoint = [moveData.get_X()+me._XY[0], moveData.get_Y()+me._XY[1]]; - var maxwidth = showPoint[0]; - showPoint[0] = me._BodyWidth - showPoint[0]; - showPoint[1] -= ((moveData.get_LockedObjectType()==2) ? me._TtHeight : 0); - - if (showPoint[1] > me._XY[1] && showPoint[1]+me._TtHeight < me._XY[1]+me._Height) { - src.text(ToolTip); - src.css({visibility: 'visible', top: showPoint[1] + 'px', right: showPoint[0] + 'px', 'max-width': maxwidth + 'px'}); - } - } - /** coauthoring end **/ - } - }; - - var onShowForeignCursorLabel = function(UserId, X, Y, color) { - if (!isUserVisible(UserId)) return; - - /** coauthoring begin **/ - var src; - for (var i=0; i-1) && !menu.items[index].checked && menu.setChecked(index, true); - } - }; - - var onSpellCheckVariantsFound = function() { - var selectedElements = me.api.getSelectedElements(true); - var props; - if (selectedElements && _.isArray(selectedElements)){ - for (var i = 0; i 0) { - moreMenu.setVisible(variants.length > 3); - moreMenu.setDisabled(me._currentParaObjDisabled); - - _.each(variants, function(variant, index) { - var mnu = new Common.UI.MenuItem({ - caption : variant, - spellword : true, - disabled : me._currentParaObjDisabled - }).on('click', function(item, e) { - if (me.api) { - me.api.asc_replaceMisspelledWord(item.caption, me._currentSpellObj); - me.fireEvent('editcomplete', me); - } - }); - - (index < 3) ? arr.push(mnu) : arrMore.push(mnu); - }); - - if (arr.length > 0) { - if (isParagraph) { - _.each(arr, function(variant, index){ - me.textMenu.insertItem(index, variant); - }) - } else { - _.each(arr, function(variant, index){ - me.menuSpellCheckTable.menu.insertItem(index, variant); - }) - } - } - - if (arrMore.length > 0) { - _.each(arrMore, function(variant, index){ - moreMenu.menu.addItem(variant); - }); - } - - spellMenu.setVisible(false); - } else { - moreMenu.setVisible(false); - spellMenu.setVisible(true); - spellMenu.setCaption(me.noSpellVariantsText, true); - } - }; - - this.clearWordVariants = function(isParagraph) { - var spellMenu = (isParagraph) ? me.textMenu : me.menuSpellCheckTable.menu; - - for (var i = 0; i < spellMenu.items.length; i++) { - if (spellMenu.items[i].options.spellword) { - if (spellMenu.checkeditem == spellMenu.items[i]) { - spellMenu.checkeditem = undefined; - spellMenu.activeItem = undefined; - } - - spellMenu.removeItem(spellMenu.items[i]); - i--; - } - } - (isParagraph) ? me.menuSpellMorePara.menu.removeAll() : me.menuSpellMoreTable.menu.removeAll(); - - me.menuSpellMorePara.menu.checkeditem = undefined; - me.menuSpellMorePara.menu.activeItem = undefined; - me.menuSpellMoreTable.menu.checkeditem = undefined; - me.menuSpellMoreTable.menu.activeItem = undefined; - }; - - this.initEquationMenu = function() { - if (!me._currentMathObj) return; - var type = me._currentMathObj.get_Type(), - value = me._currentMathObj, - mnu, arr = []; - - switch (type) { - case Asc.c_oAscMathInterfaceType.Accent: - mnu = new Common.UI.MenuItem({ - caption : me.txtRemoveAccentChar, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'remove_AccentCharacter'} - }); - arr.push(mnu); - break; - case Asc.c_oAscMathInterfaceType.BorderBox: - mnu = new Common.UI.MenuItem({ - caption : me.txtBorderProps, - equation : true, - disabled : me._currentParaObjDisabled, - menu : new Common.UI.Menu({ - cls: 'shifted-right', - menuAlign: 'tl-tr', - items : [ - { - caption: value.get_HideTop() ? me.txtAddTop : me.txtHideTop, - equationProps: {type: type, callback: 'put_HideTop', value: !value.get_HideTop()} - }, - { - caption: value.get_HideBottom() ? me.txtAddBottom : me.txtHideBottom, - equationProps: {type: type, callback: 'put_HideBottom', value: !value.get_HideBottom()} - }, - { - caption: value.get_HideLeft() ? me.txtAddLeft : me.txtHideLeft, - equationProps: {type: type, callback: 'put_HideLeft', value: !value.get_HideLeft()} - }, - { - caption: value.get_HideRight() ? me.txtAddRight : me.txtHideRight, - equationProps: {type: type, callback: 'put_HideRight', value: !value.get_HideRight()} - }, - { - caption: value.get_HideHor() ? me.txtAddHor : me.txtHideHor, - equationProps: {type: type, callback: 'put_HideHor', value: !value.get_HideHor()} - }, - { - caption: value.get_HideVer() ? me.txtAddVer : me.txtHideVer, - equationProps: {type: type, callback: 'put_HideVer', value: !value.get_HideVer()} - }, - { - caption: value.get_HideTopLTR() ? me.txtAddLT : me.txtHideLT, - equationProps: {type: type, callback: 'put_HideTopLTR', value: !value.get_HideTopLTR()} - }, - { - caption: value.get_HideTopRTL() ? me.txtAddLB : me.txtHideLB, - equationProps: {type: type, callback: 'put_HideTopRTL', value: !value.get_HideTopRTL()} - } - ] - }) - }); - arr.push(mnu); - break; - case Asc.c_oAscMathInterfaceType.Bar: - mnu = new Common.UI.MenuItem({ - caption : me.txtRemoveBar, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'remove_Bar'} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : (value.get_Pos()==Asc.c_oAscMathInterfaceBarPos.Top) ? me.txtUnderbar : me.txtOverbar, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_Pos', value: (value.get_Pos()==Asc.c_oAscMathInterfaceBarPos.Top) ? Asc.c_oAscMathInterfaceBarPos.Bottom : Asc.c_oAscMathInterfaceBarPos.Top} - }); - arr.push(mnu); - break; - case Asc.c_oAscMathInterfaceType.Script: - var scripttype = value.get_ScriptType(); - if (scripttype == Asc.c_oAscMathInterfaceScript.PreSubSup) { - mnu = new Common.UI.MenuItem({ - caption : me.txtScriptsAfter, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_ScriptType', value: Asc.c_oAscMathInterfaceScript.SubSup} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.txtRemScripts, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_ScriptType', value: Asc.c_oAscMathInterfaceScript.None} - }); - arr.push(mnu); - } else { - if (scripttype == Asc.c_oAscMathInterfaceScript.SubSup) { - mnu = new Common.UI.MenuItem({ - caption : me.txtScriptsBefore, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_ScriptType', value: Asc.c_oAscMathInterfaceScript.PreSubSup} - }); - arr.push(mnu); - } - if (scripttype == Asc.c_oAscMathInterfaceScript.SubSup || scripttype == Asc.c_oAscMathInterfaceScript.Sub ) { - mnu = new Common.UI.MenuItem({ - caption : me.txtRemSubscript, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_ScriptType', value: (scripttype == Asc.c_oAscMathInterfaceScript.SubSup) ? Asc.c_oAscMathInterfaceScript.Sup : Asc.c_oAscMathInterfaceScript.None } - }); - arr.push(mnu); - } - if (scripttype == Asc.c_oAscMathInterfaceScript.SubSup || scripttype == Asc.c_oAscMathInterfaceScript.Sup ) { - mnu = new Common.UI.MenuItem({ - caption : me.txtRemSuperscript, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_ScriptType', value: (scripttype == Asc.c_oAscMathInterfaceScript.SubSup) ? Asc.c_oAscMathInterfaceScript.Sub : Asc.c_oAscMathInterfaceScript.None } - }); - arr.push(mnu); - } - } - break; - case Asc.c_oAscMathInterfaceType.Fraction: - var fraction = value.get_FractionType(); - if (fraction==Asc.c_oAscMathInterfaceFraction.Skewed || fraction==Asc.c_oAscMathInterfaceFraction.Linear) { - mnu = new Common.UI.MenuItem({ - caption : me.txtFractionStacked, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_FractionType', value: Asc.c_oAscMathInterfaceFraction.Bar} - }); - arr.push(mnu); - } - if (fraction==Asc.c_oAscMathInterfaceFraction.Bar || fraction==Asc.c_oAscMathInterfaceFraction.Linear) { - mnu = new Common.UI.MenuItem({ - caption : me.txtFractionSkewed, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_FractionType', value: Asc.c_oAscMathInterfaceFraction.Skewed} - }); - arr.push(mnu); - } - if (fraction==Asc.c_oAscMathInterfaceFraction.Bar || fraction==Asc.c_oAscMathInterfaceFraction.Skewed) { - mnu = new Common.UI.MenuItem({ - caption : me.txtFractionLinear, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_FractionType', value: Asc.c_oAscMathInterfaceFraction.Linear} - }); - arr.push(mnu); - } - if (fraction==Asc.c_oAscMathInterfaceFraction.Bar || fraction==Asc.c_oAscMathInterfaceFraction.NoBar) { - mnu = new Common.UI.MenuItem({ - caption : (fraction==Asc.c_oAscMathInterfaceFraction.Bar) ? me.txtRemFractionBar : me.txtAddFractionBar, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_FractionType', value: (fraction==Asc.c_oAscMathInterfaceFraction.Bar) ? Asc.c_oAscMathInterfaceFraction.NoBar : Asc.c_oAscMathInterfaceFraction.Bar} - }); - arr.push(mnu); - } - break; - case Asc.c_oAscMathInterfaceType.Limit: - mnu = new Common.UI.MenuItem({ - caption : (value.get_Pos()==Asc.c_oAscMathInterfaceLimitPos.Top) ? me.txtLimitUnder : me.txtLimitOver, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_Pos', value: (value.get_Pos()==Asc.c_oAscMathInterfaceLimitPos.Top) ? Asc.c_oAscMathInterfaceLimitPos.Bottom : Asc.c_oAscMathInterfaceLimitPos.Top} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.txtRemLimit, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_Pos', value: Asc.c_oAscMathInterfaceLimitPos.None} - }); - arr.push(mnu); - break; - case Asc.c_oAscMathInterfaceType.Matrix: - mnu = new Common.UI.MenuItem({ - caption : value.get_HidePlaceholder() ? me.txtShowPlaceholder : me.txtHidePlaceholder, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_HidePlaceholder', value: !value.get_HidePlaceholder()} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.insertText, - equation : true, - disabled : me._currentParaObjDisabled, - menu : new Common.UI.Menu({ - cls: 'shifted-right', - menuAlign: 'tl-tr', - items : [ - { - caption: me.insertRowAboveText, - equationProps: {type: type, callback: 'insert_MatrixRow', value: true} - }, - { - caption: me.insertRowBelowText, - equationProps: {type: type, callback: 'insert_MatrixRow', value: false} - }, - { - caption: me.insertColumnLeftText, - equationProps: {type: type, callback: 'insert_MatrixColumn', value: true} - }, - { - caption: me.insertColumnRightText, - equationProps: {type: type, callback: 'insert_MatrixColumn', value: false} - } - ] - }) - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.deleteText, - equation : true, - disabled : me._currentParaObjDisabled, - menu : new Common.UI.Menu({ - cls: 'shifted-right', - menuAlign: 'tl-tr', - items : [ - { - caption: me.deleteRowText, - equationProps: {type: type, callback: 'delete_MatrixRow'} - }, - { - caption: me.deleteColumnText, - equationProps: {type: type, callback: 'delete_MatrixColumn'} - } - ] - }) - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.txtMatrixAlign, - equation : true, - disabled : me._currentParaObjDisabled, - menu : new Common.UI.Menu({ - cls: 'shifted-right', - menuAlign: 'tl-tr', - items : [ - { - caption: me.txtTop, - checkable : true, - checked : (value.get_MatrixAlign()==Asc.c_oAscMathInterfaceMatrixMatrixAlign.Top), - equationProps: {type: type, callback: 'put_MatrixAlign', value: Asc.c_oAscMathInterfaceMatrixMatrixAlign.Top} - }, - { - caption: me.centerText, - checkable : true, - checked : (value.get_MatrixAlign()==Asc.c_oAscMathInterfaceMatrixMatrixAlign.Center), - equationProps: {type: type, callback: 'put_MatrixAlign', value: Asc.c_oAscMathInterfaceMatrixMatrixAlign.Center} - }, - { - caption: me.txtBottom, - checkable : true, - checked : (value.get_MatrixAlign()==Asc.c_oAscMathInterfaceMatrixMatrixAlign.Bottom), - equationProps: {type: type, callback: 'put_MatrixAlign', value: Asc.c_oAscMathInterfaceMatrixMatrixAlign.Bottom} - } - ] - }) - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.txtColumnAlign, - equation : true, - disabled : me._currentParaObjDisabled, - menu : new Common.UI.Menu({ - cls: 'shifted-right', - menuAlign: 'tl-tr', - items : [ - { - caption: me.leftText, - checkable : true, - checked : (value.get_ColumnAlign()==Asc.c_oAscMathInterfaceMatrixColumnAlign.Left), - equationProps: {type: type, callback: 'put_ColumnAlign', value: Asc.c_oAscMathInterfaceMatrixColumnAlign.Left} - }, - { - caption: me.centerText, - checkable : true, - checked : (value.get_ColumnAlign()==Asc.c_oAscMathInterfaceMatrixColumnAlign.Center), - equationProps: {type: type, callback: 'put_ColumnAlign', value: Asc.c_oAscMathInterfaceMatrixColumnAlign.Center} - }, - { - caption: me.rightText, - checkable : true, - checked : (value.get_ColumnAlign()==Asc.c_oAscMathInterfaceMatrixColumnAlign.Right), - equationProps: {type: type, callback: 'put_ColumnAlign', value: Asc.c_oAscMathInterfaceMatrixColumnAlign.Right} - } - ] - }) - }); - arr.push(mnu); - break; - case Asc.c_oAscMathInterfaceType.EqArray: - mnu = new Common.UI.MenuItem({ - caption : me.txtInsertEqBefore, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'insert_Equation', value: true} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.txtInsertEqAfter, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'insert_Equation', value: false} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.txtDeleteEq, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'delete_Equation'} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.alignmentText, - equation : true, - disabled : me._currentParaObjDisabled, - menu : new Common.UI.Menu({ - cls: 'shifted-right', - menuAlign: 'tl-tr', - items : [ - { - caption: me.txtTop, - checkable : true, - checked : (value.get_Align()==Asc.c_oAscMathInterfaceEqArrayAlign.Top), - equationProps: {type: type, callback: 'put_Align', value: Asc.c_oAscMathInterfaceEqArrayAlign.Top} - }, - { - caption: me.centerText, - checkable : true, - checked : (value.get_Align()==Asc.c_oAscMathInterfaceEqArrayAlign.Center), - equationProps: {type: type, callback: 'put_Align', value: Asc.c_oAscMathInterfaceEqArrayAlign.Center} - }, - { - caption: me.txtBottom, - checkable : true, - checked : (value.get_Align()==Asc.c_oAscMathInterfaceEqArrayAlign.Bottom), - equationProps: {type: type, callback: 'put_Align', value: Asc.c_oAscMathInterfaceEqArrayAlign.Bottom} - } - ] - }) - }); - arr.push(mnu); - break; - case Asc.c_oAscMathInterfaceType.LargeOperator: - mnu = new Common.UI.MenuItem({ - caption : me.txtLimitChange, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_LimitLocation', value: (value.get_LimitLocation() == Asc.c_oAscMathInterfaceNaryLimitLocation.UndOvr) ? Asc.c_oAscMathInterfaceNaryLimitLocation.SubSup : Asc.c_oAscMathInterfaceNaryLimitLocation.UndOvr} - }); - arr.push(mnu); - if (value.get_HideUpper() !== undefined) { - mnu = new Common.UI.MenuItem({ - caption : value.get_HideUpper() ? me.txtShowTopLimit : me.txtHideTopLimit, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_HideUpper', value: !value.get_HideUpper()} - }); - arr.push(mnu); - } - if (value.get_HideLower() !== undefined) { - mnu = new Common.UI.MenuItem({ - caption : value.get_HideLower() ? me.txtShowBottomLimit : me.txtHideBottomLimit, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_HideLower', value: !value.get_HideLower()} - }); - arr.push(mnu); - } - break; - case Asc.c_oAscMathInterfaceType.Delimiter: - mnu = new Common.UI.MenuItem({ - caption : me.txtInsertArgBefore, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'insert_DelimiterArgument', value: true} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.txtInsertArgAfter, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'insert_DelimiterArgument', value: false} - }); - arr.push(mnu); - if (value.can_DeleteArgument()) { - mnu = new Common.UI.MenuItem({ - caption : me.txtDeleteArg, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'delete_DelimiterArgument'} - }); - arr.push(mnu); - } - mnu = new Common.UI.MenuItem({ - caption : value.has_Separators() ? me.txtDeleteCharsAndSeparators : me.txtDeleteChars, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'remove_DelimiterCharacters'} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : value.get_HideOpeningBracket() ? me.txtShowOpenBracket : me.txtHideOpenBracket, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_HideOpeningBracket', value: !value.get_HideOpeningBracket()} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : value.get_HideClosingBracket() ? me.txtShowCloseBracket : me.txtHideCloseBracket, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_HideClosingBracket', value: !value.get_HideClosingBracket()} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.txtStretchBrackets, - equation : true, - disabled : me._currentParaObjDisabled, - checkable : true, - checked : value.get_StretchBrackets(), - equationProps: {type: type, callback: 'put_StretchBrackets', value: !value.get_StretchBrackets()} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.txtMatchBrackets, - equation : true, - disabled : (!value.get_StretchBrackets() || me._currentParaObjDisabled), - checkable : true, - checked : value.get_StretchBrackets() && value.get_MatchBrackets(), - equationProps: {type: type, callback: 'put_MatchBrackets', value: !value.get_MatchBrackets()} - }); - arr.push(mnu); - break; - case Asc.c_oAscMathInterfaceType.GroupChar: - if (value.can_ChangePos()) { - mnu = new Common.UI.MenuItem({ - caption : (value.get_Pos()==Asc.c_oAscMathInterfaceGroupCharPos.Top) ? me.txtGroupCharUnder : me.txtGroupCharOver, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_Pos', value: (value.get_Pos()==Asc.c_oAscMathInterfaceGroupCharPos.Top) ? Asc.c_oAscMathInterfaceGroupCharPos.Bottom : Asc.c_oAscMathInterfaceGroupCharPos.Top} - }); - arr.push(mnu); - mnu = new Common.UI.MenuItem({ - caption : me.txtDeleteGroupChar, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_Pos', value: Asc.c_oAscMathInterfaceGroupCharPos.None} - }); - arr.push(mnu); - } - break; - case Asc.c_oAscMathInterfaceType.Radical: - if (value.get_HideDegree() !== undefined) { - mnu = new Common.UI.MenuItem({ - caption : value.get_HideDegree() ? me.txtShowDegree : me.txtHideDegree, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'put_HideDegree', value: !value.get_HideDegree()} - }); - arr.push(mnu); - } - mnu = new Common.UI.MenuItem({ - caption : me.txtDeleteRadical, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'remove_Radical'} - }); - arr.push(mnu); - break; - } - if (value.can_IncreaseArgumentSize()) { - mnu = new Common.UI.MenuItem({ - caption : me.txtIncreaseArg, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'increase_ArgumentSize'} - }); - arr.push(mnu); - } - if (value.can_DecreaseArgumentSize()) { - mnu = new Common.UI.MenuItem({ - caption : me.txtDecreaseArg, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'decrease_ArgumentSize'} - }); - arr.push(mnu); - } - if (value.can_InsertManualBreak()) { - mnu = new Common.UI.MenuItem({ - caption : me.txtInsertBreak, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'insert_ManualBreak'} - }); - arr.push(mnu); - } - if (value.can_DeleteManualBreak()) { - mnu = new Common.UI.MenuItem({ - caption : me.txtDeleteBreak, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'delete_ManualBreak'} - }); - arr.push(mnu); - } - if (value.can_AlignToCharacter()) { - mnu = new Common.UI.MenuItem({ - caption : me.txtAlignToChar, - equation : true, - disabled : me._currentParaObjDisabled, - equationProps: {type: type, callback: 'align_ToCharacter'} - }); - arr.push(mnu); - } - return arr; - }; - - this.addEquationMenu = function(isParagraph, insertIdx) { - if (_.isUndefined(isParagraph)) { - isParagraph = me.textMenu.isVisible(); - } - - me.clearEquationMenu(isParagraph, insertIdx); - - var equationMenu = (isParagraph) ? me.textMenu : me.tableMenu, - menuItems = me.initEquationMenu(); - - if (menuItems.length > 0) { - _.each(menuItems, function(menuItem, index) { - if (menuItem.menu) { - _.each(menuItem.menu.items, function(item) { - item.on('click', _.bind(me.equationCallback, me, item.options.equationProps)); - }); - } else - menuItem.on('click', _.bind(me.equationCallback, me, menuItem.options.equationProps)); - equationMenu.insertItem(insertIdx, menuItem); - insertIdx++; - }); - } - return menuItems.length; - }; - - this.clearEquationMenu = function(isParagraph, insertIdx) { - var equationMenu = (isParagraph) ? me.textMenu : me.tableMenu; - for (var i = insertIdx; i < equationMenu.items.length; i++) { - if (equationMenu.items[i].options.equation) { - if (equationMenu.items[i].menu) { - _.each(equationMenu.items[i].menu.items, function(item) { - item.off('click'); - }); - } else - equationMenu.items[i].off('click'); - equationMenu.removeItem(equationMenu.items[i]); - i--; - } else - break; - } - }; - - this.equationCallback = function(eqProps) { - if (eqProps) { - var eqObj; - switch (eqProps.type) { - case Asc.c_oAscMathInterfaceType.Accent: - eqObj = new CMathMenuAccent(); - break; - case Asc.c_oAscMathInterfaceType.BorderBox: - eqObj = new CMathMenuBorderBox(); - break; - case Asc.c_oAscMathInterfaceType.Box: - eqObj = new CMathMenuBox(); - break; - case Asc.c_oAscMathInterfaceType.Bar: - eqObj = new CMathMenuBar(); - break; - case Asc.c_oAscMathInterfaceType.Script: - eqObj = new CMathMenuScript(); - break; - case Asc.c_oAscMathInterfaceType.Fraction: - eqObj = new CMathMenuFraction(); - break; - case Asc.c_oAscMathInterfaceType.Limit: - eqObj = new CMathMenuLimit(); - break; - case Asc.c_oAscMathInterfaceType.Matrix: - eqObj = new CMathMenuMatrix(); - break; - case Asc.c_oAscMathInterfaceType.EqArray: - eqObj = new CMathMenuEqArray(); - break; - case Asc.c_oAscMathInterfaceType.LargeOperator: - eqObj = new CMathMenuNary(); - break; - case Asc.c_oAscMathInterfaceType.Delimiter: - eqObj = new CMathMenuDelimiter(); - break; - case Asc.c_oAscMathInterfaceType.GroupChar: - eqObj = new CMathMenuGroupCharacter(); - break; - case Asc.c_oAscMathInterfaceType.Radical: - eqObj = new CMathMenuRadical(); - break; - case Asc.c_oAscMathInterfaceType.Common: - eqObj = new CMathMenuBase(); - break; - } - if (eqObj) { - eqObj[eqProps.callback](eqProps.value); - me.api.asc_SetMathProps(eqObj); - } - } - me.fireEvent('editcomplete', me); - }; - - this.changePosition = function() { - me._XY = [ - me.cmpEl.offset().left - $(window).scrollLeft(), - me.cmpEl.offset().top - $(window).scrollTop() - ]; - onMouseMoveStart(); - }; - - this.hideTips = function() { - /** coauthoring begin **/ - if (typeof userTooltip == 'object') { - userTooltip.hide(); - userTooltip = true; - } - _.each(me.usertips, function(item) { - item.remove(); - }); - me.usertips = []; - me.usertipcount = 0; - /** coauthoring end **/ - }; - - /** coauthoring begin **/ - // Hotkeys - // --------------------- - var keymap = {}; - var hkComments = 'alt+h'; - keymap[hkComments] = function() { - if (me.api.can_AddQuotedComment()!==false && me.slidesCount>0) { - me.addComment(); - } - }; - - var hkPreview = 'command+f5,ctrl+f5'; - keymap[hkPreview] = function(e) { - var isResized = false; - e.preventDefault(); - e.stopPropagation(); - if (me.slidesCount>0) { - Common.NotificationCenter.trigger('preview:start', 0); - } - }; - Common.util.Shortcuts.delegateShortcuts({shortcuts:keymap}); - - var onApiStartDemonstration = function() { - if (me.slidesCount>0) { - Common.NotificationCenter.trigger('preview:start', 0, null, true); - } - }; - - /** coauthoring end **/ - - var onApiCountPages = function(count) { - me.slidesCount = count; - }; - - var onApiCurrentPages = function(number) { - if (me.currentMenu && me.currentMenu.isVisible() && me._isFromSlideMenu !== true && me._isFromSlideMenu !== number) - setTimeout(function() { - me.currentMenu && me.currentMenu.hide(); - }, 1); - - me._isFromSlideMenu = number; - }; - - var onApiUpdateThemeIndex = function(v) { - me._state.themeId = v; - }; - - var onApiLockDocumentTheme = function() { - me._state.themeLock = true; - }; - - var onApiUnLockDocumentTheme = function() { - me._state.themeLock = false; - }; - - var onShowSpecialPasteOptions = function(specialPasteShowOptions) { - var coord = specialPasteShowOptions.asc_getCellCoord(), - pasteContainer = me.cmpEl.find('#special-paste-container'), - pasteItems = specialPasteShowOptions.asc_getOptions(); - if (!pasteItems) return; - - // Prepare menu container - if (pasteContainer.length < 1) { - me._arrSpecialPaste = []; - me._arrSpecialPaste[Asc.c_oSpecialPasteProps.paste] = me.textPaste; - me._arrSpecialPaste[Asc.c_oSpecialPasteProps.keepTextOnly] = me.txtKeepTextOnly; - me._arrSpecialPaste[Asc.c_oSpecialPasteProps.picture] = me.txtPastePicture; - me._arrSpecialPaste[Asc.c_oSpecialPasteProps.sourceformatting] = me.txtPasteSourceFormat; - me._arrSpecialPaste[Asc.c_oSpecialPasteProps.destinationFormatting] = me.txtPasteDestFormat; - - - pasteContainer = $('
'); - me.cmpEl.append(pasteContainer); - - me.btnSpecialPaste = new Common.UI.Button({ - parentEl: $('#id-document-holder-btn-special-paste'), - cls : 'btn-toolbar', - iconCls : 'toolbar__icon btn-paste', - menu : new Common.UI.Menu({items: []}) - }); - } - - if (pasteItems.length>0) { - var menu = me.btnSpecialPaste.menu; - for (var i = 0; i < menu.items.length; i++) { - menu.removeItem(menu.items[i]); - i--; - } - - var group_prev = -1; - _.each(pasteItems, function(menuItem, index) { - var mnu = new Common.UI.MenuItem({ - caption: me._arrSpecialPaste[menuItem], - value: menuItem, - checkable: true, - toggleGroup : 'specialPasteGroup' - }).on('click', function(item, e) { - me.api.asc_SpecialPaste(item.value); - setTimeout(function(){menu.hide();}, 100); - }); - menu.addItem(mnu); - }); - (menu.items.length>0) && menu.items[0].setChecked(true, true); - } - if (coord.asc_getX()<0 || coord.asc_getY()<0) { - if (pasteContainer.is(':visible')) pasteContainer.hide(); - } else { - var showPoint = [coord.asc_getX() + coord.asc_getWidth() + 3, coord.asc_getY() + coord.asc_getHeight() + 3]; - pasteContainer.css({left: showPoint[0], top : showPoint[1]}); - pasteContainer.show(); - } - }; - - var onHideSpecialPasteOptions = function() { - var pasteContainer = me.cmpEl.find('#special-paste-container'); - if (pasteContainer.is(':visible')) - pasteContainer.hide(); - }; - - var onChangeCropState = function(state) { - this.menuImgCrop.menu.items[0].setChecked(state, true); - }; - - this.setApi = function(o) { - me.api = o; - - if (me.api) { - me.api.asc_registerCallback('asc_onContextMenu', _.bind(onContextMenu, me)); - me.api.asc_registerCallback('asc_onMouseMoveStart', _.bind(onMouseMoveStart, me)); - me.api.asc_registerCallback('asc_onMouseMoveEnd', _.bind(onMouseMoveEnd, me)); - me.api.asc_registerCallback('asc_onPaintSlideNum', _.bind(onPaintSlideNum, me)); - me.api.asc_registerCallback('asc_onEndPaintSlideNum', _.bind(onEndPaintSlideNum, me)); - me.api.asc_registerCallback('asc_onCountPages', _.bind(onApiCountPages, me)); - me.api.asc_registerCallback('asc_onCurrentPage', _.bind(onApiCurrentPages, me)); - me.slidesCount = me.api.getCountPages(); - - //hyperlink - me.api.asc_registerCallback('asc_onHyperlinkClick', _.bind(onHyperlinkClick, me)); - me.api.asc_registerCallback('asc_onMouseMove', _.bind(onMouseMove, me)); - - if (me.mode.isEdit===true) { - me.api.asc_registerCallback('asc_onDialogAddHyperlink', _.bind(onDialogAddHyperlink, me)); - me.api.asc_registerCallback('asc_doubleClickOnChart', _.bind(me.editChartClick, me)); - me.api.asc_registerCallback('asc_doubleClickOnTableOleObject', _.bind(me.onDoubleClickOnTableOleObject, me)); - me.api.asc_registerCallback('asc_onSpellCheckVariantsFound', _.bind(onSpellCheckVariantsFound, me)); - me.api.asc_registerCallback('asc_onShowSpecialPasteOptions', _.bind(onShowSpecialPasteOptions, me)); - me.api.asc_registerCallback('asc_onHideSpecialPasteOptions', _.bind(onHideSpecialPasteOptions, me)); - me.api.asc_registerCallback('asc_ChangeCropState', _.bind(onChangeCropState, me)); - me.api.asc_registerCallback('asc_onHidePlaceholderActions', _.bind(me.onHidePlaceholderActions, me)); - me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Image, _.bind(me.onInsertImage, me, true)); - me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.ImageUrl, _.bind(me.onInsertImageUrl, me, true)); - me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Chart, _.bind(me.onClickPlaceholderChart, me)); - me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Table, _.bind(me.onClickPlaceholderTable, me)); - me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Video, _.bind(me.onClickPlaceholder, me, AscCommon.PlaceholderButtonType.Video)); - me.api.asc_registerPlaceholderCallback(AscCommon.PlaceholderButtonType.Audio, _.bind(me.onClickPlaceholder, me, AscCommon.PlaceholderButtonType.Audio)); - } - me.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(onCoAuthoringDisconnect, me)); - Common.NotificationCenter.on('api:disconnect', _.bind(onCoAuthoringDisconnect, me)); - me.api.asc_registerCallback('asc_onTextLanguage', _.bind(onTextLanguage, me)); - - me.api.asc_registerCallback('asc_onShowForeignCursorLabel', _.bind(onShowForeignCursorLabel, me)); - me.api.asc_registerCallback('asc_onHideForeignCursorLabel', _.bind(onHideForeignCursorLabel, me)); - me.api.asc_registerCallback('asc_onFocusObject', _.bind(onFocusObject, me)); - me.api.asc_registerCallback('asc_onUpdateThemeIndex', _.bind(onApiUpdateThemeIndex, me)); - me.api.asc_registerCallback('asc_onLockDocumentTheme', _.bind(onApiLockDocumentTheme, me)); - me.api.asc_registerCallback('asc_onUnLockDocumentTheme', _.bind(onApiUnLockDocumentTheme, me)); - me.api.asc_registerCallback('asc_onStartDemonstration', _.bind(onApiStartDemonstration)); - } - - return me; - }; - - this.mode = {}; - - this.setMode = function(mode) { - me.mode = mode; - /** coauthoring begin **/ - !(me.mode.canCoAuthoring && me.mode.canComments) - ? Common.util.Shortcuts.suspendEvents(hkComments) - : Common.util.Shortcuts.resumeEvents(hkComments); - /** coauthoring end **/ - - me.editorConfig = {user: mode.user}; - }; - - me.on('render:after', onAfterRender, me); }, render: function () { @@ -1677,125 +76,693 @@ define([ return this; }, + setApi: function(o) { + this.api = o; + return this; + }, + + setMode: function(m) { + this.mode = m; + return this; + }, + focus: function() { var me = this; _.defer(function(){ me.cmpEl.focus(); }, 50); }, - addHyperlink: function(item){ - var win, me = this; - if (me.api) { - var _arr = []; - for (var i=0; i-1) && !menu.items[index].checked && menu.setChecked(index, true); + } + }, + + addWordVariants: function(isParagraph) { + var me = this; + if (!me.textMenu || !me.textMenu.isVisible() && !me.tableMenu.isVisible()) return; + + if (_.isUndefined(isParagraph)) { + isParagraph = me.textMenu.isVisible(); + } + + me.clearWordVariants(isParagraph); + + var moreMenu = (isParagraph) ? me.menuSpellMorePara : me.menuSpellMoreTable; + var spellMenu = (isParagraph) ? me.menuSpellPara : me.menuSpellTable; + var arr = [], + arrMore = []; + var variants = me._currentSpellObj.get_Variants(); + + if (variants.length > 0) { + moreMenu.setVisible(variants.length > 3); + moreMenu.setDisabled(me._currentParaObjDisabled); + + _.each(variants, function(variant, index) { + var mnu = new Common.UI.MenuItem({ + caption : variant, + spellword : true, + disabled : me._currentParaObjDisabled + }).on('click', function(item, e) { + if (me.api) { + me.api.asc_replaceMisspelledWord(item.caption, me._currentSpellObj); + me.fireEvent('editcomplete', me); + } + }); + + (index < 3) ? arr.push(mnu) : arrMore.push(mnu); + }); + + if (arr.length > 0) { + if (isParagraph) { + _.each(arr, function(variant, index){ + me.textMenu.insertItem(index, variant); + }) + } else { + _.each(arr, function(variant, index){ + me.menuSpellCheckTable.menu.insertItem(index, variant); + }) } } + + if (arrMore.length > 0) { + _.each(arrMore, function(variant, index){ + moreMenu.menu.addItem(variant); + }); + } + + spellMenu.setVisible(false); + } else { + moreMenu.setVisible(false); + spellMenu.setVisible(true); + spellMenu.setCaption(me.noSpellVariantsText, true); + } + }, + + clearWordVariants: function(isParagraph) { + var me = this; + var spellMenu = (isParagraph) ? me.textMenu : me.menuSpellCheckTable.menu; + + for (var i = 0; i < spellMenu.items.length; i++) { + if (spellMenu.items[i].options.spellword) { + if (spellMenu.checkeditem == spellMenu.items[i]) { + spellMenu.checkeditem = undefined; + spellMenu.activeItem = undefined; + } + + spellMenu.removeItem(spellMenu.items[i]); + i--; + } + } + (isParagraph) ? me.menuSpellMorePara.menu.removeAll() : me.menuSpellMoreTable.menu.removeAll(); + + me.menuSpellMorePara.menu.checkeditem = undefined; + me.menuSpellMorePara.menu.activeItem = undefined; + me.menuSpellMoreTable.menu.checkeditem = undefined; + me.menuSpellMoreTable.menu.activeItem = undefined; + }, + + initEquationMenu: function() { + var me = this; + if (!me._currentMathObj) return; + var type = me._currentMathObj.get_Type(), + value = me._currentMathObj, + mnu, arr = []; + + switch (type) { + case Asc.c_oAscMathInterfaceType.Accent: + mnu = new Common.UI.MenuItem({ + caption : me.txtRemoveAccentChar, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'remove_AccentCharacter'} + }); + arr.push(mnu); + break; + case Asc.c_oAscMathInterfaceType.BorderBox: + mnu = new Common.UI.MenuItem({ + caption : me.txtBorderProps, + equation : true, + disabled : me._currentParaObjDisabled, + menu : new Common.UI.Menu({ + cls: 'shifted-right', + menuAlign: 'tl-tr', + items : [ + { + caption: value.get_HideTop() ? me.txtAddTop : me.txtHideTop, + equationProps: {type: type, callback: 'put_HideTop', value: !value.get_HideTop()} + }, + { + caption: value.get_HideBottom() ? me.txtAddBottom : me.txtHideBottom, + equationProps: {type: type, callback: 'put_HideBottom', value: !value.get_HideBottom()} + }, + { + caption: value.get_HideLeft() ? me.txtAddLeft : me.txtHideLeft, + equationProps: {type: type, callback: 'put_HideLeft', value: !value.get_HideLeft()} + }, + { + caption: value.get_HideRight() ? me.txtAddRight : me.txtHideRight, + equationProps: {type: type, callback: 'put_HideRight', value: !value.get_HideRight()} + }, + { + caption: value.get_HideHor() ? me.txtAddHor : me.txtHideHor, + equationProps: {type: type, callback: 'put_HideHor', value: !value.get_HideHor()} + }, + { + caption: value.get_HideVer() ? me.txtAddVer : me.txtHideVer, + equationProps: {type: type, callback: 'put_HideVer', value: !value.get_HideVer()} + }, + { + caption: value.get_HideTopLTR() ? me.txtAddLT : me.txtHideLT, + equationProps: {type: type, callback: 'put_HideTopLTR', value: !value.get_HideTopLTR()} + }, + { + caption: value.get_HideTopRTL() ? me.txtAddLB : me.txtHideLB, + equationProps: {type: type, callback: 'put_HideTopRTL', value: !value.get_HideTopRTL()} + } + ] + }) + }); + arr.push(mnu); + break; + case Asc.c_oAscMathInterfaceType.Bar: + mnu = new Common.UI.MenuItem({ + caption : me.txtRemoveBar, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'remove_Bar'} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : (value.get_Pos()==Asc.c_oAscMathInterfaceBarPos.Top) ? me.txtUnderbar : me.txtOverbar, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_Pos', value: (value.get_Pos()==Asc.c_oAscMathInterfaceBarPos.Top) ? Asc.c_oAscMathInterfaceBarPos.Bottom : Asc.c_oAscMathInterfaceBarPos.Top} + }); + arr.push(mnu); + break; + case Asc.c_oAscMathInterfaceType.Script: + var scripttype = value.get_ScriptType(); + if (scripttype == Asc.c_oAscMathInterfaceScript.PreSubSup) { + mnu = new Common.UI.MenuItem({ + caption : me.txtScriptsAfter, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_ScriptType', value: Asc.c_oAscMathInterfaceScript.SubSup} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.txtRemScripts, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_ScriptType', value: Asc.c_oAscMathInterfaceScript.None} + }); + arr.push(mnu); + } else { + if (scripttype == Asc.c_oAscMathInterfaceScript.SubSup) { + mnu = new Common.UI.MenuItem({ + caption : me.txtScriptsBefore, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_ScriptType', value: Asc.c_oAscMathInterfaceScript.PreSubSup} + }); + arr.push(mnu); + } + if (scripttype == Asc.c_oAscMathInterfaceScript.SubSup || scripttype == Asc.c_oAscMathInterfaceScript.Sub ) { + mnu = new Common.UI.MenuItem({ + caption : me.txtRemSubscript, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_ScriptType', value: (scripttype == Asc.c_oAscMathInterfaceScript.SubSup) ? Asc.c_oAscMathInterfaceScript.Sup : Asc.c_oAscMathInterfaceScript.None } + }); + arr.push(mnu); + } + if (scripttype == Asc.c_oAscMathInterfaceScript.SubSup || scripttype == Asc.c_oAscMathInterfaceScript.Sup ) { + mnu = new Common.UI.MenuItem({ + caption : me.txtRemSuperscript, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_ScriptType', value: (scripttype == Asc.c_oAscMathInterfaceScript.SubSup) ? Asc.c_oAscMathInterfaceScript.Sub : Asc.c_oAscMathInterfaceScript.None } + }); + arr.push(mnu); + } + } + break; + case Asc.c_oAscMathInterfaceType.Fraction: + var fraction = value.get_FractionType(); + if (fraction==Asc.c_oAscMathInterfaceFraction.Skewed || fraction==Asc.c_oAscMathInterfaceFraction.Linear) { + mnu = new Common.UI.MenuItem({ + caption : me.txtFractionStacked, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_FractionType', value: Asc.c_oAscMathInterfaceFraction.Bar} + }); + arr.push(mnu); + } + if (fraction==Asc.c_oAscMathInterfaceFraction.Bar || fraction==Asc.c_oAscMathInterfaceFraction.Linear) { + mnu = new Common.UI.MenuItem({ + caption : me.txtFractionSkewed, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_FractionType', value: Asc.c_oAscMathInterfaceFraction.Skewed} + }); + arr.push(mnu); + } + if (fraction==Asc.c_oAscMathInterfaceFraction.Bar || fraction==Asc.c_oAscMathInterfaceFraction.Skewed) { + mnu = new Common.UI.MenuItem({ + caption : me.txtFractionLinear, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_FractionType', value: Asc.c_oAscMathInterfaceFraction.Linear} + }); + arr.push(mnu); + } + if (fraction==Asc.c_oAscMathInterfaceFraction.Bar || fraction==Asc.c_oAscMathInterfaceFraction.NoBar) { + mnu = new Common.UI.MenuItem({ + caption : (fraction==Asc.c_oAscMathInterfaceFraction.Bar) ? me.txtRemFractionBar : me.txtAddFractionBar, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_FractionType', value: (fraction==Asc.c_oAscMathInterfaceFraction.Bar) ? Asc.c_oAscMathInterfaceFraction.NoBar : Asc.c_oAscMathInterfaceFraction.Bar} + }); + arr.push(mnu); + } + break; + case Asc.c_oAscMathInterfaceType.Limit: + mnu = new Common.UI.MenuItem({ + caption : (value.get_Pos()==Asc.c_oAscMathInterfaceLimitPos.Top) ? me.txtLimitUnder : me.txtLimitOver, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_Pos', value: (value.get_Pos()==Asc.c_oAscMathInterfaceLimitPos.Top) ? Asc.c_oAscMathInterfaceLimitPos.Bottom : Asc.c_oAscMathInterfaceLimitPos.Top} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.txtRemLimit, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_Pos', value: Asc.c_oAscMathInterfaceLimitPos.None} + }); + arr.push(mnu); + break; + case Asc.c_oAscMathInterfaceType.Matrix: + mnu = new Common.UI.MenuItem({ + caption : value.get_HidePlaceholder() ? me.txtShowPlaceholder : me.txtHidePlaceholder, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_HidePlaceholder', value: !value.get_HidePlaceholder()} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.insertText, + equation : true, + disabled : me._currentParaObjDisabled, + menu : new Common.UI.Menu({ + cls: 'shifted-right', + menuAlign: 'tl-tr', + items : [ + { + caption: me.insertRowAboveText, + equationProps: {type: type, callback: 'insert_MatrixRow', value: true} + }, + { + caption: me.insertRowBelowText, + equationProps: {type: type, callback: 'insert_MatrixRow', value: false} + }, + { + caption: me.insertColumnLeftText, + equationProps: {type: type, callback: 'insert_MatrixColumn', value: true} + }, + { + caption: me.insertColumnRightText, + equationProps: {type: type, callback: 'insert_MatrixColumn', value: false} + } + ] + }) + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.deleteText, + equation : true, + disabled : me._currentParaObjDisabled, + menu : new Common.UI.Menu({ + cls: 'shifted-right', + menuAlign: 'tl-tr', + items : [ + { + caption: me.deleteRowText, + equationProps: {type: type, callback: 'delete_MatrixRow'} + }, + { + caption: me.deleteColumnText, + equationProps: {type: type, callback: 'delete_MatrixColumn'} + } + ] + }) + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.txtMatrixAlign, + equation : true, + disabled : me._currentParaObjDisabled, + menu : new Common.UI.Menu({ + cls: 'shifted-right', + menuAlign: 'tl-tr', + items : [ + { + caption: me.txtTop, + checkable : true, + checked : (value.get_MatrixAlign()==Asc.c_oAscMathInterfaceMatrixMatrixAlign.Top), + equationProps: {type: type, callback: 'put_MatrixAlign', value: Asc.c_oAscMathInterfaceMatrixMatrixAlign.Top} + }, + { + caption: me.centerText, + checkable : true, + checked : (value.get_MatrixAlign()==Asc.c_oAscMathInterfaceMatrixMatrixAlign.Center), + equationProps: {type: type, callback: 'put_MatrixAlign', value: Asc.c_oAscMathInterfaceMatrixMatrixAlign.Center} + }, + { + caption: me.txtBottom, + checkable : true, + checked : (value.get_MatrixAlign()==Asc.c_oAscMathInterfaceMatrixMatrixAlign.Bottom), + equationProps: {type: type, callback: 'put_MatrixAlign', value: Asc.c_oAscMathInterfaceMatrixMatrixAlign.Bottom} + } + ] + }) + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.txtColumnAlign, + equation : true, + disabled : me._currentParaObjDisabled, + menu : new Common.UI.Menu({ + cls: 'shifted-right', + menuAlign: 'tl-tr', + items : [ + { + caption: me.leftText, + checkable : true, + checked : (value.get_ColumnAlign()==Asc.c_oAscMathInterfaceMatrixColumnAlign.Left), + equationProps: {type: type, callback: 'put_ColumnAlign', value: Asc.c_oAscMathInterfaceMatrixColumnAlign.Left} + }, + { + caption: me.centerText, + checkable : true, + checked : (value.get_ColumnAlign()==Asc.c_oAscMathInterfaceMatrixColumnAlign.Center), + equationProps: {type: type, callback: 'put_ColumnAlign', value: Asc.c_oAscMathInterfaceMatrixColumnAlign.Center} + }, + { + caption: me.rightText, + checkable : true, + checked : (value.get_ColumnAlign()==Asc.c_oAscMathInterfaceMatrixColumnAlign.Right), + equationProps: {type: type, callback: 'put_ColumnAlign', value: Asc.c_oAscMathInterfaceMatrixColumnAlign.Right} + } + ] + }) + }); + arr.push(mnu); + break; + case Asc.c_oAscMathInterfaceType.EqArray: + mnu = new Common.UI.MenuItem({ + caption : me.txtInsertEqBefore, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'insert_Equation', value: true} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.txtInsertEqAfter, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'insert_Equation', value: false} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.txtDeleteEq, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'delete_Equation'} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.alignmentText, + equation : true, + disabled : me._currentParaObjDisabled, + menu : new Common.UI.Menu({ + cls: 'shifted-right', + menuAlign: 'tl-tr', + items : [ + { + caption: me.txtTop, + checkable : true, + checked : (value.get_Align()==Asc.c_oAscMathInterfaceEqArrayAlign.Top), + equationProps: {type: type, callback: 'put_Align', value: Asc.c_oAscMathInterfaceEqArrayAlign.Top} + }, + { + caption: me.centerText, + checkable : true, + checked : (value.get_Align()==Asc.c_oAscMathInterfaceEqArrayAlign.Center), + equationProps: {type: type, callback: 'put_Align', value: Asc.c_oAscMathInterfaceEqArrayAlign.Center} + }, + { + caption: me.txtBottom, + checkable : true, + checked : (value.get_Align()==Asc.c_oAscMathInterfaceEqArrayAlign.Bottom), + equationProps: {type: type, callback: 'put_Align', value: Asc.c_oAscMathInterfaceEqArrayAlign.Bottom} + } + ] + }) + }); + arr.push(mnu); + break; + case Asc.c_oAscMathInterfaceType.LargeOperator: + mnu = new Common.UI.MenuItem({ + caption : me.txtLimitChange, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_LimitLocation', value: (value.get_LimitLocation() == Asc.c_oAscMathInterfaceNaryLimitLocation.UndOvr) ? Asc.c_oAscMathInterfaceNaryLimitLocation.SubSup : Asc.c_oAscMathInterfaceNaryLimitLocation.UndOvr} + }); + arr.push(mnu); + if (value.get_HideUpper() !== undefined) { + mnu = new Common.UI.MenuItem({ + caption : value.get_HideUpper() ? me.txtShowTopLimit : me.txtHideTopLimit, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_HideUpper', value: !value.get_HideUpper()} + }); + arr.push(mnu); + } + if (value.get_HideLower() !== undefined) { + mnu = new Common.UI.MenuItem({ + caption : value.get_HideLower() ? me.txtShowBottomLimit : me.txtHideBottomLimit, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_HideLower', value: !value.get_HideLower()} + }); + arr.push(mnu); + } + break; + case Asc.c_oAscMathInterfaceType.Delimiter: + mnu = new Common.UI.MenuItem({ + caption : me.txtInsertArgBefore, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'insert_DelimiterArgument', value: true} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.txtInsertArgAfter, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'insert_DelimiterArgument', value: false} + }); + arr.push(mnu); + if (value.can_DeleteArgument()) { + mnu = new Common.UI.MenuItem({ + caption : me.txtDeleteArg, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'delete_DelimiterArgument'} + }); + arr.push(mnu); + } + mnu = new Common.UI.MenuItem({ + caption : value.has_Separators() ? me.txtDeleteCharsAndSeparators : me.txtDeleteChars, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'remove_DelimiterCharacters'} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : value.get_HideOpeningBracket() ? me.txtShowOpenBracket : me.txtHideOpenBracket, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_HideOpeningBracket', value: !value.get_HideOpeningBracket()} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : value.get_HideClosingBracket() ? me.txtShowCloseBracket : me.txtHideCloseBracket, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_HideClosingBracket', value: !value.get_HideClosingBracket()} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.txtStretchBrackets, + equation : true, + disabled : me._currentParaObjDisabled, + checkable : true, + checked : value.get_StretchBrackets(), + equationProps: {type: type, callback: 'put_StretchBrackets', value: !value.get_StretchBrackets()} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.txtMatchBrackets, + equation : true, + disabled : (!value.get_StretchBrackets() || me._currentParaObjDisabled), + checkable : true, + checked : value.get_StretchBrackets() && value.get_MatchBrackets(), + equationProps: {type: type, callback: 'put_MatchBrackets', value: !value.get_MatchBrackets()} + }); + arr.push(mnu); + break; + case Asc.c_oAscMathInterfaceType.GroupChar: + if (value.can_ChangePos()) { + mnu = new Common.UI.MenuItem({ + caption : (value.get_Pos()==Asc.c_oAscMathInterfaceGroupCharPos.Top) ? me.txtGroupCharUnder : me.txtGroupCharOver, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_Pos', value: (value.get_Pos()==Asc.c_oAscMathInterfaceGroupCharPos.Top) ? Asc.c_oAscMathInterfaceGroupCharPos.Bottom : Asc.c_oAscMathInterfaceGroupCharPos.Top} + }); + arr.push(mnu); + mnu = new Common.UI.MenuItem({ + caption : me.txtDeleteGroupChar, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_Pos', value: Asc.c_oAscMathInterfaceGroupCharPos.None} + }); + arr.push(mnu); + } + break; + case Asc.c_oAscMathInterfaceType.Radical: + if (value.get_HideDegree() !== undefined) { + mnu = new Common.UI.MenuItem({ + caption : value.get_HideDegree() ? me.txtShowDegree : me.txtHideDegree, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'put_HideDegree', value: !value.get_HideDegree()} + }); + arr.push(mnu); + } + mnu = new Common.UI.MenuItem({ + caption : me.txtDeleteRadical, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'remove_Radical'} + }); + arr.push(mnu); + break; + } + if (value.can_IncreaseArgumentSize()) { + mnu = new Common.UI.MenuItem({ + caption : me.txtIncreaseArg, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'increase_ArgumentSize'} + }); + arr.push(mnu); + } + if (value.can_DecreaseArgumentSize()) { + mnu = new Common.UI.MenuItem({ + caption : me.txtDecreaseArg, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'decrease_ArgumentSize'} + }); + arr.push(mnu); + } + if (value.can_InsertManualBreak()) { + mnu = new Common.UI.MenuItem({ + caption : me.txtInsertBreak, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'insert_ManualBreak'} + }); + arr.push(mnu); + } + if (value.can_DeleteManualBreak()) { + mnu = new Common.UI.MenuItem({ + caption : me.txtDeleteBreak, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'delete_ManualBreak'} + }); + arr.push(mnu); + } + if (value.can_AlignToCharacter()) { + mnu = new Common.UI.MenuItem({ + caption : me.txtAlignToChar, + equation : true, + disabled : me._currentParaObjDisabled, + equationProps: {type: type, callback: 'align_ToCharacter'} + }); + arr.push(mnu); + } + return arr; + }, + + addEquationMenu: function(isParagraph, insertIdx) { + var me = this; + if (_.isUndefined(isParagraph)) { + isParagraph = me.textMenu.isVisible(); + } + + me.clearEquationMenu(isParagraph, insertIdx); + + var equationMenu = (isParagraph) ? me.textMenu : me.tableMenu, + menuItems = me.initEquationMenu(); + + if (menuItems.length > 0) { + _.each(menuItems, function(menuItem, index) { + if (menuItem.menu) { + _.each(menuItem.menu.items, function(item) { + item.on('click', _.bind(me.equationCallback, me, item.options.equationProps)); + }); + } else + menuItem.on('click', _.bind(me.equationCallback, me, menuItem.options.equationProps)); + equationMenu.insertItem(insertIdx, menuItem); + insertIdx++; + }); + } + return menuItems.length; + }, + + equationCallback: function(eqProps) { + this.fireEvent('equation:callback', [eqProps]); + }, + + clearEquationMenu: function(isParagraph, insertIdx) { + var me = this; + var equationMenu = (isParagraph) ? me.textMenu : me.tableMenu; + for (var i = insertIdx; i < equationMenu.items.length; i++) { + if (equationMenu.items[i].options.equation) { + if (equationMenu.items[i].menu) { + _.each(equationMenu.items[i].menu.items, function(item) { + item.off('click'); + }); + } else + equationMenu.items[i].off('click'); + equationMenu.removeItem(equationMenu.items[i]); + i--; + } else + break; } - me.fireEvent('editcomplete', me); }, onSlidePickerShowAfter: function(picker) { if (!picker._needRecalcSlideLayout) return; - + if (picker.cmpEl && picker.dataViewItems.length>0) { var dataViewItems = picker.dataViewItems, el = $(dataViewItems[0].el), @@ -1821,19 +788,14 @@ define([ } }, - addToLayout: function() { - if (this.api) - this.api.asc_AddToLayout(); - }, - createDelayedElementsViewer: function() { var me = this; - var menuViewCopy = new Common.UI.MenuItem({ + me.menuViewCopy = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-copy', caption: me.textCopy, value: 'copy' - }).on('click', _.bind(me.onCutCopyPaste, me)); + }); var menuViewUndo = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-undo', @@ -1846,10 +808,10 @@ define([ caption: '--' }); - var menuViewAddComment = new Common.UI.MenuItem({ + me.menuViewAddComment = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-menu-comments', caption: me.addCommentText - }).on('click', _.bind(me.addComment, me)); + }); this.viewModeMenu = new Common.UI.Menu({ cls: 'shifted-right', @@ -1857,14 +819,14 @@ define([ menuViewUndo.setVisible(me.mode.canCoAuthoring && me.mode.canComments && !me._isDisabled); menuViewUndo.setDisabled(!me.api.asc_getCanUndo()); menuViewCopySeparator.setVisible(!value.isChart && me.api.can_AddQuotedComment() !== false && me.mode.canCoAuthoring && me.mode.canComments && !me._isDisabled); - menuViewAddComment.setVisible(!value.isChart && me.api.can_AddQuotedComment() !== false && me.mode.canCoAuthoring && me.mode.canComments && !me._isDisabled); - menuViewAddComment.setDisabled(value.locked); + me.menuViewAddComment.setVisible(!value.isChart && me.api.can_AddQuotedComment() !== false && me.mode.canCoAuthoring && me.mode.canComments && !me._isDisabled); + me.menuViewAddComment.setDisabled(value.locked); }, items: [ - menuViewCopy, + me.menuViewCopy, menuViewUndo, menuViewCopySeparator, - menuViewAddComment + me.menuViewAddComment ] }).on('hide:after', function (menu, e, isFromInputControl) { if (me.suppressEditComplete) { @@ -1933,6 +895,8 @@ define([ if (!isFromInputControl) me.fireEvent('editcomplete', me); me.currentMenu = null; }); + + this.fireEvent('createdelayedelements', [this, 'view']); }, createDelayedElements: function(){ @@ -2038,11 +1002,11 @@ define([ } }); - var menuSlidePaste = new Common.UI.MenuItem({ + me.menuSlidePaste = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-paste', caption : me.textPaste, value : 'paste' - }).on('click', _.bind(me.onCutCopyPaste, me)); + }); var menuSlideSettings = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-menu-slide', @@ -2065,15 +1029,13 @@ define([ } }); - - me.slideMenu = new Common.UI.Menu({ cls: 'shifted-right', restoreHeightAndTop: true, initMenu: function(value) { var selectedLast = me.api.asc_IsLastSlideSelected(), selectedFirst = me.api.asc_IsFirstSlideSelected(); - menuSlidePaste.setVisible(value.fromThumbs!==true); + me.menuSlidePaste.setVisible(value.fromThumbs!==true); me.slideMenu.items[1].setVisible(value.fromThumbs===true); // New Slide me.slideMenu.items[2].setVisible(value.isSlideSelect===true); // Duplicate Slide mnuDeleteSlide.setVisible(value.isSlideSelect===true); @@ -2127,7 +1089,7 @@ define([ mnuPrintSelection.setDisabled(me.slidesCount<1); }, items: [ - menuSlidePaste, + me.menuSlidePaste, new Common.UI.MenuItem({ caption : me.txtNewSlide }).on('click', function(item) { @@ -2632,14 +1594,14 @@ define([ caption : '--' }); - var menuAddHyperlinkPara = new Common.UI.MenuItem({ + me.menuAddHyperlinkPara = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-inserthyperlink', caption : me.hyperlinkText - }).on('click', _.bind(me.addHyperlink, me)); + }); - var menuEditHyperlinkPara = new Common.UI.MenuItem({ + me.menuEditHyperlinkPara = new Common.UI.MenuItem({ caption : me.editHyperlinkText - }).on('click', _.bind(me.editHyperlink, me)); + }); var menuRemoveHyperlinkPara = new Common.UI.MenuItem({ caption : me.removeHyperlinkText @@ -2659,20 +1621,20 @@ define([ cls: 'shifted-right', menuAlign: 'tl-tr', items: [ - menuEditHyperlinkPara, + me.menuEditHyperlinkPara, menuRemoveHyperlinkPara ] }) }); - var menuAddHyperlinkTable = new Common.UI.MenuItem({ + me.menuAddHyperlinkTable = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-inserthyperlink', caption : me.hyperlinkText - }).on('click', _.bind(me.addHyperlink, me)); + }); - var menuEditHyperlinkTable = new Common.UI.MenuItem({ + me.menuEditHyperlinkTable = new Common.UI.MenuItem({ caption : me.editHyperlinkText - }).on('click', _.bind(me.editHyperlink, me)); + }); var menuRemoveHyperlinkTable = new Common.UI.MenuItem({ caption : me.removeHyperlinkText @@ -2692,7 +1654,7 @@ define([ cls: 'shifted-right', menuAlign: 'tl-tr', items: [ - menuEditHyperlinkTable, + me.menuEditHyperlinkTable, menuRemoveHyperlinkTable ] }) @@ -2862,10 +1824,10 @@ define([ })() }); - var menuChartEdit = new Common.UI.MenuItem({ + me.menuChartEdit = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-menu-chart', caption : me.editChartText - }).on('click', _.bind(me.editChartClick, me, undefined)); + }); var menuParagraphVAlign = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-align-top', @@ -2989,26 +1951,23 @@ define([ } }); - var menuImgReplace = new Common.UI.MenuItem({ + me.menuImgReplace = new Common.UI.MenuItem({ caption : me.textReplace, menu : new Common.UI.Menu({ cls: 'shifted-right', menuAlign: 'tl-tr', items: [ new Common.UI.MenuItem({ - caption : this.textFromFile - }).on('click', function(item) { - setTimeout(function(){ - me.onInsertImage(); - }, 10); + caption : this.textFromFile, + value: 0 }), new Common.UI.MenuItem({ - caption : this.textFromUrl - }).on('click', _.bind(me.onInsertImageUrl, me, false)), + caption : this.textFromUrl, + value: 1 + }), new Common.UI.MenuItem({ - caption : this.textFromStorage - }).on('click', function(item) { - Common.NotificationCenter.trigger('storage:image-load', 'change'); + caption : this.textFromStorage, + value: 2 }) ] }) @@ -3098,87 +2057,87 @@ define([ }); /** coauthoring begin **/ - var menuAddCommentPara = new Common.UI.MenuItem({ + me.menuAddCommentPara = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-menu-comments', caption : me.addCommentText - }).on('click', _.bind(me.addComment, me)); - menuAddCommentPara.hide(); + }); + me.menuAddCommentPara.hide(); - var menuAddCommentTable = new Common.UI.MenuItem({ + me.menuAddCommentTable = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-menu-comments', caption : me.addCommentText - }).on('click', _.bind(me.addComment, me)); - menuAddCommentTable.hide(); + }); + me.menuAddCommentTable.hide(); var menuCommentSeparatorImg = new Common.UI.MenuItem({ caption : '--' }); menuCommentSeparatorImg.hide(); - var menuAddCommentImg = new Common.UI.MenuItem({ + me.menuAddCommentImg = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-menu-comments', caption : me.addCommentText - }).on('click', _.bind(me.addComment, me)); - menuAddCommentImg.hide(); + }); + me.menuAddCommentImg.hide(); /** coauthoring end **/ - var menuAddToLayoutImg = new Common.UI.MenuItem({ + me.menuAddToLayoutImg = new Common.UI.MenuItem({ caption : me.addToLayoutText - }).on('click', _.bind(me.addToLayout, me)); + }); - var menuParaCopy = new Common.UI.MenuItem({ + me.menuParaCopy = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-copy', caption : me.textCopy, value : 'copy' - }).on('click', _.bind(me.onCutCopyPaste, me)); + }); - var menuParaPaste = new Common.UI.MenuItem({ + me.menuParaPaste = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-paste', caption : me.textPaste, value : 'paste' - }).on('click', _.bind(me.onCutCopyPaste, me)); + }); - var menuParaCut = new Common.UI.MenuItem({ + me.menuParaCut = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-cut', caption : me.textCut, value : 'cut' - }).on('click', _.bind(me.onCutCopyPaste, me)); + }); - var menuImgCopy = new Common.UI.MenuItem({ + me.menuImgCopy = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-copy', caption : me.textCopy, value : 'copy' - }).on('click', _.bind(me.onCutCopyPaste, me)); + }); - var menuImgPaste = new Common.UI.MenuItem({ + me.menuImgPaste = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-paste', caption : me.textPaste, value : 'paste' - }).on('click', _.bind(me.onCutCopyPaste, me)); + }); - var menuImgCut = new Common.UI.MenuItem({ + me.menuImgCut = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-cut', caption : me.textCut, value : 'cut' - }).on('click', _.bind(me.onCutCopyPaste, me)); + }); - var menuTableCopy = new Common.UI.MenuItem({ + me.menuTableCopy = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-copy', caption : me.textCopy, value : 'copy' - }).on('click', _.bind(me.onCutCopyPaste, me)); + }); - var menuTablePaste = new Common.UI.MenuItem({ + me.menuTablePaste = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-paste', caption : me.textPaste, value : 'paste' - }).on('click', _.bind(me.onCutCopyPaste, me)); + }); - var menuTableCut = new Common.UI.MenuItem({ + me.menuTableCut = new Common.UI.MenuItem({ iconCls: 'menu__icon btn-cut', caption : me.textCut, value : 'cut' - }).on('click', _.bind(me.onCutCopyPaste, me)); + }); var menuEquationSeparator = new Common.UI.MenuItem({ caption : '--' @@ -3188,9 +2147,9 @@ define([ caption : '--' }); - var menuAddToLayoutTable = new Common.UI.MenuItem({ + me.menuAddToLayoutTable = new Common.UI.MenuItem({ caption : me.addToLayoutText - }).on('click', _.bind(me.addToLayout, me)); + }); var menuImgEditPoints = new Common.UI.MenuItem({ caption: me.textEditPoints @@ -3265,32 +2224,32 @@ define([ text = me.api.can_AddHyperlink(); } - menuAddHyperlinkPara.setVisible(value.hyperProps===undefined && text!==false); + me.menuAddHyperlinkPara.setVisible(value.hyperProps===undefined && text!==false); menuHyperlinkPara.setVisible(value.hyperProps!==undefined); - menuEditHyperlinkPara.hyperProps = value.hyperProps; + me.menuEditHyperlinkPara.hyperProps = value.hyperProps; if (text!==false) { - menuAddHyperlinkPara.hyperProps = {}; - menuAddHyperlinkPara.hyperProps.value = new Asc.CHyperlinkProperty(); - menuAddHyperlinkPara.hyperProps.value.put_Text(text); + me.menuAddHyperlinkPara.hyperProps = {}; + me.menuAddHyperlinkPara.hyperProps.value = new Asc.CHyperlinkProperty(); + me.menuAddHyperlinkPara.hyperProps.value.put_Text(text); } /** coauthoring begin **/ - menuAddCommentPara.setVisible(!isInChart && isInShape && me.api.can_AddQuotedComment()!==false && me.mode.canCoAuthoring && me.mode.canComments); + me.menuAddCommentPara.setVisible(!isInChart && isInShape && me.api.can_AddQuotedComment()!==false && me.mode.canCoAuthoring && me.mode.canComments); /** coauthoring end **/ - menuCommentParaSeparator.setVisible(/** coauthoring begin **/ menuAddCommentPara.isVisible() || /** coauthoring end **/ menuAddHyperlinkPara.isVisible() || menuHyperlinkPara.isVisible()); - menuAddHyperlinkPara.setDisabled(disabled); + menuCommentParaSeparator.setVisible(/** coauthoring begin **/ me.menuAddCommentPara.isVisible() || /** coauthoring end **/ me.menuAddHyperlinkPara.isVisible() || menuHyperlinkPara.isVisible()); + me.menuAddHyperlinkPara.setDisabled(disabled); menuHyperlinkPara.setDisabled(disabled); /** coauthoring begin **/ - menuAddCommentPara.setDisabled(disabled); + me.menuAddCommentPara.setDisabled(disabled); /** coauthoring end **/ menuParagraphAdvanced.setDisabled(disabled); - menuParaCut.setDisabled(disabled); - menuParaPaste.setDisabled(disabled); + me.menuParaCut.setDisabled(disabled); + me.menuParaPaste.setDisabled(disabled); // spellCheck var spell = (value.spellProps!==undefined && value.spellProps.value.get_Checked()===false); @@ -3332,9 +2291,9 @@ define([ menuToDictionaryPara, me.langParaMenu, menuIgnoreSpellParaSeparator, - menuParaCut, - menuParaCopy, - menuParaPaste, + me.menuParaCut, + me.menuParaCopy, + me.menuParaPaste, menuEquationSeparator, { caption: '--' }, menuParagraphVAlign, @@ -3342,9 +2301,9 @@ define([ menuParagraphAdvanced, menuCommentParaSeparator, /** coauthoring begin **/ - menuAddCommentPara, + me.menuAddCommentPara, /** coauthoring end **/ - menuAddHyperlinkPara, + me.menuAddHyperlinkPara, menuHyperlinkPara ] }).on('hide:after', function(menu, e, isFromInputControl) { @@ -3402,8 +2361,8 @@ define([ menuTableCellAlign.setDisabled(value.tableProps.locked || disabled); menuTableAdvanced.setDisabled(value.tableProps.locked || disabled); - menuTableCut.setDisabled(value.tableProps.locked || disabled); - menuTablePaste.setDisabled(value.tableProps.locked || disabled); + me.menuTableCut.setDisabled(value.tableProps.locked || disabled); + me.menuTablePaste.setDisabled(value.tableProps.locked || disabled); // hyperlink properties var text = null; @@ -3412,27 +2371,27 @@ define([ text = me.api.can_AddHyperlink(); } - menuAddHyperlinkTable.setVisible(!_.isUndefined(value.paraProps) && _.isUndefined(value.hyperProps) && text!==false); + me.menuAddHyperlinkTable.setVisible(!_.isUndefined(value.paraProps) && _.isUndefined(value.hyperProps) && text!==false); menuHyperlinkTable.setVisible(!_.isUndefined(value.paraProps) && !_.isUndefined(value.hyperProps)); - menuEditHyperlinkTable.hyperProps = value.hyperProps; + me.menuEditHyperlinkTable.hyperProps = value.hyperProps; if (text!==false) { - menuAddHyperlinkTable.hyperProps = {}; - menuAddHyperlinkTable.hyperProps.value = new Asc.CHyperlinkProperty(); - menuAddHyperlinkTable.hyperProps.value.put_Text(text); + me.menuAddHyperlinkTable.hyperProps = {}; + me.menuAddHyperlinkTable.hyperProps.value = new Asc.CHyperlinkProperty(); + me.menuAddHyperlinkTable.hyperProps.value.put_Text(text); } if (!_.isUndefined(value.paraProps)) { - menuAddHyperlinkTable.setDisabled(value.paraProps.locked || disabled); + me.menuAddHyperlinkTable.setDisabled(value.paraProps.locked || disabled); menuHyperlinkTable.setDisabled(value.paraProps.locked || disabled); me._currentParaObjDisabled = value.paraProps.locked || disabled; } /** coauthoring begin **/ - menuAddCommentTable.setVisible(me.api.can_AddQuotedComment()!==false && me.mode.canCoAuthoring && me.mode.canComments); - menuAddCommentTable.setDisabled(!_.isUndefined(value.paraProps) && value.paraProps.locked || disabled); + me.menuAddCommentTable.setVisible(me.api.can_AddQuotedComment()!==false && me.mode.canCoAuthoring && me.mode.canComments); + me.menuAddCommentTable.setDisabled(!_.isUndefined(value.paraProps) && value.paraProps.locked || disabled); /** coauthoring end **/ - menuHyperlinkSeparator.setVisible(menuAddHyperlinkTable.isVisible() || menuHyperlinkTable.isVisible() /** coauthoring begin **/|| menuAddCommentTable.isVisible()/** coauthoring end **/); + menuHyperlinkSeparator.setVisible(me.menuAddHyperlinkTable.isVisible() || menuHyperlinkTable.isVisible() /** coauthoring begin **/|| me.menuAddCommentTable.isVisible()/** coauthoring end **/); me.menuSpellCheckTable.setVisible(value.spellProps!==undefined && value.spellProps.value.get_Checked()===false); menuToDictionaryTable.setVisible(me.mode.isDesktopApp); @@ -3463,9 +2422,9 @@ define([ items: [ me.menuSpellCheckTable, menuSpellcheckTableSeparator, - menuTableCut, - menuTableCopy, - menuTablePaste, + me.menuTableCut, + me.menuTableCopy, + me.menuTablePaste, { caption: '--' }, new Common.UI.MenuItem({ caption : me.selectText, @@ -3554,12 +2513,12 @@ define([ menuTableAdvanced, menuHyperlinkSeparator, /** coauthoring begin **/ - menuAddCommentTable, + me.menuAddCommentTable, /** coauthoring end **/ - menuAddHyperlinkTable, + me.menuAddHyperlinkTable, menuHyperlinkTable, { caption: '--' }, - menuAddToLayoutTable + me.menuAddToLayoutTable ] }).on('hide:after', function(menu, e, isFromInputControl) { if (me.suppressEditComplete) { @@ -3605,10 +2564,10 @@ define([ if (menuImgOriginalSize.isVisible()) menuImgOriginalSize.setDisabled(disabled || _.isNull(value.imgProps.value.get_ImageUrl()) || _.isUndefined(value.imgProps.value.get_ImageUrl())); - menuImgReplace.setVisible(isimage && (pluginGuid===null || pluginGuid===undefined)); - if (menuImgReplace.isVisible()) - menuImgReplace.setDisabled(disabled || pluginGuid===null); - menuImgReplace.menu.items[2].setVisible(me.mode.canRequestInsertImage || me.mode.fileChoiceUrl && me.mode.fileChoiceUrl.indexOf("{documentType}")>-1); + me.menuImgReplace.setVisible(isimage && (pluginGuid===null || pluginGuid===undefined)); + if (me.menuImgReplace.isVisible()) + me.menuImgReplace.setDisabled(disabled || pluginGuid===null); + me.menuImgReplace.menu.items[2].setVisible(me.mode.canRequestInsertImage || me.mode.fileChoiceUrl && me.mode.fileChoiceUrl.indexOf("{documentType}")>-1); me.menuImgCrop.setVisible(me.api.asc_canEditCrop()); if (me.menuImgCrop.isVisible()) @@ -3621,12 +2580,12 @@ define([ menuImageAdvanced.setVisible(isimage); menuShapeAdvanced.setVisible(_.isUndefined(value.imgProps) && _.isUndefined(value.chartProps)); - menuChartEdit.setVisible(_.isUndefined(value.imgProps) && !_.isUndefined(value.chartProps) && (_.isUndefined(value.shapeProps) || value.shapeProps.isChart)); - menuImgShapeSeparator.setVisible(menuImageAdvanced.isVisible() || menuShapeAdvanced.isVisible() || menuChartEdit.isVisible()); + me.menuChartEdit.setVisible(_.isUndefined(value.imgProps) && !_.isUndefined(value.chartProps) && (_.isUndefined(value.shapeProps) || value.shapeProps.isChart)); + menuImgShapeSeparator.setVisible(menuImageAdvanced.isVisible() || menuShapeAdvanced.isVisible() || me.menuChartEdit.isVisible()); /** coauthoring begin **/ - menuAddCommentImg.setVisible(me.api.can_AddQuotedComment()!==false && me.mode.canCoAuthoring && me.mode.canComments); - menuCommentSeparatorImg.setVisible(menuAddCommentImg.isVisible()); - menuAddCommentImg.setDisabled(disabled); + me.menuAddCommentImg.setVisible(me.api.can_AddQuotedComment()!==false && me.mode.canCoAuthoring && me.mode.canComments); + menuCommentSeparatorImg.setVisible(me.menuAddCommentImg.isVisible()); + me.menuAddCommentImg.setDisabled(disabled); /** coauthoring end **/ menuImgShapeAlign.setDisabled(disabled); if (!disabled) { @@ -3637,18 +2596,18 @@ define([ } menuImageAdvanced.setDisabled(disabled); menuShapeAdvanced.setDisabled(disabled); - if (menuChartEdit.isVisible()) - menuChartEdit.setDisabled(disabled); + if (me.menuChartEdit.isVisible()) + me.menuChartEdit.setDisabled(disabled); - menuImgCut.setDisabled(disabled); - menuImgPaste.setDisabled(disabled); + me.menuImgCut.setDisabled(disabled); + me.menuImgPaste.setDisabled(disabled); menuImgShapeArrange.setDisabled(disabled); - menuAddToLayoutImg.setDisabled(disabled); + me.menuAddToLayoutImg.setDisabled(disabled); }, items: [ - menuImgCut, - menuImgCopy, - menuImgPaste, + me.menuImgCut, + me.menuImgCopy, + me.menuImgPaste, { caption: '--' }, menuImgEditPoints, menuImgEditPointsSeparator, @@ -3658,16 +2617,16 @@ define([ menuImgShapeSeparator, me.menuImgCrop, menuImgOriginalSize, - menuImgReplace, + me.menuImgReplace, menuImageAdvanced, menuShapeAdvanced - ,menuChartEdit + ,me.menuChartEdit /** coauthoring begin **/ ,menuCommentSeparatorImg, - menuAddCommentImg, + me.menuAddCommentImg, /** coauthoring end **/ { caption: '--' }, - menuAddToLayoutImg + me.menuAddToLayoutImg ] }).on('hide:after', function(menu, e, isFromInputControl) { if (me.suppressEditComplete) { @@ -3692,6 +2651,8 @@ define([ title : me.textPrevPage + Common.Utils.String.platformKey('PgUp'), placement : 'top-right' }); + + this.fireEvent('createdelayedelements', [this, 'edit']); }, setLanguages: function(langs){ @@ -3738,165 +2699,6 @@ define([ this._isDisabled = state; }, - onInsertImage: function(placeholder, obj, x, y) { - if (this.api) - (placeholder) ? this.api.asc_addImage(obj) : this.api.ChangeImageFromFile(); - this.fireEvent('editcomplete', this); - }, - - onInsertImageUrl: function(placeholder, obj, x, y) { - var me = this; - (new Common.Views.ImageFromUrlDialog({ - handler: function(result, value) { - if (result == 'ok') { - if (me.api) { - var checkUrl = value.replace(/ /g, ''); - if (!_.isEmpty(checkUrl)) { - if (placeholder) - me.api.AddImageUrl([checkUrl], undefined, undefined, obj); - else { - var props = new Asc.asc_CImgProperty(); - props.put_ImageUrl(checkUrl); - me.api.ImgApply(props, obj); - } - } - } - } - me.fireEvent('editcomplete', me); - } - })).show(); - }, - - onClickPlaceholderChart: function(obj, x, y) { - if (!this.api) return; - - this._state.placeholderObj = obj; - var menu = this.placeholderMenuChart, - menuContainer = menu ? this.cmpEl.find(Common.Utils.String.format('#menu-container-{0}', menu.id)) : null, - me = this; - this._fromShowPlaceholder = true; - Common.UI.Menu.Manager.hideAll(); - - if (!menu) { - this.placeholderMenuChart = menu = new Common.UI.Menu({ - style: 'width: 364px;padding-top: 12px;', - items: [ - {template: _.template('')} - ] - }); - // Prepare menu container - menuContainer = $(Common.Utils.String.format('', menu.id)); - this.cmpEl.append(menuContainer); - menu.render(menuContainer); - menu.cmpEl.attr({tabindex: "-1"}); - menu.on('hide:after', function(){ - if (!me._fromShowPlaceholder) - me.api.asc_uncheckPlaceholders(); - }); - - var picker = new Common.UI.DataView({ - el: $('#id-placeholder-menu-chart'), - parentMenu: menu, - showLast: false, - // restoreHeight: 421, - groups: new Common.UI.DataViewGroupStore(Common.define.chartData.getChartGroupData()), - store: new Common.UI.DataViewStore(Common.define.chartData.getChartData()), - itemTemplate: _.template('
\">
') - }); - picker.on('item:click', function (picker, item, record, e) { - me.editChartClick(record.get('type'), me._state.placeholderObj); - }); - } - menuContainer.css({left: x, top : y}); - menuContainer.attr('data-value', 'prevent-canvas-click'); - this._preventClick = true; - menu.show(); - - menu.alignPosition(); - _.delay(function() { - menu.cmpEl.find('.dataview').focus(); - }, 10); - this._fromShowPlaceholder = false; - }, - - onClickPlaceholderTable: function(obj, x, y) { - if (!this.api) return; - - this._state.placeholderObj = obj; - var menu = this.placeholderMenuTable, - menuContainer = menu ? this.cmpEl.find(Common.Utils.String.format('#menu-container-{0}', menu.id)) : null, - me = this; - this._fromShowPlaceholder = true; - Common.UI.Menu.Manager.hideAll(); - - if (!menu) { - this.placeholderMenuTable = menu = new Common.UI.Menu({ - cls: 'shifted-left', - items: [ - {template: _.template('
')}, - {caption: me.mniCustomTable, value: 'custom'} - ] - }); - // Prepare menu container - menuContainer = $(Common.Utils.String.format('', menu.id)); - this.cmpEl.append(menuContainer); - menu.render(menuContainer); - menu.cmpEl.attr({tabindex: "-1"}); - menu.on('hide:after', function(){ - if (!me._fromShowPlaceholder) - me.api.asc_uncheckPlaceholders(); - }); - - var picker = new Common.UI.DimensionPicker({ - el: $('#id-placeholder-menu-tablepicker'), - minRows: 8, - minColumns: 10, - maxRows: 8, - maxColumns: 10 - }); - picker.on('select', function(picker, columns, rows){ - me.api.put_Table(columns, rows, me._state.placeholderObj); - me.fireEvent('editcomplete', me); - }); - menu.on('item:click', function(menu, item, e){ - if (item.value === 'custom') { - (new Common.Views.InsertTableDialog({ - handler: function(result, value) { - if (result == 'ok') - me.api.put_Table(value.columns, value.rows, me._state.placeholderObj); - me.fireEvent('editcomplete', me); - } - })).show(); - } - }); - } - menuContainer.css({left: x, top : y}); - menuContainer.attr('data-value', 'prevent-canvas-click'); - this._preventClick = true; - menu.show(); - - menu.alignPosition(); - _.delay(function() { - menu.cmpEl.focus(); - }, 10); - this._fromShowPlaceholder = false; - }, - - onHidePlaceholderActions: function() { - this.placeholderMenuChart && this.placeholderMenuChart.hide(); - this.placeholderMenuTable && this.placeholderMenuTable.hide(); - }, - - onClickPlaceholder: function(type, obj, x, y) { - if (!this.api) return; - if (type == AscCommon.PlaceholderButtonType.Video) { - this.api.asc_AddVideo(obj); - } else if (type == AscCommon.PlaceholderButtonType.Audio) { - this.api.asc_AddAudio(obj); - } - this.fireEvent('editcomplete', this); - }, - insertRowAboveText : 'Row Above', insertRowBelowText : 'Row Below', insertColumnLeftText : 'Column Left',