diff --git a/README.md b/README.md index 16f726a..a55dfc2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#Firebrick JS version: 0.13.4 +#Firebrick JS version: 0.13.6 JavaScript MVC Framework built with: diff --git a/bower.json b/bower.json index a2a221f..6c7593c 100644 --- a/bower.json +++ b/bower.json @@ -14,7 +14,7 @@ "framework", "javascript" ], - "version": "0.13.4", + "version": "0.13.6", "dependencies": { "jquery": "2.x", "knockoutjs": "3.x", diff --git a/dist/firebrick.js b/dist/firebrick.js index e473585..430810c 100644 --- a/dist/firebrick.js +++ b/dist/firebrick.js @@ -1,7 +1,7 @@ /*! * Firebrick JS - JavaScript MVC Framework powered by jQuery and Knockout JS * @author Steven Masala [me@smasala.com] -* @version 0.13.4 +* @version 0.13.6 */ -(function(e,t){typeof define=="function"&&define.amd?define(["jquery","knockout","knockout-mapping","text"],function(e,n,r){return n.mapping=r,t(e,n)}):t(e.jQuery,e.ko)})(this,function(e,t){if(window.Firebrick||window.fb){console.error("unable to initialise FirebrickJS, window.Firebrick or window.fb are already defined");return}var n={version:"0.13.4",app:{name:""},application:function(t){var r=this;r.app=t.app,r.utils.initSplash(t.splash||r.templates.loadingTpl),n.boot.prepApplication(t),t.require&&t.require.length>0?(e.isArray(t.require)||(t.require=[t.require]),require(t.require,function(){r.utils.clearSplash();var i=arguments;e(document).ready(function(){t.ready&&t.ready.apply(n,i)})})):(r.utils.clearSplash(),e(document).ready(function(){t.ready&&t.ready()}))},stackTrace:function(){return(new Error).stack},shortcut:function(e,t,n){return e[t].apply(e,n)},get:function(){return this.shortcut(this.classes,"get",arguments)},getById:function(){return this.shortcut(this.classes,"getById",arguments)},create:function(){return this.shortcut(this.classes,"create",arguments)},define:function(){return this.shortcut(this.classes,"define",arguments)},createController:function(){return this.shortcut(this.controllers,"createController",arguments)},require:function(){return this.shortcut(this.utils,"require",arguments)},loadRaw:function(){return this.shortcut(this.views,"loadRaw",arguments)},createView:function(){return this.shortcut(this.views,"createView",arguments)},defineView:function(){return this.shortcut(this.views,"defineView",arguments)},getBody:function(){return this.shortcut(this.views,"getBody",arguments)},delay:function(){return this.shortcut(this.utils,"delay",arguments)},addListener:function(){return this.shortcut(this.events,"addListener",arguments)},removeListener:function(){return this.shortcut(this.events,"removeListener",arguments)},fireEvent:function(){return this.shortcut(this.events,"fireEvent",arguments)},on:function(){return this.shortcut(this.events,"on",arguments)},off:function(){return this.shortcut(this.events,"off",arguments)},createStore:function(){return this.shortcut(this.data.store,"createStore",arguments)},text:function(){return this.shortcut(this.languages,"getByKey",arguments)},scrollTopOffset:0,scrollContainerSelector:"body, html",classes:{_classRegistry:{},_createdClasses:{},_sNames:{},get:function(e){var t=this;return t._classRegistry[e]},addSNames:function(e){var t=this;return t._sNames=n.utils.overwrite(t._sNames,e),t._sNames},getById:function(e){var t=this;return e?t._createdClasses[e]:null},getSNameConfig:function(e){return this._sNames[e.toLowerCase()]},removeClass:function(e){var t=typeof e=="string"?n.get(e):e;t&&t.id&&delete n.classes._createdClasses[t.id]},_callParentConstructor:function(e,t){return function(){var r=this,i=n.utils.uniqId(),s;r.callParent&&(s="_scope_callParent_"+i,r[s]=r.callParent),r.callParent=function(e){return t.apply(r,e)};var o=e.apply(r,arguments);return s?(r.callParent=r[s],delete r[s]):delete r.callParent,o}},extend:function(t,n){var r=this,i={},s;for(s in t)t.hasOwnProperty(s)&&(i[s]=Object.getOwnPropertyDescriptor(t,s),n[s]&&e.isFunction(n[s])&&e.isFunction(t[s])&&(i[s].value=r._callParentConstructor(i[s].value,n[s])));var o=Object.create(n);return Object.create(Object.getPrototypeOf(o),i)},create:function(e,t){var r=this,i=r.get(e);return i?i=r.extend(t,i):i=r.define(e,t||{}),i.initialConfig=t,i.id||(i.id=i.getId?i.getId():n.utils.uniqId()),r._createdClasses[i.id]=i,i.init&&i.init(),i},_initMixins:function(t,r){var i=this;if(t.hasOwnProperty("mixins")){var s=function(t,r){return e.isPlainObject(r)?i._doMix(t,r):typeof r=="string"&&(i._mixinAdded(t,r),r=n.get(r),r||new Error("unable to find mixin",t.mixins),i._doMix(t,r)),r};if(e.isArray(t.mixins))for(var o=0,u=t.mixins.length;o"},views:{bootView:function(e){return n.utils.clearSplash(),n.createView(n.app.name+".view.Index",{target:e.target||"body",store:e.viewData,async:!0,listeners:{ready:function(){n.fireEvent("viewReady",this)}}})},createView:function(t,r){return t&&!r&&(e.isPlainObject(t)?(r=t,t="tmp-"+n.utils.uniqId(),r.fbTmpClass=!0):r={}),r=this._basicViewConfigurations(r),n.create(t,r)},defineView:function(e,t){var r=this;return t=r._basicViewConfigurations(t),n.define(e,t)},initSubViews:function(t){var n=this,r=t.subViews;if(r)if(e.isArray(r))for(var i=0,s=r.length;i0?n:null},renderTo:function(t,n,r,i){var s=e(n);return s.hide(),r===!0?t.append(s):t.html(s),s.show(i)}},boot:{prepApplication:function(t){t.cache===!1&&(require.config({urlArgs:"fb="+(new Date).getTime()}),e.ajaxSetup({cache:!1})),t.dev&&(requirejs.onError=function(e){e.requireType==="timeout"?console.log("modules: "+e.requireModules):(console.error(e.message),console.error(e.text),console.error(e.requireMap),console.error(e.stack),new Error(e))}),t.lang&&n.languages.init(t.lang),t.autoRender!==!1&&n.views.bootView(t)}},utils:{requiredFiles:{},intervalRegistry:{},splashCleared:!1,initSplash:function(t){var r=this;n.delay(function(){r.splashCleared||e("html").append("
"+t+"
")},1)},clearSplash:function(){this.splashCleared=!0,e("#fb-splash").remove()},dataFor:function(){return t.dataFor.apply(t,arguments)},getDeepProperty:function(e,t){var n=this,r,i=e.split("."),s=t;for(var o=0,u=i.length;o0&&e.indexOf(r)===0?(e=e.replace(r,""),r+e.replace(/\./g,"/")+(t?"."+t:"")):e},_globalC:1,uniqId:function(){var e=this,t=new Date,n=t.getMilliseconds()+"",r=++t+n+(++e._globalC===1e4?e._globalC=1:e._globalC);return r},loadCSS:function(e){var t=document.createElement("link");t.type="text/css",t.rel="stylesheet",t.href=e,document.getElementsByTagName("head")[0].appendChild(t)},firstToUpper:function(e){return e.charAt(0).toUpperCase()+e.slice(1)}},languages:{lang:t.observable("en"),keys:t.observable({}),init:function(t){var r=this;typeof t=="string"?n.createStore({url:t,autoLoad:!1}).load({callback:function(){r.keys(this.getData())}}):t.isStore?r.keys(t.getData()):e.isPlainObject?r.keys(t):console.error("unable to load languages",t)},getByKey:function(t){var n=this,r;return t=e.isFunction(t)?t():t,r=n.keys()[n.lang()],r&&r[t]?e.isFunction(r[t])?r[t]():r[t]:t},setLang:function(e){this.lang(e)},getLang:function(){return this.lang()},allLanguages:function(){var e=this,n=[],r=t.mapping.toJS(e.keys),i;for(i in r)r.hasOwnProperty(i)&&n.push(i);return n}},events:{_eventRegistry:{},addListener:function(t,r,i){var s=this,o;if(e.isPlainObject(t))return s._addListener(t);if(!r.conf){r.conf={},r.conf.callbackId=n.utils.uniqId(),r.conf.scope=i,t=t.split(",");for(var u=0,a=t.length;u=0?e.substr(i):null,u=null;t.history._initialised&&o&&(e=e.substr(0,i)),s!==-1&&(e=e.substr(0,s));for(var a in n)if(n.hasOwnProperty(a)){u=e.match(new RegExp(a,"i"));if(u){u=n[a];break}}return u&&(u.originalUrl=r),u},_getParamsForMatch:function(e){var t,n,r,i,s={map:{},arr:[]};if(e){t=e.originalUrl,n=e.path.split("/"),t=t.replace(window.location.origin,""),t=t.split("/"),n.reverse(),t.reverse();for(var o=0,u=n.length;o=0;!o&&!u&&(n.preventDefault(),t.location(s,arguments))})},location:function(e,t){var r=e.indexOf("#")===0,i=n.fireEvent("router.pre.pushState",e);i.preventDefault!==!0&&(window.history.pushState(e,"",e),r?e!=="#"&&n.router.scrollTo(e):n.router.callRoute(e,t),n.fireEvent("router.post.pushState",e))},_registerPopEvent:function(){var e=this;window.addEventListener("popstate",function(e){var t=e.state,r=n.fireEvent("router.pre.popState",e),i=n.router._routes;r.preventDefault!==!0&&(typeof t=="string"?(n.router.callRoute(t,arguments),n.fireEvent("router.post.popState",t)):console.warn("undefined popstate",t))})}},hashbang:{_initialised:!1,set:function(e){var t=this;n.router._set(e),t._initialised||(t._initialised=!0,t.onHashChange())},onHashChange:function(t,r){return e(window).on("hashchange",function(){var e=n.fireEvent("router.pre.hashbang",r,arguments);e.preventDefault!==!0&&(n.router.callRoute(n.router.getRoute().path,arguments),n.fireEvent("router.post.hashbang",r,arguments))})}},init:function(){n.router.callRoute(n.router.getRoute().path)},is:function(e){var t=this,n=t.getRoute(),r=n.cleanHash;return r?r===e:n.path===e},getRoute:function(){var e=this,t=window.location,n=t.href.replace(t.origin,""),r=t.hash,i=r.indexOf("?"),s=n.indexOf("?"),o=n,u=e._getParamsForMatch(e.match(t.href));return r&&(o=n.replace(r,"")),s!==-1&&(o=n.substr(0,s)),{href:t.href,origin:t.origin,path:n,cleanPath:o,hash:r,cleanHash:i!==-1?r.substr(0,i):r,parameters:e.getUrlParam(n),urlParameters:u?u.map:{},hashbang:e.hashbang._initialised}},getUrlParam:function(e){var t=e,n={},r,i=/[?&]?([^=]+)=([^&]*)/g;t=t.substr(t.indexOf("?")+1,t.length),t=t.split("+").join(" ");while(r=i.exec(t))n[decodeURIComponent(r[1])]=decodeURIComponent(r[2]);return n}}};return n.define("Firebrick.class.Base",{initialConfig:null,_cloneListener:function(e){return function(){return e.apply(this,arguments)}},sName:null,init:function(){var t=this,r,i,s={};if(t.listeners){n.utils.merge("listeners",t);for(r in t.listeners)t.listeners.hasOwnProperty(r)&&(i=t.listeners[r],e.isFunction(i)&&(s[r]=t._cloneListener(i,r)));t.listeners=s,t.on(t.listeners)}return t.fireEvent(t.classReadyEvent),t},classReadyEvent:"ready",autoDestroy:!0,mixins:null,_mixins:null,_idPrefix:"fb-",id:null,localEventRegistry:null,getId:function(){var e=this,t=e.id;return t||(t=e._idPrefix+n.utils.uniqId(),e.id=t),t},destroy:function(){var e=this;e.fireEvent("destroy"),n.classes.removeClass(e)},listeners:null,_addEvent:function(e,t,r){var i=this,s;e=e.split(",");for(var o=0,u=e.length;o').html(r))),r},_renderHTML:function(){var e=this,t=e.getTarget(),n=e.appendTarget,r=e.animations,i,s;return i=e.prepHtml(),e.enclosedBind&&(s=e.getEnclosedTarget(),s&&(t=s,n=!1)),e._render(t,i,n,r),e.fireEvent("htmlRendered"),e},_render:function(){return n.views.renderTo.apply(n.views,arguments)},bindContent:function(){var e=this,n=e.getData(),r=e.getTarget(),i=r[0];e.enclosedBind&&(r=e.getEnclosedTarget(),i=r[0]),r.attr(e.bindAttribute,!0),r.prop(e.bindAttribute,e),e.applyBindingsToDescendants?t.applyBindingsToDescendants(n,i):t.applyBindings(n,i),e.setDisposeCallback(i)},bind:function(){var e=this,t=e.getTarget();e.isTargetBound()?console.info("target or bindTarget where not found, unable to render and bind the data",t):(e.hide(),e._renderHTML(),e._state="rendered",e.bindContent(),e.stopLoader(),e.show(),e.fireEvent("rendered",e))},render:function(){var e=this,t=e.getTarget();return t?(e.fireEvent("beforeRender",e),e.unbind(),e.bind(),e.initSubViews()):console.warn("unable to render, no target found for",e.target,this),e},setDisposeCallback:function(n){var r=this;t.utils.domNodeDisposal.addDisposeCallback(n,function(t){var n=e(t).prop(r.bindAttribute);n.unbound()})},unbound:function(){var e=this,t=e.getStore();e._state="unbound",e.autoDestroy&&t&&(t.fireEvent("unbound",e),e.store=null),e.fireEvent("unbound",e)},show:function(){var e=this,t=e.getTarget();t&&t.show()},hide:function(){var e=this,t=e.getTarget();t&&t.hide()},isVisible:function(){var e=this,t=e.getTarget();return t?t.is(":visible"):!1},initStore:function(){var e=this;return e.store=e.store,e.store&&!e.store.isStore&&(e.store=n.createStore({data:e.store})),e},update:function(e){var t=this;return t.getStore().setData(e),t},startLoader:function(){var e=this,t=e.getTarget();t&&!e.loading&&(e.loading=!0,n.delay(function(){e.loading&&(e.hide(),t.before("
"+e.loadingTpl+"
"))},1))},stopLoader:function(){var t=this;t.loading&&(e("#fb-loader-"+t.getId()).remove(),t.show(),t.loading=!1)}}),n.define("Firebrick.controller.Base",{extend:"Firebrick.class.Base",init:function(){return this.callParent(arguments)},app:{on:function(){return n.events.on.apply(n.events,arguments)},listeners:function(){return n.events.addListener.apply(n.events,arguments)}}}),n.define("Firebrick.store.Base",{extend:"Firebrick.class.Base",init:function(){var e=this;return e.dataInitialised||(e.autoLoad?e.load():e.data&&e.setData(e.data)),e.autoDestroy&&e.on("unbound",function(){e.autoDestroy&&e.destroy()}),this.callParent(arguments)},dataType:"json",url:{get:null,submit:null},stringifyData:!0,loadProtocol:"GET",submitProtocol:"POST",status:"initial",isStore:!0,dataInitialised:!1,autoLoad:!1,data:null,params:null,_initialData:null,async:!0,root:null,getUrl:function(t){var n=this;return t?n.url[t]:e.isPlainObject(n.url)?n.url.get:n.url},load:function(e){return n.data.store._loadStore(this,e)},getData:function(){var t=this;return t.root&&e.isPlainObject(t.data)?e.isFunction(t.data[t.root])?t.data[t.root]():t.data[t.root]:t.data},destroy:function(){var e=this;return e.data=null,e.status="destroyed",e.dataInitialised=!1,e.callParent(arguments)},getRawData:function(n){var r=this;if(n)return r._initialData;var i=r.getData();return i=e.isFunction(i)?i():i,t.toJS(i)},setData:function(e){var n=this;return n.dataInitialised?t.mapping.isMapped(e)?console.error("cannot update store data using a mapped object",e):(n._initialData=e,t.mapping.fromJS(e,n.data)):(t.mapping.isMapped(e)||(n._initialData=e,typeof e=="string"?e=t.mapping.fromJSON(e):e=t.mapping.fromJS(e)),n.data=e,n.dataInitialised=!0),n},submit:function(){return n.data.store._submit(this)},toPlainObject:function(){var n=this,r=n.getData();return e.isFunction(r)?t.toJS(r):e.isPlainObject(r)&&r.__ko_mapping__?t.mapping.toJS(r):n.data},toJson:function(){return JSON.stringify(this.toPlainObject())}}),window.Firebrick=n,n}); \ No newline at end of file +(function(e,t){typeof define=="function"&&define.amd?define(["jquery","knockout","knockout-mapping","text"],function(e,n,r){return n.mapping=r,t(e,n)}):t(e.jQuery,e.ko)})(this,function(e,t){if(window.Firebrick||window.fb){console.error("unable to initialise FirebrickJS, window.Firebrick or window.fb are already defined");return}var n={version:"0.13.6",app:{name:""},application:function(t){var r=this;r.app=t.app,r.utils.initSplash(t.splash||r.templates.loadingTpl),n.boot.prepApplication(t),t.require&&t.require.length>0?(e.isArray(t.require)||(t.require=[t.require]),require(t.require,function(){r.utils.clearSplash();var i=arguments;e(document).ready(function(){t.ready&&t.ready.apply(n,i)})})):(r.utils.clearSplash(),e(document).ready(function(){t.ready&&t.ready()}))},stackTrace:function(){return(new Error).stack},shortcut:function(e,t,n){return e[t].apply(e,n)},get:function(){return this.shortcut(this.classes,"get",arguments)},getById:function(){return this.shortcut(this.classes,"getById",arguments)},create:function(){return this.shortcut(this.classes,"create",arguments)},define:function(){return this.shortcut(this.classes,"define",arguments)},createController:function(){return this.shortcut(this.controllers,"createController",arguments)},require:function(){return this.shortcut(this.utils,"require",arguments)},loadRaw:function(){return this.shortcut(this.views,"loadRaw",arguments)},createView:function(){return this.shortcut(this.views,"createView",arguments)},defineView:function(){return this.shortcut(this.views,"defineView",arguments)},getBody:function(){return this.shortcut(this.views,"getBody",arguments)},delay:function(){return this.shortcut(this.utils,"delay",arguments)},addListener:function(){return this.shortcut(this.events,"addListener",arguments)},removeListener:function(){return this.shortcut(this.events,"removeListener",arguments)},fireEvent:function(){return this.shortcut(this.events,"fireEvent",arguments)},on:function(){return this.shortcut(this.events,"on",arguments)},off:function(){return this.shortcut(this.events,"off",arguments)},createStore:function(){return this.shortcut(this.data.store,"createStore",arguments)},text:function(){return this.shortcut(this.languages,"getByKey",arguments)},scrollTopOffset:0,scrollContainerSelector:"body, html",classes:{_classRegistry:{},_createdClasses:{},_sNames:{},get:function(e){var t=this;return t._classRegistry[e]},addSNames:function(e){var t=this;return t._sNames=n.utils.overwrite(t._sNames,e),t._sNames},getById:function(e){var t=this;return e?t._createdClasses[e]:null},getSNameConfig:function(e){return this._sNames[e.toLowerCase()]},removeClass:function(e){var t=typeof e=="string"?n.get(e):e;t&&t.id&&delete n.classes._createdClasses[t.id]},_callParentConstructor:function(e,t){return function(){var r=this,i=n.utils.uniqId(),s;r.callParent&&(s="_scope_callParent_"+i,r[s]=r.callParent),r.callParent=function(e){return t.apply(r,e)};var o=e.apply(r,arguments);return s?(r.callParent=r[s],delete r[s]):delete r.callParent,o}},extend:function(t,n){var r=this,i={},s;for(s in t)t.hasOwnProperty(s)&&(i[s]=Object.getOwnPropertyDescriptor(t,s),n[s]&&e.isFunction(n[s])&&e.isFunction(t[s])&&(i[s].value=r._callParentConstructor(i[s].value,n[s])));var o=Object.create(n);return Object.create(Object.getPrototypeOf(o),i)},create:function(e,t){var r=this,i=r.get(e);return i?i=r.extend(t,i):i=r.define(e,t||{}),i.initialConfig=t,i.id||(i.id=i.getId?i.getId():n.utils.uniqId()),r._createdClasses[i.id]=i,i.init&&i.init(),i},_initMixins:function(t,r){var i=this;if(t.hasOwnProperty("mixins")){var s=function(t,r){return e.isPlainObject(r)?i._doMix(t,r):typeof r=="string"&&(i._mixinAdded(t,r),r=n.get(r),r||new Error("unable to find mixin",t.mixins),i._doMix(t,r)),r};if(e.isArray(t.mixins))for(var o=0,u=t.mixins.length;o"},views:{bootView:function(e){return n.utils.clearSplash(),n.createView(n.app.name+".view.Index",{target:e.target||"body",store:e.viewData,async:!0,listeners:{ready:function(){n.fireEvent("viewReady",this)}}})},createView:function(t,r){return t&&!r&&(e.isPlainObject(t)?(r=t,t="tmp-"+n.utils.uniqId(),r.fbTmpClass=!0):r={}),r=this._basicViewConfigurations(r),n.create(t,r)},defineView:function(e,t){var r=this;return t=r._basicViewConfigurations(t),n.define(e,t)},initSubViews:function(t){var n=this,r=t.subViews;if(r)if(e.isArray(r))for(var i=0,s=r.length;i0?n:null},renderTo:function(t,n,r,i){var s=e(n);return s.hide(),r===!0?t.append(s):t.html(s),s.show(i)}},boot:{prepApplication:function(t){t.cache===!1&&(require.config({urlArgs:"fb="+(new Date).getTime()}),e.ajaxSetup({cache:!1})),t.dev&&(requirejs.onError=function(e){e.requireType==="timeout"?console.log("modules: "+e.requireModules):(console.error(e.message),console.error(e.text),console.error(e.requireMap),console.error(e.stack),new Error(e))}),t.lang&&n.languages.init(t.lang),t.autoRender!==!1&&n.views.bootView(t)}},utils:{requiredFiles:{},intervalRegistry:{},splashCleared:!1,initSplash:function(t){var r=this;n.delay(function(){r.splashCleared||e("html").append("
"+t+"
")},1)},clearSplash:function(){this.splashCleared=!0,e("#fb-splash").remove()},dataFor:function(){return t.dataFor.apply(t,arguments)},getDeepProperty:function(e,t){var n=this,r,i=e.split("."),s=t;for(var o=0,u=i.length;o0&&e.indexOf(r)===0?(e=e.replace(r,""),r+e.replace(/\./g,"/")+(t?"."+t:"")):e},_globalC:1,uniqId:function(){var e=this,t=new Date,n=t.getMilliseconds()+"",r=++t+n+(++e._globalC===1e4?e._globalC=1:e._globalC);return r},loadCSS:function(e){var t=document.createElement("link");t.type="text/css",t.rel="stylesheet",t.href=e,document.getElementsByTagName("head")[0].appendChild(t)},firstToUpper:function(e){return e.charAt(0).toUpperCase()+e.slice(1)}},languages:{lang:t.observable("en"),keys:t.observable({}),init:function(t){var r=this;typeof t=="string"?n.createStore({url:t,autoLoad:!1}).load({callback:function(){r.keys(this.getData())}}):t.isStore?r.keys(t.getData()):e.isPlainObject?r.keys(t):console.error("unable to load languages",t)},getByKey:function(t){var n=this,r;return t=e.isFunction(t)?t():t,r=n.keys()[n.lang()],r&&r[t]?e.isFunction(r[t])?r[t]():r[t]:t},setLang:function(e){this.lang(e)},getLang:function(){return this.lang()},allLanguages:function(){var e=this,n=[],r=t.mapping.toJS(e.keys),i;for(i in r)r.hasOwnProperty(i)&&n.push(i);return n}},events:{_eventRegistry:{},addListener:function(t,r,i){var s=this,o;if(e.isPlainObject(t))return s._addListener(t);if(!r.conf){r.conf={},r.conf.callbackId=n.utils.uniqId(),r.conf.scope=i,t=t.split(",");for(var u=0,a=t.length;u=0?e.substr(i):null,u=null;t.history._initialised&&o&&(e=e.substr(0,i)),s!==-1&&(e=e.substr(0,s));for(var a in n)if(n.hasOwnProperty(a)){u=e.match(new RegExp(a,"i"));if(u){u=n[a];break}}return u&&(u.originalUrl=r),u},_getParamsForMatch:function(e){var t,n,r,i,s={map:{},arr:[]};if(e){t=e.originalUrl,n=e.path.split("/"),t=t.replace(window.location.origin,""),t=t.split("/"),n.reverse(),t.reverse();for(var o=0,u=n.length;o=0;!o&&!u&&(n.preventDefault(),t.location(s,arguments))})},location:function(e,t){var r=e.indexOf("#")===0,i=n.fireEvent("router.pre.pushState",e);i.preventDefault!==!0&&(window.history.pushState(e,"",e),r?e!=="#"&&n.router.scrollTo(e):n.router.callRoute(e,t),n.fireEvent("router.post.pushState",e))},_registerPopEvent:function(){var e=this;window.addEventListener("popstate",function(e){var t=e.state,r=n.fireEvent("router.pre.popState",e),i=n.router._routes;r.preventDefault!==!0&&(typeof t=="string"?(n.router.callRoute(t,arguments),n.fireEvent("router.post.popState",t)):console.warn("undefined popstate",t))})}},hashbang:{_initialised:!1,set:function(e){var t=this;n.router._set(e),t._initialised||(t._initialised=!0,t.onHashChange())},onHashChange:function(t,r){return e(window).on("hashchange",function(){var e=n.fireEvent("router.pre.hashbang",r,arguments);e.preventDefault!==!0&&(n.router.callRoute(n.router.getRoute().path,arguments),n.fireEvent("router.post.hashbang",r,arguments))})}},init:function(){n.router.callRoute(n.router.getRoute().path)},is:function(e){var t=this,n=t.getRoute(),r=n.cleanHash;return r?r===e:n.path===e},getRoute:function(){var e=this,t=window.location,n=t.href.replace(t.origin,""),r=t.hash,i=r.indexOf("?"),s=n.indexOf("?"),o=n,u=e._getParamsForMatch(e.match(t.href));return r&&(o=n.replace(r,"")),s!==-1&&(o=n.substr(0,s)),{href:t.href,origin:t.origin,path:n,cleanPath:o,hash:r,cleanHash:i!==-1?r.substr(0,i):r,parameters:e.getUrlParam(n),urlParameters:u?u.map:{},hashbang:e.hashbang._initialised}},getUrlParam:function(e){var t=e,n={},r,i=/[?&]?([^=]+)=([^&]*)/g;t=t.substr(t.indexOf("?")+1,t.length),t=t.split("+").join(" ");while(r=i.exec(t))n[decodeURIComponent(r[1])]=decodeURIComponent(r[2]);return n}}};return n.define("Firebrick.class.Base",{initialConfig:null,_cloneListener:function(e){return function(){return e.apply(this,arguments)}},sName:null,init:function(){var t=this,r,i,s={};if(t.listeners){n.utils.merge("listeners",t);for(r in t.listeners)t.listeners.hasOwnProperty(r)&&(i=t.listeners[r],e.isFunction(i)&&(s[r]=t._cloneListener(i,r)));t.listeners=s,t.on(t.listeners)}return t.fireEvent(t.classReadyEvent),t},classReadyEvent:"ready",autoDestroy:!0,mixins:null,_mixins:null,_idPrefix:"fb-",id:null,localEventRegistry:null,getId:function(){var e=this,t=e.id;return t||(t=e._idPrefix+n.utils.uniqId(),e.id=t),t},destroy:function(){var e=this;e.fireEvent("destroy"),n.classes.removeClass(e)},listeners:null,_addEvent:function(e,t,r){var i=this,s;e=e.split(",");for(var o=0,u=e.length;o').html(r))),r},_renderHTML:function(){var e=this,t=e.getTarget(),n=e.appendTarget,r=e.animations,i,s;return i=e.prepHtml(),e.enclosedBind&&(s=e.getEnclosedTarget(),s&&(t=s,n=!1)),e._render(t,i,n,r),e.fireEvent("htmlRendered"),e},_render:function(){return n.views.renderTo.apply(n.views,arguments)},bindContent:function(){var e=this,n=e.getData(),r=e.getTarget(),i=r[0];e.enclosedBind&&(r=e.getEnclosedTarget(),i=r[0]),r.attr(e.bindAttribute,!0),r.prop(e.bindAttribute,e),e.applyBindingsToDescendants?t.applyBindingsToDescendants(n,i):t.applyBindings(n,i),e.setDisposeCallback(i)},bind:function(){var e=this,t=e.getTarget();e.isTargetBound()?console.info("target or bindTarget where not found, unable to render and bind the data",t):(e.hide(),e._renderHTML(),e._state="rendered",e.bindContent(),e.stopLoader(),e.show(),e.fireEvent("rendered",e))},render:function(){var e=this,t=e.getTarget();return t?(e.fireEvent("beforeRender",e),e.unbind(),e.bind(),e.initSubViews()):console.warn("unable to render, no target found for",e.target,this),e},setDisposeCallback:function(n){var r=this;t.utils.domNodeDisposal.addDisposeCallback(n,function(t){var n=e(t).prop(r.bindAttribute);n.unbound()})},unbound:function(){var e=this,t=e.getStore();e._state="unbound",e.autoDestroy&&t&&(t.fireEvent("unbound",e),e.store=null),e.fireEvent("unbound",e)},show:function(){var e=this,t=e.getTarget();t&&t.show()},hide:function(){var e=this,t=e.getTarget();t&&t.hide()},isVisible:function(){var e=this,t=e.getTarget();return t?t.is(":visible"):!1},initStore:function(){var e=this;return e.store=e.store,e.store&&!e.store.isStore&&(e.store=n.createStore({data:e.store})),e},update:function(e){var t=this;return t.getStore().setData(e),t},startLoader:function(){var e=this,t=e.getTarget();t&&!e.loading&&(e.loading=!0,n.delay(function(){e.loading&&(e.hide(),t.before("
"+e.loadingTpl+"
"))},1))},stopLoader:function(){var t=this;t.loading&&(e("#fb-loader-"+t.getId()).remove(),t.show(),t.loading=!1)}}),n.define("Firebrick.controller.Base",{extend:"Firebrick.class.Base",init:function(){return this.callParent(arguments)},app:{on:function(){return n.events.on.apply(n.events,arguments)},listeners:function(){return n.events.addListener.apply(n.events,arguments)}}}),n.define("Firebrick.store.Base",{extend:"Firebrick.class.Base",init:function(){var e=this;return e.dataInitialised||(e.autoLoad?e.load():e.data&&e.setData(e.data)),e.autoDestroy&&e.on("unbound",function(){e.autoDestroy&&e.destroy()}),this.callParent(arguments)},dataType:"json",url:{get:null,submit:null},stringifyData:!0,loadProtocol:"GET",submitProtocol:"POST",status:"initial",isStore:!0,dataInitialised:!1,autoLoad:!1,data:null,params:null,_initialData:null,async:!0,root:null,getUrl:function(t){var n=this;return t?n.url[t]:e.isPlainObject(n.url)?n.url.get:n.url},load:function(e){return n.data.store._loadStore(this,e)},getData:function(){var t=this;return t.root&&e.isPlainObject(t.data)?e.isFunction(t.data[t.root])?t.data[t.root]():t.data[t.root]:t.data},destroy:function(){var e=this;return e.data=null,e.status="destroyed",e.dataInitialised=!1,e.callParent(arguments)},getRawData:function(n){var r=this;if(n)return r._initialData;var i=r.getData();return i=e.isFunction(i)?i():i,t.toJS(i)},setData:function(e){var n=this;return n.dataInitialised?t.mapping.isMapped(e)?console.error("cannot update store data using a mapped object",e):(n._initialData=e,t.mapping.fromJS(e,n.data)):(t.mapping.isMapped(e)||(n._initialData=e,typeof e=="string"?e=t.mapping.fromJSON(e):e=t.mapping.fromJS(e)),n.data=e,n.dataInitialised=!0),n},submit:function(){return n.data.store._submit(this)},toPlainObject:function(){var n=this,r=n.getData();return e.isFunction(r)?t.toJS(r):e.isPlainObject(r)&&r.__ko_mapping__?t.mapping.toJS(r):n.data},toJson:function(){return JSON.stringify(this.toPlainObject())}}),window.Firebrick=n,n}); \ No newline at end of file diff --git a/docs/classes/Boot.html b/docs/classes/Boot.html index 640f8cb..9cf31b4 100644 --- a/docs/classes/Boot.html +++ b/docs/classes/Boot.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Classes.html b/docs/classes/Classes.html index 7529550..1a0b1a0 100644 --- a/docs/classes/Classes.html +++ b/docs/classes/Classes.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Controllers.html b/docs/classes/Controllers.html index e3efa16..b9ea286 100644 --- a/docs/classes/Controllers.html +++ b/docs/classes/Controllers.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Data.Store.html b/docs/classes/Data.Store.html index 8ae082a..aba6804 100644 --- a/docs/classes/Data.Store.html +++ b/docs/classes/Data.Store.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Data.html b/docs/classes/Data.html index c14cf1e..6dbc61e 100644 --- a/docs/classes/Data.html +++ b/docs/classes/Data.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Events.html b/docs/classes/Events.html index 07f4f9d..34696f5 100644 --- a/docs/classes/Events.html +++ b/docs/classes/Events.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Firebrick.html b/docs/classes/Firebrick.html index cc293c0..0066a3a 100644 --- a/docs/classes/Firebrick.html +++ b/docs/classes/Firebrick.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Languages.html b/docs/classes/Languages.html index f9f21e7..9acbc8a 100644 --- a/docs/classes/Languages.html +++ b/docs/classes/Languages.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Router.Hashbang.html b/docs/classes/Router.Hashbang.html index 0664034..9c0a046 100644 --- a/docs/classes/Router.Hashbang.html +++ b/docs/classes/Router.Hashbang.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Router.History.html b/docs/classes/Router.History.html index 6c2d6d2..f893b3d 100644 --- a/docs/classes/Router.History.html +++ b/docs/classes/Router.History.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Router.Router.html b/docs/classes/Router.Router.html index e3306b1..89f063f 100644 --- a/docs/classes/Router.Router.html +++ b/docs/classes/Router.Router.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Router.class.Base.html b/docs/classes/Router.class.Base.html index bbe1960..cf05438 100644 --- a/docs/classes/Router.class.Base.html +++ b/docs/classes/Router.class.Base.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Router.html b/docs/classes/Router.html index 756ad5c..a017d6e 100644 --- a/docs/classes/Router.html +++ b/docs/classes/Router.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Templates.html b/docs/classes/Templates.html index 2021778..8df17b4 100644 --- a/docs/classes/Templates.html +++ b/docs/classes/Templates.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Utils.html b/docs/classes/Utils.html index 2bdd057..0527955 100644 --- a/docs/classes/Utils.html +++ b/docs/classes/Utils.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/Views.html b/docs/classes/Views.html index 1ca80cd..2016397 100644 --- a/docs/classes/Views.html +++ b/docs/classes/Views.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/controller.Base.html b/docs/classes/controller.Base.html index 813d355..047f0ee 100644 --- a/docs/classes/controller.Base.html +++ b/docs/classes/controller.Base.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/store.Base.html b/docs/classes/store.Base.html index d386b4c..4aaa450 100644 --- a/docs/classes/store.Base.html +++ b/docs/classes/store.Base.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/view.Base.html b/docs/classes/view.Base.html index f905706..4dc2973 100644 --- a/docs/classes/view.Base.html +++ b/docs/classes/view.Base.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/classes/window.html b/docs/classes/window.html index 64ef796..ad4f745 100644 --- a/docs/classes/window.html +++ b/docs/classes/window.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/data.json b/docs/data.json index c4feb1a..b45b51b 100644 --- a/docs/data.json +++ b/docs/data.json @@ -2,7 +2,7 @@ "project": { "name": "Firebrick JS API", "description": "Firebrick JS API: A lightweight JavaScript MVC Framework powered with jQuery, Bootstrap, Knockout JS and Require JS", - "version": "0.13.4", + "version": "0.13.6", "url": "https://github.com/smasala", "logo": "fb_small.png" }, diff --git a/docs/files/src_firebrick.js.html b/docs/files/src_firebrick.js.html index c452b6c..f60ba4d 100644 --- a/docs/files/src_firebrick.js.html +++ b/docs/files/src_firebrick.js.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
@@ -133,7 +133,7 @@

