MCPcopy
hub / github.com/layui/layui / on

Function on

src/modules/jquery.js:4896–4949  ·  view source on GitHub ↗
(elem, types, selector, data, fn, one)

Source from the content-addressed store, hash-verified

4894 }
4895
4896 function on(elem, types, selector, data, fn, one) {
4897 var origFn, type;
4898
4899 // Types can be a map of types/handlers
4900 if (typeof types === 'object') {
4901 // ( types-Object, selector, data )
4902 if (typeof selector !== 'string') {
4903 // ( types-Object, data )
4904 data = data || selector;
4905 selector = undefined;
4906 }
4907 for (type in types) {
4908 on(elem, type, selector, data, types[type], one);
4909 }
4910 return elem;
4911 }
4912
4913 if (data == null && fn == null) {
4914 // ( types, fn )
4915 fn = selector;
4916 data = selector = undefined;
4917 } else if (fn == null) {
4918 if (typeof selector === 'string') {
4919 // ( types, selector, fn )
4920 fn = data;
4921 data = undefined;
4922 } else {
4923 // ( types, data, fn )
4924 fn = data;
4925 data = selector;
4926 selector = undefined;
4927 }
4928 }
4929 if (fn === false) {
4930 fn = returnFalse;
4931 } else if (!fn) {
4932 return elem;
4933 }
4934
4935 if (one === 1) {
4936 origFn = fn;
4937 fn = function (event) {
4938 // Can use an empty set, since event contains the info
4939 jQuery().off(event);
4940 return origFn.apply(this, arguments);
4941 };
4942
4943 // Use same guid so caller can remove using origFn
4944 fn.guid = origFn.guid || (origFn.guid = jQuery.guid++);
4945 }
4946 return elem.each(function () {
4947 jQuery.event.add(this, types, fn, data, selector);
4948 });
4949 }
4950
4951 /*
4952 * Helper functions for managing events -- not part of the public interface.

Callers 1

jquery.jsFile · 0.85

Calls 1

jQueryFunction · 0.85

Tested by

no test coverage detected