Skip to content

Commit 71e2e23

Browse files
committed
Added "positioning" property to View interface.
1 parent fe15d75 commit 71e2e23

File tree

4 files changed

+78
-5
lines changed

4 files changed

+78
-5
lines changed

src/ko/bindingHandlers/bindingHandlers.helpCenter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ export class HelpCenterBindingHandler {
1919
},
2020
resizing: {
2121
directions: "vertically horizontally",
22-
initialWidth: 500,
23-
initialHeight: 700
22+
initialWidth: 600,
23+
initialHeight: 700,
2424
},
25+
positioning: "center",
2526
scrolling: false
2627
};
2728

src/ko/bindingHandlers/bindingHandlers.surface.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { View } from "@paperbits/common/ui";
33
import "@paperbits/common/extensions";
44
import { ISettingsProvider } from "@paperbits/common/configuration";
5+
import { PositioningOptions } from "@paperbits/common/ui/positioningOptions";
56

67

78
interface EditorSettings {
@@ -52,6 +53,58 @@ export class SurfaceBindingHandler {
5253
element.style.top = editorSettings.top + "px";
5354
}
5455
}
56+
else {
57+
if (view.positioning) {
58+
let positioning: PositioningOptions;
59+
60+
const defaultOffset = 20;
61+
const rect = element.getBoundingClientRect();
62+
63+
if (typeof view.positioning === "string") {
64+
switch (view.positioning) {
65+
case "left":
66+
positioning = {
67+
left: defaultOffset,
68+
top: (document.body.clientHeight / 2) - (rect.height / 2)
69+
};
70+
break;
71+
case "right":
72+
positioning = {
73+
right: defaultOffset,
74+
top: (document.body.clientHeight / 2) - (rect.height / 2)
75+
};
76+
break;
77+
case "top":
78+
positioning = {
79+
top: defaultOffset,
80+
left: (document.body.clientWidth / 2) - (rect.width / 2)
81+
};
82+
break;
83+
case "bottom":
84+
positioning = {
85+
bottom: defaultOffset,
86+
left: (document.body.clientWidth / 2) - (rect.width / 2)
87+
};
88+
break;
89+
case "center":
90+
positioning = {
91+
left: (document.body.clientWidth / 2) - (rect.width / 2),
92+
top: (document.body.clientHeight / 2) - (rect.height / 2)
93+
};
94+
}
95+
}
96+
else {
97+
positioning = view.positioning as PositioningOptions;
98+
}
99+
100+
element.style.left = (document.body.clientWidth / 2) - (rect.width / 2) + "px";
101+
element.style.top = document.body.clientHeight / 2 - rect.height / 2 + "px";
102+
element.style.left = positioning.left ? positioning.left + "px" : null;
103+
element.style.top = positioning.top ? positioning.top + "px" : null;
104+
element.style.right = positioning.right ? positioning.right + "px" : null;
105+
element.style.bottom = positioning.bottom ? positioning.bottom + "px" : null;
106+
}
107+
}
55108

56109
ko.applyBindingsToNode(element, {
57110
dragsource: {

src/ko/ui/defaultViewManager.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ <h1 class="toast-header" data-bind="text: title"></h1>
3333

3434
<!-- ko with: activeView() -->
3535
<div role="dialog" aria-labelledby="popupHeading" tabindex="-1"
36-
class="toolbox toolbox-popup toolbox-position-left-offset"
36+
class="toolbox toolbox-popup"
3737
data-bind="resizable: resizing, surface: $data, dialog: {}">
3838
<div role="document" class="editor resizable-content flex flex-column">
3939
<!-- ko if: heading -->

src/ko/ui/defaultViewManager.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ViewStack } from "@paperbits/common/ui/viewStack";
1717
import { ISettingsProvider } from "@paperbits/common/configuration";
1818

1919
declare let uploadDialog: HTMLInputElement;
20+
const defaultEditorWidth = 320;
2021

2122

2223
@Component({
@@ -375,7 +376,25 @@ export class DefaultViewManager implements ViewManager {
375376
}
376377

377378
if (!view.resizing) {
378-
view.resizing = "vertically horizontally";
379+
view.resizing = {
380+
directions: "vertically horizontally",
381+
initialWidth: defaultEditorWidth
382+
}
383+
}
384+
else {
385+
if (typeof view.resizing === "string" && view.name !== "text-block-editor") {
386+
view.resizing = {
387+
directions: view.resizing,
388+
initialWidth: defaultEditorWidth
389+
};
390+
}
391+
}
392+
393+
if (!view.positioning) {
394+
view.positioning = {
395+
top: 20,
396+
left: 150
397+
}
379398
}
380399

381400
this.clearContextualCommands();
@@ -443,7 +462,7 @@ export class DefaultViewManager implements ViewManager {
443462
},
444463
scrolling: "editorScrolling" in binding ? <boolean>binding.editorScrolling : true,
445464
heading: binding.displayName,
446-
resizing: <string>binding.editorResizing || "vertically horizontally",
465+
resizing: <string>binding.editorResizing,
447466
returnFocusTo: document.getElementById("contentEditor")
448467
};
449468

0 commit comments

Comments
 (0)