Make elements window-like: a floating titled container, draggable and resizable.
const widget = require('winjet');
const myElm = document.getElementById('target');
widget('My Title', myElm, {options}).mount();
When the first parameter is a string, your widget will get a default header (like in the image above) and the string will be used as the title text. The default header comes with 3 action buttons for closing, maximizing and minimizing the widget.
When the first parameter is an HTMLElement
, it will be used as the widget's whole header. Action buttons are not included.
widget(myHeaderElm, myBodyElm, {options});
IMPORTANT NOTE: Widget is based on classnames & css. Meaning, some of the API methods only manipulate the widget classnames and results can only be seen by using a matching css. You can use
./default-style.css
as a starting point.
-
minWidth
- Number. Resize minimum width in pixels. (default =0
) -
minHeight
- Number. Resize minimum height in pixels. (default =0
) -
top
- Number. Initial top position in pixels. -
bottom
- Number. Initial bottom position in pixels. -
left
- Number. Initial left position in pixels. -
right
- Number. Initial right position in pixels. -
id
- String. The widgetid
attribute. No default. -
classname
- String. The widgetclass
attribute. No default. -
showActions
- Boolean. Show action buttons (maximize, minimize, close). (default =true
) -
showClose
- Boolean. Show theclose
button. (default =true
) -
showMinimize
- Boolean. Show theminimize
button. (default =true
) -
showMaximize
- Boolean. Show themaximize
button. (default =true
) -
showHeader
- Boolean. Show the widget header. (default =true
) -
toggleHeader
- Boolean. Toggle the header visibility on hover. Show on enter, hide on leave. (default =false
) -
toggleActions
- Boolean. Toggle the action buttons visibility on hover. Show on enter, hide on leave. (default =false
)
Calling the widget()
function returns a Widget
instance:
const w = widget(elm);
It has the following methods:
Appends the widget to the <body>
and binds event listeners.
Removes the widget from the DOM and unbinds event listeners.
Toggle widget visibility.
Toggle widget header visibility. If you pass an element or an element selector string, it will be used as the drag grip handle. By default it's the widget title, or the widget body (if there's no header or it's hidden).
Toggle widget action buttons visibility.
Minimizes the widget by hiding its body, only the header is visible.
Reverts the .minimize()
by showing the body. Does not maximize.
Maximizes the widget (fullscreen). Disables drag & resize.
Reverts the .maximize()
to previous widget size. Does not minimize.
Reverts both .minimize()
& .maximize()
.
Sets a new widget title.
Sets a new custom header. Replaces the default header.
Sets a new widget body.
Sets a new widget title and body (or header and body).
Kills the Widget
instance for good, unbinds events, releases element references.
On initialization, the target element will be placed inside the
<body>
element and will be given an inline style ofposition: absolute
.
A widget instance holds two instances of draggable-elm
& resizable-elm
. You can listen to their different events. Check out their docs to learn more.