Windowise Docs

Basic Ideas

Windowise is a Promise-based library. Every window class (Window/Modal/Input/Nft/Push) has a getPromise() method. When you call open(), it will create a new Promise for the instance. This Promise will be resolved/rejected just after the window closes. That is to say when the class has just been constructed (before you call open()), it DOES NOT have a Promise.

For complex windows, one suggestion is create another layer to control all contents and the window itself (just like what I did in Modal/Input/Nft/Push). Since you can pass your content as a dom, it is easy to change anything inside.

class Window

constructor(options)

options.title | string or dom

Value will be shown in the topbar.

options.content | string or dom
options.animation | string

default: 'pop'

acceptable: 'pop', 'flip', 'left', 'top', 'right', 'bottom', 'min', null

options.topbar | object or boolean

default: { showCloseButton: true, showMinButton: false }

Topbar will not show when the value is false.

options.overlay | boolean

default: false

options.keepOverlay | boolean

default: false

Indicate overlay will be removed or not after window closes.

options.clickOverlayToClose | boolean

default: true

Take effect when options.overlay=true.

options.position | string

default: 'center'

examples: '30% bottom', 'right top', 'left 500px'

You can specify two keywords, while the first one indicates the position of X axis and the second one indicates the position of Y axis.

If you only specify one keyword, the other value will be 'center'.

Note: All values are indicates the position of window's mid point except 'left', 'right', 'top' and 'bottom'.

options.removeBackground | boolean

default: false

Indicate remove content's background or not.

options.noRadius | boolean

default: false

Indicate remove window's border radius or not.

options.draggable | boolean or string

default: false

acceptable: true, false, 'horizontal', 'vertical'

options.style | object

Apply specific style to the window.

options.margin | string

Apply margin to the window. Acceptable values are same as CSS margin property.

getPromise()

Return current Promise. You should recall this method when you re-open the window.

open()

Open the window. It returns a Promise which will be resolved when the window has been opened (after animations).

close()

Close the window. It returns a Promise which will be resolved when the window has been closed (after animations). NOTE: It is not the same Promise when you call getPromise()!

resume()

Resume the window. Basically it is a open() with { animation: 'min' }.

min()

Minimize the window. Basically it is a close() with { animation: 'min' }.

static create(dom, options)

Helps you to create your window. It will use the content of the first div in dom with class 'title' as title, and use the content of the first div with class 'content' as content. Other options are same as options in constructor.

constructor(options)

options.type | string

default: 'ok'

acceptable: 'ok', 'info', 'caution', 'error'

It changes the icon and color of the modal.

options.title | string
options.text | string
options.content | string or dom

You can put your own content in it.

options.animation | string

Same as Window()

options.keepOverlay | boolean

Same as Window()

options.buttons | array

An array of buttons. Different types have different default configs. See button config for details.

options.closeAfter | number

Close the modal after specific time. Unit: ms. If the modal is closed by timer, the Promise will be resolved with 'timer'.

NOTE: Modals always have overlay.

open()

Same as Window().

close()

Same as Window().

getPromise()

If you specified button ids, this Promise will resolve the button id that user clicked after the modal closes.

class Input

constructor(options)

options.type | string

default: 'info'

Same as Modal().

options.keepOverlay | boolean

Same as Window().

options.title | string

default: 'Input'

options.text | string
options.okText | string

default: 'OK'

options.cancelText | string

default: 'Cancel'

options.showCancel | boolean

default: false

options.placeholder | string

default: ''

Placeholder for the input.

options.validator | function

default: null

If it is not null, Input will call this validator and pass the value of the input when user is clicking OK button. Validator should return a Promise while resolved means passed and rejected means error occured. See specific usage in this demo.

open()

Same as Window().

close()

Same as Window().

getPromise()

Promise will be resolved if user clicks OK button and passes validation. It will be rejected if user clicks cancel button.

class Nft

constructor(options)

options.type | string

default: null

acceptable: null, 'ok', 'info', 'caution', 'error', 'text'

options.content | string or dom
options.animation | string

default: 'right'

Same as Window()

options.position | string

default: 'right top'

Same as Window()

options.showClose | boolean

default: true

Show the close button in the right.

options.clickToClose | boolean

default: false

Indicate it will close or not when user clicks notification body.

options.closeAfter | number

Close the notification after specific time. Unit: ms.

options.style | object

Same as Window().

open()

close()

getPromise()

Same as Window().

class Push

constructor(options)

options.type | string

default: null

acceptable: null, 'ok', 'info', 'caution', 'error', 'text'

options.content | string or dom
options.position | string

default: 'top'

acceptable: 'top', 'bottom'

options.overlay | boolean

default: false

options.clickOverlayToClose | boolean

default: false

options.style | object

Apply specific style to the push.

options.textAlign | string

default: 'center'

options.clickToClose | boolean

default: false

Indicate it will close or not when user clicks push body.

options.closeAfter | number

Close the notification after specific time. Unit: ms.

options.append | string or dom

Append something after content.

options.buttons | array

default: []

An array of buttons. See button config for details.

open()

close()

getPromise()

Same as Window().

Button Configuration

{ id, key, text, normal, onClick }

id | string

If onClick is not specified, the Promise will be resolved with this value when user clicks the button.

key | number

Not necessary. Indicate which key will triiger this button. You can find key codes on keycode.info or css-tricks.

text | string
normal | boolean

Change the style of the button.

onClick | function

If it is specified, the Window will NOT close and the Promise will NOT be resolved automatically when user clicks the button. You should handle these by yourself.

class Progress

constructor(options)

options.percentage | boolean

If it is true, the progress bar will change the width by percentage instead of showing loop animation.

options.color | string

Change the color of the bar.

set(value)

value | number

Set percentage.

End of Docs