Fixed position of extension buttons

This commit is contained in:
benweet 2014-05-27 14:33:51 +01:00
parent c2055098a1
commit 81b37f3f1e
3 changed files with 33 additions and 4 deletions

View File

@ -198,6 +198,7 @@ define([
// Operations on Layout // Operations on Layout
addEventHook("onLayoutCreated"); addEventHook("onLayoutCreated");
addEventHook("onLayoutResize"); addEventHook("onLayoutResize");
addEventHook("onExtensionButtonResize");
// Operations on editor // Operations on editor
addEventHook("onPagedownConfigure"); addEventHook("onPagedownConfigure");

View File

@ -4,7 +4,7 @@ define([
"utils", "utils",
"classes/Extension", "classes/Extension",
"text!html/buttonStat.html", "text!html/buttonStat.html",
"text!html/buttonStatSettingsBlock.html", "text!html/buttonStatSettingsBlock.html"
], function($, _, utils, Extension, buttonStatHTML, buttonStatSettingsBlockHTML) { ], function($, _, utils, Extension, buttonStatHTML, buttonStatSettingsBlockHTML) {
var buttonStat = new Extension("buttonStat", 'Button "Statistics"', true, true); var buttonStat = new Extension("buttonStat", 'Button "Statistics"', true, true);
@ -15,7 +15,12 @@ define([
name2: "Words", name2: "Words",
value2: "\\S+", value2: "\\S+",
name3: "Paragraphs", name3: "Paragraphs",
value3: "\\S.*", value3: "\\S.*"
};
var eventMgr;
buttonStat.onEventMgrCreated = function(eventMgrParam) {
eventMgr = eventMgrParam;
}; };
buttonStat.onLoadSettings = function() { buttonStat.onLoadSettings = function() {
@ -72,6 +77,7 @@ define([
valueElt.textContent = value1Elt.textContent = (text.match(regex1) || []).length; valueElt.textContent = value1Elt.textContent = (text.match(regex1) || []).length;
value2Elt.textContent = (text.match(regex2) || []).length; value2Elt.textContent = (text.match(regex2) || []).length;
value3Elt.textContent = (text.match(regex3) || []).length; value3Elt.textContent = (text.match(regex3) || []).length;
eventMgr.onExtensionButtonResize();
}; };
return buttonStat; return buttonStat;

View File

@ -25,6 +25,7 @@ define([
var menuPanelWidth = 280; var menuPanelWidth = 280;
var documentPanelWidth = 320; var documentPanelWidth = 320;
var titleMinWidth = 200; var titleMinWidth = 200;
var previewButtonsClosedOffset = 18;
var previewButtonsDropdownMargin = 130; var previewButtonsDropdownMargin = 130;
var previewButtonsOffset = { var previewButtonsOffset = {
x: -45, x: -45,
@ -606,10 +607,14 @@ define([
previewButtons.x = previewButtonsOffset.x; previewButtons.x = previewButtonsOffset.x;
previewButtons.y = previewButtonsOffset.y; previewButtons.y = previewButtonsOffset.y;
previewButtons.applyCss(); previewButtons.applyCss();
setTimeout(function() {
previewButtons.$elt.addClass('animate');
}, 0);
function openPreviewButtons() { function openPreviewButtons() {
clearTimeout(closeTimeoutId); clearTimeout(closeTimeoutId);
if(!previewButtons.isDragged) { if(!previewButtons.isDragged) {
previewButtons.isOpen = true;
previewButtons.x = previewButtonsOffset.x; previewButtons.x = previewButtonsOffset.x;
previewButtons.applyCss(); previewButtons.applyCss();
} }
@ -622,13 +627,14 @@ define([
clearTimeout(closeTimeoutId); clearTimeout(closeTimeoutId);
closeTimeoutId = setTimeout(function() { closeTimeoutId = setTimeout(function() {
if(!previewButtons.isDragged && !dropdownOpen) { if(!previewButtons.isDragged && !dropdownOpen) {
previewButtons.$elt.addClass('animate'); previewButtons.isOpen = false;
previewButtons.x = previewButtonsOffset.x + previewButtons.elt.offsetWidth; previewButtons.x = previewButtonsOffset.x + previewButtons.elt.offsetWidth + previewButtonsClosedOffset;
previewButtons.applyCss(); previewButtons.applyCss();
} }
}, 3000); }, 3000);
} }
openPreviewButtons();
closePreviewButtons(); closePreviewButtons();
previewButtons.$elt.hover(openPreviewButtons, closePreviewButtons).on('show.bs.dropdown', function() { previewButtons.$elt.hover(openPreviewButtons, closePreviewButtons).on('show.bs.dropdown', function() {
dropdownOpen = true; 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); eventMgr.onLayoutCreated(layout);
return layout; return layout;
}); });