UNPKG

lettuce

Version:

Lettuce JS, Mini Mobile Framework for Romantic with DSL.

2 lines 6.04 kB
/*! lettuce 02-03-2015 */ !function(a,b){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){"use strict";function c(){this._callbacks=[]}var d=function(){};d.VERSION="0.2.3",a.lettuce=d,d.isObject=function(a){var b=typeof a;return"function"===b||"object"===b&&!!a},d.isFunction=function(a){return"function"==typeof a||!1},d.defaults=function(a){if(!d.isObject(a))return a;for(var b=1,c=arguments.length;c>b;b++){var e=arguments[b];for(var f in e)void 0===a[f]&&(a[f]=e[f])}return a},d.extend=function(a){if(!d.isObject(a))return a;for(var b,c,e=1,f=arguments.length;f>e;e++){b=arguments[e];for(c in b)hasOwnProperty.call(b,c)&&(a[c]=b[c])}return a},d.prototype.Class=function(a,b){var c=function e(c,f){function g(){var a=this instanceof g?this:new h;return a.init.apply(a,arguments),a}function h(){}g.Basic=h;var i=h[a]=c[a],j=h[a]=g[a]=new h;j.constructor=g,g.extend=function(a){return new e(g,a)};var k=g.open=function(a){if(d.isFunction(a)&&(a=a.call(g,j,i,g,c)),d.isObject(a))for(var e in a)b.call(a,e)&&(j[e]=a[e]);return"init"in j||(j.init=c),g};return k(f)};return c}("prototype",{}.hasOwnProperty);var e=new d.prototype.Class({});e.prototype.init=function(a){this.options=a||{},d.defaults(this.options,{first:"first",regex:/.*Page/,last:"last"})},e.prototype.run=function(a){var b=this;b.methods=a,b.execute(b.options.first);for(var c in b.methods)c!==b.options.last&&c.match(b.options.regex)&&this.execute(c);b.execute(b.options.last)},e.prototype.execute=function(a){this.methods[a]()};var f={Parser:e};d.prototype=d.extend(d.prototype,f),d.get=function(a,b){d.send(a,"GET",b)},d.load=function(a,b){d.send(a,"GET",b)},d.post=function(a,b,c){d.send(a,"POST",c,b)},d.send=function(a,b,c,d){d=d||null;var e=new XMLHttpRequest;c instanceof Function&&(e.onreadystatechange=function(){4!==e.readyState||200!==e.status&&0!==e.status||c(e.responseText)}),e.open(b,a,!0),d instanceof Object&&(d=JSON.stringify(d),e.setRequestHeader("Content-Type","application/json")),e.setRequestHeader("X-Requested-With","XMLHttpRequest"),e.send(d)};var g={on:function(a,b){this._events=this._events||{},this._events[a]=this._events[a]||[],this._events[a].push(b)},off:function(a,b){this._events=this._events||{},a in this._events!=!1&&this._events[a].splice(this._events[a].indexOf(b),1)},trigger:function(a){if(this._events=this._events||{},a in this._events!=!1)for(var b=0;b<this._events[a].length;b++)this._events[a][b].apply(this,Array.prototype.slice.call(arguments,1))}},h={Event:g};d.prototype=d.extend(d.prototype,h);var i={regexp:/([\s'\\])(?!(?:[^{]|\{(?!%))*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g,encReg:/[<>&"'\x00]/g,encMap:{"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#39;"},arg:"o",helper:",print=function(s,e){_s+=e?(s==null?'':s):_e(s);},include=function(s,d){_s+=tmpl(s,d);}",tmpl:function(a,b){var c=/[^\w\-\.:]/.test(a)?this.compile(a):"";return c(b,this)},compile:function(a){var b,c;return c=this.arg+",tmpl",b="var _e=tmpl.encode"+this.helper+",_s='"+a.replace(this.regexp,this.func)+"';",b+="return _s;",new Function(c,b)},encode:function(a){var b=/[<>&"'\x00]/g,c={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#39;"};return(null==a?"":""+a).replace(b,function(a){return c[a]||""})},func:function(a,b,c,d,e,f){var g={"\n":"\\n","\r":"\\r"," ":"\\t"," ":" "};return b?g[b]||"\\"+b:c?"="===c?"'+_e("+d+")+'":"'+("+d+"==null?'':"+d+")+'":e?"';":f?"_s+='":void 0}},j={Template:i};d.prototype=d.extend(d.prototype,j),c.prototype.then=function(a,b){var d;return this._isdone?d=a.apply(b,this.result):(d=new c,this._callbacks.push(function(){var c=a.apply(b,arguments);c&&"function"==typeof c.then&&c.then(d.done,d)})),d},c.prototype.done=function(){this.result=arguments,this._isdone=!0;for(var a=0;a<this._callbacks.length;a++)this._callbacks[a].apply(null,arguments);this._callbacks=[]};var k={Promise:c};d.prototype=d.extend(d.prototype,k);var l={easing:{linear:function(a){return a},quadratic:function(a){return Math.pow(a,2)},swing:function(a){return.5-Math.cos(a*Math.PI)/2},circ:function(a){return 1-Math.sin(Math.acos(a))},back:function(a,b){return Math.pow(a,2)*((b+1)*a-b)},bounce:function(a){for(var b=0,c=1;1;b+=c,c/=2)if(a>=(7-4*b)/11)return-Math.pow((11-6*b-11*a)/4,2)+Math.pow(c,2)},elastic:function(a,b){return Math.pow(2,10*(a-1))*Math.cos(20*Math.PI*b/3*a)}},animate:function(a){var b=new Date,c=setInterval(function(){var d=new Date-b,e=d/a.duration;e>1&&(e=1),a.progress=e;var f=a.delta(e);a.step(f),1==e&&(clearInterval(c),a.complete())},a.delay||10)},fadeOut:function(a,b){var c=1;this.animate({duration:b.duration,delta:function(a){return a=this.progress,l.easing.swing(a)},complete:b.complete,step:function(b){a.style.opacity=c-b}})},fadeIn:function(a,b){var c=0;this.animate({duration:b.duration,delta:function(a){return a=this.progress,l.easing.swing(a)},complete:b.complete,step:function(b){a.style.opacity=c+b}})}},m={FX:l};d.prototype=d.extend(d.prototype,m);var n={routes:[],hashStrip:/^#*/,location:a.location,getFragment:function(){return this.location.hash.replace(this.hashStrip,"")},add:function(a,b){return d.isFunction(a)&&(b=a,a=""),this.routes.push({regex:a,handler:b}),this},check:function(a){for(var b=a.getFragment(),c=0;c<a.routes.length;c++){var d="#"+b,e=d.match(a.routes[c].regex);e&&(e.shift(),a.routes[c].handler.apply({},e))}},load:function(){function b(){a.addEventListener?a.addEventListener("hashchange",d,!1):a.attachEvent&&a.attachEvent("onhashchange",d)}var c,d;return c=this,d=function(){c.check(c)},b(),this},navigate:function(a){return a=a?a:"",this.location.href.match(/#(.*)$/),this.location.href=this.location.href.replace(/#(.*)$/,"")+"#"+a,this}},o={Router:n};d.prototype=d.extend(d.prototype,o),"function"==typeof define&&define.amd&&define("lettuce",[],function(){return d});var p="undefined";return typeof b===p&&(a.Lettuce=d),d});