router.dev.js 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972
  1. "format register";
  2. System.register("angular2/src/router/router_link_transform", ["angular2/compiler", "angular2/src/core/change_detection/parser/ast", "angular2/src/facade/exceptions", "angular2/core", "angular2/src/core/change_detection/parser/parser"], true, function(require, exports, module) {
  3. var global = System.global,
  4. __define = global.define;
  5. global.define = undefined;
  6. var __extends = (this && this.__extends) || function(d, b) {
  7. for (var p in b)
  8. if (b.hasOwnProperty(p))
  9. d[p] = b[p];
  10. function __() {
  11. this.constructor = d;
  12. }
  13. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  14. };
  15. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  16. var c = arguments.length,
  17. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  18. d;
  19. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  20. r = Reflect.decorate(decorators, target, key, desc);
  21. else
  22. for (var i = decorators.length - 1; i >= 0; i--)
  23. if (d = decorators[i])
  24. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  25. return c > 3 && r && Object.defineProperty(target, key, r), r;
  26. };
  27. var __metadata = (this && this.__metadata) || function(k, v) {
  28. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  29. return Reflect.metadata(k, v);
  30. };
  31. var compiler_1 = require("angular2/compiler");
  32. var ast_1 = require("angular2/src/core/change_detection/parser/ast");
  33. var exceptions_1 = require("angular2/src/facade/exceptions");
  34. var core_1 = require("angular2/core");
  35. var parser_1 = require("angular2/src/core/change_detection/parser/parser");
  36. var FixedPart = (function() {
  37. function FixedPart(value) {
  38. this.value = value;
  39. }
  40. return FixedPart;
  41. })();
  42. var AuxiliaryStart = (function() {
  43. function AuxiliaryStart() {}
  44. return AuxiliaryStart;
  45. })();
  46. var AuxiliaryEnd = (function() {
  47. function AuxiliaryEnd() {}
  48. return AuxiliaryEnd;
  49. })();
  50. var Params = (function() {
  51. function Params(ast) {
  52. this.ast = ast;
  53. }
  54. return Params;
  55. })();
  56. var RouterLinkLexer = (function() {
  57. function RouterLinkLexer(parser, exp) {
  58. this.parser = parser;
  59. this.exp = exp;
  60. this.index = 0;
  61. }
  62. RouterLinkLexer.prototype.tokenize = function() {
  63. var tokens = [];
  64. while (this.index < this.exp.length) {
  65. tokens.push(this._parseToken());
  66. }
  67. return tokens;
  68. };
  69. RouterLinkLexer.prototype._parseToken = function() {
  70. var c = this.exp[this.index];
  71. if (c == '[') {
  72. this.index++;
  73. return new AuxiliaryStart();
  74. } else if (c == ']') {
  75. this.index++;
  76. return new AuxiliaryEnd();
  77. } else if (c == '(') {
  78. return this._parseParams();
  79. } else if (c == '/' && this.index !== 0) {
  80. this.index++;
  81. return this._parseFixedPart();
  82. } else {
  83. return this._parseFixedPart();
  84. }
  85. };
  86. RouterLinkLexer.prototype._parseParams = function() {
  87. var start = this.index;
  88. for (; this.index < this.exp.length; ++this.index) {
  89. var c = this.exp[this.index];
  90. if (c == ')') {
  91. var paramsContent = this.exp.substring(start + 1, this.index);
  92. this.index++;
  93. return new Params(this.parser.parseBinding("{" + paramsContent + "}", null).ast);
  94. }
  95. }
  96. throw new exceptions_1.BaseException("Cannot find ')'");
  97. };
  98. RouterLinkLexer.prototype._parseFixedPart = function() {
  99. var start = this.index;
  100. var sawNonSlash = false;
  101. for (; this.index < this.exp.length; ++this.index) {
  102. var c = this.exp[this.index];
  103. if (c == '(' || c == '[' || c == ']' || (c == '/' && sawNonSlash)) {
  104. break;
  105. }
  106. if (c != '.' && c != '/') {
  107. sawNonSlash = true;
  108. }
  109. }
  110. var fixed = this.exp.substring(start, this.index);
  111. if (start === this.index || !sawNonSlash || fixed.startsWith('//')) {
  112. throw new exceptions_1.BaseException("Invalid router link");
  113. }
  114. return new FixedPart(fixed);
  115. };
  116. return RouterLinkLexer;
  117. })();
  118. var RouterLinkAstGenerator = (function() {
  119. function RouterLinkAstGenerator(tokens) {
  120. this.tokens = tokens;
  121. this.index = 0;
  122. }
  123. RouterLinkAstGenerator.prototype.generate = function() {
  124. return this._genAuxiliary();
  125. };
  126. RouterLinkAstGenerator.prototype._genAuxiliary = function() {
  127. var arr = [];
  128. for (; this.index < this.tokens.length; this.index++) {
  129. var r = this.tokens[this.index];
  130. if (r instanceof FixedPart) {
  131. arr.push(new ast_1.LiteralPrimitive(r.value));
  132. } else if (r instanceof Params) {
  133. arr.push(r.ast);
  134. } else if (r instanceof AuxiliaryEnd) {
  135. break;
  136. } else if (r instanceof AuxiliaryStart) {
  137. this.index++;
  138. arr.push(this._genAuxiliary());
  139. }
  140. }
  141. return new ast_1.LiteralArray(arr);
  142. };
  143. return RouterLinkAstGenerator;
  144. })();
  145. var RouterLinkAstTransformer = (function(_super) {
  146. __extends(RouterLinkAstTransformer, _super);
  147. function RouterLinkAstTransformer(parser) {
  148. _super.call(this);
  149. this.parser = parser;
  150. }
  151. RouterLinkAstTransformer.prototype.visitQuote = function(ast) {
  152. if (ast.prefix == "route") {
  153. return parseRouterLinkExpression(this.parser, ast.uninterpretedExpression);
  154. } else {
  155. return _super.prototype.visitQuote.call(this, ast);
  156. }
  157. };
  158. return RouterLinkAstTransformer;
  159. })(ast_1.AstTransformer);
  160. function parseRouterLinkExpression(parser, exp) {
  161. var tokens = new RouterLinkLexer(parser, exp.trim()).tokenize();
  162. return new RouterLinkAstGenerator(tokens).generate();
  163. }
  164. exports.parseRouterLinkExpression = parseRouterLinkExpression;
  165. var RouterLinkTransform = (function() {
  166. function RouterLinkTransform(parser) {
  167. this.astTransformer = new RouterLinkAstTransformer(parser);
  168. }
  169. RouterLinkTransform.prototype.visitNgContent = function(ast, context) {
  170. return ast;
  171. };
  172. RouterLinkTransform.prototype.visitEmbeddedTemplate = function(ast, context) {
  173. return ast;
  174. };
  175. RouterLinkTransform.prototype.visitElement = function(ast, context) {
  176. var _this = this;
  177. var updatedChildren = ast.children.map(function(c) {
  178. return c.visit(_this, context);
  179. });
  180. var updatedInputs = ast.inputs.map(function(c) {
  181. return c.visit(_this, context);
  182. });
  183. var updatedDirectives = ast.directives.map(function(c) {
  184. return c.visit(_this, context);
  185. });
  186. return new compiler_1.ElementAst(ast.name, ast.attrs, updatedInputs, ast.outputs, ast.exportAsVars, updatedDirectives, updatedChildren, ast.ngContentIndex, ast.sourceSpan);
  187. };
  188. RouterLinkTransform.prototype.visitVariable = function(ast, context) {
  189. return ast;
  190. };
  191. RouterLinkTransform.prototype.visitEvent = function(ast, context) {
  192. return ast;
  193. };
  194. RouterLinkTransform.prototype.visitElementProperty = function(ast, context) {
  195. return ast;
  196. };
  197. RouterLinkTransform.prototype.visitAttr = function(ast, context) {
  198. return ast;
  199. };
  200. RouterLinkTransform.prototype.visitBoundText = function(ast, context) {
  201. return ast;
  202. };
  203. RouterLinkTransform.prototype.visitText = function(ast, context) {
  204. return ast;
  205. };
  206. RouterLinkTransform.prototype.visitDirective = function(ast, context) {
  207. var _this = this;
  208. var updatedInputs = ast.inputs.map(function(c) {
  209. return c.visit(_this, context);
  210. });
  211. return new compiler_1.DirectiveAst(ast.directive, updatedInputs, ast.hostProperties, ast.hostEvents, ast.exportAsVars, ast.sourceSpan);
  212. };
  213. RouterLinkTransform.prototype.visitDirectiveProperty = function(ast, context) {
  214. var transformedValue = ast.value.visit(this.astTransformer);
  215. return new compiler_1.BoundDirectivePropertyAst(ast.directiveName, ast.templateName, transformedValue, ast.sourceSpan);
  216. };
  217. RouterLinkTransform = __decorate([core_1.Injectable(), __metadata('design:paramtypes', [parser_1.Parser])], RouterLinkTransform);
  218. return RouterLinkTransform;
  219. })();
  220. exports.RouterLinkTransform = RouterLinkTransform;
  221. global.define = __define;
  222. return module.exports;
  223. });
  224. System.register("angular2/router/router_link_dsl", ["angular2/compiler", "angular2/core", "angular2/src/router/router_link_transform", "angular2/src/facade/lang", "angular2/src/router/router_link_transform"], true, function(require, exports, module) {
  225. var global = System.global,
  226. __define = global.define;
  227. global.define = undefined;
  228. var compiler_1 = require("angular2/compiler");
  229. var core_1 = require("angular2/core");
  230. var router_link_transform_1 = require("angular2/src/router/router_link_transform");
  231. var lang_1 = require("angular2/src/facade/lang");
  232. var router_link_transform_2 = require("angular2/src/router/router_link_transform");
  233. exports.RouterLinkTransform = router_link_transform_2.RouterLinkTransform;
  234. exports.ROUTER_LINK_DSL_PROVIDER = lang_1.CONST_EXPR(new core_1.Provider(compiler_1.TEMPLATE_TRANSFORMS, {
  235. useClass: router_link_transform_1.RouterLinkTransform,
  236. multi: true
  237. }));
  238. global.define = __define;
  239. return module.exports;
  240. });
  241. System.register("angular2/src/router/route_config_impl", ["angular2/src/facade/lang"], true, function(require, exports, module) {
  242. var global = System.global,
  243. __define = global.define;
  244. global.define = undefined;
  245. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  246. var c = arguments.length,
  247. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  248. d;
  249. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  250. r = Reflect.decorate(decorators, target, key, desc);
  251. else
  252. for (var i = decorators.length - 1; i >= 0; i--)
  253. if (d = decorators[i])
  254. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  255. return c > 3 && r && Object.defineProperty(target, key, r), r;
  256. };
  257. var __metadata = (this && this.__metadata) || function(k, v) {
  258. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  259. return Reflect.metadata(k, v);
  260. };
  261. var lang_1 = require("angular2/src/facade/lang");
  262. var RouteConfig = (function() {
  263. function RouteConfig(configs) {
  264. this.configs = configs;
  265. }
  266. RouteConfig = __decorate([lang_1.CONST(), __metadata('design:paramtypes', [Array])], RouteConfig);
  267. return RouteConfig;
  268. })();
  269. exports.RouteConfig = RouteConfig;
  270. var Route = (function() {
  271. function Route(_a) {
  272. var path = _a.path,
  273. component = _a.component,
  274. name = _a.name,
  275. data = _a.data,
  276. useAsDefault = _a.useAsDefault;
  277. this.aux = null;
  278. this.loader = null;
  279. this.redirectTo = null;
  280. this.path = path;
  281. this.component = component;
  282. this.name = name;
  283. this.data = data;
  284. this.useAsDefault = useAsDefault;
  285. }
  286. Route = __decorate([lang_1.CONST(), __metadata('design:paramtypes', [Object])], Route);
  287. return Route;
  288. })();
  289. exports.Route = Route;
  290. var AuxRoute = (function() {
  291. function AuxRoute(_a) {
  292. var path = _a.path,
  293. component = _a.component,
  294. name = _a.name;
  295. this.data = null;
  296. this.aux = null;
  297. this.loader = null;
  298. this.redirectTo = null;
  299. this.useAsDefault = false;
  300. this.path = path;
  301. this.component = component;
  302. this.name = name;
  303. }
  304. AuxRoute = __decorate([lang_1.CONST(), __metadata('design:paramtypes', [Object])], AuxRoute);
  305. return AuxRoute;
  306. })();
  307. exports.AuxRoute = AuxRoute;
  308. var AsyncRoute = (function() {
  309. function AsyncRoute(_a) {
  310. var path = _a.path,
  311. loader = _a.loader,
  312. name = _a.name,
  313. data = _a.data,
  314. useAsDefault = _a.useAsDefault;
  315. this.aux = null;
  316. this.path = path;
  317. this.loader = loader;
  318. this.name = name;
  319. this.data = data;
  320. this.useAsDefault = useAsDefault;
  321. }
  322. AsyncRoute = __decorate([lang_1.CONST(), __metadata('design:paramtypes', [Object])], AsyncRoute);
  323. return AsyncRoute;
  324. })();
  325. exports.AsyncRoute = AsyncRoute;
  326. var Redirect = (function() {
  327. function Redirect(_a) {
  328. var path = _a.path,
  329. redirectTo = _a.redirectTo;
  330. this.name = null;
  331. this.loader = null;
  332. this.data = null;
  333. this.aux = null;
  334. this.useAsDefault = false;
  335. this.path = path;
  336. this.redirectTo = redirectTo;
  337. }
  338. Redirect = __decorate([lang_1.CONST(), __metadata('design:paramtypes', [Object])], Redirect);
  339. return Redirect;
  340. })();
  341. exports.Redirect = Redirect;
  342. global.define = __define;
  343. return module.exports;
  344. });
  345. System.register("angular2/src/router/instruction", ["angular2/src/facade/collection", "angular2/src/facade/lang", "angular2/src/facade/async"], true, function(require, exports, module) {
  346. var global = System.global,
  347. __define = global.define;
  348. global.define = undefined;
  349. var __extends = (this && this.__extends) || function(d, b) {
  350. for (var p in b)
  351. if (b.hasOwnProperty(p))
  352. d[p] = b[p];
  353. function __() {
  354. this.constructor = d;
  355. }
  356. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  357. };
  358. var collection_1 = require("angular2/src/facade/collection");
  359. var lang_1 = require("angular2/src/facade/lang");
  360. var async_1 = require("angular2/src/facade/async");
  361. var RouteParams = (function() {
  362. function RouteParams(params) {
  363. this.params = params;
  364. }
  365. RouteParams.prototype.get = function(param) {
  366. return lang_1.normalizeBlank(collection_1.StringMapWrapper.get(this.params, param));
  367. };
  368. return RouteParams;
  369. })();
  370. exports.RouteParams = RouteParams;
  371. var RouteData = (function() {
  372. function RouteData(data) {
  373. if (data === void 0) {
  374. data = lang_1.CONST_EXPR({});
  375. }
  376. this.data = data;
  377. }
  378. RouteData.prototype.get = function(key) {
  379. return lang_1.normalizeBlank(collection_1.StringMapWrapper.get(this.data, key));
  380. };
  381. return RouteData;
  382. })();
  383. exports.RouteData = RouteData;
  384. exports.BLANK_ROUTE_DATA = new RouteData();
  385. var Instruction = (function() {
  386. function Instruction() {
  387. this.auxInstruction = {};
  388. }
  389. Object.defineProperty(Instruction.prototype, "urlPath", {
  390. get: function() {
  391. return this.component.urlPath;
  392. },
  393. enumerable: true,
  394. configurable: true
  395. });
  396. Object.defineProperty(Instruction.prototype, "urlParams", {
  397. get: function() {
  398. return this.component.urlParams;
  399. },
  400. enumerable: true,
  401. configurable: true
  402. });
  403. Object.defineProperty(Instruction.prototype, "specificity", {
  404. get: function() {
  405. var total = 0;
  406. if (lang_1.isPresent(this.component)) {
  407. total += this.component.specificity;
  408. }
  409. if (lang_1.isPresent(this.child)) {
  410. total += this.child.specificity;
  411. }
  412. return total;
  413. },
  414. enumerable: true,
  415. configurable: true
  416. });
  417. Instruction.prototype.toRootUrl = function() {
  418. return this.toUrlPath() + this.toUrlQuery();
  419. };
  420. Instruction.prototype._toNonRootUrl = function() {
  421. return this._stringifyPathMatrixAuxPrefixed() + (lang_1.isPresent(this.child) ? this.child._toNonRootUrl() : '');
  422. };
  423. Instruction.prototype.toUrlQuery = function() {
  424. return this.urlParams.length > 0 ? ('?' + this.urlParams.join('&')) : '';
  425. };
  426. Instruction.prototype.replaceChild = function(child) {
  427. return new ResolvedInstruction(this.component, child, this.auxInstruction);
  428. };
  429. Instruction.prototype.toUrlPath = function() {
  430. return this.urlPath + this._stringifyAux() + (lang_1.isPresent(this.child) ? this.child._toNonRootUrl() : '');
  431. };
  432. Instruction.prototype.toLinkUrl = function() {
  433. return this.urlPath + this._stringifyAux() + (lang_1.isPresent(this.child) ? this.child._toLinkUrl() : '');
  434. };
  435. Instruction.prototype._toLinkUrl = function() {
  436. return this._stringifyPathMatrixAuxPrefixed() + (lang_1.isPresent(this.child) ? this.child._toLinkUrl() : '');
  437. };
  438. Instruction.prototype._stringifyPathMatrixAuxPrefixed = function() {
  439. var primary = this._stringifyPathMatrixAux();
  440. if (primary.length > 0) {
  441. primary = '/' + primary;
  442. }
  443. return primary;
  444. };
  445. Instruction.prototype._stringifyMatrixParams = function() {
  446. return this.urlParams.length > 0 ? (';' + this.component.urlParams.join(';')) : '';
  447. };
  448. Instruction.prototype._stringifyPathMatrixAux = function() {
  449. if (lang_1.isBlank(this.component)) {
  450. return '';
  451. }
  452. return this.urlPath + this._stringifyMatrixParams() + this._stringifyAux();
  453. };
  454. Instruction.prototype._stringifyAux = function() {
  455. var routes = [];
  456. collection_1.StringMapWrapper.forEach(this.auxInstruction, function(auxInstruction, _) {
  457. routes.push(auxInstruction._stringifyPathMatrixAux());
  458. });
  459. if (routes.length > 0) {
  460. return '(' + routes.join('//') + ')';
  461. }
  462. return '';
  463. };
  464. return Instruction;
  465. })();
  466. exports.Instruction = Instruction;
  467. var ResolvedInstruction = (function(_super) {
  468. __extends(ResolvedInstruction, _super);
  469. function ResolvedInstruction(component, child, auxInstruction) {
  470. _super.call(this);
  471. this.component = component;
  472. this.child = child;
  473. this.auxInstruction = auxInstruction;
  474. }
  475. ResolvedInstruction.prototype.resolveComponent = function() {
  476. return async_1.PromiseWrapper.resolve(this.component);
  477. };
  478. return ResolvedInstruction;
  479. })(Instruction);
  480. exports.ResolvedInstruction = ResolvedInstruction;
  481. var DefaultInstruction = (function(_super) {
  482. __extends(DefaultInstruction, _super);
  483. function DefaultInstruction(component, child) {
  484. _super.call(this);
  485. this.component = component;
  486. this.child = child;
  487. }
  488. DefaultInstruction.prototype.resolveComponent = function() {
  489. return async_1.PromiseWrapper.resolve(this.component);
  490. };
  491. DefaultInstruction.prototype.toLinkUrl = function() {
  492. return '';
  493. };
  494. DefaultInstruction.prototype._toLinkUrl = function() {
  495. return '';
  496. };
  497. return DefaultInstruction;
  498. })(Instruction);
  499. exports.DefaultInstruction = DefaultInstruction;
  500. var UnresolvedInstruction = (function(_super) {
  501. __extends(UnresolvedInstruction, _super);
  502. function UnresolvedInstruction(_resolver, _urlPath, _urlParams) {
  503. if (_urlPath === void 0) {
  504. _urlPath = '';
  505. }
  506. if (_urlParams === void 0) {
  507. _urlParams = lang_1.CONST_EXPR([]);
  508. }
  509. _super.call(this);
  510. this._resolver = _resolver;
  511. this._urlPath = _urlPath;
  512. this._urlParams = _urlParams;
  513. }
  514. Object.defineProperty(UnresolvedInstruction.prototype, "urlPath", {
  515. get: function() {
  516. if (lang_1.isPresent(this.component)) {
  517. return this.component.urlPath;
  518. }
  519. if (lang_1.isPresent(this._urlPath)) {
  520. return this._urlPath;
  521. }
  522. return '';
  523. },
  524. enumerable: true,
  525. configurable: true
  526. });
  527. Object.defineProperty(UnresolvedInstruction.prototype, "urlParams", {
  528. get: function() {
  529. if (lang_1.isPresent(this.component)) {
  530. return this.component.urlParams;
  531. }
  532. if (lang_1.isPresent(this._urlParams)) {
  533. return this._urlParams;
  534. }
  535. return [];
  536. },
  537. enumerable: true,
  538. configurable: true
  539. });
  540. UnresolvedInstruction.prototype.resolveComponent = function() {
  541. var _this = this;
  542. if (lang_1.isPresent(this.component)) {
  543. return async_1.PromiseWrapper.resolve(this.component);
  544. }
  545. return this._resolver().then(function(resolution) {
  546. _this.child = resolution.child;
  547. return _this.component = resolution.component;
  548. });
  549. };
  550. return UnresolvedInstruction;
  551. })(Instruction);
  552. exports.UnresolvedInstruction = UnresolvedInstruction;
  553. var RedirectInstruction = (function(_super) {
  554. __extends(RedirectInstruction, _super);
  555. function RedirectInstruction(component, child, auxInstruction) {
  556. _super.call(this, component, child, auxInstruction);
  557. }
  558. return RedirectInstruction;
  559. })(ResolvedInstruction);
  560. exports.RedirectInstruction = RedirectInstruction;
  561. var ComponentInstruction = (function() {
  562. function ComponentInstruction(urlPath, urlParams, data, componentType, terminal, specificity, params) {
  563. if (params === void 0) {
  564. params = null;
  565. }
  566. this.urlPath = urlPath;
  567. this.urlParams = urlParams;
  568. this.componentType = componentType;
  569. this.terminal = terminal;
  570. this.specificity = specificity;
  571. this.params = params;
  572. this.reuse = false;
  573. this.routeData = lang_1.isPresent(data) ? data : exports.BLANK_ROUTE_DATA;
  574. }
  575. return ComponentInstruction;
  576. })();
  577. exports.ComponentInstruction = ComponentInstruction;
  578. global.define = __define;
  579. return module.exports;
  580. });
  581. System.register("angular2/src/router/url_parser", ["angular2/src/facade/collection", "angular2/src/facade/lang", "angular2/src/facade/exceptions"], true, function(require, exports, module) {
  582. var global = System.global,
  583. __define = global.define;
  584. global.define = undefined;
  585. var __extends = (this && this.__extends) || function(d, b) {
  586. for (var p in b)
  587. if (b.hasOwnProperty(p))
  588. d[p] = b[p];
  589. function __() {
  590. this.constructor = d;
  591. }
  592. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  593. };
  594. var collection_1 = require("angular2/src/facade/collection");
  595. var lang_1 = require("angular2/src/facade/lang");
  596. var exceptions_1 = require("angular2/src/facade/exceptions");
  597. var Url = (function() {
  598. function Url(path, child, auxiliary, params) {
  599. if (child === void 0) {
  600. child = null;
  601. }
  602. if (auxiliary === void 0) {
  603. auxiliary = lang_1.CONST_EXPR([]);
  604. }
  605. if (params === void 0) {
  606. params = null;
  607. }
  608. this.path = path;
  609. this.child = child;
  610. this.auxiliary = auxiliary;
  611. this.params = params;
  612. }
  613. Url.prototype.toString = function() {
  614. return this.path + this._matrixParamsToString() + this._auxToString() + this._childString();
  615. };
  616. Url.prototype.segmentToString = function() {
  617. return this.path + this._matrixParamsToString();
  618. };
  619. Url.prototype._auxToString = function() {
  620. return this.auxiliary.length > 0 ? ('(' + this.auxiliary.map(function(sibling) {
  621. return sibling.toString();
  622. }).join('//') + ')') : '';
  623. };
  624. Url.prototype._matrixParamsToString = function() {
  625. if (lang_1.isBlank(this.params)) {
  626. return '';
  627. }
  628. return ';' + serializeParams(this.params).join(';');
  629. };
  630. Url.prototype._childString = function() {
  631. return lang_1.isPresent(this.child) ? ('/' + this.child.toString()) : '';
  632. };
  633. return Url;
  634. })();
  635. exports.Url = Url;
  636. var RootUrl = (function(_super) {
  637. __extends(RootUrl, _super);
  638. function RootUrl(path, child, auxiliary, params) {
  639. if (child === void 0) {
  640. child = null;
  641. }
  642. if (auxiliary === void 0) {
  643. auxiliary = lang_1.CONST_EXPR([]);
  644. }
  645. if (params === void 0) {
  646. params = null;
  647. }
  648. _super.call(this, path, child, auxiliary, params);
  649. }
  650. RootUrl.prototype.toString = function() {
  651. return this.path + this._auxToString() + this._childString() + this._queryParamsToString();
  652. };
  653. RootUrl.prototype.segmentToString = function() {
  654. return this.path + this._queryParamsToString();
  655. };
  656. RootUrl.prototype._queryParamsToString = function() {
  657. if (lang_1.isBlank(this.params)) {
  658. return '';
  659. }
  660. return '?' + serializeParams(this.params).join('&');
  661. };
  662. return RootUrl;
  663. })(Url);
  664. exports.RootUrl = RootUrl;
  665. function pathSegmentsToUrl(pathSegments) {
  666. var url = new Url(pathSegments[pathSegments.length - 1]);
  667. for (var i = pathSegments.length - 2; i >= 0; i -= 1) {
  668. url = new Url(pathSegments[i], url);
  669. }
  670. return url;
  671. }
  672. exports.pathSegmentsToUrl = pathSegmentsToUrl;
  673. var SEGMENT_RE = lang_1.RegExpWrapper.create('^[^\\/\\(\\)\\?;=&#]+');
  674. function matchUrlSegment(str) {
  675. var match = lang_1.RegExpWrapper.firstMatch(SEGMENT_RE, str);
  676. return lang_1.isPresent(match) ? match[0] : '';
  677. }
  678. var UrlParser = (function() {
  679. function UrlParser() {}
  680. UrlParser.prototype.peekStartsWith = function(str) {
  681. return this._remaining.startsWith(str);
  682. };
  683. UrlParser.prototype.capture = function(str) {
  684. if (!this._remaining.startsWith(str)) {
  685. throw new exceptions_1.BaseException("Expected \"" + str + "\".");
  686. }
  687. this._remaining = this._remaining.substring(str.length);
  688. };
  689. UrlParser.prototype.parse = function(url) {
  690. this._remaining = url;
  691. if (url == '' || url == '/') {
  692. return new Url('');
  693. }
  694. return this.parseRoot();
  695. };
  696. UrlParser.prototype.parseRoot = function() {
  697. if (this.peekStartsWith('/')) {
  698. this.capture('/');
  699. }
  700. var path = matchUrlSegment(this._remaining);
  701. this.capture(path);
  702. var aux = [];
  703. if (this.peekStartsWith('(')) {
  704. aux = this.parseAuxiliaryRoutes();
  705. }
  706. if (this.peekStartsWith(';')) {
  707. this.parseMatrixParams();
  708. }
  709. var child = null;
  710. if (this.peekStartsWith('/') && !this.peekStartsWith('//')) {
  711. this.capture('/');
  712. child = this.parseSegment();
  713. }
  714. var queryParams = null;
  715. if (this.peekStartsWith('?')) {
  716. queryParams = this.parseQueryParams();
  717. }
  718. return new RootUrl(path, child, aux, queryParams);
  719. };
  720. UrlParser.prototype.parseSegment = function() {
  721. if (this._remaining.length == 0) {
  722. return null;
  723. }
  724. if (this.peekStartsWith('/')) {
  725. this.capture('/');
  726. }
  727. var path = matchUrlSegment(this._remaining);
  728. this.capture(path);
  729. var matrixParams = null;
  730. if (this.peekStartsWith(';')) {
  731. matrixParams = this.parseMatrixParams();
  732. }
  733. var aux = [];
  734. if (this.peekStartsWith('(')) {
  735. aux = this.parseAuxiliaryRoutes();
  736. }
  737. var child = null;
  738. if (this.peekStartsWith('/') && !this.peekStartsWith('//')) {
  739. this.capture('/');
  740. child = this.parseSegment();
  741. }
  742. return new Url(path, child, aux, matrixParams);
  743. };
  744. UrlParser.prototype.parseQueryParams = function() {
  745. var params = {};
  746. this.capture('?');
  747. this.parseParam(params);
  748. while (this._remaining.length > 0 && this.peekStartsWith('&')) {
  749. this.capture('&');
  750. this.parseParam(params);
  751. }
  752. return params;
  753. };
  754. UrlParser.prototype.parseMatrixParams = function() {
  755. var params = {};
  756. while (this._remaining.length > 0 && this.peekStartsWith(';')) {
  757. this.capture(';');
  758. this.parseParam(params);
  759. }
  760. return params;
  761. };
  762. UrlParser.prototype.parseParam = function(params) {
  763. var key = matchUrlSegment(this._remaining);
  764. if (lang_1.isBlank(key)) {
  765. return ;
  766. }
  767. this.capture(key);
  768. var value = true;
  769. if (this.peekStartsWith('=')) {
  770. this.capture('=');
  771. var valueMatch = matchUrlSegment(this._remaining);
  772. if (lang_1.isPresent(valueMatch)) {
  773. value = valueMatch;
  774. this.capture(value);
  775. }
  776. }
  777. params[key] = value;
  778. };
  779. UrlParser.prototype.parseAuxiliaryRoutes = function() {
  780. var routes = [];
  781. this.capture('(');
  782. while (!this.peekStartsWith(')') && this._remaining.length > 0) {
  783. routes.push(this.parseSegment());
  784. if (this.peekStartsWith('//')) {
  785. this.capture('//');
  786. }
  787. }
  788. this.capture(')');
  789. return routes;
  790. };
  791. return UrlParser;
  792. })();
  793. exports.UrlParser = UrlParser;
  794. exports.parser = new UrlParser();
  795. function serializeParams(paramMap) {
  796. var params = [];
  797. if (lang_1.isPresent(paramMap)) {
  798. collection_1.StringMapWrapper.forEach(paramMap, function(value, key) {
  799. if (value == true) {
  800. params.push(key);
  801. } else {
  802. params.push(key + '=' + value);
  803. }
  804. });
  805. }
  806. return params;
  807. }
  808. exports.serializeParams = serializeParams;
  809. global.define = __define;
  810. return module.exports;
  811. });
  812. System.register("angular2/src/router/async_route_handler", ["angular2/src/facade/lang", "angular2/src/router/instruction"], true, function(require, exports, module) {
  813. var global = System.global,
  814. __define = global.define;
  815. global.define = undefined;
  816. var lang_1 = require("angular2/src/facade/lang");
  817. var instruction_1 = require("angular2/src/router/instruction");
  818. var AsyncRouteHandler = (function() {
  819. function AsyncRouteHandler(_loader, data) {
  820. if (data === void 0) {
  821. data = null;
  822. }
  823. this._loader = _loader;
  824. this._resolvedComponent = null;
  825. this.data = lang_1.isPresent(data) ? new instruction_1.RouteData(data) : instruction_1.BLANK_ROUTE_DATA;
  826. }
  827. AsyncRouteHandler.prototype.resolveComponentType = function() {
  828. var _this = this;
  829. if (lang_1.isPresent(this._resolvedComponent)) {
  830. return this._resolvedComponent;
  831. }
  832. return this._resolvedComponent = this._loader().then(function(componentType) {
  833. _this.componentType = componentType;
  834. return componentType;
  835. });
  836. };
  837. return AsyncRouteHandler;
  838. })();
  839. exports.AsyncRouteHandler = AsyncRouteHandler;
  840. global.define = __define;
  841. return module.exports;
  842. });
  843. System.register("angular2/src/router/sync_route_handler", ["angular2/src/facade/async", "angular2/src/facade/lang", "angular2/src/router/instruction"], true, function(require, exports, module) {
  844. var global = System.global,
  845. __define = global.define;
  846. global.define = undefined;
  847. var async_1 = require("angular2/src/facade/async");
  848. var lang_1 = require("angular2/src/facade/lang");
  849. var instruction_1 = require("angular2/src/router/instruction");
  850. var SyncRouteHandler = (function() {
  851. function SyncRouteHandler(componentType, data) {
  852. this.componentType = componentType;
  853. this._resolvedComponent = null;
  854. this._resolvedComponent = async_1.PromiseWrapper.resolve(componentType);
  855. this.data = lang_1.isPresent(data) ? new instruction_1.RouteData(data) : instruction_1.BLANK_ROUTE_DATA;
  856. }
  857. SyncRouteHandler.prototype.resolveComponentType = function() {
  858. return this._resolvedComponent;
  859. };
  860. return SyncRouteHandler;
  861. })();
  862. exports.SyncRouteHandler = SyncRouteHandler;
  863. global.define = __define;
  864. return module.exports;
  865. });
  866. System.register("angular2/src/router/route_config_decorator", ["angular2/src/router/route_config_impl", "angular2/src/core/util/decorators", "angular2/src/router/route_config_impl"], true, function(require, exports, module) {
  867. var global = System.global,
  868. __define = global.define;
  869. global.define = undefined;
  870. var route_config_impl_1 = require("angular2/src/router/route_config_impl");
  871. var decorators_1 = require("angular2/src/core/util/decorators");
  872. var route_config_impl_2 = require("angular2/src/router/route_config_impl");
  873. exports.Route = route_config_impl_2.Route;
  874. exports.Redirect = route_config_impl_2.Redirect;
  875. exports.AuxRoute = route_config_impl_2.AuxRoute;
  876. exports.AsyncRoute = route_config_impl_2.AsyncRoute;
  877. exports.RouteConfig = decorators_1.makeDecorator(route_config_impl_1.RouteConfig);
  878. global.define = __define;
  879. return module.exports;
  880. });
  881. System.register("angular2/src/router/location_strategy", ["angular2/src/facade/lang", "angular2/core"], true, function(require, exports, module) {
  882. var global = System.global,
  883. __define = global.define;
  884. global.define = undefined;
  885. var lang_1 = require("angular2/src/facade/lang");
  886. var core_1 = require("angular2/core");
  887. var LocationStrategy = (function() {
  888. function LocationStrategy() {}
  889. return LocationStrategy;
  890. })();
  891. exports.LocationStrategy = LocationStrategy;
  892. exports.APP_BASE_HREF = lang_1.CONST_EXPR(new core_1.OpaqueToken('appBaseHref'));
  893. function normalizeQueryParams(params) {
  894. return (params.length > 0 && params.substring(0, 1) != '?') ? ('?' + params) : params;
  895. }
  896. exports.normalizeQueryParams = normalizeQueryParams;
  897. function joinWithSlash(start, end) {
  898. if (start.length == 0) {
  899. return end;
  900. }
  901. if (end.length == 0) {
  902. return start;
  903. }
  904. var slashes = 0;
  905. if (start.endsWith('/')) {
  906. slashes++;
  907. }
  908. if (end.startsWith('/')) {
  909. slashes++;
  910. }
  911. if (slashes == 2) {
  912. return start + end.substring(1);
  913. }
  914. if (slashes == 1) {
  915. return start + end;
  916. }
  917. return start + '/' + end;
  918. }
  919. exports.joinWithSlash = joinWithSlash;
  920. global.define = __define;
  921. return module.exports;
  922. });
  923. System.register("angular2/src/router/lifecycle_annotations_impl", ["angular2/src/facade/lang"], true, function(require, exports, module) {
  924. var global = System.global,
  925. __define = global.define;
  926. global.define = undefined;
  927. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  928. var c = arguments.length,
  929. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  930. d;
  931. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  932. r = Reflect.decorate(decorators, target, key, desc);
  933. else
  934. for (var i = decorators.length - 1; i >= 0; i--)
  935. if (d = decorators[i])
  936. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  937. return c > 3 && r && Object.defineProperty(target, key, r), r;
  938. };
  939. var __metadata = (this && this.__metadata) || function(k, v) {
  940. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  941. return Reflect.metadata(k, v);
  942. };
  943. var lang_1 = require("angular2/src/facade/lang");
  944. var RouteLifecycleHook = (function() {
  945. function RouteLifecycleHook(name) {
  946. this.name = name;
  947. }
  948. RouteLifecycleHook = __decorate([lang_1.CONST(), __metadata('design:paramtypes', [String])], RouteLifecycleHook);
  949. return RouteLifecycleHook;
  950. })();
  951. exports.RouteLifecycleHook = RouteLifecycleHook;
  952. var CanActivate = (function() {
  953. function CanActivate(fn) {
  954. this.fn = fn;
  955. }
  956. CanActivate = __decorate([lang_1.CONST(), __metadata('design:paramtypes', [Function])], CanActivate);
  957. return CanActivate;
  958. })();
  959. exports.CanActivate = CanActivate;
  960. exports.routerCanReuse = lang_1.CONST_EXPR(new RouteLifecycleHook("routerCanReuse"));
  961. exports.routerCanDeactivate = lang_1.CONST_EXPR(new RouteLifecycleHook("routerCanDeactivate"));
  962. exports.routerOnActivate = lang_1.CONST_EXPR(new RouteLifecycleHook("routerOnActivate"));
  963. exports.routerOnReuse = lang_1.CONST_EXPR(new RouteLifecycleHook("routerOnReuse"));
  964. exports.routerOnDeactivate = lang_1.CONST_EXPR(new RouteLifecycleHook("routerOnDeactivate"));
  965. global.define = __define;
  966. return module.exports;
  967. });
  968. System.register("angular2/src/router/lifecycle_annotations", ["angular2/src/core/util/decorators", "angular2/src/router/lifecycle_annotations_impl", "angular2/src/router/lifecycle_annotations_impl"], true, function(require, exports, module) {
  969. var global = System.global,
  970. __define = global.define;
  971. global.define = undefined;
  972. var decorators_1 = require("angular2/src/core/util/decorators");
  973. var lifecycle_annotations_impl_1 = require("angular2/src/router/lifecycle_annotations_impl");
  974. var lifecycle_annotations_impl_2 = require("angular2/src/router/lifecycle_annotations_impl");
  975. exports.routerCanReuse = lifecycle_annotations_impl_2.routerCanReuse;
  976. exports.routerCanDeactivate = lifecycle_annotations_impl_2.routerCanDeactivate;
  977. exports.routerOnActivate = lifecycle_annotations_impl_2.routerOnActivate;
  978. exports.routerOnReuse = lifecycle_annotations_impl_2.routerOnReuse;
  979. exports.routerOnDeactivate = lifecycle_annotations_impl_2.routerOnDeactivate;
  980. exports.CanActivate = decorators_1.makeDecorator(lifecycle_annotations_impl_1.CanActivate);
  981. global.define = __define;
  982. return module.exports;
  983. });
  984. System.register("angular2/src/router/router_link", ["angular2/core", "angular2/src/facade/lang", "angular2/src/router/router", "angular2/src/router/location"], true, function(require, exports, module) {
  985. var global = System.global,
  986. __define = global.define;
  987. global.define = undefined;
  988. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  989. var c = arguments.length,
  990. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  991. d;
  992. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  993. r = Reflect.decorate(decorators, target, key, desc);
  994. else
  995. for (var i = decorators.length - 1; i >= 0; i--)
  996. if (d = decorators[i])
  997. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  998. return c > 3 && r && Object.defineProperty(target, key, r), r;
  999. };
  1000. var __metadata = (this && this.__metadata) || function(k, v) {
  1001. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  1002. return Reflect.metadata(k, v);
  1003. };
  1004. var core_1 = require("angular2/core");
  1005. var lang_1 = require("angular2/src/facade/lang");
  1006. var router_1 = require("angular2/src/router/router");
  1007. var location_1 = require("angular2/src/router/location");
  1008. var RouterLink = (function() {
  1009. function RouterLink(_router, _location) {
  1010. this._router = _router;
  1011. this._location = _location;
  1012. }
  1013. Object.defineProperty(RouterLink.prototype, "isRouteActive", {
  1014. get: function() {
  1015. return this._router.isRouteActive(this._navigationInstruction);
  1016. },
  1017. enumerable: true,
  1018. configurable: true
  1019. });
  1020. Object.defineProperty(RouterLink.prototype, "routeParams", {
  1021. set: function(changes) {
  1022. this._routeParams = changes;
  1023. this._navigationInstruction = this._router.generate(this._routeParams);
  1024. var navigationHref = this._navigationInstruction.toLinkUrl();
  1025. this.visibleHref = this._location.prepareExternalUrl(navigationHref);
  1026. },
  1027. enumerable: true,
  1028. configurable: true
  1029. });
  1030. RouterLink.prototype.onClick = function() {
  1031. if (!lang_1.isString(this.target) || this.target == '_self') {
  1032. this._router.navigateByInstruction(this._navigationInstruction);
  1033. return false;
  1034. }
  1035. return true;
  1036. };
  1037. RouterLink = __decorate([core_1.Directive({
  1038. selector: '[routerLink]',
  1039. inputs: ['routeParams: routerLink', 'target: target'],
  1040. host: {
  1041. '(click)': 'onClick()',
  1042. '[attr.href]': 'visibleHref',
  1043. '[class.router-link-active]': 'isRouteActive'
  1044. }
  1045. }), __metadata('design:paramtypes', [router_1.Router, location_1.Location])], RouterLink);
  1046. return RouterLink;
  1047. })();
  1048. exports.RouterLink = RouterLink;
  1049. global.define = __define;
  1050. return module.exports;
  1051. });
  1052. System.register("angular2/src/router/hash_location_strategy", ["angular2/core", "angular2/src/router/location_strategy", "angular2/src/facade/lang", "angular2/src/router/platform_location"], true, function(require, exports, module) {
  1053. var global = System.global,
  1054. __define = global.define;
  1055. global.define = undefined;
  1056. var __extends = (this && this.__extends) || function(d, b) {
  1057. for (var p in b)
  1058. if (b.hasOwnProperty(p))
  1059. d[p] = b[p];
  1060. function __() {
  1061. this.constructor = d;
  1062. }
  1063. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1064. };
  1065. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  1066. var c = arguments.length,
  1067. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  1068. d;
  1069. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  1070. r = Reflect.decorate(decorators, target, key, desc);
  1071. else
  1072. for (var i = decorators.length - 1; i >= 0; i--)
  1073. if (d = decorators[i])
  1074. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  1075. return c > 3 && r && Object.defineProperty(target, key, r), r;
  1076. };
  1077. var __metadata = (this && this.__metadata) || function(k, v) {
  1078. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  1079. return Reflect.metadata(k, v);
  1080. };
  1081. var __param = (this && this.__param) || function(paramIndex, decorator) {
  1082. return function(target, key) {
  1083. decorator(target, key, paramIndex);
  1084. };
  1085. };
  1086. var core_1 = require("angular2/core");
  1087. var location_strategy_1 = require("angular2/src/router/location_strategy");
  1088. var lang_1 = require("angular2/src/facade/lang");
  1089. var platform_location_1 = require("angular2/src/router/platform_location");
  1090. var HashLocationStrategy = (function(_super) {
  1091. __extends(HashLocationStrategy, _super);
  1092. function HashLocationStrategy(_platformLocation, _baseHref) {
  1093. _super.call(this);
  1094. this._platformLocation = _platformLocation;
  1095. this._baseHref = '';
  1096. if (lang_1.isPresent(_baseHref)) {
  1097. this._baseHref = _baseHref;
  1098. }
  1099. }
  1100. HashLocationStrategy.prototype.onPopState = function(fn) {
  1101. this._platformLocation.onPopState(fn);
  1102. this._platformLocation.onHashChange(fn);
  1103. };
  1104. HashLocationStrategy.prototype.getBaseHref = function() {
  1105. return this._baseHref;
  1106. };
  1107. HashLocationStrategy.prototype.path = function() {
  1108. var path = this._platformLocation.hash;
  1109. return (path.length > 0 ? path.substring(1) : path) + location_strategy_1.normalizeQueryParams(this._platformLocation.search);
  1110. };
  1111. HashLocationStrategy.prototype.prepareExternalUrl = function(internal) {
  1112. var url = location_strategy_1.joinWithSlash(this._baseHref, internal);
  1113. return url.length > 0 ? ('#' + url) : url;
  1114. };
  1115. HashLocationStrategy.prototype.pushState = function(state, title, path, queryParams) {
  1116. var url = this.prepareExternalUrl(path + location_strategy_1.normalizeQueryParams(queryParams));
  1117. if (url.length == 0) {
  1118. url = this._platformLocation.pathname;
  1119. }
  1120. this._platformLocation.pushState(state, title, url);
  1121. };
  1122. HashLocationStrategy.prototype.replaceState = function(state, title, path, queryParams) {
  1123. var url = this.prepareExternalUrl(path + location_strategy_1.normalizeQueryParams(queryParams));
  1124. if (url.length == 0) {
  1125. url = this._platformLocation.pathname;
  1126. }
  1127. this._platformLocation.replaceState(state, title, url);
  1128. };
  1129. HashLocationStrategy.prototype.forward = function() {
  1130. this._platformLocation.forward();
  1131. };
  1132. HashLocationStrategy.prototype.back = function() {
  1133. this._platformLocation.back();
  1134. };
  1135. HashLocationStrategy = __decorate([core_1.Injectable(), __param(1, core_1.Optional()), __param(1, core_1.Inject(location_strategy_1.APP_BASE_HREF)), __metadata('design:paramtypes', [platform_location_1.PlatformLocation, String])], HashLocationStrategy);
  1136. return HashLocationStrategy;
  1137. })(location_strategy_1.LocationStrategy);
  1138. exports.HashLocationStrategy = HashLocationStrategy;
  1139. global.define = __define;
  1140. return module.exports;
  1141. });
  1142. System.register("angular2/src/router/path_location_strategy", ["angular2/core", "angular2/src/facade/lang", "angular2/src/facade/exceptions", "angular2/src/router/location_strategy", "angular2/src/router/platform_location"], true, function(require, exports, module) {
  1143. var global = System.global,
  1144. __define = global.define;
  1145. global.define = undefined;
  1146. var __extends = (this && this.__extends) || function(d, b) {
  1147. for (var p in b)
  1148. if (b.hasOwnProperty(p))
  1149. d[p] = b[p];
  1150. function __() {
  1151. this.constructor = d;
  1152. }
  1153. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1154. };
  1155. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  1156. var c = arguments.length,
  1157. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  1158. d;
  1159. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  1160. r = Reflect.decorate(decorators, target, key, desc);
  1161. else
  1162. for (var i = decorators.length - 1; i >= 0; i--)
  1163. if (d = decorators[i])
  1164. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  1165. return c > 3 && r && Object.defineProperty(target, key, r), r;
  1166. };
  1167. var __metadata = (this && this.__metadata) || function(k, v) {
  1168. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  1169. return Reflect.metadata(k, v);
  1170. };
  1171. var __param = (this && this.__param) || function(paramIndex, decorator) {
  1172. return function(target, key) {
  1173. decorator(target, key, paramIndex);
  1174. };
  1175. };
  1176. var core_1 = require("angular2/core");
  1177. var lang_1 = require("angular2/src/facade/lang");
  1178. var exceptions_1 = require("angular2/src/facade/exceptions");
  1179. var location_strategy_1 = require("angular2/src/router/location_strategy");
  1180. var platform_location_1 = require("angular2/src/router/platform_location");
  1181. var PathLocationStrategy = (function(_super) {
  1182. __extends(PathLocationStrategy, _super);
  1183. function PathLocationStrategy(_platformLocation, href) {
  1184. _super.call(this);
  1185. this._platformLocation = _platformLocation;
  1186. if (lang_1.isBlank(href)) {
  1187. href = this._platformLocation.getBaseHrefFromDOM();
  1188. }
  1189. if (lang_1.isBlank(href)) {
  1190. throw new exceptions_1.BaseException("No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.");
  1191. }
  1192. this._baseHref = href;
  1193. }
  1194. PathLocationStrategy.prototype.onPopState = function(fn) {
  1195. this._platformLocation.onPopState(fn);
  1196. this._platformLocation.onHashChange(fn);
  1197. };
  1198. PathLocationStrategy.prototype.getBaseHref = function() {
  1199. return this._baseHref;
  1200. };
  1201. PathLocationStrategy.prototype.prepareExternalUrl = function(internal) {
  1202. return location_strategy_1.joinWithSlash(this._baseHref, internal);
  1203. };
  1204. PathLocationStrategy.prototype.path = function() {
  1205. return this._platformLocation.pathname + location_strategy_1.normalizeQueryParams(this._platformLocation.search);
  1206. };
  1207. PathLocationStrategy.prototype.pushState = function(state, title, url, queryParams) {
  1208. var externalUrl = this.prepareExternalUrl(url + location_strategy_1.normalizeQueryParams(queryParams));
  1209. this._platformLocation.pushState(state, title, externalUrl);
  1210. };
  1211. PathLocationStrategy.prototype.replaceState = function(state, title, url, queryParams) {
  1212. var externalUrl = this.prepareExternalUrl(url + location_strategy_1.normalizeQueryParams(queryParams));
  1213. this._platformLocation.replaceState(state, title, externalUrl);
  1214. };
  1215. PathLocationStrategy.prototype.forward = function() {
  1216. this._platformLocation.forward();
  1217. };
  1218. PathLocationStrategy.prototype.back = function() {
  1219. this._platformLocation.back();
  1220. };
  1221. PathLocationStrategy = __decorate([core_1.Injectable(), __param(1, core_1.Optional()), __param(1, core_1.Inject(location_strategy_1.APP_BASE_HREF)), __metadata('design:paramtypes', [platform_location_1.PlatformLocation, String])], PathLocationStrategy);
  1222. return PathLocationStrategy;
  1223. })(location_strategy_1.LocationStrategy);
  1224. exports.PathLocationStrategy = PathLocationStrategy;
  1225. global.define = __define;
  1226. return module.exports;
  1227. });
  1228. System.register("angular2/src/router/route_definition", [], true, function(require, exports, module) {
  1229. var global = System.global,
  1230. __define = global.define;
  1231. global.define = undefined;
  1232. global.define = __define;
  1233. return module.exports;
  1234. });
  1235. System.register("angular2/src/router/path_recognizer", ["angular2/src/facade/lang", "angular2/src/facade/exceptions", "angular2/src/facade/collection", "angular2/src/router/url_parser"], true, function(require, exports, module) {
  1236. var global = System.global,
  1237. __define = global.define;
  1238. global.define = undefined;
  1239. var lang_1 = require("angular2/src/facade/lang");
  1240. var exceptions_1 = require("angular2/src/facade/exceptions");
  1241. var collection_1 = require("angular2/src/facade/collection");
  1242. var url_parser_1 = require("angular2/src/router/url_parser");
  1243. var TouchMap = (function() {
  1244. function TouchMap(map) {
  1245. var _this = this;
  1246. this.map = {};
  1247. this.keys = {};
  1248. if (lang_1.isPresent(map)) {
  1249. collection_1.StringMapWrapper.forEach(map, function(value, key) {
  1250. _this.map[key] = lang_1.isPresent(value) ? value.toString() : null;
  1251. _this.keys[key] = true;
  1252. });
  1253. }
  1254. }
  1255. TouchMap.prototype.get = function(key) {
  1256. collection_1.StringMapWrapper.delete(this.keys, key);
  1257. return this.map[key];
  1258. };
  1259. TouchMap.prototype.getUnused = function() {
  1260. var _this = this;
  1261. var unused = {};
  1262. var keys = collection_1.StringMapWrapper.keys(this.keys);
  1263. keys.forEach(function(key) {
  1264. return unused[key] = collection_1.StringMapWrapper.get(_this.map, key);
  1265. });
  1266. return unused;
  1267. };
  1268. return TouchMap;
  1269. })();
  1270. function normalizeString(obj) {
  1271. if (lang_1.isBlank(obj)) {
  1272. return null;
  1273. } else {
  1274. return obj.toString();
  1275. }
  1276. }
  1277. var ContinuationSegment = (function() {
  1278. function ContinuationSegment() {
  1279. this.name = '';
  1280. }
  1281. ContinuationSegment.prototype.generate = function(params) {
  1282. return '';
  1283. };
  1284. ContinuationSegment.prototype.match = function(path) {
  1285. return true;
  1286. };
  1287. return ContinuationSegment;
  1288. })();
  1289. var StaticSegment = (function() {
  1290. function StaticSegment(path) {
  1291. this.path = path;
  1292. this.name = '';
  1293. }
  1294. StaticSegment.prototype.match = function(path) {
  1295. return path == this.path;
  1296. };
  1297. StaticSegment.prototype.generate = function(params) {
  1298. return this.path;
  1299. };
  1300. return StaticSegment;
  1301. })();
  1302. var DynamicSegment = (function() {
  1303. function DynamicSegment(name) {
  1304. this.name = name;
  1305. }
  1306. DynamicSegment.prototype.match = function(path) {
  1307. return path.length > 0;
  1308. };
  1309. DynamicSegment.prototype.generate = function(params) {
  1310. if (!collection_1.StringMapWrapper.contains(params.map, this.name)) {
  1311. throw new exceptions_1.BaseException("Route generator for '" + this.name + "' was not included in parameters passed.");
  1312. }
  1313. return normalizeString(params.get(this.name));
  1314. };
  1315. return DynamicSegment;
  1316. })();
  1317. var StarSegment = (function() {
  1318. function StarSegment(name) {
  1319. this.name = name;
  1320. }
  1321. StarSegment.prototype.match = function(path) {
  1322. return true;
  1323. };
  1324. StarSegment.prototype.generate = function(params) {
  1325. return normalizeString(params.get(this.name));
  1326. };
  1327. return StarSegment;
  1328. })();
  1329. var paramMatcher = /^:([^\/]+)$/g;
  1330. var wildcardMatcher = /^\*([^\/]+)$/g;
  1331. function parsePathString(route) {
  1332. if (route.startsWith("/")) {
  1333. route = route.substring(1);
  1334. }
  1335. var segments = splitBySlash(route);
  1336. var results = [];
  1337. var specificity = 0;
  1338. if (segments.length > 98) {
  1339. throw new exceptions_1.BaseException("'" + route + "' has more than the maximum supported number of segments.");
  1340. }
  1341. var limit = segments.length - 1;
  1342. for (var i = 0; i <= limit; i++) {
  1343. var segment = segments[i],
  1344. match;
  1345. if (lang_1.isPresent(match = lang_1.RegExpWrapper.firstMatch(paramMatcher, segment))) {
  1346. results.push(new DynamicSegment(match[1]));
  1347. specificity += (100 - i);
  1348. } else if (lang_1.isPresent(match = lang_1.RegExpWrapper.firstMatch(wildcardMatcher, segment))) {
  1349. results.push(new StarSegment(match[1]));
  1350. } else if (segment == '...') {
  1351. if (i < limit) {
  1352. throw new exceptions_1.BaseException("Unexpected \"...\" before the end of the path for \"" + route + "\".");
  1353. }
  1354. results.push(new ContinuationSegment());
  1355. } else {
  1356. results.push(new StaticSegment(segment));
  1357. specificity += 100 * (100 - i);
  1358. }
  1359. }
  1360. var result = collection_1.StringMapWrapper.create();
  1361. collection_1.StringMapWrapper.set(result, 'segments', results);
  1362. collection_1.StringMapWrapper.set(result, 'specificity', specificity);
  1363. return result;
  1364. }
  1365. function pathDslHash(segments) {
  1366. return segments.map(function(segment) {
  1367. if (segment instanceof StarSegment) {
  1368. return '*';
  1369. } else if (segment instanceof ContinuationSegment) {
  1370. return '...';
  1371. } else if (segment instanceof DynamicSegment) {
  1372. return ':';
  1373. } else if (segment instanceof StaticSegment) {
  1374. return segment.path;
  1375. }
  1376. }).join('/');
  1377. }
  1378. function splitBySlash(url) {
  1379. return url.split('/');
  1380. }
  1381. var RESERVED_CHARS = lang_1.RegExpWrapper.create('//|\\(|\\)|;|\\?|=');
  1382. function assertPath(path) {
  1383. if (lang_1.StringWrapper.contains(path, '#')) {
  1384. throw new exceptions_1.BaseException("Path \"" + path + "\" should not include \"#\". Use \"HashLocationStrategy\" instead.");
  1385. }
  1386. var illegalCharacter = lang_1.RegExpWrapper.firstMatch(RESERVED_CHARS, path);
  1387. if (lang_1.isPresent(illegalCharacter)) {
  1388. throw new exceptions_1.BaseException("Path \"" + path + "\" contains \"" + illegalCharacter[0] + "\" which is not allowed in a route config.");
  1389. }
  1390. }
  1391. var PathRecognizer = (function() {
  1392. function PathRecognizer(path) {
  1393. this.path = path;
  1394. this.terminal = true;
  1395. assertPath(path);
  1396. var parsed = parsePathString(path);
  1397. this._segments = parsed['segments'];
  1398. this.specificity = parsed['specificity'];
  1399. this.hash = pathDslHash(this._segments);
  1400. var lastSegment = this._segments[this._segments.length - 1];
  1401. this.terminal = !(lastSegment instanceof ContinuationSegment);
  1402. }
  1403. PathRecognizer.prototype.recognize = function(beginningSegment) {
  1404. var nextSegment = beginningSegment;
  1405. var currentSegment;
  1406. var positionalParams = {};
  1407. var captured = [];
  1408. for (var i = 0; i < this._segments.length; i += 1) {
  1409. var segment = this._segments[i];
  1410. currentSegment = nextSegment;
  1411. if (segment instanceof ContinuationSegment) {
  1412. break;
  1413. }
  1414. if (lang_1.isPresent(currentSegment)) {
  1415. captured.push(currentSegment.path);
  1416. if (segment instanceof StarSegment) {
  1417. positionalParams[segment.name] = currentSegment.toString();
  1418. nextSegment = null;
  1419. break;
  1420. }
  1421. if (segment instanceof DynamicSegment) {
  1422. positionalParams[segment.name] = currentSegment.path;
  1423. } else if (!segment.match(currentSegment.path)) {
  1424. return null;
  1425. }
  1426. nextSegment = currentSegment.child;
  1427. } else if (!segment.match('')) {
  1428. return null;
  1429. }
  1430. }
  1431. if (this.terminal && lang_1.isPresent(nextSegment)) {
  1432. return null;
  1433. }
  1434. var urlPath = captured.join('/');
  1435. var auxiliary;
  1436. var urlParams;
  1437. var allParams;
  1438. if (lang_1.isPresent(currentSegment)) {
  1439. var paramsSegment = beginningSegment instanceof url_parser_1.RootUrl ? beginningSegment : currentSegment;
  1440. allParams = lang_1.isPresent(paramsSegment.params) ? collection_1.StringMapWrapper.merge(paramsSegment.params, positionalParams) : positionalParams;
  1441. urlParams = url_parser_1.serializeParams(paramsSegment.params);
  1442. auxiliary = currentSegment.auxiliary;
  1443. } else {
  1444. allParams = positionalParams;
  1445. auxiliary = [];
  1446. urlParams = [];
  1447. }
  1448. return {
  1449. urlPath: urlPath,
  1450. urlParams: urlParams,
  1451. allParams: allParams,
  1452. auxiliary: auxiliary,
  1453. nextSegment: nextSegment
  1454. };
  1455. };
  1456. PathRecognizer.prototype.generate = function(params) {
  1457. var paramTokens = new TouchMap(params);
  1458. var path = [];
  1459. for (var i = 0; i < this._segments.length; i++) {
  1460. var segment = this._segments[i];
  1461. if (!(segment instanceof ContinuationSegment)) {
  1462. path.push(segment.generate(paramTokens));
  1463. }
  1464. }
  1465. var urlPath = path.join('/');
  1466. var nonPositionalParams = paramTokens.getUnused();
  1467. var urlParams = url_parser_1.serializeParams(nonPositionalParams);
  1468. return {
  1469. urlPath: urlPath,
  1470. urlParams: urlParams
  1471. };
  1472. };
  1473. return PathRecognizer;
  1474. })();
  1475. exports.PathRecognizer = PathRecognizer;
  1476. global.define = __define;
  1477. return module.exports;
  1478. });
  1479. System.register("angular2/src/router/component_recognizer", ["angular2/src/facade/lang", "angular2/src/facade/exceptions", "angular2/src/facade/collection", "angular2/src/facade/async", "angular2/src/router/route_recognizer", "angular2/src/router/route_config_impl", "angular2/src/router/async_route_handler", "angular2/src/router/sync_route_handler"], true, function(require, exports, module) {
  1480. var global = System.global,
  1481. __define = global.define;
  1482. global.define = undefined;
  1483. var lang_1 = require("angular2/src/facade/lang");
  1484. var exceptions_1 = require("angular2/src/facade/exceptions");
  1485. var collection_1 = require("angular2/src/facade/collection");
  1486. var async_1 = require("angular2/src/facade/async");
  1487. var route_recognizer_1 = require("angular2/src/router/route_recognizer");
  1488. var route_config_impl_1 = require("angular2/src/router/route_config_impl");
  1489. var async_route_handler_1 = require("angular2/src/router/async_route_handler");
  1490. var sync_route_handler_1 = require("angular2/src/router/sync_route_handler");
  1491. var ComponentRecognizer = (function() {
  1492. function ComponentRecognizer() {
  1493. this.names = new collection_1.Map();
  1494. this.auxNames = new collection_1.Map();
  1495. this.auxRoutes = new collection_1.Map();
  1496. this.matchers = [];
  1497. this.defaultRoute = null;
  1498. }
  1499. ComponentRecognizer.prototype.config = function(config) {
  1500. var handler;
  1501. if (lang_1.isPresent(config.name) && config.name[0].toUpperCase() != config.name[0]) {
  1502. var suggestedName = config.name[0].toUpperCase() + config.name.substring(1);
  1503. throw new exceptions_1.BaseException("Route \"" + config.path + "\" with name \"" + config.name + "\" does not begin with an uppercase letter. Route names should be CamelCase like \"" + suggestedName + "\".");
  1504. }
  1505. if (config instanceof route_config_impl_1.AuxRoute) {
  1506. handler = new sync_route_handler_1.SyncRouteHandler(config.component, config.data);
  1507. var path = config.path.startsWith('/') ? config.path.substring(1) : config.path;
  1508. var recognizer = new route_recognizer_1.RouteRecognizer(config.path, handler);
  1509. this.auxRoutes.set(path, recognizer);
  1510. if (lang_1.isPresent(config.name)) {
  1511. this.auxNames.set(config.name, recognizer);
  1512. }
  1513. return recognizer.terminal;
  1514. }
  1515. var useAsDefault = false;
  1516. if (config instanceof route_config_impl_1.Redirect) {
  1517. var redirector = new route_recognizer_1.RedirectRecognizer(config.path, config.redirectTo);
  1518. this._assertNoHashCollision(redirector.hash, config.path);
  1519. this.matchers.push(redirector);
  1520. return true;
  1521. }
  1522. if (config instanceof route_config_impl_1.Route) {
  1523. handler = new sync_route_handler_1.SyncRouteHandler(config.component, config.data);
  1524. useAsDefault = lang_1.isPresent(config.useAsDefault) && config.useAsDefault;
  1525. } else if (config instanceof route_config_impl_1.AsyncRoute) {
  1526. handler = new async_route_handler_1.AsyncRouteHandler(config.loader, config.data);
  1527. useAsDefault = lang_1.isPresent(config.useAsDefault) && config.useAsDefault;
  1528. }
  1529. var recognizer = new route_recognizer_1.RouteRecognizer(config.path, handler);
  1530. this._assertNoHashCollision(recognizer.hash, config.path);
  1531. if (useAsDefault) {
  1532. if (lang_1.isPresent(this.defaultRoute)) {
  1533. throw new exceptions_1.BaseException("Only one route can be default");
  1534. }
  1535. this.defaultRoute = recognizer;
  1536. }
  1537. this.matchers.push(recognizer);
  1538. if (lang_1.isPresent(config.name)) {
  1539. this.names.set(config.name, recognizer);
  1540. }
  1541. return recognizer.terminal;
  1542. };
  1543. ComponentRecognizer.prototype._assertNoHashCollision = function(hash, path) {
  1544. this.matchers.forEach(function(matcher) {
  1545. if (hash == matcher.hash) {
  1546. throw new exceptions_1.BaseException("Configuration '" + path + "' conflicts with existing route '" + matcher.path + "'");
  1547. }
  1548. });
  1549. };
  1550. ComponentRecognizer.prototype.recognize = function(urlParse) {
  1551. var solutions = [];
  1552. this.matchers.forEach(function(routeRecognizer) {
  1553. var pathMatch = routeRecognizer.recognize(urlParse);
  1554. if (lang_1.isPresent(pathMatch)) {
  1555. solutions.push(pathMatch);
  1556. }
  1557. });
  1558. return solutions;
  1559. };
  1560. ComponentRecognizer.prototype.recognizeAuxiliary = function(urlParse) {
  1561. var routeRecognizer = this.auxRoutes.get(urlParse.path);
  1562. if (lang_1.isPresent(routeRecognizer)) {
  1563. return [routeRecognizer.recognize(urlParse)];
  1564. }
  1565. return [async_1.PromiseWrapper.resolve(null)];
  1566. };
  1567. ComponentRecognizer.prototype.hasRoute = function(name) {
  1568. return this.names.has(name);
  1569. };
  1570. ComponentRecognizer.prototype.componentLoaded = function(name) {
  1571. return this.hasRoute(name) && lang_1.isPresent(this.names.get(name).handler.componentType);
  1572. };
  1573. ComponentRecognizer.prototype.loadComponent = function(name) {
  1574. return this.names.get(name).handler.resolveComponentType();
  1575. };
  1576. ComponentRecognizer.prototype.generate = function(name, params) {
  1577. var pathRecognizer = this.names.get(name);
  1578. if (lang_1.isBlank(pathRecognizer)) {
  1579. return null;
  1580. }
  1581. return pathRecognizer.generate(params);
  1582. };
  1583. ComponentRecognizer.prototype.generateAuxiliary = function(name, params) {
  1584. var pathRecognizer = this.auxNames.get(name);
  1585. if (lang_1.isBlank(pathRecognizer)) {
  1586. return null;
  1587. }
  1588. return pathRecognizer.generate(params);
  1589. };
  1590. return ComponentRecognizer;
  1591. })();
  1592. exports.ComponentRecognizer = ComponentRecognizer;
  1593. global.define = __define;
  1594. return module.exports;
  1595. });
  1596. System.register("angular2/src/router/route_config_nomalizer", ["angular2/src/router/route_config_decorator", "angular2/src/facade/lang", "angular2/src/facade/exceptions"], true, function(require, exports, module) {
  1597. var global = System.global,
  1598. __define = global.define;
  1599. global.define = undefined;
  1600. var route_config_decorator_1 = require("angular2/src/router/route_config_decorator");
  1601. var lang_1 = require("angular2/src/facade/lang");
  1602. var exceptions_1 = require("angular2/src/facade/exceptions");
  1603. function normalizeRouteConfig(config, registry) {
  1604. if (config instanceof route_config_decorator_1.AsyncRoute) {
  1605. var wrappedLoader = wrapLoaderToReconfigureRegistry(config.loader, registry);
  1606. return new route_config_decorator_1.AsyncRoute({
  1607. path: config.path,
  1608. loader: wrappedLoader,
  1609. name: config.name,
  1610. data: config.data,
  1611. useAsDefault: config.useAsDefault
  1612. });
  1613. }
  1614. if (config instanceof route_config_decorator_1.Route || config instanceof route_config_decorator_1.Redirect || config instanceof route_config_decorator_1.AuxRoute) {
  1615. return config;
  1616. }
  1617. if ((+!!config.component) + (+!!config.redirectTo) + (+!!config.loader) != 1) {
  1618. throw new exceptions_1.BaseException("Route config should contain exactly one \"component\", \"loader\", or \"redirectTo\" property.");
  1619. }
  1620. if (config.as && config.name) {
  1621. throw new exceptions_1.BaseException("Route config should contain exactly one \"as\" or \"name\" property.");
  1622. }
  1623. if (config.as) {
  1624. config.name = config.as;
  1625. }
  1626. if (config.loader) {
  1627. var wrappedLoader = wrapLoaderToReconfigureRegistry(config.loader, registry);
  1628. return new route_config_decorator_1.AsyncRoute({
  1629. path: config.path,
  1630. loader: wrappedLoader,
  1631. name: config.name,
  1632. useAsDefault: config.useAsDefault
  1633. });
  1634. }
  1635. if (config.aux) {
  1636. return new route_config_decorator_1.AuxRoute({
  1637. path: config.aux,
  1638. component: config.component,
  1639. name: config.name
  1640. });
  1641. }
  1642. if (config.component) {
  1643. if (typeof config.component == 'object') {
  1644. var componentDefinitionObject = config.component;
  1645. if (componentDefinitionObject.type == 'constructor') {
  1646. return new route_config_decorator_1.Route({
  1647. path: config.path,
  1648. component: componentDefinitionObject.constructor,
  1649. name: config.name,
  1650. data: config.data,
  1651. useAsDefault: config.useAsDefault
  1652. });
  1653. } else if (componentDefinitionObject.type == 'loader') {
  1654. return new route_config_decorator_1.AsyncRoute({
  1655. path: config.path,
  1656. loader: componentDefinitionObject.loader,
  1657. name: config.name,
  1658. useAsDefault: config.useAsDefault
  1659. });
  1660. } else {
  1661. throw new exceptions_1.BaseException("Invalid component type \"" + componentDefinitionObject.type + "\". Valid types are \"constructor\" and \"loader\".");
  1662. }
  1663. }
  1664. return new route_config_decorator_1.Route(config);
  1665. }
  1666. if (config.redirectTo) {
  1667. return new route_config_decorator_1.Redirect({
  1668. path: config.path,
  1669. redirectTo: config.redirectTo
  1670. });
  1671. }
  1672. return config;
  1673. }
  1674. exports.normalizeRouteConfig = normalizeRouteConfig;
  1675. function wrapLoaderToReconfigureRegistry(loader, registry) {
  1676. return function() {
  1677. return loader().then(function(componentType) {
  1678. registry.configFromComponent(componentType);
  1679. return componentType;
  1680. });
  1681. };
  1682. }
  1683. function assertComponentExists(component, path) {
  1684. if (!lang_1.isType(component)) {
  1685. throw new exceptions_1.BaseException("Component for route \"" + path + "\" is not defined, or is not a class.");
  1686. }
  1687. }
  1688. exports.assertComponentExists = assertComponentExists;
  1689. global.define = __define;
  1690. return module.exports;
  1691. });
  1692. System.register("angular2/src/router/location", ["angular2/src/router/location_strategy", "angular2/src/facade/async", "angular2/core"], true, function(require, exports, module) {
  1693. var global = System.global,
  1694. __define = global.define;
  1695. global.define = undefined;
  1696. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  1697. var c = arguments.length,
  1698. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  1699. d;
  1700. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  1701. r = Reflect.decorate(decorators, target, key, desc);
  1702. else
  1703. for (var i = decorators.length - 1; i >= 0; i--)
  1704. if (d = decorators[i])
  1705. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  1706. return c > 3 && r && Object.defineProperty(target, key, r), r;
  1707. };
  1708. var __metadata = (this && this.__metadata) || function(k, v) {
  1709. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  1710. return Reflect.metadata(k, v);
  1711. };
  1712. var location_strategy_1 = require("angular2/src/router/location_strategy");
  1713. var async_1 = require("angular2/src/facade/async");
  1714. var core_1 = require("angular2/core");
  1715. var Location = (function() {
  1716. function Location(platformStrategy) {
  1717. var _this = this;
  1718. this.platformStrategy = platformStrategy;
  1719. this._subject = new async_1.EventEmitter();
  1720. var browserBaseHref = this.platformStrategy.getBaseHref();
  1721. this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref));
  1722. this.platformStrategy.onPopState(function(ev) {
  1723. async_1.ObservableWrapper.callEmit(_this._subject, {
  1724. 'url': _this.path(),
  1725. 'pop': true,
  1726. 'type': ev.type
  1727. });
  1728. });
  1729. }
  1730. Location.prototype.path = function() {
  1731. return this.normalize(this.platformStrategy.path());
  1732. };
  1733. Location.prototype.normalize = function(url) {
  1734. return stripTrailingSlash(_stripBaseHref(this._baseHref, stripIndexHtml(url)));
  1735. };
  1736. Location.prototype.prepareExternalUrl = function(url) {
  1737. if (url.length > 0 && !url.startsWith('/')) {
  1738. url = '/' + url;
  1739. }
  1740. return this.platformStrategy.prepareExternalUrl(url);
  1741. };
  1742. Location.prototype.go = function(path, query) {
  1743. if (query === void 0) {
  1744. query = '';
  1745. }
  1746. this.platformStrategy.pushState(null, '', path, query);
  1747. };
  1748. Location.prototype.replaceState = function(path, query) {
  1749. if (query === void 0) {
  1750. query = '';
  1751. }
  1752. this.platformStrategy.replaceState(null, '', path, query);
  1753. };
  1754. Location.prototype.forward = function() {
  1755. this.platformStrategy.forward();
  1756. };
  1757. Location.prototype.back = function() {
  1758. this.platformStrategy.back();
  1759. };
  1760. Location.prototype.subscribe = function(onNext, onThrow, onReturn) {
  1761. if (onThrow === void 0) {
  1762. onThrow = null;
  1763. }
  1764. if (onReturn === void 0) {
  1765. onReturn = null;
  1766. }
  1767. return async_1.ObservableWrapper.subscribe(this._subject, onNext, onThrow, onReturn);
  1768. };
  1769. Location = __decorate([core_1.Injectable(), __metadata('design:paramtypes', [location_strategy_1.LocationStrategy])], Location);
  1770. return Location;
  1771. })();
  1772. exports.Location = Location;
  1773. function _stripBaseHref(baseHref, url) {
  1774. if (baseHref.length > 0 && url.startsWith(baseHref)) {
  1775. return url.substring(baseHref.length);
  1776. }
  1777. return url;
  1778. }
  1779. function stripIndexHtml(url) {
  1780. if (/\/index.html$/g.test(url)) {
  1781. return url.substring(0, url.length - 11);
  1782. }
  1783. return url;
  1784. }
  1785. function stripTrailingSlash(url) {
  1786. if (/\/$/g.test(url)) {
  1787. url = url.substring(0, url.length - 1);
  1788. }
  1789. return url;
  1790. }
  1791. global.define = __define;
  1792. return module.exports;
  1793. });
  1794. System.register("angular2/src/router/route_lifecycle_reflector", ["angular2/src/facade/lang", "angular2/src/router/lifecycle_annotations_impl", "angular2/src/core/reflection/reflection"], true, function(require, exports, module) {
  1795. var global = System.global,
  1796. __define = global.define;
  1797. global.define = undefined;
  1798. var lang_1 = require("angular2/src/facade/lang");
  1799. var lifecycle_annotations_impl_1 = require("angular2/src/router/lifecycle_annotations_impl");
  1800. var reflection_1 = require("angular2/src/core/reflection/reflection");
  1801. function hasLifecycleHook(e, type) {
  1802. if (!(type instanceof lang_1.Type))
  1803. return false;
  1804. return e.name in type.prototype;
  1805. }
  1806. exports.hasLifecycleHook = hasLifecycleHook;
  1807. function getCanActivateHook(type) {
  1808. var annotations = reflection_1.reflector.annotations(type);
  1809. for (var i = 0; i < annotations.length; i += 1) {
  1810. var annotation = annotations[i];
  1811. if (annotation instanceof lifecycle_annotations_impl_1.CanActivate) {
  1812. return annotation.fn;
  1813. }
  1814. }
  1815. return null;
  1816. }
  1817. exports.getCanActivateHook = getCanActivateHook;
  1818. global.define = __define;
  1819. return module.exports;
  1820. });
  1821. System.register("angular2/src/router/router_outlet", ["angular2/src/facade/async", "angular2/src/facade/collection", "angular2/src/facade/lang", "angular2/src/facade/exceptions", "angular2/core", "angular2/src/router/router", "angular2/src/router/instruction", "angular2/src/router/lifecycle_annotations", "angular2/src/router/route_lifecycle_reflector"], true, function(require, exports, module) {
  1822. var global = System.global,
  1823. __define = global.define;
  1824. global.define = undefined;
  1825. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  1826. var c = arguments.length,
  1827. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  1828. d;
  1829. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  1830. r = Reflect.decorate(decorators, target, key, desc);
  1831. else
  1832. for (var i = decorators.length - 1; i >= 0; i--)
  1833. if (d = decorators[i])
  1834. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  1835. return c > 3 && r && Object.defineProperty(target, key, r), r;
  1836. };
  1837. var __metadata = (this && this.__metadata) || function(k, v) {
  1838. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  1839. return Reflect.metadata(k, v);
  1840. };
  1841. var __param = (this && this.__param) || function(paramIndex, decorator) {
  1842. return function(target, key) {
  1843. decorator(target, key, paramIndex);
  1844. };
  1845. };
  1846. var async_1 = require("angular2/src/facade/async");
  1847. var collection_1 = require("angular2/src/facade/collection");
  1848. var lang_1 = require("angular2/src/facade/lang");
  1849. var exceptions_1 = require("angular2/src/facade/exceptions");
  1850. var core_1 = require("angular2/core");
  1851. var routerMod = require("angular2/src/router/router");
  1852. var instruction_1 = require("angular2/src/router/instruction");
  1853. var hookMod = require("angular2/src/router/lifecycle_annotations");
  1854. var route_lifecycle_reflector_1 = require("angular2/src/router/route_lifecycle_reflector");
  1855. var _resolveToTrue = async_1.PromiseWrapper.resolve(true);
  1856. var RouterOutlet = (function() {
  1857. function RouterOutlet(_elementRef, _loader, _parentRouter, nameAttr) {
  1858. this._elementRef = _elementRef;
  1859. this._loader = _loader;
  1860. this._parentRouter = _parentRouter;
  1861. this.name = null;
  1862. this._componentRef = null;
  1863. this._currentInstruction = null;
  1864. if (lang_1.isPresent(nameAttr)) {
  1865. this.name = nameAttr;
  1866. this._parentRouter.registerAuxOutlet(this);
  1867. } else {
  1868. this._parentRouter.registerPrimaryOutlet(this);
  1869. }
  1870. }
  1871. RouterOutlet.prototype.activate = function(nextInstruction) {
  1872. var _this = this;
  1873. var previousInstruction = this._currentInstruction;
  1874. this._currentInstruction = nextInstruction;
  1875. var componentType = nextInstruction.componentType;
  1876. var childRouter = this._parentRouter.childRouter(componentType);
  1877. var providers = core_1.Injector.resolve([core_1.provide(instruction_1.RouteData, {useValue: nextInstruction.routeData}), core_1.provide(instruction_1.RouteParams, {useValue: new instruction_1.RouteParams(nextInstruction.params)}), core_1.provide(routerMod.Router, {useValue: childRouter})]);
  1878. return this._loader.loadNextToLocation(componentType, this._elementRef, providers).then(function(componentRef) {
  1879. _this._componentRef = componentRef;
  1880. if (route_lifecycle_reflector_1.hasLifecycleHook(hookMod.routerOnActivate, componentType)) {
  1881. return _this._componentRef.instance.routerOnActivate(nextInstruction, previousInstruction);
  1882. }
  1883. });
  1884. };
  1885. RouterOutlet.prototype.reuse = function(nextInstruction) {
  1886. var previousInstruction = this._currentInstruction;
  1887. this._currentInstruction = nextInstruction;
  1888. if (lang_1.isBlank(this._componentRef)) {
  1889. throw new exceptions_1.BaseException("Cannot reuse an outlet that does not contain a component.");
  1890. }
  1891. return async_1.PromiseWrapper.resolve(route_lifecycle_reflector_1.hasLifecycleHook(hookMod.routerOnReuse, this._currentInstruction.componentType) ? this._componentRef.instance.routerOnReuse(nextInstruction, previousInstruction) : true);
  1892. };
  1893. RouterOutlet.prototype.deactivate = function(nextInstruction) {
  1894. var _this = this;
  1895. var next = _resolveToTrue;
  1896. if (lang_1.isPresent(this._componentRef) && lang_1.isPresent(this._currentInstruction) && route_lifecycle_reflector_1.hasLifecycleHook(hookMod.routerOnDeactivate, this._currentInstruction.componentType)) {
  1897. next = async_1.PromiseWrapper.resolve(this._componentRef.instance.routerOnDeactivate(nextInstruction, this._currentInstruction));
  1898. }
  1899. return next.then(function(_) {
  1900. if (lang_1.isPresent(_this._componentRef)) {
  1901. _this._componentRef.dispose();
  1902. _this._componentRef = null;
  1903. }
  1904. });
  1905. };
  1906. RouterOutlet.prototype.routerCanDeactivate = function(nextInstruction) {
  1907. if (lang_1.isBlank(this._currentInstruction)) {
  1908. return _resolveToTrue;
  1909. }
  1910. if (route_lifecycle_reflector_1.hasLifecycleHook(hookMod.routerCanDeactivate, this._currentInstruction.componentType)) {
  1911. return async_1.PromiseWrapper.resolve(this._componentRef.instance.routerCanDeactivate(nextInstruction, this._currentInstruction));
  1912. }
  1913. return _resolveToTrue;
  1914. };
  1915. RouterOutlet.prototype.routerCanReuse = function(nextInstruction) {
  1916. var result;
  1917. if (lang_1.isBlank(this._currentInstruction) || this._currentInstruction.componentType != nextInstruction.componentType) {
  1918. result = false;
  1919. } else if (route_lifecycle_reflector_1.hasLifecycleHook(hookMod.routerCanReuse, this._currentInstruction.componentType)) {
  1920. result = this._componentRef.instance.routerCanReuse(nextInstruction, this._currentInstruction);
  1921. } else {
  1922. result = nextInstruction == this._currentInstruction || (lang_1.isPresent(nextInstruction.params) && lang_1.isPresent(this._currentInstruction.params) && collection_1.StringMapWrapper.equals(nextInstruction.params, this._currentInstruction.params));
  1923. }
  1924. return async_1.PromiseWrapper.resolve(result);
  1925. };
  1926. RouterOutlet = __decorate([core_1.Directive({selector: 'router-outlet'}), __param(3, core_1.Attribute('name')), __metadata('design:paramtypes', [core_1.ElementRef, core_1.DynamicComponentLoader, routerMod.Router, String])], RouterOutlet);
  1927. return RouterOutlet;
  1928. })();
  1929. exports.RouterOutlet = RouterOutlet;
  1930. global.define = __define;
  1931. return module.exports;
  1932. });
  1933. System.register("angular2/src/router/platform_location", ["angular2/src/platform/dom/dom_adapter", "angular2/core"], true, function(require, exports, module) {
  1934. var global = System.global,
  1935. __define = global.define;
  1936. global.define = undefined;
  1937. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  1938. var c = arguments.length,
  1939. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  1940. d;
  1941. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  1942. r = Reflect.decorate(decorators, target, key, desc);
  1943. else
  1944. for (var i = decorators.length - 1; i >= 0; i--)
  1945. if (d = decorators[i])
  1946. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  1947. return c > 3 && r && Object.defineProperty(target, key, r), r;
  1948. };
  1949. var __metadata = (this && this.__metadata) || function(k, v) {
  1950. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  1951. return Reflect.metadata(k, v);
  1952. };
  1953. var dom_adapter_1 = require("angular2/src/platform/dom/dom_adapter");
  1954. var core_1 = require("angular2/core");
  1955. var PlatformLocation = (function() {
  1956. function PlatformLocation() {
  1957. this._init();
  1958. }
  1959. PlatformLocation.prototype._init = function() {
  1960. this._location = dom_adapter_1.DOM.getLocation();
  1961. this._history = dom_adapter_1.DOM.getHistory();
  1962. };
  1963. PlatformLocation.prototype.getBaseHrefFromDOM = function() {
  1964. return dom_adapter_1.DOM.getBaseHref();
  1965. };
  1966. PlatformLocation.prototype.onPopState = function(fn) {
  1967. dom_adapter_1.DOM.getGlobalEventTarget('window').addEventListener('popstate', fn, false);
  1968. };
  1969. PlatformLocation.prototype.onHashChange = function(fn) {
  1970. dom_adapter_1.DOM.getGlobalEventTarget('window').addEventListener('hashchange', fn, false);
  1971. };
  1972. Object.defineProperty(PlatformLocation.prototype, "pathname", {
  1973. get: function() {
  1974. return this._location.pathname;
  1975. },
  1976. set: function(newPath) {
  1977. this._location.pathname = newPath;
  1978. },
  1979. enumerable: true,
  1980. configurable: true
  1981. });
  1982. Object.defineProperty(PlatformLocation.prototype, "search", {
  1983. get: function() {
  1984. return this._location.search;
  1985. },
  1986. enumerable: true,
  1987. configurable: true
  1988. });
  1989. Object.defineProperty(PlatformLocation.prototype, "hash", {
  1990. get: function() {
  1991. return this._location.hash;
  1992. },
  1993. enumerable: true,
  1994. configurable: true
  1995. });
  1996. PlatformLocation.prototype.pushState = function(state, title, url) {
  1997. this._history.pushState(state, title, url);
  1998. };
  1999. PlatformLocation.prototype.replaceState = function(state, title, url) {
  2000. this._history.replaceState(state, title, url);
  2001. };
  2002. PlatformLocation.prototype.forward = function() {
  2003. this._history.forward();
  2004. };
  2005. PlatformLocation.prototype.back = function() {
  2006. this._history.back();
  2007. };
  2008. PlatformLocation = __decorate([core_1.Injectable(), __metadata('design:paramtypes', [])], PlatformLocation);
  2009. return PlatformLocation;
  2010. })();
  2011. exports.PlatformLocation = PlatformLocation;
  2012. global.define = __define;
  2013. return module.exports;
  2014. });
  2015. System.register("angular2/src/router/route_recognizer", ["angular2/src/facade/lang", "angular2/src/facade/exceptions", "angular2/src/facade/promise", "angular2/src/facade/collection", "angular2/src/router/instruction", "angular2/src/router/path_recognizer"], true, function(require, exports, module) {
  2016. var global = System.global,
  2017. __define = global.define;
  2018. global.define = undefined;
  2019. var __extends = (this && this.__extends) || function(d, b) {
  2020. for (var p in b)
  2021. if (b.hasOwnProperty(p))
  2022. d[p] = b[p];
  2023. function __() {
  2024. this.constructor = d;
  2025. }
  2026. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2027. };
  2028. var lang_1 = require("angular2/src/facade/lang");
  2029. var exceptions_1 = require("angular2/src/facade/exceptions");
  2030. var promise_1 = require("angular2/src/facade/promise");
  2031. var collection_1 = require("angular2/src/facade/collection");
  2032. var instruction_1 = require("angular2/src/router/instruction");
  2033. var path_recognizer_1 = require("angular2/src/router/path_recognizer");
  2034. var RouteMatch = (function() {
  2035. function RouteMatch() {}
  2036. return RouteMatch;
  2037. })();
  2038. exports.RouteMatch = RouteMatch;
  2039. var PathMatch = (function(_super) {
  2040. __extends(PathMatch, _super);
  2041. function PathMatch(instruction, remaining, remainingAux) {
  2042. _super.call(this);
  2043. this.instruction = instruction;
  2044. this.remaining = remaining;
  2045. this.remainingAux = remainingAux;
  2046. }
  2047. return PathMatch;
  2048. })(RouteMatch);
  2049. exports.PathMatch = PathMatch;
  2050. var RedirectMatch = (function(_super) {
  2051. __extends(RedirectMatch, _super);
  2052. function RedirectMatch(redirectTo, specificity) {
  2053. _super.call(this);
  2054. this.redirectTo = redirectTo;
  2055. this.specificity = specificity;
  2056. }
  2057. return RedirectMatch;
  2058. })(RouteMatch);
  2059. exports.RedirectMatch = RedirectMatch;
  2060. var RedirectRecognizer = (function() {
  2061. function RedirectRecognizer(path, redirectTo) {
  2062. this.path = path;
  2063. this.redirectTo = redirectTo;
  2064. this._pathRecognizer = new path_recognizer_1.PathRecognizer(path);
  2065. this.hash = this._pathRecognizer.hash;
  2066. }
  2067. RedirectRecognizer.prototype.recognize = function(beginningSegment) {
  2068. var match = null;
  2069. if (lang_1.isPresent(this._pathRecognizer.recognize(beginningSegment))) {
  2070. match = new RedirectMatch(this.redirectTo, this._pathRecognizer.specificity);
  2071. }
  2072. return promise_1.PromiseWrapper.resolve(match);
  2073. };
  2074. RedirectRecognizer.prototype.generate = function(params) {
  2075. throw new exceptions_1.BaseException("Tried to generate a redirect.");
  2076. };
  2077. return RedirectRecognizer;
  2078. })();
  2079. exports.RedirectRecognizer = RedirectRecognizer;
  2080. var RouteRecognizer = (function() {
  2081. function RouteRecognizer(path, handler) {
  2082. this.path = path;
  2083. this.handler = handler;
  2084. this.terminal = true;
  2085. this._cache = new collection_1.Map();
  2086. this._pathRecognizer = new path_recognizer_1.PathRecognizer(path);
  2087. this.specificity = this._pathRecognizer.specificity;
  2088. this.hash = this._pathRecognizer.hash;
  2089. this.terminal = this._pathRecognizer.terminal;
  2090. }
  2091. RouteRecognizer.prototype.recognize = function(beginningSegment) {
  2092. var _this = this;
  2093. var res = this._pathRecognizer.recognize(beginningSegment);
  2094. if (lang_1.isBlank(res)) {
  2095. return null;
  2096. }
  2097. return this.handler.resolveComponentType().then(function(_) {
  2098. var componentInstruction = _this._getInstruction(res['urlPath'], res['urlParams'], res['allParams']);
  2099. return new PathMatch(componentInstruction, res['nextSegment'], res['auxiliary']);
  2100. });
  2101. };
  2102. RouteRecognizer.prototype.generate = function(params) {
  2103. var generated = this._pathRecognizer.generate(params);
  2104. var urlPath = generated['urlPath'];
  2105. var urlParams = generated['urlParams'];
  2106. return this._getInstruction(urlPath, urlParams, params);
  2107. };
  2108. RouteRecognizer.prototype.generateComponentPathValues = function(params) {
  2109. return this._pathRecognizer.generate(params);
  2110. };
  2111. RouteRecognizer.prototype._getInstruction = function(urlPath, urlParams, params) {
  2112. if (lang_1.isBlank(this.handler.componentType)) {
  2113. throw new exceptions_1.BaseException("Tried to get instruction before the type was loaded.");
  2114. }
  2115. var hashKey = urlPath + '?' + urlParams.join('?');
  2116. if (this._cache.has(hashKey)) {
  2117. return this._cache.get(hashKey);
  2118. }
  2119. var instruction = new instruction_1.ComponentInstruction(urlPath, urlParams, this.handler.data, this.handler.componentType, this.terminal, this.specificity, params);
  2120. this._cache.set(hashKey, instruction);
  2121. return instruction;
  2122. };
  2123. return RouteRecognizer;
  2124. })();
  2125. exports.RouteRecognizer = RouteRecognizer;
  2126. global.define = __define;
  2127. return module.exports;
  2128. });
  2129. System.register("angular2/src/router/route_registry", ["angular2/src/facade/collection", "angular2/src/facade/async", "angular2/src/facade/lang", "angular2/src/facade/exceptions", "angular2/src/core/reflection/reflection", "angular2/core", "angular2/src/router/route_config_impl", "angular2/src/router/route_recognizer", "angular2/src/router/component_recognizer", "angular2/src/router/instruction", "angular2/src/router/route_config_nomalizer", "angular2/src/router/url_parser"], true, function(require, exports, module) {
  2130. var global = System.global,
  2131. __define = global.define;
  2132. global.define = undefined;
  2133. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  2134. var c = arguments.length,
  2135. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  2136. d;
  2137. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  2138. r = Reflect.decorate(decorators, target, key, desc);
  2139. else
  2140. for (var i = decorators.length - 1; i >= 0; i--)
  2141. if (d = decorators[i])
  2142. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  2143. return c > 3 && r && Object.defineProperty(target, key, r), r;
  2144. };
  2145. var __metadata = (this && this.__metadata) || function(k, v) {
  2146. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  2147. return Reflect.metadata(k, v);
  2148. };
  2149. var __param = (this && this.__param) || function(paramIndex, decorator) {
  2150. return function(target, key) {
  2151. decorator(target, key, paramIndex);
  2152. };
  2153. };
  2154. var collection_1 = require("angular2/src/facade/collection");
  2155. var async_1 = require("angular2/src/facade/async");
  2156. var lang_1 = require("angular2/src/facade/lang");
  2157. var exceptions_1 = require("angular2/src/facade/exceptions");
  2158. var reflection_1 = require("angular2/src/core/reflection/reflection");
  2159. var core_1 = require("angular2/core");
  2160. var route_config_impl_1 = require("angular2/src/router/route_config_impl");
  2161. var route_recognizer_1 = require("angular2/src/router/route_recognizer");
  2162. var component_recognizer_1 = require("angular2/src/router/component_recognizer");
  2163. var instruction_1 = require("angular2/src/router/instruction");
  2164. var route_config_nomalizer_1 = require("angular2/src/router/route_config_nomalizer");
  2165. var url_parser_1 = require("angular2/src/router/url_parser");
  2166. var _resolveToNull = async_1.PromiseWrapper.resolve(null);
  2167. exports.ROUTER_PRIMARY_COMPONENT = lang_1.CONST_EXPR(new core_1.OpaqueToken('RouterPrimaryComponent'));
  2168. var RouteRegistry = (function() {
  2169. function RouteRegistry(_rootComponent) {
  2170. this._rootComponent = _rootComponent;
  2171. this._rules = new collection_1.Map();
  2172. }
  2173. RouteRegistry.prototype.config = function(parentComponent, config) {
  2174. config = route_config_nomalizer_1.normalizeRouteConfig(config, this);
  2175. if (config instanceof route_config_impl_1.Route) {
  2176. route_config_nomalizer_1.assertComponentExists(config.component, config.path);
  2177. } else if (config instanceof route_config_impl_1.AuxRoute) {
  2178. route_config_nomalizer_1.assertComponentExists(config.component, config.path);
  2179. }
  2180. var recognizer = this._rules.get(parentComponent);
  2181. if (lang_1.isBlank(recognizer)) {
  2182. recognizer = new component_recognizer_1.ComponentRecognizer();
  2183. this._rules.set(parentComponent, recognizer);
  2184. }
  2185. var terminal = recognizer.config(config);
  2186. if (config instanceof route_config_impl_1.Route) {
  2187. if (terminal) {
  2188. assertTerminalComponent(config.component, config.path);
  2189. } else {
  2190. this.configFromComponent(config.component);
  2191. }
  2192. }
  2193. };
  2194. RouteRegistry.prototype.configFromComponent = function(component) {
  2195. var _this = this;
  2196. if (!lang_1.isType(component)) {
  2197. return ;
  2198. }
  2199. if (this._rules.has(component)) {
  2200. return ;
  2201. }
  2202. var annotations = reflection_1.reflector.annotations(component);
  2203. if (lang_1.isPresent(annotations)) {
  2204. for (var i = 0; i < annotations.length; i++) {
  2205. var annotation = annotations[i];
  2206. if (annotation instanceof route_config_impl_1.RouteConfig) {
  2207. var routeCfgs = annotation.configs;
  2208. routeCfgs.forEach(function(config) {
  2209. return _this.config(component, config);
  2210. });
  2211. }
  2212. }
  2213. }
  2214. };
  2215. RouteRegistry.prototype.recognize = function(url, ancestorInstructions) {
  2216. var parsedUrl = url_parser_1.parser.parse(url);
  2217. return this._recognize(parsedUrl, ancestorInstructions);
  2218. };
  2219. RouteRegistry.prototype._recognize = function(parsedUrl, ancestorInstructions, _aux) {
  2220. var _this = this;
  2221. if (_aux === void 0) {
  2222. _aux = false;
  2223. }
  2224. var parentComponent = ancestorInstructions.length > 0 ? ancestorInstructions[ancestorInstructions.length - 1].component.componentType : this._rootComponent;
  2225. var componentRecognizer = this._rules.get(parentComponent);
  2226. if (lang_1.isBlank(componentRecognizer)) {
  2227. return _resolveToNull;
  2228. }
  2229. var possibleMatches = _aux ? componentRecognizer.recognizeAuxiliary(parsedUrl) : componentRecognizer.recognize(parsedUrl);
  2230. var matchPromises = possibleMatches.map(function(candidate) {
  2231. return candidate.then(function(candidate) {
  2232. if (candidate instanceof route_recognizer_1.PathMatch) {
  2233. var auxParentInstructions = ancestorInstructions.length > 0 ? [ancestorInstructions[ancestorInstructions.length - 1]] : [];
  2234. var auxInstructions = _this._auxRoutesToUnresolved(candidate.remainingAux, auxParentInstructions);
  2235. var instruction = new instruction_1.ResolvedInstruction(candidate.instruction, null, auxInstructions);
  2236. if (candidate.instruction.terminal) {
  2237. return instruction;
  2238. }
  2239. var newAncestorComponents = ancestorInstructions.concat([instruction]);
  2240. return _this._recognize(candidate.remaining, newAncestorComponents).then(function(childInstruction) {
  2241. if (lang_1.isBlank(childInstruction)) {
  2242. return null;
  2243. }
  2244. if (childInstruction instanceof instruction_1.RedirectInstruction) {
  2245. return childInstruction;
  2246. }
  2247. instruction.child = childInstruction;
  2248. return instruction;
  2249. });
  2250. }
  2251. if (candidate instanceof route_recognizer_1.RedirectMatch) {
  2252. var instruction = _this.generate(candidate.redirectTo, ancestorInstructions);
  2253. return new instruction_1.RedirectInstruction(instruction.component, instruction.child, instruction.auxInstruction);
  2254. }
  2255. });
  2256. });
  2257. if ((lang_1.isBlank(parsedUrl) || parsedUrl.path == '') && possibleMatches.length == 0) {
  2258. return async_1.PromiseWrapper.resolve(this.generateDefault(parentComponent));
  2259. }
  2260. return async_1.PromiseWrapper.all(matchPromises).then(mostSpecific);
  2261. };
  2262. RouteRegistry.prototype._auxRoutesToUnresolved = function(auxRoutes, parentInstructions) {
  2263. var _this = this;
  2264. var unresolvedAuxInstructions = {};
  2265. auxRoutes.forEach(function(auxUrl) {
  2266. unresolvedAuxInstructions[auxUrl.path] = new instruction_1.UnresolvedInstruction(function() {
  2267. return _this._recognize(auxUrl, parentInstructions, true);
  2268. });
  2269. });
  2270. return unresolvedAuxInstructions;
  2271. };
  2272. RouteRegistry.prototype.generate = function(linkParams, ancestorInstructions, _aux) {
  2273. if (_aux === void 0) {
  2274. _aux = false;
  2275. }
  2276. var normalizedLinkParams = splitAndFlattenLinkParams(linkParams);
  2277. var first = collection_1.ListWrapper.first(normalizedLinkParams);
  2278. var rest = collection_1.ListWrapper.slice(normalizedLinkParams, 1);
  2279. if (first == '') {
  2280. ancestorInstructions = [];
  2281. } else if (first == '..') {
  2282. ancestorInstructions.pop();
  2283. while (collection_1.ListWrapper.first(rest) == '..') {
  2284. rest = collection_1.ListWrapper.slice(rest, 1);
  2285. ancestorInstructions.pop();
  2286. if (ancestorInstructions.length <= 0) {
  2287. throw new exceptions_1.BaseException("Link \"" + collection_1.ListWrapper.toJSON(linkParams) + "\" has too many \"../\" segments.");
  2288. }
  2289. }
  2290. } else if (first != '.') {
  2291. var parentComponent = this._rootComponent;
  2292. var grandparentComponent = null;
  2293. if (ancestorInstructions.length > 1) {
  2294. parentComponent = ancestorInstructions[ancestorInstructions.length - 1].component.componentType;
  2295. grandparentComponent = ancestorInstructions[ancestorInstructions.length - 2].component.componentType;
  2296. } else if (ancestorInstructions.length == 1) {
  2297. parentComponent = ancestorInstructions[0].component.componentType;
  2298. grandparentComponent = this._rootComponent;
  2299. }
  2300. var childRouteExists = this.hasRoute(first, parentComponent);
  2301. var parentRouteExists = lang_1.isPresent(grandparentComponent) && this.hasRoute(first, grandparentComponent);
  2302. if (parentRouteExists && childRouteExists) {
  2303. var msg = "Link \"" + collection_1.ListWrapper.toJSON(linkParams) + "\" is ambiguous, use \"./\" or \"../\" to disambiguate.";
  2304. throw new exceptions_1.BaseException(msg);
  2305. }
  2306. if (parentRouteExists) {
  2307. ancestorInstructions.pop();
  2308. }
  2309. rest = linkParams;
  2310. }
  2311. if (rest[rest.length - 1] == '') {
  2312. rest.pop();
  2313. }
  2314. if (rest.length < 1) {
  2315. var msg = "Link \"" + collection_1.ListWrapper.toJSON(linkParams) + "\" must include a route name.";
  2316. throw new exceptions_1.BaseException(msg);
  2317. }
  2318. var generatedInstruction = this._generate(rest, ancestorInstructions, _aux);
  2319. for (var i = ancestorInstructions.length - 1; i >= 0; i--) {
  2320. var ancestorInstruction = ancestorInstructions[i];
  2321. generatedInstruction = ancestorInstruction.replaceChild(generatedInstruction);
  2322. }
  2323. return generatedInstruction;
  2324. };
  2325. RouteRegistry.prototype._generate = function(linkParams, ancestorInstructions, _aux) {
  2326. var _this = this;
  2327. if (_aux === void 0) {
  2328. _aux = false;
  2329. }
  2330. var parentComponent = ancestorInstructions.length > 0 ? ancestorInstructions[ancestorInstructions.length - 1].component.componentType : this._rootComponent;
  2331. if (linkParams.length == 0) {
  2332. return this.generateDefault(parentComponent);
  2333. }
  2334. var linkIndex = 0;
  2335. var routeName = linkParams[linkIndex];
  2336. if (!lang_1.isString(routeName)) {
  2337. throw new exceptions_1.BaseException("Unexpected segment \"" + routeName + "\" in link DSL. Expected a string.");
  2338. } else if (routeName == '' || routeName == '.' || routeName == '..') {
  2339. throw new exceptions_1.BaseException("\"" + routeName + "/\" is only allowed at the beginning of a link DSL.");
  2340. }
  2341. var params = {};
  2342. if (linkIndex + 1 < linkParams.length) {
  2343. var nextSegment_1 = linkParams[linkIndex + 1];
  2344. if (lang_1.isStringMap(nextSegment_1) && !lang_1.isArray(nextSegment_1)) {
  2345. params = nextSegment_1;
  2346. linkIndex += 1;
  2347. }
  2348. }
  2349. var auxInstructions = {};
  2350. var nextSegment;
  2351. while (linkIndex + 1 < linkParams.length && lang_1.isArray(nextSegment = linkParams[linkIndex + 1])) {
  2352. var auxParentInstruction = ancestorInstructions.length > 0 ? [ancestorInstructions[ancestorInstructions.length - 1]] : [];
  2353. var auxInstruction = this._generate(nextSegment, auxParentInstruction, true);
  2354. auxInstructions[auxInstruction.component.urlPath] = auxInstruction;
  2355. linkIndex += 1;
  2356. }
  2357. var componentRecognizer = this._rules.get(parentComponent);
  2358. if (lang_1.isBlank(componentRecognizer)) {
  2359. throw new exceptions_1.BaseException("Component \"" + lang_1.getTypeNameForDebugging(parentComponent) + "\" has no route config.");
  2360. }
  2361. var routeRecognizer = (_aux ? componentRecognizer.auxNames : componentRecognizer.names).get(routeName);
  2362. if (!lang_1.isPresent(routeRecognizer)) {
  2363. throw new exceptions_1.BaseException("Component \"" + lang_1.getTypeNameForDebugging(parentComponent) + "\" has no route named \"" + routeName + "\".");
  2364. }
  2365. if (!lang_1.isPresent(routeRecognizer.handler.componentType)) {
  2366. var compInstruction = routeRecognizer.generateComponentPathValues(params);
  2367. return new instruction_1.UnresolvedInstruction(function() {
  2368. return routeRecognizer.handler.resolveComponentType().then(function(_) {
  2369. return _this._generate(linkParams, ancestorInstructions, _aux);
  2370. });
  2371. }, compInstruction['urlPath'], compInstruction['urlParams']);
  2372. }
  2373. var componentInstruction = _aux ? componentRecognizer.generateAuxiliary(routeName, params) : componentRecognizer.generate(routeName, params);
  2374. var remaining = linkParams.slice(linkIndex + 1);
  2375. var instruction = new instruction_1.ResolvedInstruction(componentInstruction, null, auxInstructions);
  2376. if (lang_1.isPresent(componentInstruction.componentType)) {
  2377. var childInstruction = null;
  2378. if (linkIndex + 1 < linkParams.length) {
  2379. var childAncestorComponents = ancestorInstructions.concat([instruction]);
  2380. childInstruction = this._generate(remaining, childAncestorComponents);
  2381. } else if (!componentInstruction.terminal) {
  2382. childInstruction = this.generateDefault(componentInstruction.componentType);
  2383. if (lang_1.isBlank(childInstruction)) {
  2384. throw new exceptions_1.BaseException("Link \"" + collection_1.ListWrapper.toJSON(linkParams) + "\" does not resolve to a terminal instruction.");
  2385. }
  2386. }
  2387. instruction.child = childInstruction;
  2388. }
  2389. return instruction;
  2390. };
  2391. RouteRegistry.prototype.hasRoute = function(name, parentComponent) {
  2392. var componentRecognizer = this._rules.get(parentComponent);
  2393. if (lang_1.isBlank(componentRecognizer)) {
  2394. return false;
  2395. }
  2396. return componentRecognizer.hasRoute(name);
  2397. };
  2398. RouteRegistry.prototype.generateDefault = function(componentCursor) {
  2399. var _this = this;
  2400. if (lang_1.isBlank(componentCursor)) {
  2401. return null;
  2402. }
  2403. var componentRecognizer = this._rules.get(componentCursor);
  2404. if (lang_1.isBlank(componentRecognizer) || lang_1.isBlank(componentRecognizer.defaultRoute)) {
  2405. return null;
  2406. }
  2407. var defaultChild = null;
  2408. if (lang_1.isPresent(componentRecognizer.defaultRoute.handler.componentType)) {
  2409. var componentInstruction = componentRecognizer.defaultRoute.generate({});
  2410. if (!componentRecognizer.defaultRoute.terminal) {
  2411. defaultChild = this.generateDefault(componentRecognizer.defaultRoute.handler.componentType);
  2412. }
  2413. return new instruction_1.DefaultInstruction(componentInstruction, defaultChild);
  2414. }
  2415. return new instruction_1.UnresolvedInstruction(function() {
  2416. return componentRecognizer.defaultRoute.handler.resolveComponentType().then(function(_) {
  2417. return _this.generateDefault(componentCursor);
  2418. });
  2419. });
  2420. };
  2421. RouteRegistry = __decorate([core_1.Injectable(), __param(0, core_1.Inject(exports.ROUTER_PRIMARY_COMPONENT)), __metadata('design:paramtypes', [lang_1.Type])], RouteRegistry);
  2422. return RouteRegistry;
  2423. })();
  2424. exports.RouteRegistry = RouteRegistry;
  2425. function splitAndFlattenLinkParams(linkParams) {
  2426. return linkParams.reduce(function(accumulation, item) {
  2427. if (lang_1.isString(item)) {
  2428. var strItem = item;
  2429. return accumulation.concat(strItem.split('/'));
  2430. }
  2431. accumulation.push(item);
  2432. return accumulation;
  2433. }, []);
  2434. }
  2435. function mostSpecific(instructions) {
  2436. return collection_1.ListWrapper.maximum(instructions, function(instruction) {
  2437. return instruction.specificity;
  2438. });
  2439. }
  2440. function assertTerminalComponent(component, path) {
  2441. if (!lang_1.isType(component)) {
  2442. return ;
  2443. }
  2444. var annotations = reflection_1.reflector.annotations(component);
  2445. if (lang_1.isPresent(annotations)) {
  2446. for (var i = 0; i < annotations.length; i++) {
  2447. var annotation = annotations[i];
  2448. if (annotation instanceof route_config_impl_1.RouteConfig) {
  2449. throw new exceptions_1.BaseException("Child routes are not allowed for \"" + path + "\". Use \"...\" on the parent's route path.");
  2450. }
  2451. }
  2452. }
  2453. }
  2454. global.define = __define;
  2455. return module.exports;
  2456. });
  2457. System.register("angular2/src/router/router", ["angular2/src/facade/async", "angular2/src/facade/collection", "angular2/src/facade/lang", "angular2/src/facade/exceptions", "angular2/core", "angular2/src/router/route_registry", "angular2/src/router/location", "angular2/src/router/route_lifecycle_reflector"], true, function(require, exports, module) {
  2458. var global = System.global,
  2459. __define = global.define;
  2460. global.define = undefined;
  2461. var __extends = (this && this.__extends) || function(d, b) {
  2462. for (var p in b)
  2463. if (b.hasOwnProperty(p))
  2464. d[p] = b[p];
  2465. function __() {
  2466. this.constructor = d;
  2467. }
  2468. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  2469. };
  2470. var __decorate = (this && this.__decorate) || function(decorators, target, key, desc) {
  2471. var c = arguments.length,
  2472. r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
  2473. d;
  2474. if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
  2475. r = Reflect.decorate(decorators, target, key, desc);
  2476. else
  2477. for (var i = decorators.length - 1; i >= 0; i--)
  2478. if (d = decorators[i])
  2479. r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  2480. return c > 3 && r && Object.defineProperty(target, key, r), r;
  2481. };
  2482. var __metadata = (this && this.__metadata) || function(k, v) {
  2483. if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
  2484. return Reflect.metadata(k, v);
  2485. };
  2486. var __param = (this && this.__param) || function(paramIndex, decorator) {
  2487. return function(target, key) {
  2488. decorator(target, key, paramIndex);
  2489. };
  2490. };
  2491. var async_1 = require("angular2/src/facade/async");
  2492. var collection_1 = require("angular2/src/facade/collection");
  2493. var lang_1 = require("angular2/src/facade/lang");
  2494. var exceptions_1 = require("angular2/src/facade/exceptions");
  2495. var core_1 = require("angular2/core");
  2496. var route_registry_1 = require("angular2/src/router/route_registry");
  2497. var location_1 = require("angular2/src/router/location");
  2498. var route_lifecycle_reflector_1 = require("angular2/src/router/route_lifecycle_reflector");
  2499. var _resolveToTrue = async_1.PromiseWrapper.resolve(true);
  2500. var _resolveToFalse = async_1.PromiseWrapper.resolve(false);
  2501. var Router = (function() {
  2502. function Router(registry, parent, hostComponent) {
  2503. this.registry = registry;
  2504. this.parent = parent;
  2505. this.hostComponent = hostComponent;
  2506. this.navigating = false;
  2507. this._currentInstruction = null;
  2508. this._currentNavigation = _resolveToTrue;
  2509. this._outlet = null;
  2510. this._auxRouters = new collection_1.Map();
  2511. this._subject = new async_1.EventEmitter();
  2512. }
  2513. Router.prototype.childRouter = function(hostComponent) {
  2514. return this._childRouter = new ChildRouter(this, hostComponent);
  2515. };
  2516. Router.prototype.auxRouter = function(hostComponent) {
  2517. return new ChildRouter(this, hostComponent);
  2518. };
  2519. Router.prototype.registerPrimaryOutlet = function(outlet) {
  2520. if (lang_1.isPresent(outlet.name)) {
  2521. throw new exceptions_1.BaseException("registerPrimaryOutlet expects to be called with an unnamed outlet.");
  2522. }
  2523. this._outlet = outlet;
  2524. if (lang_1.isPresent(this._currentInstruction)) {
  2525. return this.commit(this._currentInstruction, false);
  2526. }
  2527. return _resolveToTrue;
  2528. };
  2529. Router.prototype.registerAuxOutlet = function(outlet) {
  2530. var outletName = outlet.name;
  2531. if (lang_1.isBlank(outletName)) {
  2532. throw new exceptions_1.BaseException("registerAuxOutlet expects to be called with an outlet with a name.");
  2533. }
  2534. var router = this.auxRouter(this.hostComponent);
  2535. this._auxRouters.set(outletName, router);
  2536. router._outlet = outlet;
  2537. var auxInstruction;
  2538. if (lang_1.isPresent(this._currentInstruction) && lang_1.isPresent(auxInstruction = this._currentInstruction.auxInstruction[outletName])) {
  2539. return router.commit(auxInstruction);
  2540. }
  2541. return _resolveToTrue;
  2542. };
  2543. Router.prototype.isRouteActive = function(instruction) {
  2544. var router = this;
  2545. while (lang_1.isPresent(router.parent) && lang_1.isPresent(instruction.child)) {
  2546. router = router.parent;
  2547. instruction = instruction.child;
  2548. }
  2549. return lang_1.isPresent(this._currentInstruction) && this._currentInstruction.component == instruction.component;
  2550. };
  2551. Router.prototype.config = function(definitions) {
  2552. var _this = this;
  2553. definitions.forEach(function(routeDefinition) {
  2554. _this.registry.config(_this.hostComponent, routeDefinition);
  2555. });
  2556. return this.renavigate();
  2557. };
  2558. Router.prototype.navigate = function(linkParams) {
  2559. var instruction = this.generate(linkParams);
  2560. return this.navigateByInstruction(instruction, false);
  2561. };
  2562. Router.prototype.navigateByUrl = function(url, _skipLocationChange) {
  2563. var _this = this;
  2564. if (_skipLocationChange === void 0) {
  2565. _skipLocationChange = false;
  2566. }
  2567. return this._currentNavigation = this._currentNavigation.then(function(_) {
  2568. _this.lastNavigationAttempt = url;
  2569. _this._startNavigating();
  2570. return _this._afterPromiseFinishNavigating(_this.recognize(url).then(function(instruction) {
  2571. if (lang_1.isBlank(instruction)) {
  2572. return false;
  2573. }
  2574. return _this._navigate(instruction, _skipLocationChange);
  2575. }));
  2576. });
  2577. };
  2578. Router.prototype.navigateByInstruction = function(instruction, _skipLocationChange) {
  2579. var _this = this;
  2580. if (_skipLocationChange === void 0) {
  2581. _skipLocationChange = false;
  2582. }
  2583. if (lang_1.isBlank(instruction)) {
  2584. return _resolveToFalse;
  2585. }
  2586. return this._currentNavigation = this._currentNavigation.then(function(_) {
  2587. _this._startNavigating();
  2588. return _this._afterPromiseFinishNavigating(_this._navigate(instruction, _skipLocationChange));
  2589. });
  2590. };
  2591. Router.prototype._navigate = function(instruction, _skipLocationChange) {
  2592. var _this = this;
  2593. return this._settleInstruction(instruction).then(function(_) {
  2594. return _this._routerCanReuse(instruction);
  2595. }).then(function(_) {
  2596. return _this._canActivate(instruction);
  2597. }).then(function(result) {
  2598. if (!result) {
  2599. return false;
  2600. }
  2601. return _this._routerCanDeactivate(instruction).then(function(result) {
  2602. if (result) {
  2603. return _this.commit(instruction, _skipLocationChange).then(function(_) {
  2604. _this._emitNavigationFinish(instruction.toRootUrl());
  2605. return true;
  2606. });
  2607. }
  2608. });
  2609. });
  2610. };
  2611. Router.prototype._settleInstruction = function(instruction) {
  2612. var _this = this;
  2613. return instruction.resolveComponent().then(function(_) {
  2614. instruction.component.reuse = false;
  2615. var unsettledInstructions = [];
  2616. if (lang_1.isPresent(instruction.child)) {
  2617. unsettledInstructions.push(_this._settleInstruction(instruction.child));
  2618. }
  2619. collection_1.StringMapWrapper.forEach(instruction.auxInstruction, function(instruction, _) {
  2620. unsettledInstructions.push(_this._settleInstruction(instruction));
  2621. });
  2622. return async_1.PromiseWrapper.all(unsettledInstructions);
  2623. });
  2624. };
  2625. Router.prototype._emitNavigationFinish = function(url) {
  2626. async_1.ObservableWrapper.callEmit(this._subject, url);
  2627. };
  2628. Router.prototype._afterPromiseFinishNavigating = function(promise) {
  2629. var _this = this;
  2630. return async_1.PromiseWrapper.catchError(promise.then(function(_) {
  2631. return _this._finishNavigating();
  2632. }), function(err) {
  2633. _this._finishNavigating();
  2634. throw err;
  2635. });
  2636. };
  2637. Router.prototype._routerCanReuse = function(instruction) {
  2638. var _this = this;
  2639. if (lang_1.isBlank(this._outlet)) {
  2640. return _resolveToFalse;
  2641. }
  2642. return this._outlet.routerCanReuse(instruction.component).then(function(result) {
  2643. instruction.component.reuse = result;
  2644. if (result && lang_1.isPresent(_this._childRouter) && lang_1.isPresent(instruction.child)) {
  2645. return _this._childRouter._routerCanReuse(instruction.child);
  2646. }
  2647. });
  2648. };
  2649. Router.prototype._canActivate = function(nextInstruction) {
  2650. return canActivateOne(nextInstruction, this._currentInstruction);
  2651. };
  2652. Router.prototype._routerCanDeactivate = function(instruction) {
  2653. var _this = this;
  2654. if (lang_1.isBlank(this._outlet)) {
  2655. return _resolveToTrue;
  2656. }
  2657. var next;
  2658. var childInstruction = null;
  2659. var reuse = false;
  2660. var componentInstruction = null;
  2661. if (lang_1.isPresent(instruction)) {
  2662. childInstruction = instruction.child;
  2663. componentInstruction = instruction.component;
  2664. reuse = instruction.component.reuse;
  2665. }
  2666. if (reuse) {
  2667. next = _resolveToTrue;
  2668. } else {
  2669. next = this._outlet.routerCanDeactivate(componentInstruction);
  2670. }
  2671. return next.then(function(result) {
  2672. if (result == false) {
  2673. return false;
  2674. }
  2675. if (lang_1.isPresent(_this._childRouter)) {
  2676. return _this._childRouter._routerCanDeactivate(childInstruction);
  2677. }
  2678. return true;
  2679. });
  2680. };
  2681. Router.prototype.commit = function(instruction, _skipLocationChange) {
  2682. var _this = this;
  2683. if (_skipLocationChange === void 0) {
  2684. _skipLocationChange = false;
  2685. }
  2686. this._currentInstruction = instruction;
  2687. var next = _resolveToTrue;
  2688. if (lang_1.isPresent(this._outlet)) {
  2689. var componentInstruction = instruction.component;
  2690. if (componentInstruction.reuse) {
  2691. next = this._outlet.reuse(componentInstruction);
  2692. } else {
  2693. next = this.deactivate(instruction).then(function(_) {
  2694. return _this._outlet.activate(componentInstruction);
  2695. });
  2696. }
  2697. if (lang_1.isPresent(instruction.child)) {
  2698. next = next.then(function(_) {
  2699. if (lang_1.isPresent(_this._childRouter)) {
  2700. return _this._childRouter.commit(instruction.child);
  2701. }
  2702. });
  2703. }
  2704. }
  2705. var promises = [];
  2706. this._auxRouters.forEach(function(router, name) {
  2707. if (lang_1.isPresent(instruction.auxInstruction[name])) {
  2708. promises.push(router.commit(instruction.auxInstruction[name]));
  2709. }
  2710. });
  2711. return next.then(function(_) {
  2712. return async_1.PromiseWrapper.all(promises);
  2713. });
  2714. };
  2715. Router.prototype._startNavigating = function() {
  2716. this.navigating = true;
  2717. };
  2718. Router.prototype._finishNavigating = function() {
  2719. this.navigating = false;
  2720. };
  2721. Router.prototype.subscribe = function(onNext) {
  2722. return async_1.ObservableWrapper.subscribe(this._subject, onNext);
  2723. };
  2724. Router.prototype.deactivate = function(instruction) {
  2725. var _this = this;
  2726. var childInstruction = null;
  2727. var componentInstruction = null;
  2728. if (lang_1.isPresent(instruction)) {
  2729. childInstruction = instruction.child;
  2730. componentInstruction = instruction.component;
  2731. }
  2732. var next = _resolveToTrue;
  2733. if (lang_1.isPresent(this._childRouter)) {
  2734. next = this._childRouter.deactivate(childInstruction);
  2735. }
  2736. if (lang_1.isPresent(this._outlet)) {
  2737. next = next.then(function(_) {
  2738. return _this._outlet.deactivate(componentInstruction);
  2739. });
  2740. }
  2741. return next;
  2742. };
  2743. Router.prototype.recognize = function(url) {
  2744. var ancestorComponents = this._getAncestorInstructions();
  2745. return this.registry.recognize(url, ancestorComponents);
  2746. };
  2747. Router.prototype._getAncestorInstructions = function() {
  2748. var ancestorComponents = [];
  2749. var ancestorRouter = this;
  2750. while (lang_1.isPresent(ancestorRouter.parent) && lang_1.isPresent(ancestorRouter.parent._currentInstruction)) {
  2751. ancestorRouter = ancestorRouter.parent;
  2752. ancestorComponents.unshift(ancestorRouter._currentInstruction);
  2753. }
  2754. return ancestorComponents;
  2755. };
  2756. Router.prototype.renavigate = function() {
  2757. if (lang_1.isBlank(this.lastNavigationAttempt)) {
  2758. return this._currentNavigation;
  2759. }
  2760. return this.navigateByUrl(this.lastNavigationAttempt);
  2761. };
  2762. Router.prototype.generate = function(linkParams) {
  2763. var ancestorInstructions = this._getAncestorInstructions();
  2764. return this.registry.generate(linkParams, ancestorInstructions);
  2765. };
  2766. return Router;
  2767. })();
  2768. exports.Router = Router;
  2769. var RootRouter = (function(_super) {
  2770. __extends(RootRouter, _super);
  2771. function RootRouter(registry, location, primaryComponent) {
  2772. var _this = this;
  2773. _super.call(this, registry, null, primaryComponent);
  2774. this._location = location;
  2775. this._locationSub = this._location.subscribe(function(change) {
  2776. _this.recognize(change['url']).then(function(instruction) {
  2777. _this.navigateByInstruction(instruction, lang_1.isPresent(change['pop'])).then(function(_) {
  2778. if (lang_1.isPresent(change['pop']) && change['type'] != 'hashchange') {
  2779. return ;
  2780. }
  2781. var emitPath = instruction.toUrlPath();
  2782. var emitQuery = instruction.toUrlQuery();
  2783. if (emitPath.length > 0) {
  2784. emitPath = '/' + emitPath;
  2785. }
  2786. if (change['type'] == 'hashchange') {
  2787. if (instruction.toRootUrl() != _this._location.path()) {
  2788. _this._location.replaceState(emitPath, emitQuery);
  2789. }
  2790. } else {
  2791. _this._location.go(emitPath, emitQuery);
  2792. }
  2793. });
  2794. });
  2795. });
  2796. this.registry.configFromComponent(primaryComponent);
  2797. this.navigateByUrl(location.path());
  2798. }
  2799. RootRouter.prototype.commit = function(instruction, _skipLocationChange) {
  2800. var _this = this;
  2801. if (_skipLocationChange === void 0) {
  2802. _skipLocationChange = false;
  2803. }
  2804. var emitPath = instruction.toUrlPath();
  2805. var emitQuery = instruction.toUrlQuery();
  2806. if (emitPath.length > 0) {
  2807. emitPath = '/' + emitPath;
  2808. }
  2809. var promise = _super.prototype.commit.call(this, instruction);
  2810. if (!_skipLocationChange) {
  2811. promise = promise.then(function(_) {
  2812. _this._location.go(emitPath, emitQuery);
  2813. });
  2814. }
  2815. return promise;
  2816. };
  2817. RootRouter.prototype.dispose = function() {
  2818. if (lang_1.isPresent(this._locationSub)) {
  2819. async_1.ObservableWrapper.dispose(this._locationSub);
  2820. this._locationSub = null;
  2821. }
  2822. };
  2823. RootRouter = __decorate([core_1.Injectable(), __param(2, core_1.Inject(route_registry_1.ROUTER_PRIMARY_COMPONENT)), __metadata('design:paramtypes', [route_registry_1.RouteRegistry, location_1.Location, lang_1.Type])], RootRouter);
  2824. return RootRouter;
  2825. })(Router);
  2826. exports.RootRouter = RootRouter;
  2827. var ChildRouter = (function(_super) {
  2828. __extends(ChildRouter, _super);
  2829. function ChildRouter(parent, hostComponent) {
  2830. _super.call(this, parent.registry, parent, hostComponent);
  2831. this.parent = parent;
  2832. }
  2833. ChildRouter.prototype.navigateByUrl = function(url, _skipLocationChange) {
  2834. if (_skipLocationChange === void 0) {
  2835. _skipLocationChange = false;
  2836. }
  2837. return this.parent.navigateByUrl(url, _skipLocationChange);
  2838. };
  2839. ChildRouter.prototype.navigateByInstruction = function(instruction, _skipLocationChange) {
  2840. if (_skipLocationChange === void 0) {
  2841. _skipLocationChange = false;
  2842. }
  2843. return this.parent.navigateByInstruction(instruction, _skipLocationChange);
  2844. };
  2845. return ChildRouter;
  2846. })(Router);
  2847. function canActivateOne(nextInstruction, prevInstruction) {
  2848. var next = _resolveToTrue;
  2849. if (lang_1.isPresent(nextInstruction.child)) {
  2850. next = canActivateOne(nextInstruction.child, lang_1.isPresent(prevInstruction) ? prevInstruction.child : null);
  2851. }
  2852. return next.then(function(result) {
  2853. if (result == false) {
  2854. return false;
  2855. }
  2856. if (nextInstruction.component.reuse) {
  2857. return true;
  2858. }
  2859. var hook = route_lifecycle_reflector_1.getCanActivateHook(nextInstruction.component.componentType);
  2860. if (lang_1.isPresent(hook)) {
  2861. return hook(nextInstruction.component, lang_1.isPresent(prevInstruction) ? prevInstruction.component : null);
  2862. }
  2863. return true;
  2864. });
  2865. }
  2866. global.define = __define;
  2867. return module.exports;
  2868. });
  2869. System.register("angular2/router", ["angular2/src/router/router", "angular2/src/router/router_outlet", "angular2/src/router/router_link", "angular2/src/router/instruction", "angular2/src/router/platform_location", "angular2/src/router/route_registry", "angular2/src/router/location_strategy", "angular2/src/router/hash_location_strategy", "angular2/src/router/path_location_strategy", "angular2/src/router/location", "angular2/src/router/route_config_decorator", "angular2/src/router/route_definition", "angular2/src/router/lifecycle_annotations", "angular2/src/router/instruction", "angular2/core", "angular2/src/router/platform_location", "angular2/src/router/location_strategy", "angular2/src/router/path_location_strategy", "angular2/src/router/router", "angular2/src/router/router_outlet", "angular2/src/router/router_link", "angular2/src/router/route_registry", "angular2/src/router/location", "angular2/core", "angular2/src/facade/lang", "angular2/src/facade/exceptions"], true, function(require, exports, module) {
  2870. var global = System.global,
  2871. __define = global.define;
  2872. global.define = undefined;
  2873. function __export(m) {
  2874. for (var p in m)
  2875. if (!exports.hasOwnProperty(p))
  2876. exports[p] = m[p];
  2877. }
  2878. var router_1 = require("angular2/src/router/router");
  2879. exports.Router = router_1.Router;
  2880. var router_outlet_1 = require("angular2/src/router/router_outlet");
  2881. exports.RouterOutlet = router_outlet_1.RouterOutlet;
  2882. var router_link_1 = require("angular2/src/router/router_link");
  2883. exports.RouterLink = router_link_1.RouterLink;
  2884. var instruction_1 = require("angular2/src/router/instruction");
  2885. exports.RouteParams = instruction_1.RouteParams;
  2886. exports.RouteData = instruction_1.RouteData;
  2887. var platform_location_1 = require("angular2/src/router/platform_location");
  2888. exports.PlatformLocation = platform_location_1.PlatformLocation;
  2889. var route_registry_1 = require("angular2/src/router/route_registry");
  2890. exports.RouteRegistry = route_registry_1.RouteRegistry;
  2891. exports.ROUTER_PRIMARY_COMPONENT = route_registry_1.ROUTER_PRIMARY_COMPONENT;
  2892. var location_strategy_1 = require("angular2/src/router/location_strategy");
  2893. exports.LocationStrategy = location_strategy_1.LocationStrategy;
  2894. exports.APP_BASE_HREF = location_strategy_1.APP_BASE_HREF;
  2895. var hash_location_strategy_1 = require("angular2/src/router/hash_location_strategy");
  2896. exports.HashLocationStrategy = hash_location_strategy_1.HashLocationStrategy;
  2897. var path_location_strategy_1 = require("angular2/src/router/path_location_strategy");
  2898. exports.PathLocationStrategy = path_location_strategy_1.PathLocationStrategy;
  2899. var location_1 = require("angular2/src/router/location");
  2900. exports.Location = location_1.Location;
  2901. __export(require("angular2/src/router/route_config_decorator"));
  2902. __export(require("angular2/src/router/route_definition"));
  2903. var lifecycle_annotations_1 = require("angular2/src/router/lifecycle_annotations");
  2904. exports.CanActivate = lifecycle_annotations_1.CanActivate;
  2905. var instruction_2 = require("angular2/src/router/instruction");
  2906. exports.Instruction = instruction_2.Instruction;
  2907. exports.ComponentInstruction = instruction_2.ComponentInstruction;
  2908. var core_1 = require("angular2/core");
  2909. exports.OpaqueToken = core_1.OpaqueToken;
  2910. var platform_location_2 = require("angular2/src/router/platform_location");
  2911. var location_strategy_2 = require("angular2/src/router/location_strategy");
  2912. var path_location_strategy_2 = require("angular2/src/router/path_location_strategy");
  2913. var router_2 = require("angular2/src/router/router");
  2914. var router_outlet_2 = require("angular2/src/router/router_outlet");
  2915. var router_link_2 = require("angular2/src/router/router_link");
  2916. var route_registry_2 = require("angular2/src/router/route_registry");
  2917. var location_2 = require("angular2/src/router/location");
  2918. var core_2 = require("angular2/core");
  2919. var lang_1 = require("angular2/src/facade/lang");
  2920. var exceptions_1 = require("angular2/src/facade/exceptions");
  2921. exports.ROUTER_DIRECTIVES = lang_1.CONST_EXPR([router_outlet_2.RouterOutlet, router_link_2.RouterLink]);
  2922. exports.ROUTER_PROVIDERS = lang_1.CONST_EXPR([route_registry_2.RouteRegistry, lang_1.CONST_EXPR(new core_2.Provider(location_strategy_2.LocationStrategy, {useClass: path_location_strategy_2.PathLocationStrategy})), platform_location_2.PlatformLocation, location_2.Location, lang_1.CONST_EXPR(new core_2.Provider(router_2.Router, {
  2923. useFactory: routerFactory,
  2924. deps: lang_1.CONST_EXPR([route_registry_2.RouteRegistry, location_2.Location, route_registry_2.ROUTER_PRIMARY_COMPONENT, core_2.ApplicationRef])
  2925. })), lang_1.CONST_EXPR(new core_2.Provider(route_registry_2.ROUTER_PRIMARY_COMPONENT, {
  2926. useFactory: routerPrimaryComponentFactory,
  2927. deps: lang_1.CONST_EXPR([core_2.ApplicationRef])
  2928. }))]);
  2929. exports.ROUTER_BINDINGS = exports.ROUTER_PROVIDERS;
  2930. function routerFactory(registry, location, primaryComponent, appRef) {
  2931. var rootRouter = new router_2.RootRouter(registry, location, primaryComponent);
  2932. appRef.registerDisposeListener(function() {
  2933. return rootRouter.dispose();
  2934. });
  2935. return rootRouter;
  2936. }
  2937. function routerPrimaryComponentFactory(app) {
  2938. if (app.componentTypes.length == 0) {
  2939. throw new exceptions_1.BaseException("Bootstrap at least one component before injecting Router.");
  2940. }
  2941. return app.componentTypes[0];
  2942. }
  2943. global.define = __define;
  2944. return module.exports;
  2945. });
  2946. //# sourceMappingURLDisabled=router.dev.js.map