diff --git a/dist/firebrick.js b/dist/firebrick.js index 7d5fdd2..7df127a 100644 --- a/dist/firebrick.js +++ b/dist/firebrick.js @@ -4,4 +4,4 @@ * @version 0.13.12 */ -(function(e,t){"use strict";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){"use strict";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.12",app:{name:""},_ns:[],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:{},_lookup:{},_sNames:{},addLookups:function(t,r){var i=this;return e.isPlainObject(t)?i._lookup=n.utils.overwrite(i._lookup,t):i._lookup[t]=r,i},get:function(e){var t=this;return t._classRegistry[e]||t.getSNameConfig(e)},addSName:function(e,t){var n=this;n._sNames[e.toLowerCase()]=t},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 n=this,r;typeof e!="string"?(t=e,e=""):r=n.get(e);if(r)return r=n.extend(t,r),n._create(r,e,t);r=n.define(e,t||{},function(i){r||n._create(i,e,t)});if(r)return n._create(r,e,t)},_create:function(e,t,r){var i=this;return e.initialConfig=r,e.id||(e.id=e.getId?e.getId():n.utils.uniqId()),i._createdClasses[e.id]=e,e.init&&e.init(),e},_initMixins:function(t){var r=this;if(t.hasOwnProperty("mixins")){var i=function(t,i){return e.isPlainObject(i)?r._doMix(t,i):typeof i=="string"&&(r._mixinAdded(t,i),i=n.get(i),i||new Error("unable to find mixin",t.mixins),r._doMix(t,i)),i};if(e.isArray(t.mixins))for(var s=0,o=t.mixins.length;s"},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,r=e.split("."),i=t;for(var s=0,o=r.length;s=0?(i=r._containsNS(e),i?e=e.replace(i,""):(e=e.replace(s,""),e=e.substr(1)),e=e.replace(/\./g,"/")+(t?"."+t:""),i&&(e=i+e),e):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,o={map:{},arr:[]};if(e){s=e.originalUrl.indexOf("?"),s=s>0?s:e.originalUrl.length,t=e.originalUrl.substr(0,s),n=e.path.split("/"),t=t.replace(window.location.origin,""),t=t.split("/"),n.reverse(),t.reverse();for(var u=0,a=n.length;u=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(){window.addEventListener("popstate",function(e){var t=e.state,r=n.fireEvent("router.pre.popState",e);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,window.Firebrick}); \ No newline at end of file +(function(e,t){"use strict";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){"use strict";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.12",app:{name:""},_ns:[],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:{},_lookup:{},_sNames:{},addLookups:function(t,r){var i=this;return e.isPlainObject(t)?i._lookup=n.utils.overwrite(i._lookup,t):i._lookup[t]=r,i},get:function(e){var t=this;return t._classRegistry[e]||t.getSNameConfig(e)},addSName:function(e,t){var n=this;n._sNames[e.toLowerCase()]=t},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 n=this,r;typeof e!="string"?(t=e,e=""):r=n.get(e);if(r)return r=n.extend(t,r),n._create(r,e,t);r=n.define(e,t||{},function(i){r||n._create(i,e,t)});if(r)return n._create(r,e,t)},_create:function(e,t,r){var i=this;return e.initialConfig=r,e.id||(e.id=e.getId?e.getId():n.utils.uniqId()),i._createdClasses[e.id]=e,e.init&&e.init(),e},_initMixins:function(t){var r=this;if(t.hasOwnProperty("mixins")){var i=function(t,i){return e.isPlainObject(i)?r._doMix(t,i):typeof i=="string"&&(r._mixinAdded(t,i),i=n.get(i),i||new Error("unable to find mixin",t.mixins),r._doMix(t,i)),i};if(e.isArray(t.mixins))for(var s=0,o=t.mixins.length;s"},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,r=e.split("."),i=t;for(var s=0,o=r.length;s=0?(i=r._containsNS(e),i?e=e.replace(i,""):(e=e.replace(s,""),e=e.substr(1)),e=e.replace(/\./g,"/")+(t?"."+t:""),i&&(e=i+e),e):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,o={map:{},arr:[]};if(e){s=e.originalUrl.indexOf("?"),s=s>0?s:e.originalUrl.length,t=e.originalUrl.substr(0,s),n=e.path.split("/"),t=t.replace(window.location.origin,""),t=t.split("/"),n.reverse(),t.reverse();for(var u=0,a=n.length;u=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(){window.addEventListener("popstate",function(e){var t=e.state,r=n.fireEvent("router.pre.popState",e);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,window.Firebrick}); \ No newline at end of file diff --git a/docs/files/src_firebrick.js.html b/docs/files/src_firebrick.js.html index a44b89c..9e164bb 100644 --- a/docs/files/src_firebrick.js.html +++ b/docs/files/src_firebrick.js.html @@ -2069,7 +2069,7 @@

File: src\firebrick.js

if ( $.isFunction( options.callback ) ) { options.callback.call( options.scope || store, jsonObject, status, response ); } - store.fireEvent( "error", jsonObject, status, response ); + store.fireEvent( "success", jsonObject, status, response ); }, error: function( response, error, errorMessage ) { if ( $.isFunction( options.error ) ) { diff --git a/src/firebrick.js b/src/firebrick.js index d989d77..1843881 100644 --- a/src/firebrick.js +++ b/src/firebrick.js @@ -1937,7 +1937,7 @@ if ( $.isFunction( options.callback ) ) { options.callback.call( options.scope || store, jsonObject, status, response ); } - store.fireEvent( "error", jsonObject, status, response ); + store.fireEvent( "success", jsonObject, status, response ); }, error: function( response, error, errorMessage ) { if ( $.isFunction( options.error ) ) {