3.4.0 • Published 2 years ago

wtc-modal-view v3.4.0

Weekly downloads
107
License
MIT
Repository
github
Last release
2 years ago

wtc-modal-view 3.4.0

A simple, unopinionated modal class.

src/wtc-modal-view.js

new Modal()

A Modal class which can display programatically-generated content, or pull in content from an existing DOM node.

Examples
const myModal = new Modal();
const triggerButton = document.querySelector('trigger');

myModal.optionalClass = "modal--myModal";
myModal.content = '<p>Some sample content!</p>';
myModal.focusOnClose = triggerButton;

triggerButton.addEventListener('click', () => {
  myModal.open();
});
Returns
  • Void

Modal.close()

Closes modal.

If onCloseStartis defined that is called and waits for the callback. Otherwise it removes content and optional class, and shifts user focus back to triggering element, if specified.

Returns
  • Void

open()

Opens modal, adds content and optional CSS class

Returns
  • Void

focusFirstElement()

Shifts focus to the first element inside the content

Returns
  • Void

focusLastElement()

Shifts focus to the last element inside the content

Returns
  • Void

focusOnClose()

Gets the element that will be focused when the modal closes

Returns
  • HTMLElement

focusOnClose(element)

Sets the element that will be focused when the modal closes.
Setter. Usage: modalInstance.focusOnClose = myElement

Parameters
NameTypeDescription
elementHTMLElementMust be a focusable element 
Returns
  • Void

onOpen()

Gets the function that is called when the modal opens

Returns
  • Function

onOpen(callback)

Sets the function that is called when the modal opens. The function gets called with the modals DOM element. Setter. Usage: modalInstance.onOpen = (modalElement) => {}

Parameters
NameTypeDescription
callbackFunction 
Returns
  • Void

onClose()

Get the function that is called when the modal closes

Returns
  • Function

onClose(callback)

Sets the function that is called when the modal closes.
Setter. Usage: modalInstance.onClose = myFunction

Parameters
NameTypeDescription
callbackFunction 
Returns
  • Void

onCloseStart()

Get the function that is called just before the modal closes

Returns
  • Function

onCloseStart(callback)

Sets the function that is called just before the modal closes. If this is set, when modalInstance.close()` is called it will run the set function with a the modal DOM element and a callback. It will then wait for that callback to be run before completing the close function and calling onClose.

Setter. Usage: `modalInstance.onCloseStart = (modalElement, cb) => { // do some animation with modalElement cb();
}

modalInstance.close(); `

Parameters
NameTypeDescription
callbackFunction 
Returns
  • Void

optionalClass(className)

Sets an optional class name on the modal for custom styling.
Setter. Usage: modalInstance.optionalClass = "modal--myclass"

Parameters
NameTypeDescription
classNameString Array 
Returns
  • Void

optionalClass()

Gets the optional class name

Returns
  • String Array optionalClass

closeButtonContent(content)

Sets the content of the close button, useful for localizing.
Setter. Usage: modalInstance.closeButtonContent = "<String of HTML!>"

Parameters
NameTypeDescription
contentstring HTMLElement 
Returns
  • Void

content(content)

Sets the content of the modal.
Setter. Usage: modalInstance.content = MyHTMLElement

Parameters
NameTypeDescription
contentstring HTMLElement 
Returns
  • Void

Documentation generated with doxdox.

3.4.0

2 years ago

3.3.0

3 years ago

3.2.0

3 years ago

3.1.0

3 years ago

3.0.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.5

4 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago