App.js http://code.kik.com/app/2/index.html
(function (app,$) {var appload = app.load;var appback = app.back;function Geturlpath (Args, options, callback,url) {var path = null;if (typeof args === "string") {Path = args;} Else if (typeof options === "string") {path = options;} Else if (typeof callback === "string") {Path = callback;} Else if (typeof url === "string") {Path = url;} Return path;} App.load = function (Pagename, args, options, callback,url) {var url = Geturlpath (Args, options, callback,url);p ushstate (pageName); // // whether a page with the same name has been loaded if (App._pages.has (PageName)) {appload (pagename, args, options, callback); return;} Parsing incoming htmlfunction parsepage (HTML) {return html; // todo we can Enhance this }$.get (Url,function (res) {VAR PAGehtml = parsepage (res); $ ("Body"). Append (pagehtml); var page = $ (pagehtml). AppendTo (" Body "); App.add (pagename,$ ("[data-page= '" +pagename+ "]") [0]); AppLoad (Pagename, args, options, callback) ;});}; var internalback = false; App.back = function (pagename, callback) {Internalback = true;appback (pageName, callback); History.back ();}; Function pushstate (pageName) {window.history.pushState ({name:pagename}, "", "#/" +pagename);} Window.onpopstate = function (event) {Var state = event.state;console.log (state); Internalback) {appback ();} Internalback = false;}}) (Window. app,$);
App.js Add browser Back key support