text: function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},_createClass=function(){function e(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,o,r){return o&&e(t.prototype,o),r&&e(t,r),t}}(),Controller=function(){function Controller(e){_classCallCheck(this,Controller),this.route=e.route,this.app=e.app}return _createClass(Controller,[{key:"url",value:function(){return Uri.url()}},{key:"compile",value:function(e){return this.evalInContext(e,this)}},{key:"evalInContext",value:function evalInContext(js,context){return function(){return eval(js)}.call(context)}},{key:"request",value:function(e){Request.post(e)}}]),Controller}(),Request=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"load_file",value:function(e){jQuery.ajaxSetup({async:!1});var t=e.url,o=e.loaded;console.log("loading file: "+t),$.ajax({url:t,success:function(e){jQuery.ajaxSetup({async:!0}),o(e)}}).fail(function(e,t,o){throw Error("Unable to load request! Error Code: "+t+", Message: "+o)})}},{key:"post",value:function(e){var t="";void 0!=e.url&&(t=e.url);var o="get";void 0!=e.method&&(o=e.method);var r="";void 0!=e.data&&(r=$.param(e.data));var n=function(){throw Error("Request returned a success but no success callback was set.")},s=function(){throw Error("Request returned a failure but no success callback was set.")},a=function(){throw Error("Request returned an error but no error callback was set.")};void 0!=e.success&&(n=e.success),void 0!=e.fail&&(s=e.fail),void 0!=e.error&&(a=e.error),console.log("Ajax Call: "+t),$.ajax({url:t,method:o,data:r,success:function(e){null!=e&&void 0!=e?e.status?n(e):s(e):a("")},error:function(e){s(e)}})}}]),e}(),Page=function(){function e(t,o){_classCallCheck(this,e),this.base_content="",this.content="",this.controller=null,this.route=t,this.app=o,console.log("Created page")}return _createClass(e,[{key:"start",value:function(){var e=this;if(null==this.route||void 0==this.route)throw"Malformatted route! Page::start()";Request.load_file({url:Uri.get_base_url()+this.app.path+"/"+this.route.view,async:!1,loaded:function(t){e.base_content=t,e.render_page()}})}},{key:"includes",value:function(){console.log("including files");var e=this;$("include").each(function(){var t=$(this);Request.load_file({url:Uri.get_base_url()+e.app.path+"/"+t.attr("file"),loaded:function(e){t.replaceWith(e)}})}),this.finish()}},{key:"on_load",value:function(){console.log("Page loaded, loading late files");$("onload").each(function(){var e=$(this),t=e.attr("type").toLowerCase(),o=null;switch(t.toLowerCase().replace(" ","")){case"python":case"ruby":case"jscript":case"javascript":case"js":case"script":o=e.attr("src"),e.replaceWith("<script src='"+o+"'></script>");break;case"css1":case"css2":case"css3":case"stylesheet":case"style":case"css":o=e.attr("src"),e.replaceWith("<link rel='stylesheet' href='"+o+"'>")}})}},{key:"generate_hooks",value:function(){console.log("Generating hooks");setTimeout(function(){$("a").each(function(e,t){var o=$(this),r=o.attr("esref");null!=r&&void 0!=r&&(o.attr("href",Uri.get_base_url()+"#"+r),console.log(r)),r==Uri.get_path()?o.addClass(o.attr("es-active")):o.removeClass(o.attr("es-active"))});var e=$("[es-active]");e.each(function(){var e=$(this);$(this).find("a").each(function(t,o){var r=$(this),n=r.attr("esref");n==Uri.get_path()?e.addClass(e.attr("es-active")):e.removeClass(e.attr("es-active"))})})},0)}},{key:"finish",value:function(){this.generate_hooks(),this.parse_page(),this.on_load()}},{key:"get_html",value:function(){for(var e=document.documentElement.innerHTML,t=document.documentElement.attributes,o=0,r="",n="<!DOCTYPE "+document.doctype.name+(document.doctype.publicId?' PUBLIC "'+document.doctype.publicId+'"':"")+(!document.doctype.publicId&&document.doctype.systemId?" SYSTEM":"")+(document.doctype.systemId?' "'+document.doctype.systemId+'"':"")+">";o<t.length;o+=1)r+=" "+t[o].name+'="'+t[o].value+'"';return n+"\n<html"+r+">"+e+"</html>"}},{key:"parse_page",value:function(){var e=/(\{\{(.*?)\}\})/g;console.log("Parsing replaces");for(var t,o=($("html"),this.get_html());null!==(t=e.exec(o));){var r=this.controller.compile(t[1]);o=o.replace(t[0],r)}document.documentElement.innerHTML=o}},{key:"render_page",value:function(){if(null==this.content)throw"Content was null Page::render_page()";this.controller=new Controller(this),void 0!=this.route.controller&&null!=this.route.controller&&(console.log(_typeof(this.route.controller)==Controller),this.route.controller(this.controller)),console.log("Setting page html"),$("view").html(this.base_content),console.log("Done setting page html"),this.includes()}}]),e}(),Router=function(){function e(t){_classCallCheck(this,e),this.states=[],this.app=t,this.page=null}return _createClass(e,[{key:"set_routes",value:function(e){if(!$.isArray(e))throw"route was not an array Router::set_routes()";var t=this.states;$.each(e,function(e,o){if(void 0==o.url)throw"Route.url was not defined Router::set_routes()";console.log(o.url),t[o.url]=o}),console.log("Set routes")}},{key:"do_route",value:function(){var e=this.get_route(Uri.get_path());if(null!=e&&void 0!=e)console.log("This was a valid route: "+Uri.get_path()+", Route: "+e.url),this.load_route(e);else{if(e=this.get_route("/"),null==e||void 0==e)throw"No root route('/') found exiting Router::do_route()";console.log("invalid route loading root route('/')"),this.load_route(e)}}},{key:"load_route",value:function(e){if(void 0==e.view)throw"Route undefined Router::load_route(route)";console.log("creating page"),this.page=new Page(e,this.app),this.route_start(this.page)}},{key:"route_start",value:function(e){if(null==e||void 0==e)throw"Passed page was null Router::route_start()";console.log("Starting page"),e.start()}},{key:"get_route",value:function(e){return void 0!=this.states[e]?this.states[e]:null}}]),e}(),Uri=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"get_current_url",value:function(){var e=window.location.href,t=/((\w)*\.(php|html|py|jsp|htm|rb))/g;return e=e.replace(t,"",e)}},{key:"url",value:function(){return e.get_base_url()}},{key:"get_base_url",value:function(){var t=e.get_current_url();"/"==t.substring(t.length-1)&&(t=t.substring(0,t.length-1));var o=t.indexOf("?");o>-1&&(t=t.substring(0,o));var r=t.indexOf("#");return"/"!=t.substring(t.length-1)&&(t+="/"),r>-1?t.substring(0,t.indexOf("#")):t}},{key:"get_path",value:function(){var t=e.get_current_url(),o=t.indexOf("#");return t=o>-1?t.substring(o):t.replace(e.get_current_url(),""),"#"==t.substring(0,1)&&(t=t.substring(1,t.length)),(""==t||void 0==t||null==t)&&(t="/"),t}}]),e}(),Application=function(){function e(t,o){var r=this;_classCallCheck(this,e),this.name=t,this.path=o,this.routes=new Router(this),$(window).on("hashchange",function(){r.routes.do_route()})}return _createClass(e,[{key:"run",value:function(e){this.routes.set_routes(e),this.routes.do_route()}}]),e}();