MCPcopy
hub / github.com/angular-ui/ui-router / bindJQuery

Function bindJQuery

test/angular/1.7/angular.js:2040–2089  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2038
2039var bindJQueryFired = false;
2040function bindJQuery() {
2041 var originalCleanData;
2042
2043 if (bindJQueryFired) {
2044 return;
2045 }
2046
2047 // bind to jQuery if present;
2048 var jqName = jq();
2049 jQuery = isUndefined(jqName) ? window.jQuery : // use jQuery (if present)
2050 !jqName ? undefined : // use jqLite
2051 window[jqName]; // use jQuery specified by `ngJq`
2052
2053 // Use jQuery if it exists with proper functionality, otherwise default to us.
2054 // AngularJS 1.2+ requires jQuery 1.7+ for on()/off() support.
2055 // AngularJS 1.3+ technically requires at least jQuery 2.1+ but it may work with older
2056 // versions. It will not work for sure with jQuery <1.7, though.
2057 if (jQuery && jQuery.fn.on) {
2058 jqLite = jQuery;
2059 extend(jQuery.fn, {
2060 scope: JQLitePrototype.scope,
2061 isolateScope: JQLitePrototype.isolateScope,
2062 controller: /** @type {?} */ (JQLitePrototype).controller,
2063 injector: JQLitePrototype.injector,
2064 inheritedData: JQLitePrototype.inheritedData
2065 });
2066 } else {
2067 jqLite = JQLite;
2068 }
2069
2070 // All nodes removed from the DOM via various jqLite/jQuery APIs like .remove()
2071 // are passed through jqLite/jQuery.cleanData. Monkey-patch this method to fire
2072 // the $destroy event on all removed nodes.
2073 originalCleanData = jqLite.cleanData;
2074 jqLite.cleanData = function(elems) {
2075 var events;
2076 for (var i = 0, elem; (elem = elems[i]) != null; i++) {
2077 events = (jqLite._data(elem) || {}).events;
2078 if (events && events.$destroy) {
2079 jqLite(elem).triggerHandler('$destroy');
2080 }
2081 }
2082 originalCleanData(elems);
2083 };
2084
2085 angular.element = jqLite;
2086
2087 // Prevent double-proxying.
2088 bindJQueryFired = true;
2089}
2090
2091/**
2092 * throw error if the argument is falsy.

Callers 1

angular.jsFile · 0.70

Calls 3

jqFunction · 0.70
isUndefinedFunction · 0.70
extendFunction · 0.70

Tested by

no test coverage detected