service_wev8.js 1.75 KB
define("mService",["mUtil","mobilebone","i18n"],function(d,v,u){var f={},a="mService/",r={setService:function(e,t){this[e]=t},getService:function(e){return this[e]}};function m(e){var t=r.getService(e);if(t)return t;var i=e.indexOf("/"),n=-1===i?e:e.substring(0,i);this.id=e,this.name=a+e,this.css="css!"+a+n+"_css",this.html=a+e+"_html",this.setService=function(e){this.service=e},this.setTpl=function(e){this.tpl=e},r.setService(e,this)}return m.prototype={load:function(i){var n=$.Deferred(),a=this;return i=i||function(){},a.tpl?(i(a.tpl,a.service),n.resolve(a.tpl,a.service)):(require([this.name,this.css],function(t){require([a.html],function(e){i(e,t),n.resolve(e,t),a.setTpl(e),a.setService(t)})}),n)},preload:function(){require([this.name,this.css])}},{show:function(e,i){var t="page_service_"+e.replace("/","_"),n=i&&i._identity;n&&(t+="_"+n);var a=!0,r=$(".in."+v.classPage),s=t;n&&(s=s.replace("_"+n,"")),s=s.replace(/_/g,"-"),r.length&&(t+="_"+r[0].id);var o=f[t];o?a=!n:(o=$('<div id="'+t+'" class="'+s+' page out" data-onpagefirstinto="none" data-callback="serviceChange"><div class="page-loading wev-loading">'+u.LOADING_DATA+"</div></div>"),$(document.body).append(o),f[t]=o);var c=o[0];if(i.classAnimation&&!i.preload){var l=r.attr("data-form");!l&&r.attr("data-form",i.classAnimation),o.attr("data-form",i.classAnimation),c.flagAniBind=!1,c.animationend=function(e,t){"out"==t&&e.classList.contains("reverse")&&(!l&&r.removeAttr("data-form").removeClass(i.classAnimation),o.removeAttr("data-form").removeClass(i.classAnimation))}}(!i.preload&&v.transition(c,r[0],!1,{}),a)&&new m(e).load().then(function(e,t){e=d.replaceI18n(e),o.html(e),t.mounted(o,i)})},preload:function(e){new m(e).preload()},load:function(e,t){new m(e).load(t)},getService:function(e){return new m(e)}}});