MCPcopy Create free account
hub / github.com/angular/angular / initialize

Method initialize

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

Source from the content-addressed store, hash-verified

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