onmount

WebJar for onmount

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.bower
Идентификатор

Идентификатор

onmount
Последняя версия

Последняя версия

1.3.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

onmount
WebJar for onmount
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/rstacruz/onmount

Скачать onmount

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.bower/onmount/ -->
<dependency>
    <groupId>org.webjars.bower</groupId>
    <artifactId>onmount</artifactId>
    <version>1.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.bower/onmount/
implementation 'org.webjars.bower:onmount:1.3.0'
// https://jarcasting.com/artifacts/org.webjars.bower/onmount/
implementation ("org.webjars.bower:onmount:1.3.0")
'org.webjars.bower:onmount:jar:1.3.0'
<dependency org="org.webjars.bower" name="onmount" rev="1.3.0">
  <artifact name="onmount" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.bower', module='onmount', version='1.3.0')
)
libraryDependencies += "org.webjars.bower" % "onmount" % "1.3.0"
[org.webjars.bower/onmount "1.3.0"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

onmount

Run something when a DOM element appears and when it exits.
No dependencies. Legacy IE compatible. 1kb .min.gz.

Status

Overview

Detecting elements

Run something to initialize an element on its first appearance.

onmount = require('onmount')

onmount('.push-button', function() {
  $(this).on('click', function() {
    alert('working...')
  })
})

See: Premise

Using with React

🎉 If you're looking to use Onmount to mount React components, check out Remount instead.

Polling for changes

Call $.onmount() everytime your code changes.

$('<button class="push-button">Do something</button>').appendTo('body')

$.onmount()

$('.push-button').click() //=> 'working...'

See: Idempotency

jQuery integration

jQuery is optional; use it to poll on popular events.

$(document).on('ready show.bs closed.bs load page:change', function() {
  $.onmount()
})

See: API

Cleanups

Supply a 2nd function to onmount() to execute something when the node is first detached.

$.onmount(
  '.push-button',
  function() {
    /*...*/
  },
  function() {
    alert('button was removed')
  }
)

document.body.innerHTML = ''

$.onmount() //=> 'button was removed'

See: Cleanups

What for?

Onmount is a safe, reliable, idempotent, and testable way to attach JavaScript behaviors to DOM nodes. It's great for common websites that are not Single-Page Apps. Read more on its premise and motivation.

rsjs (Reasonable System for JavaScript Structure) is a great standard that onmount fits perfectly into.

Usage

Onmount is available via npm and Bower.

npm install onmount
bower install onmount

It can be used as a CommonJS module or on its own. It doesn't require jQuery, but if jQuery is found, it'll attach itself to it as $.onmount.

onmount = require('onmount') // With CommonJS (ie, Browserify)
window.onmount // with no module loaders:
$.onmount // with jQuery

API

See: API

Browser compatibility

All modern browsers and IE8+. For legacy IE, use it with jQuery 1.x.

Examples

Examples are available in the source repo. See examples →

Thanks

onmount © 2015+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz

Версии библиотеки

Версия
1.3.0
1.2.1
1.1.0