diff --git a/public/res/eventMgr.js b/public/res/eventMgr.js index 331b7f8d..ab0adcbf 100644 --- a/public/res/eventMgr.js +++ b/public/res/eventMgr.js @@ -198,6 +198,7 @@ define([ // Operations on Layout addEventHook("onLayoutCreated"); addEventHook("onLayoutResize"); + addEventHook("onExtensionButtonResize"); // Operations on editor addEventHook("onPagedownConfigure"); diff --git a/public/res/extensions/buttonStat.js b/public/res/extensions/buttonStat.js index b9f7ec62..ba3cb9e0 100644 --- a/public/res/extensions/buttonStat.js +++ b/public/res/extensions/buttonStat.js @@ -4,7 +4,7 @@ define([ "utils", "classes/Extension", "text!html/buttonStat.html", - "text!html/buttonStatSettingsBlock.html", + "text!html/buttonStatSettingsBlock.html" ], function($, _, utils, Extension, buttonStatHTML, buttonStatSettingsBlockHTML) { var buttonStat = new Extension("buttonStat", 'Button "Statistics"', true, true); @@ -15,7 +15,12 @@ define([ name2: "Words", value2: "\\S+", name3: "Paragraphs", - value3: "\\S.*", + value3: "\\S.*" + }; + + var eventMgr; + buttonStat.onEventMgrCreated = function(eventMgrParam) { + eventMgr = eventMgrParam; }; buttonStat.onLoadSettings = function() { @@ -72,6 +77,7 @@ define([ valueElt.textContent = value1Elt.textContent = (text.match(regex1) || []).length; value2Elt.textContent = (text.match(regex2) || []).length; value3Elt.textContent = (text.match(regex3) || []).length; + eventMgr.onExtensionButtonResize(); }; return buttonStat; diff --git a/public/res/layout.js b/public/res/layout.js index d4398acb..1ec59696 100644 --- a/public/res/layout.js +++ b/public/res/layout.js @@ -25,6 +25,7 @@ define([ var menuPanelWidth = 280; var documentPanelWidth = 320; var titleMinWidth = 200; + var previewButtonsClosedOffset = 18; var previewButtonsDropdownMargin = 130; var previewButtonsOffset = { x: -45, @@ -606,10 +607,14 @@ define([ previewButtons.x = previewButtonsOffset.x; previewButtons.y = previewButtonsOffset.y; previewButtons.applyCss(); + setTimeout(function() { + previewButtons.$elt.addClass('animate'); + }, 0); function openPreviewButtons() { clearTimeout(closeTimeoutId); if(!previewButtons.isDragged) { + previewButtons.isOpen = true; previewButtons.x = previewButtonsOffset.x; previewButtons.applyCss(); } @@ -622,13 +627,14 @@ define([ clearTimeout(closeTimeoutId); closeTimeoutId = setTimeout(function() { if(!previewButtons.isDragged && !dropdownOpen) { - previewButtons.$elt.addClass('animate'); - previewButtons.x = previewButtonsOffset.x + previewButtons.elt.offsetWidth; + previewButtons.isOpen = false; + previewButtons.x = previewButtonsOffset.x + previewButtons.elt.offsetWidth + previewButtonsClosedOffset; previewButtons.applyCss(); } }, 3000); } + openPreviewButtons(); closePreviewButtons(); previewButtons.$elt.hover(openPreviewButtons, closePreviewButtons).on('show.bs.dropdown', function() { dropdownOpen = true; @@ -656,6 +662,22 @@ define([ }); }); + eventMgr.addListener('onExtensionButtonResize', function() { + if(!previewButtons.isDragged) { + if(!previewButtons.isOpen) { + previewButtons.$elt.removeClass('animate'); + previewButtons.x = previewButtonsOffset.x + previewButtons.elt.offsetWidth + previewButtonsClosedOffset; + previewButtons.applyCss(); + setTimeout(function() { + previewButtons.$elt.addClass('animate'); + }, 0); + } + } + else { + previewButtons.adjustPosition(); + } + }); + eventMgr.onLayoutCreated(layout); return layout; });