File: src\firebrick.js

/*! * Firebrick JS - JavaScript MVC Framework powered by jQuery and Knockout JS * @author Steven Masala [me@smasala.com] -* @version 0.13.4 +* @version 0.13.6 */ (function (root, factory) { @@ -170,7 +170,7 @@

File: src\firebrick.js

* @property version * @type {String} */ - version: "0.13.4", + version: "0.13.6", /**2 * used to store configurations set Firebrick.ready() @@ -2303,7 +2303,7 @@

File: src\firebrick.js

if(match){ - params = me._getParamsForMatch( match ); + params = me._getParamsForMatch( match ).arr || []; //are dependencies required to run this pattern if($.isPlainObject(match) && match.require){ @@ -2315,7 +2315,7 @@

File: src\firebrick.js

require(deps, function(){ //check if pattern has a callback and fire - me._routeCallback( match.callback, [params.arr, arguments, args] ); + me._routeCallback( match.callback, [params, arguments, args] ); }); }else{ //no dependencies - just fire the callback @@ -2328,7 +2328,7 @@

File: src\firebrick.js

callback = match; } - me._routeCallback( callback, [args] ); + me._routeCallback( callback, [params, args] ); } } diff --git a/docs/index.html b/docs/index.html index fa38de2..8824745 100644 --- a/docs/index.html +++ b/docs/index.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/modules/Firebrick.class.html b/docs/modules/Firebrick.class.html index f5da96b..6a87b23 100644 --- a/docs/modules/Firebrick.class.html +++ b/docs/modules/Firebrick.class.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/modules/Firebrick.html b/docs/modules/Firebrick.html index 98be4e5..8f83b4e 100644 --- a/docs/modules/Firebrick.html +++ b/docs/modules/Firebrick.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/docs/modules/Global.html b/docs/modules/Global.html index 185ca70..c7325a9 100644 --- a/docs/modules/Global.html +++ b/docs/modules/Global.html @@ -19,7 +19,7 @@

- API Docs for: 0.13.4 + API Docs for: 0.13.6
diff --git a/release-notes b/release-notes index 0f48506..e33d594 100644 --- a/release-notes +++ b/release-notes @@ -1,3 +1,7 @@ +v0.13.6 +---------------------------- +* fix router when no require array is defined + v0.13.5 ---------------------------- * router regex improvements diff --git a/src/firebrick.js b/src/firebrick.js index d3b4cab..94fe34d 100644 --- a/src/firebrick.js +++ b/src/firebrick.js @@ -1,7 +1,7 @@ /*! * Firebrick JS - JavaScript MVC Framework powered by jQuery and Knockout JS * @author Steven Masala [me@smasala.com] -* @version 0.13.4 +* @version 0.13.6 */ (function (root, factory) { @@ -38,7 +38,7 @@ * @property version * @type {String} */ - version: "0.13.4", + version: "0.13.6", /**2 * used to store configurations set Firebrick.ready() @@ -2171,7 +2171,7 @@ if(match){ - params = me._getParamsForMatch( match ); + params = me._getParamsForMatch( match ).arr || []; //are dependencies required to run this pattern if($.isPlainObject(match) && match.require){ @@ -2183,7 +2183,7 @@ require(deps, function(){ //check if pattern has a callback and fire - me._routeCallback( match.callback, [params.arr, arguments, args] ); + me._routeCallback( match.callback, [params, arguments, args] ); }); }else{ //no dependencies - just fire the callback @@ -2196,7 +2196,7 @@ callback = match; } - me._routeCallback( callback, [args] ); + me._routeCallback( callback, [params, args] ); } } diff --git a/yuidoc.json b/yuidoc.json index f460054..d29e206 100644 --- a/yuidoc.json +++ b/yuidoc.json @@ -1,7 +1,7 @@ { "name": "Firebrick JS API", "description": "Firebrick JS API: A lightweight JavaScript MVC Framework powered with jQuery, Bootstrap, Knockout JS and Require JS", - "version": "0.13.4", + "version": "0.13.6", "url": "https://github.com/smasala", "logo": "fb_small.png", "options": {