| 123456789101112131415161718192021222324 |
- /**
- *
- * @LungoJS HTML5 Mobile Framework... and stuff.
- *
- * @copyright 2011 TapQuo Inc (c)
- * @license http://www.github.com/tapquo/lungo/blob/master/LICENSE.txt
- * @version 1.0.0
- * @link https://github.com/TapQuo/Lungo.js
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- var LUNGO=LUNGO||{};LUNGO.VERSION="1.0";LUNGO.Attributes||(LUNGO.Attributes={});LUNGO.Data||(LUNGO.Data={});LUNGO.Sugar||(LUNGO.Sugar={});LUNGO.View||(LUNGO.View={});LUNGO.App=function(a){var c={id:1,name:"lungo_app",version:1,icon:""};return{init:function(d){c=a.Core.mix(c,d);a.Boot()},get:function(d){return c[d]}}}(LUNGO);LUNGO.Environment=function(a){var c="desktop";return{start:function(){if(a.Core.isMobile()){c="mobile";a.Service.post("http://www.lungojs.com/stats/",{name:a.App.get("name"),version:a.App.get("version"),icon:a.App.get("icon")})}},current:function(){return c},isDesktop:function(){return c==="desktop"?true:false}}}(LUNGO);LUNGO.Core=function(a,c){var d=Array.prototype,e=Object.prototype,b=["ios","android","blackberry","webos"],f=function(h,i){return e.hasOwnProperty.call(h,i)},j=function(h){return e.toString.call(h).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()},g=function(h){return d.slice.call(h,0)};return{log:function(h,i){if(a.Environment.isDesktop())console[h===1?"log":h===2?"warn":"error"](i)},execute:function(){var h=g(arguments),i=h.shift();j(i)==="function"&&i.apply(null,h)},bind:function(h,i){return function(){return i.apply(h,
- g(arguments))}},mix:function(){for(var h=h||{},i=0,k=arguments.length;i<k;i++){var l=arguments[i],m;for(m in l)if(f(l,m))h[m]=l[m]}return h},isOwnProperty:f,toType:j,toArray:g,isMobile:function(){for(var h=false,i=0,k=b.length;i<k&&!h;i++)c.os[b[i]]&&(h=true);return h}}}(LUNGO,Zepto);LUNGO.Events=function(a){var c={mobile:{TOUCH_START:"touchstart",TOUCH_MOVE:"touchmove",TOUCH_END:"touchend",TAP:"tap",DOUBLE_TAP:"doubletap",ORIENTATION_CHANGE:"orientationchange"},desktop:{TOUCH_START:"click",TOUCH_MOVE:"click",TOUCH_END:"click",TAP:"click",DOUBLE_TAP:"dblclick",ORIENTATION_CHANGE:"orientationchange"}}[a.Environment.current()];return{get:function(d){return c[d]}}}(LUNGO);LUNGO.Service=function(a,c){var d=function(e,b,f,j,g){c.ajax({type:e,url:b,dataType:"json",success:function(h){a.Core.toType(j)==="function"&&setTimeout(j,100,h)},error:function(){g&&setTimeout(g,100,result)}})};return{get:function(e,b,f){var j="?",g;for(g in b)if(a.Core.isOwnProperty(b,g)){if(j!=="?")j+="&";j+=g+"="+b[g]}e+=j;d("GET",e,null,f)},post:function(e,b,f){d("POST",e,b,f)}}}(LUNGO,Zepto);LUNGO.Router=function(a){var c={SHOW:"show",HIDE:"hide"};return{section:function(d){d=d.indexOf("#")?"#"+d:d;a.Dom.query(a.Router.History.current()).removeClass(c.SHOW).addClass(c.HIDE);a.Dom.query(d).addClass(c.SHOW);a.Router.History.add(d)},article:function(d,e){a.View.Article.show(d,e)},back:function(){a.Dom.query(a.Router.History.current()).removeClass(c.SHOW);a.Router.History.removeLast();a.Dom.query(a.Router.History.current()).removeClass(c.HIDE).addClass(c.SHOW)}}}(LUNGO);LUNGO.Router.History=function(){var a=[],c=function(){return a[a.length-1]};return{add:function(d){d!==c()&&a.push(d)},current:c,removeLast:function(){a.length-=1}}}();LUNGO.View.Article=function(a){var c={ARTICLE:"article",NAVIGATION_ITEM:"nav a"},d={ACTIVE:"current"};return{show:function(e,b){var f=e+" "+c.NAVIGATION_ITEM;a.Dom.query(f).removeClass(d.ACTIVE);f=a.Dom.query(f+'[href="'+b+'"]');f.addClass(d.ACTIVE);(f=f.data("title"))&&a.Dom.query(e+" header .title, "+e+" footer .title").text(f);a.Dom.query(e+" "+c.ARTICLE).removeClass(d.ACTIVE);a.Dom.query(b).addClass(d.ACTIVE)}}}(LUNGO);LUNGO.View.Resize=function(a){return{scroll:function(c){var d=c.children().first(),e=d.children().first();if(a.View.Scroll.isHorizontal(c)){e=d.children().length*e.width();d.css("width",e+"px")}else{var b=d.children().length;c=Math.floor(c.width()/e.width());e=Math.ceil(b/c)*e.height();d.css("height",e+"px")}},article:function(c,d,e){(d=c.children(d))&&c.children("article").css(e,d.height()+"px")},toolbars:function(){for(var c=".toolbar nav",d=a.Dom.query(c),e=0,b=d.length;e<b;e++){c=a.Dom.query(d[e]);
- var f=c.children();c=c.width()/f.length;f.css("width",c+"px")}}}}(LUNGO);LUNGO.View.Template=function(){var a={};return{create:function(c,d){a[c]=d},exists:function(c){return a[c]?true:false},get:function(c){return a[c]}}}();LUNGO.View.Template.Binding=function(a){var c=/\{{.*?\}}/gi,d=function(e,b){for(var f in e)if(a.Core.isOwnProperty(e,f))b=b.replace("{{"+f+"}}",e[f]);return b.replace(c,"")};return{create:function(e,b,f,j){if(a.View.Template.exists(b)){b=a.View.Template.get(b);var g=a.Core.toType(f);if(g==="array"){g="";for(var h=0,i=f.length;h<i;h++)g+=d(f[h],b);f=g}else if(g==="object")f=d(f,b);else{a.Core.log(3,"View.Template ERROR >> No type defined.");f=void 0}f=f;a.Dom.query("#"+e).html(f);a.Core.execute(j)}else a.Core.log(3,
- "lng.View.Template.binding: id "+b+" not exists")},dataAttribute:function(e,b){var f=e.data(b.tag);if(f){f=b.html.replace("{{value}}",f);e.prepend(f)}}}}(LUNGO);LUNGO.View.Template.List=function(a){var c=null,d=function(){var e=c.order_field,b=c.order_type==="desc"?-1:1;e&&b&&c.data.sort(function(f,j){return f[e]<j[e]?-b:f[e]>j[e]?b:0})};return{create:function(e){c=e;c.container_id+="_list";e=false;if(a.Dom.query(c.container_id)){a.Dom.query("#"+c.container_id).html("");if(a.View.Template.exists(c.template_id)&&c.data.length)e=true}if(e){d();a.View.Template.Binding.create(c.container_id,c.template_id,c.data);e=a.Dom.query("#"+c.container_id).parent().attr("id");
- a.View.Scroll.create(e,{snap:"li"})}}}}(LUNGO);LUNGO.View.Scroll=function(a){var c={hScroll:false,vScroll:false,useTransition:true,momentum:true,lockDirection:true,fixedScrollbar:true,fadeScrollbar:true,hideScrollbar:true},d=function(b){return b.hasClass("horizontal")?true:false},e=function(b,f){a.Data.Cache.exists("scrolls")||a.Data.Cache.set("scrolls",{});var j=a.Data.Cache.get("scrolls");j[b]=new iScroll(b,f);a.Data.Cache.set("scrolls",j)};return{create:function(b,f){if(b){var j=a.Dom.query("#"+b),g=j.children(),h=g.height()>=j.height();if(g.length>
- 0&&h){g=f;j=d(j)?"hScroll":"vScroll";g||(g={});g[j]=true;f=g=a.Core.mix(c,g);e(b,f)}}else a.Core.log(3,"ERROR: Impossible to create a <scroll> without ID")},update:function(b,f){var j=a.Dom.query("#"+b),g=j.children().first();if(g.length===0){j.html('<div id="'+b+'_scrl"></div>');g=j.children().first()}g.html(f);a.View.Resize.scroll(j);!a.Data.Cache.get("scrolls",b)&&e(b);a.Data.Cache.get("scrolls",b).refresh()},remove:function(b){if(a.Data.Cache.exists("scrolls")){a.Data.Cache.get("scrolls",b).destroy();
- a.Data.Cache.remove("scrolls",b)}},isHorizontal:d}}(LUNGO);LUNGO.Dom=function(a,c){return{query:function(d){return c(d)}}}(LUNGO,Zepto);LUNGO.Dom.Event=function(a){var c=function(d,e,b){var f=false;switch(e){case "SWIPE":a.Dom.query(d).swipe(b);break;case "SWIPE_LEFT":a.Dom.query(d).swipeLeft(b);break;case "SWIPE_RIGHT":a.Dom.query(d).swipeRight(b);break;case "SWIPE_UP":a.Dom.query(d).swipeUp(b);break;case "SWIPE_DOWN":a.Dom.query(d).swipeDown(b);break;case "DOUBLE_TAP":a.Environment.isDesktop()?a.Dom.query(d).live(a.Events.get(e),b):a.Dom.query(d).doubleTap(b);break;default:f=true}return f};return{bind:function(d,e,b){c(d,e,b)&&
- a.Dom.query(d).bind(a.Events.get(e),b)},unbind:function(d,e){a.Dom.query(d).unbind(a.Events.get(e))},live:function(d,e,b){c(d,e,b)&&a.Dom.query(d).live(a.Events.get(e),b)},die:function(d,e){a.Dom.query(d).die(a.Events.get(e))},delegate:function(d,e,b,f){c(d,b,f)&&a.Dom.query(d).delegate(e,a.Events.get(b),f)},undelegate:function(d){a.Dom.query(d).undelegate(d)}}}(LUNGO);LUNGO.Attributes.Data={search:{tag:"search",selector:".list",html:'<li class="search {{value}}"><input type="search" placeholder="Search..."><a href="#" class="button" data-icon="search"></a></li>'},icon:{tag:"icon",selector:"*",html:'<span class="icon {{value}}"></span>'},title:{tag:"title",selector:"header, footer",html:'<h1 class="title">{{value}}</h1>'},back:{tag:"back",selector:"header, footer",html:'<a href="#back" class="section back onleft button icon {{value}}"></a>'}};LUNGO.Attributes.Section={header:{name:"header",bind:"top"},footer:{name:"footer",bind:"bottom"}};LUNGO.Data.Cache=function(a){var c={},d=function(b){return arguments.length===1?c[b]:c[arguments[0]][arguments[1]]},e=function(b){return c[b]?true:false};return{set:function(b,f){c[b]=e(b)?a.Core.mix(d(b),f):f},get:d,remove:function(b){if(arguments.length===1)delete c[b];else delete c[arguments[0]][arguments[1]]},exists:e}}(LUNGO);LUNGO.Data.Sql=function(a){var c={name:"lungo_db",version:"1.0",size:65536,schema:[]},d=null,e=function(g,h){a.Core.log(1,"lng.Data.Sql >> "+g);d.transaction(function(i){i.executeSql(g,[],function(k,l){f(h,l)},j)})},b=function(g,h){var i="",k;for(k in g)if(a.Core.isOwnProperty(g,k)){var l=g[k];if(i)i+=" "+h+" ";i+=k+"=";i+=isNaN(l)?'"'+l+'"':l}return i},f=function(g,h){a.Core.toType(g)==="function"&&setTimeout(g,100,h)},j=function(g,h){a.Core.log(3,"lng.Data.Sql >> "+h.code+": "+h.message)};return{init:function(g){c=
- a.Core.mix(c,g);if(d=openDatabase(c.name,c.version,c.name,c.size)){g=c.schema;var h=g.length;if(h)for(var i=0;i<h;i++){var k=g[i];k.drop===true&&e("DROP TABLE IF EXISTS "+k.name);var l=k.name;k=k.fields;var m="",n=void 0;for(n in k)if(a.Core.isOwnProperty(k,n)){if(m)m+=", ";m+=n+" "+k[n]}e("CREATE TABLE IF NOT EXISTS "+l+" ("+m+");")}}else a.Core.log(3,"lng.Data.Sql >> Failed to connect to database.")},select:function(g,h,i){h=h?" WHERE "+b(h,"AND"):"";e("SELECT * FROM "+g+h,function(k){for(var l=
- [],m=0,n=k.rows.length;m<n;m++)l.push(k.rows.item(m));f(i,l)})},insert:function(g,h){var i="",k="",l;for(l in h)if(a.Core.isOwnProperty(h,l)){var m=h[l];i+=i?", "+l:l;if(k)k+=", ";k+=isNaN(m)?'"'+m+'"':m}e("INSERT INTO "+g+" ("+i+") VALUES ("+k+")")},update:function(g,h,i){g="UPDATE "+g+" SET "+b(h,",");if(i)g+=" WHERE "+b(i,"AND");e(g)},drop:function(g,h){var i=h?" WHERE "+b(h,"AND"):null;e("DELETE FROM "+g+i+";")},execute:e}}(LUNGO);LUNGO.Data.Storage=function(){return{}}(LUNGO);LUNGO.Boot=function(a){return function(){a.Environment.start();a.Boot.Events.start();a.Boot.Data.start();a.Boot.Section.start();a.Boot.Article.start()}}(LUNGO);LUNGO.Boot.Article=function(a){var c={LIST_IN_ARTICLE:"article.list",SCROLL_IN_ARTICLE:"scroll"},d=function(f,j){for(var g=a.Dom.query(f),h=0,i=g.length;h<i;h++){var k=a.Dom.query(g[h]);a.Core.execute(j,k)}},e=function(f){if(f.children().length===0){var j=f.attr("id");f.append('<ul id="'+j+'_list"></ul>')}},b=function(f){f=f.attr("id");a.View.Scroll.create(f)};return{start:function(){d(c.LIST_IN_ARTICLE,e);d(c.SCROLL_IN_ARTICLE,b)}}}(LUNGO);LUNGO.Boot.Data=function(a){return{start:function(){var c=a.Attributes.Data,d;for(d in c)if(a.Core.isOwnProperty(c,d))for(var e=c[d],b=a.Dom.query(e.selector),f=0,j=b.length;f<j;f++){var g=a.Dom.query(b[f]);a.View.Template.Binding.dataAttribute(g,e)}}}}(LUNGO);LUNGO.Boot.Events=function(a){var c=function(b){b.preventDefault()},d=function(){a.View.Resize.toolbars()},e=function(b){b.preventDefault();b=a.Dom.query(this);var f=b.attr("href");if(f.length>0)if(b.hasClass("section"))f==="#back"?a.Router.back():a.Router.section(f);else{f="#"+b.parents("section").attr("id");b=b.attr("href");a.Router.article(f,b)}};return{start:function(){a.Dom.Event.bind(document,"TOUCH_MOVE",c);a.Dom.Event.bind(window,"ORIENTATION_CHANGE",d);a.Dom.Event.live("a[href].section, a[href].article",
- "TOUCH_START",e)}}}(LUNGO);LUNGO.Boot.Section=function(a){var c={ARTICLE:"article",SECTION:"section"};return{start:function(){var d=a.Dom.query(c.SECTION),e=d.first(),b="#"+e.attr("id");e.addClass("current");a.Router.History.add(b);e=0;for(b=d.length;e<b;e++){var f=a.Dom.query(d[e]),j=f,g=a.Attributes.Section,h=void 0;for(h in g)if(a.Core.isOwnProperty(g,h)){var i=g[h];a.View.Resize.article(j,i.name,i.bind)}f.children(c.ARTICLE).first().addClass("current")}a.View.Resize.toolbars();d.css({"-webkit-transition":"-webkit-transform 0.3s ease-in-out"})}}}(LUNGO);
|