MCPcopy
hub / github.com/angular/angular / initialize

Method initialize

packages/common/upgrade/src/location_shim.ts:98–261  ·  view source on GitHub ↗
($injector: any)

Source from the content-addressed store, hash-verified

96 }
97
98 private initialize($injector: any) {
99 const $rootScope = $injector.get('$rootScope');
100 const $rootElement = $injector.get('$rootElement');
101
102 $rootElement.on('click', (event: any) => {
103 if (
104 event.ctrlKey ||
105 event.metaKey ||
106 event.shiftKey ||
107 event.which === 2 ||
108 event.button === 2
109 ) {
110 return;
111 }
112
113 let elm: (Node & ParentNode) | null = event.target;
114
115 // traverse the DOM up to find first A tag
116 while (elm && elm.nodeName.toLowerCase() !== 'a') {
117 // ignore rewriting if no A tag (reached root element, or no parent - removed from document)
118 if (elm === $rootElement[0] || !(elm = elm.parentNode)) {
119 return;
120 }
121 }
122
123 if (!isAnchor(elm)) {
124 return;
125 }
126
127 const absHref = elm.href;
128 const relHref = elm.getAttribute('href');
129
130 // Ignore when url is started with javascript: or mailto:
131 if (IGNORE_URI_REGEXP.test(absHref)) {
132 return;
133 }
134
135 if (absHref && !elm.getAttribute('target') && !event.isDefaultPrevented()) {
136 if (this.$$parseLinkUrl(absHref, relHref)) {
137 // We do a preventDefault for all urls that are part of the AngularJS application,
138 // in html5mode and also without, so that we are able to abort navigation without
139 // getting double entries in the location history.
140 event.preventDefault();
141 // update location manually
142 if (this.absUrl() !== this.browserUrl()) {
143 $rootScope.$apply();
144 }
145 }
146 }
147 });
148
149 this.urlChanges.subscribe(({newUrl, newState}) => {
150 const oldUrl = this.absUrl();
151 const oldState = this.$$state;
152 this.$$parse(newUrl);
153 newUrl = this.absUrl();
154 this.$$state = newState;
155 const defaultPrevented = $rootScope.$broadcast(

Callers 1

constructorMethod · 0.95

Calls 15

$$parseLinkUrlMethod · 0.95
absUrlMethod · 0.95
browserUrlMethod · 0.95
$$parseMethod · 0.95
stateMethod · 0.95
urlMethod · 0.95
resetBrowserUpdateMethod · 0.95
browserStateMethod · 0.95
isAnchorFunction · 0.90
areEqualMethod · 0.80

Tested by

no test coverage detected