| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489 |
- /**
- *
- * /$$
- * | $$
- * | $$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$
- * | $$ | $$ | $$| $$__ $$ /$$__ $$ /$$__ $$
- * | $$ | $$ | $$| $$ \ $$| $$ \ $$| $$ \ $$
- * | $$ | $$ | $$| $$ | $$| $$ | $$| $$ | $$
- * | $$$$$$$$| $$$$$$/| $$ | $$| $$$$$$$| $$$$$$/
- * |________/ \______/ |__/ |__/ \____ $$ \______/
- * /$$ \ $$
- * | $$$$$$/
- * \______/
- *
- * @copyright 2011 TapQuo Inc (c)
- * @license http://www.github.com/tapquo/lungo/blob/master/LICENSE.txt
- * @version 1.2
- * @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.2';
- LUNGO.Attributes || (LUNGO.Attributes = {});
- LUNGO.Data || (LUNGO.Data = {});
- LUNGO.Sugar || (LUNGO.Sugar = {});
- LUNGO.View || (LUNGO.View = {});
- LUNGO.Device || (LUNGO.Device = {});
- LUNGO.ready || (LUNGO.ready = Quo().ready);/**
- * Object with data-attributes (HTML5) with a special <markup>
- *
- * @namespace LUNGO
- * @class Constants
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Constants = {
- ELEMENT: {
- SECTION: 'section',
- ARTICLE: 'article',
- ASIDE: 'aside',
- BODY: 'body',
- DIV: 'div',
- LIST: '<ul></ul>',
- SPAN: '<span> </span>'
- },
- CLASS: {
- ACTIVE: 'active',
- ASIDE: 'aside',
- SHOW: 'show',
- HIDE: 'hide',
- CURRENT: 'current',
- RIGHT: 'onright',
- LEFT: 'onleft',
- HORIZONTAL: 'horizontal',
- MINI: 'mini'
- },
- TRIGGER: {
- LOAD: 'load',
- UNLOAD: 'unload'
- },
- ATTRIBUTE: {
- ID: 'id',
- HREF: 'href',
- TITLE: 'title',
- ARTICLE: 'article',
- CLASS: 'class',
- WIDTH: 'width',
- HEIGHT: 'height',
- PIXEL: 'px',
- PERCENT: '%',
- TARGET: 'target',
- FIRST: 'first',
- LAST: 'last',
- EMPTY: ''
- },
- BINDING: {
- START: '{{',
- END: '}}',
- KEY: 'value',
- PARSER: /\{{.*?\}}/gi
- },
- ERROR: {
- CREATE_SCROLL: 'ERROR: Impossible to create a <scroll> without ID.',
- BINDING_DATA_TYPE: 'ERROR: Processing the type of binding data.',
- BINDING_TEMPLATE: 'ERROR: Binding Template not exists >> ',
- BINDING_LIST: 'ERROR: Processing parameters for list binding.',
- DATABASE: 'ERROR: Connecting to Data.Sql.',
- ROUTER: 'ERROR: The target does not exists >>',
- LOADING_RESOURCE: 'ERROR: Loading resource.'
- }
- };/**
- * Lungo sandbox APP initialization
- *
- * @namespace LUNGO
- * @class App
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.App = (function(lng, undefined) {
- var default_config = {
- id: 1,
- name: 'lungo_app',
- version: 1.0,
- icon: ''
- };
- /**
- * Initializes all LungoJS system: setting properties for the application,
- * subscribing to automatic events, initializing sections & articles
- * and stating the title.
- *
- * @method init
- *
- * @param {object} Application configuration properties
- */
- var init = function(app_config) {
- default_config = lng.Core.mix(default_config, app_config);
- lng.Boot();
- };
- var get = function(property) {
- return default_config[property];
- };
- return {
- init: init,
- get: get
- };
- })(LUNGO);/**
- * Contains all the common functions used in Lungo.
- *
- * @namespace LUNGO
- * @class Core
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Core = (function(lng, $$, undefined) {
- var ARRAY_PROTO = Array.prototype;
- var HASHTAG_CHARACTER = '#';
- /**
- * Console system to display messages when you are in debug mode.
- *
- * @method log
- *
- * @param {number} Severity based in (1)Log, (2)Warn, (>2)Error
- * @param {string} Message to show in console
- */
- var log = function(severity, message) {
- if (!lng.Core.isMobile()) {
- console[(severity === 1) ? 'log' : (severity === 2) ? 'warn' : 'error'](message);
- } else {
- // @todo : send to the server
- }
- };
- /**
- * Executes callbacks based on the parameters received.
- *
- * @method execute
- *
- * @param {Function} callback to execute
- */
- var execute = function() {
- var args = toArray(arguments);
- var callback = args.shift();
- if (toType(callback) === 'function') {
- callback.apply(null, args);
- }
- };
- /**
- * Creates a new function that, when called, itself calls this function in
- * the context of the provided this value, with a given sequence of arguments
- * preceding any provided when the new function was called.
- *
- * @method bind
- *
- * @param {object} object to which the 'this' can refer in the new function when the new function is called.
- * @param {Function} method A function object.
- */
- var bind = function(object, method) {
- return function() {
- return method.apply(object, toArray(arguments));
- };
- };
- /**
- * Copy from any number of objects and mix them all into a new object.
- * The implementation is simple; just loop through arguments and
- * copy every property of every object passed to the function.
- *
- * @method mix
- *
- * @param {object} arguments to mix them all into a new object.
- * @return {object} child a new object with all the objects from the arguments mixed.
- */
- var mix = function() {
- var child = child || {};
- for (var arg = 0, len = arguments.length; arg < len; arg++) {
- var argument = arguments[arg];
- for (var prop in argument) {
- if (isOwnProperty(argument, prop)) {
- child[prop] = argument[prop];
- }
- }
- }
- return child;
- };
- /**
- * Every object descended from Object inherits the hasOwnProperty method.
- * This method can be used to determine whether an object has the specified property
- * as a direct property of that object.
- *
- * @param {object} object to test for a property's existence inside itself.
- * @param {string} property the name of the property to test.
- * @return {boolean} indicating whether the object has the specified property.
- */
- var isOwnProperty = function(object, property) {
- return $$.isOwnProperty(object, property);
- };
- /**
- * Determine the internal JavaScript [[Class]] of an object.
- *
- * @param {object} obj to get the real type of itself.
- * @return {string} with the internal JavaScript [[Class]] of itself.
- */
- var toType = function(obj) {
- return $$.toType(obj);
- };
- /**
- * Convert an array-like object into a true JavaScript array.
- *
- * @param {object} obj Any object to turn into a native Array.
- * @return {object} The object is now a plain array.
- */
- var toArray = function(obj) {
- return ARRAY_PROTO.slice.call(obj, 0);
- };
- /**
- * Determine if the current environment is a mobile environment
- *
- * @method isMobile
- *
- * @return {boolean} true if is mobile environment, false if not.
- */
- var isMobile = function() {
- return $$.isMobile();
- };
- /**
- * Returns information of execute environment
- *
- * @method environment
- *
- * @return {object} Environment information
- */
- var environment = function() {
- return $$.environment();
- };
- /**
- * Returns a ordered list of objects by a property
- *
- * @method orderByProperty
- *
- * @param {list} List of objects
- * @param {string} Name of property
- * @param {string} Type of order: asc (ascendent) or desc (descendent)
- * @return {list} Ordered list
- */
- var orderByProperty = function(data, property, order) {
- var order_operator = (order === 'desc') ? -1 : 1;
- return data.sort(function(a, b) {
- return (a[property] < b[property]) ? - order_operator :
- (a[property] > b[property])
- ?
- order_operator : 0;
- }
- );
- };
- /**
- * Returns a correct URL using hashtag character
- *
- * @method parseUrl
- *
- * @param {string} Url
- * @return {string} Url parsed
- */
- var parseUrl = function(href) {
- var href_hashtag = href.lastIndexOf(HASHTAG_CHARACTER);
- if (href_hashtag > 0) {
- href = href.substring(href_hashtag);
- } else if (href_hashtag === -1) {
- href = HASHTAG_CHARACTER + href ;
- }
- return href;
- };
- /**
- * Returns a Object in a list by a property value
- *
- * @method objectInListByProperty
- *
- * @param {list} List of objects
- * @param {string} Name of property
- * @param {var} Value for comparision
- * @return {object} Instance of object founded (if exists)
- */
- var findByProperty = function(list, property, value) {
- var search = null;
- for (var i = 0, len = list.length; i < len; i++) {
- var element = list[i];
- if (element[property] == value) {
- search = element;
- break;
- }
- };
- return search;
- };
- return {
- log: log,
- execute: execute,
- bind: bind,
- mix: mix,
- isOwnProperty: isOwnProperty,
- toType: toType,
- toArray: toArray,
- isMobile: isMobile,
- environment: environment,
- orderByProperty: orderByProperty,
- parseUrl: parseUrl,
- findByProperty: findByProperty
- };
- })(LUNGO, Quo);/**
- * LungoJS Dom Handler
- *
- * @namespace LUNGO
- * @class Dom
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- /**
- * Add an event listener
- *
- * @method dom
- *
- * @param {string} <Markup> element selector
- * @return {Object} QuoJS <element> instance
- */
- LUNGO.dom = function(selector) {
- return $$(selector);
- };/**
- * External Data & Services Manager
- *
- * @namespace LUNGO
- * @class Service
- * @requires QuoJS
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Service = (function(lng, $$, undefined) {
- var URL_CACHE_INDEX_KEY = 'lungojs_service_cache';
- var DATE_PATTERN = {
- MINUTE: 'minute',
- HOUR: 'hour',
- DAY: 'day'
- };
- /**
- * Load data from the server using a HTTP GET request.
- *
- * @method get
- *
- * @param {string} Containing the URL to which the request is sent
- * @param {object} A map or string that is sent to the server with the request
- * @param {Function} Callback function after the request [OPTIONAL]
- * @param {string} Mime-Type: json, xml, html, or text [OPTIONAL]
- */
- var get = function(url, data, success, dataType) {
- return $$.get(url, data, success, dataType);
- };
- /**
- * Load data from the server using a HTTP POST request.
- *
- * @method post
- *
- * @param {string} Containing the URL to which the request is sent
- * @param {object} A map or string that is sent to the server with the request
- * @param {Function} Callback function after the request [OPTIONAL]
- * @param {string} Mime-Type: json, xml, html, or text [OPTIONAL]
- */
- var post = function(url, data, success, dataType) {
- return $$.post(url, data, success, dataType);
- };
- /**
- * Load data from the server using a HTTP GET request.
- *
- * @method json
- *
- * @param {string} Containing the URL to which the request is sent
- * @param {object} A map or string that is sent to the server with the request
- * @param {Function} [OPTIONAL] Callback function after the request
- */
- var json = function(url, data, success) {
- return $$.json(url, data, success);
- };
- /**
- * Auto-caching system with date pattern.
- *
- * @method cache
- *
- * @param {string} Containing the URL to which the request is sent
- * @param {object} A map or string that is sent to the server with the request
- * @param {string} Date pattern (example: 15 minutes, 1 hour, 3 days)
- * @param {Function} [OPTIONAL] Callback function after the request
- * @param {string} Mime-Type: json, xml, html, or text [OPTIONAL]
- */
- var cache = function(url, data, date_pattern, callback, dataType) {
- var url_key = url + $$.serializeParameters(data);
- if (_urlCached(url_key, date_pattern)) {
- var value = lng.Data.Storage.persistent(url_key);
- if (value) {
- return callback.call(callback, value);
- }
- } else {
- return $$.get(url, data, function(result) {
- _saveServiceInCache(url_key, result);
- callback.call(callback, result);
- }, dataType);
- }
- };
- var _urlCached = function(url, date_pattern) {
- var in_cache = false;
- var url_cache_index = lng.Data.Storage.persistent(URL_CACHE_INDEX_KEY);
- if (url_cache_index) {
- var time_between = _calculateTimeSpent(url_cache_index[url]);
- in_cache = _checkIsValidPattern(time_between, date_pattern);
- }
- return in_cache;
- };
- var _calculateTimeSpent = function(url_last_access) {
- var now = new Date().getTime();
- var service_last_access = new Date(url_last_access).getTime();
- return now - service_last_access;
- };
- var _checkIsValidPattern = function(time_between, date_pattern) {
- var pattern = date_pattern.split(' ');
- var diference_time = _calculateDiferenceTime(pattern[1], time_between);
- return (diference_time < pattern[0]) ? true : false;
- };
- var _calculateDiferenceTime = function(pattern_name, time_between) {
- var diference = (time_between / 1000) / 60;
- if (pattern_name.indexOf(DATE_PATTERN.HOUR) >= 0) {
- diference = diference / 60;
- } else if (pattern_name.indexOf(DATE_PATTERN.DAY) >= 0) {
- diference = (diference / 60) / 24;
- }
- return diference;
- };
- var _saveServiceInCache = function(url, result) {
- var service_cache_index = lng.Data.Storage.persistent(URL_CACHE_INDEX_KEY) || {};
- service_cache_index[url] = new Date();
- lng.Data.Storage.persistent(URL_CACHE_INDEX_KEY, service_cache_index);
- lng.Data.Storage.persistent(url, result);
- };
- return {
- get: get,
- post: post,
- json: json,
- cache: cache,
- Settings: $$.ajaxSettings
- };
- })(LUNGO, Quo);/**
- * ?
- *
- * @namespace LUNGO
- * @class Fallback
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- */
- LUNGO.Fallback = (function(lng, undefined) {
- var androidInputs = function(article_id, active) {
- environment = lng.Core.environment();
- if (environment.isMobile && environment.os.name === 'android' && environment.os.version < '4') {
- var selector = article_id + ' input, ' + article_id + ' textarea, ' + article_id + ' select';
- var input_elements = lng.dom(selector);
- for (var i = 0, len = input_elements.length; i < len; i++) {
- (active) ? _enableAndroidInput(input_elements[i]) : _disableAndroidInput(input_elements[i]);
- }
- }
- };
- var positionFixed = function(sections) {
- environment = lng.Core.environment();
- if (environment.isMobile && environment.os.name === 'ios' && environment.os.version >= '4.2') {
- sections.style('position', 'fixed');
- }
- };
- var _enableAndroidInput = function(input) {
- input.removeAttribute('disabled');
- };
- var _disableAndroidInput = function(input) {
- input.setAttribute('disabled', 'disabled');
- };
- return {
- androidInputs: androidInputs,
- positionFixed: positionFixed
- }
- })(LUNGO);/**
- * Handles the <sections> and <articles> to show
- *
- * @namespace LUNGO
- * @class Router
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Router = (function(lng, undefined) {
- var CLASS = lng.Constants.CLASS;
- var ELEMENT = lng.Constants.ELEMENT;
- var ERROR = lng.Constants.ERROR;
- var TRIGGER = lng.Constants.TRIGGER;
- /**
- * Navigate to a <section>.
- *
- * @method section
- *
- * @param {string} Id of the <section>
- */
- var section = function(section_id) {
- var section_id = lng.Core.parseUrl(section_id);
- var current = _getHistoryCurrent();
- var target = ELEMENT.SECTION + section_id;
- if (_exists(target) && _notCurrentTarget(target)) {
- lng.dom(current).removeClass(CLASS.SHOW).addClass(CLASS.HIDE);
- lng.dom(target).addClass(CLASS.SHOW).trigger(TRIGGER.LOAD);
- lng.Router.History.add(section_id);
- }
- };
- /**
- * Displays the <article> in a particular <section>.
- *
- * @method article
- *
- * @param {string} <section> Id
- * @param {string} <article> Id
- */
- var article = function(section_id, article_id) {
- var section_id = lng.Core.parseUrl(section_id);
- var article_id = lng.Core.parseUrl(article_id);
- var target = ELEMENT.SECTION + section_id + ' ' + ELEMENT.ARTICLE + article_id;
- if (_exists(target) && _notCurrentTarget(target)) {
- lng.dom(target).trigger(TRIGGER.LOAD);
- lng.View.Article.show(section_id, article_id);
- }
- };
- /**
- * Displays the <aside> in a particular <section>.
- *
- * @method aside
- *
- * @param {string} <section> Id
- * @param {string} <aside> Id
- */
- var aside = function(section_id, aside_id) {
- var section_id = lng.Core.parseUrl(section_id);
- var aside_id = lng.Core.parseUrl(aside_id);
- var target = ELEMENT.ASIDE + aside_id;
- if (_exists(target)) {
- var is_visible = lng.dom(target).hasClass(CLASS.CURRENT);
- if (is_visible) {
- lng.View.Aside.hide(section_id, aside_id);
- } else {
- lng.View.Aside.show(section_id, aside_id);
- }
- }
- };
- /**
- * Return to previous section.
- *
- * @method back
- */
- var back = function() {
- var current_section = ELEMENT.SECTION + _getHistoryCurrent();
- lng.dom(current_section).removeClass(CLASS.SHOW).trigger(TRIGGER.UNLOAD);
- lng.Router.History.removeLast();
- lng.dom(_getHistoryCurrent()).removeClass(CLASS.HIDE).addClass(CLASS.SHOW);
- };
- var _notCurrentTarget = function(target) {
- return lng.dom(target).hasClass(CLASS.CURRENT) ? false : true;
- };
- var _exists = function(target) {
- var exists = false;
- if (lng.dom(target).length > 0) {
- exists = true;
- } else {
- lng.Core.log(3, ERROR.ROUTER + target);
- }
- return exists;
- };
- var _getHistoryCurrent = function() {
- return lng.Router.History.current();
- };
- return {
- section: section,
- article: article,
- aside: aside,
- back: back
- };
- })(LUNGO);/**
- * Stores the displayed <sections> as a historical.
- *
- * @namespace LUNGO.Router
- * @class History
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Router.History = (function(undefined) {
- var _history = [];
- /**
- * Create a new element to the browsing history based on the current section id.
- *
- * @method add
- *
- * @param {string} Id of the section
- */
- var add = function(section_id) {
- if (section_id !== current()) {
- _history.push(section_id);
- }
- };
- /**
- * Returns the current browsing history section id.
- *
- * @method current
- *
- * @return {string} Current section id
- */
- var current = function() {
- return _history[_history.length - 1];
- };
- /**
- * Removes the current item browsing history.
- *
- * @method removeLast
- */
- var removeLast = function() {
- _history.length -= 1;
- };
- return {
- add: add,
- current: current,
- removeLast: removeLast
- };
- })();/**
- * Initialize the <articles> layout of a certain <section>
- *
- * @namespace LUNGO.View
- * @class Article
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.View.Article = (function(lng, undefined) {
- var ELEMENT = lng.Constants.ELEMENT;
- var CLASS = lng.Constants.CLASS;
- var ATTRIBUTE = lng.Constants.ATTRIBUTE;
- var TRIGGER = lng.Constants.TRIGGER;
- var SELECTORS = {
- NAVIGATION_ITEM: 'a[href][data-target="article"]',
- REFERENCE_LINK: ' a[href][data-article]'
- };
- /**
- * ?
- *
- * @method show
- */
- var show = function(section_id, article_id) {
- _toggleNavItems(section_id, article_id);
- showReferenceLinks(section_id, article_id.replace('#', ''));
- _showContainer(section_id, article_id);
- };
- /**
- * ?
- *
- * @method showReferenceLinks
- */
- var showReferenceLinks = function(section_id, article_id) {
- var links = lng.dom(ELEMENT.SECTION + section_id + SELECTORS.REFERENCE_LINK);
- for (var i = 0, len = links.length; i < len; i++) {
- var link = lng.dom(links[i]);
- (link.data(ATTRIBUTE.ARTICLE) === article_id) ? link.show() : link.hide();
- }
- };
- var _toggleNavItems = function(section_id, article_id) {
- var nav_items = lng.dom(section_id + ' ' + SELECTORS.NAVIGATION_ITEM);
- nav_items.removeClass(CLASS.CURRENT);
- for (var i = 0, len = nav_items.length; i < len; i++) {
- var nav_item = lng.dom(nav_items[i]);
- var nav_item_parsed_url = lng.Core.parseUrl(nav_item.attr(ATTRIBUTE.HREF));
- if (nav_item_parsed_url === article_id) {
- nav_item.addClass(CLASS.CURRENT);
- _setTitle(section_id, nav_item);
- }
- }
- };
- var _showContainer = function(section_id, article_id) {
- var section_articles = section_id + ' ' + ELEMENT.ARTICLE + '.' + CLASS.CURRENT;
- var current_active_article_id = '#' + lng.dom(section_articles).attr(ATTRIBUTE.ID);
- lng.dom(section_articles).removeClass(CLASS.CURRENT).trigger(TRIGGER.UNLOAD);
- lng.Fallback.androidInputs(current_active_article_id, false);
- lng.dom(article_id).addClass(CLASS.CURRENT);
- lng.Fallback.androidInputs(article_id, true);
- };
- var _setTitle = function(id, item) {
- var title = item.data(ATTRIBUTE.TITLE);
- if (title) {
- var section_title = id + ' header .title, ' + id + ' footer .title';
- lng.dom(section_title).text(title);
- }
- };
- return {
- show: show,
- showReferenceLinks: showReferenceLinks
- };
- })(LUNGO);/**
- *
- *
- * @namespace LUNGO.View
- * @class Resize
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.View.Resize = (function(lng, undefined) {
- var ATTRIBUTE = lng.Constants.ATTRIBUTE;
- /**
- * Sets toolbars width, using total screen width
- *
- * @method toolbars
- */
- var toolbars = function() {
- var toolbar = '.toolbar nav, .groupbar';
- var all_toolbars = lng.dom(toolbar);
- for (var i = 0, len = all_toolbars.length; i < len; i++) {
- var toolbar = lng.dom(all_toolbars[i]);
- var toolbar_children = toolbar.children();
- var toolbar_children_percent = 100 / toolbar.children().length;
- toolbar_children.style(ATTRIBUTE.WIDTH, toolbar_children_percent + ATTRIBUTE.PERCENT);
- }
- };
- return {
- toolbars: toolbars
- };
- })(LUNGO);/**
- * Lungo Template system
- *
- * @namespace LUNGO.View
- * @class Template
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.View.Template = (function(lng, undefined) {
- var ERROR = lng.Constants.ERROR;
- var _templates = {};
- /**
- * Create a new databinding template based on a <markup>
- *
- * @method create
- *
- * @param {String} Id of the new databinding template
- * @param {String} <markup> of the new databinding template
- */
- var create = function(id, markup) {
- _templates[id] = markup;
- };
- /**
- * Returns the existence of a certain Id databinding template
- *
- * @method exists
- *
- * @param {String} Id of the databinding template
- * @return {Boolean} true if exists, false if not.
- */
- var exists = function(id) {
- return (_templates[id]) ? true : false;
- };
- /**
- * Returns the instance of a certain Id databinding template
- *
- * @method get
- *
- * @param {String} Id of the databinding template
- * @return {String} Markup of template
- */
- var get = function(id) {
- return _templates[id];
- };
- /**
- * Performs databinding process for a data set and a given template
- *
- * @method render
- *
- * @param {String} Element selector for showing the result of databinding
- * @param {String} Databinding Template Id
- * @param {Object} Data for binding
- * @param {Function} Callback when the process is complete
- */
- var render = function(element, template_id, data, callback) {
- if (lng.View.Template.exists(template_id)) {
- var container = lng.dom(element);
- var markup = this.markup(template_id, data);
- container.html(markup);
- lng.Core.execute(callback);
- } else {
- lng.Core.log(3, ERROR.BINDING_TEMPLATE + template_id);
- }
- };
- /**
- * Performs databinding process for a data set and a given template
- *
- * @method markup
- *
- * @param {String} Databinding Template Id
- * @param {Object} Data for binding
- */
- var markup = function(template_id, data) {
- return lng.View.Template.Binding.create(template_id, data);
- };
- return {
- create: create,
- exists: exists,
- get: get,
- render: render,
- markup: markup
- };
- })(LUNGO);/**
- * Lungo Data-Binding system
- *
- * @namespace LUNGO.View.Template
- * @class Binding
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.View.Template.Binding = (function(lng, undefined) {
- var BINDING = lng.Constants.BINDING;
- var ERROR = lng.Constants.ERROR;
- /**
- * Performs databinding process for a data set and a given template
- *
- * @method create
- *
- * @param {String} Databinding Template Id
- * @param {Object} Data for binding
- */
- var create = function(template_id, data) {
- var template = lng.View.Template.get(template_id);
- return _processData(data, template);
- };
- var dataAttribute = function(element, attribute) {
- var data = element.data(attribute.tag);
- if (data) {
- var html_binded = attribute.html.replace(BINDING.START + BINDING.KEY + BINDING.END, data);
- element.prepend(html_binded);
- }
- };
- var _processData = function(data, template) {
- var data_type = lng.Core.toType(data);
- if (data_type === 'array') {
- return _bindPropertiesInMultiplesElements(data, template);
- } else if (data_type === 'object') {
- return _bindProperties(data, template);
- } else {
- lng.Core.log(3, ERROR.BINDING_DATA_TYPE);
- }
- };
- var _bindPropertiesInMultiplesElements = function(elements, template) {
- var markup = '';
- for (var i = 0, len = elements.length; i < len; i++) {
- markup += _bindProperties(elements[i], template);
- }
- return markup;
- };
- var _bindProperties = function(element, template) {
- var binding_field;
- for (var property in element) {
- if (lng.Core.isOwnProperty(element, property) && element[property] !== null) {
- binding_field = new RegExp(BINDING.START + property + BINDING.END, 'g');
- template = template.replace(binding_field, element[property]);
- }
- }
- return _removeNoBindedProperties(template);
- };
- var _removeNoBindedProperties = function(template) {
- return template.replace(BINDING.PARSER, '');
- };
- return {
- create: create,
- dataAttribute: dataAttribute
- };
- })(LUNGO);/**
- * Auto generate lists based on Template and Data-Binding system
- *
- * @namespace LUNGO.View.Template
- * @class List
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.View.Template.List = (function(lng, undefined) {
- var ERROR = lng.Constants.ERROR;
- var ATTRIBUTE = lng.Constants.ATTRIBUTE;
- /**
- * Create a list based DataBind with a configuration object for an element <article>
- * if the config has a 'norecords' property it will display the norecords markup rather than nothing.
- *
- * @method create
- *
- * @param {object} Id of the container showing the result of databinding
- */
- var create = function(config) {
- config.container = _getContainer(config.el);
- if (_validateConfig(config)) {
- config.data = _order(config);
- _render(config);
- _scroll(config.el);
- }
- };
- /**
- * Append a list based DataBind with a configuration object for an element <article>
- * if the config has a 'norecords' property it will display the norecords markup rather than nothing.
- *
- * @method append
- *
- * @param {object} Id of the container showing the result of databinding
- */
- var append = function(config) {
- var markup = lng.View.Template.markup(config.template, config.data);
- var container = _getContainer(config.el);
- container.append(markup);
- _scroll(config.el, ATTRIBUTE.LAST);
- };
- /**
- * Prepend a list based DataBind with a configuration object for an element <article>
- * if the config has a 'norecords' property it will display the norecords markup rather than nothing.
- *
- * @method prepend
- *
- * @param {object} Id of the container showing the result of databinding
- */
- var prepend = function(config) {
- var markup = lng.View.Template.markup(config.template, config.data);
- var container = _getContainer(config.el);
- container.prepend(markup);
- _scroll(config.el, ATTRIBUTE.FIRST);
- };
- var _validateConfig = function(config) {
- var checked = false;
- var container_exists = !! config.container.length > 0;
- var template_exists = lng.View.Template.exists(config.template);
- if (container_exists && template_exists) {
- var type = lng.Core.toType(config.data);
- if (type === 'array' || type === 'object') {
- checked = true;
- }
- } else {
- lng.Core.log(3, ERROR.BINDING_LIST);
- }
- return checked;
- };
- var _getContainer = function(element) {
- return lng.dom(element).children().first();
- }
- var _order = function(config) {
- if (config.order && config.order.field && config.order.type) {
- config.data = lng.Core.orderByProperty(config.data, config.order.field, config.order.type);
- }
- return config.data;
- };
- var _render = function(config) {
- lng.View.Template.render(config.container.selector, config.template, config.data);
- };
- var _scroll = function(element, direction) {
- var element_id = lng.dom(element).attr(ATTRIBUTE.ID);
- lng.View.Scroll.init(element_id);
- if (direction) {
- lng.View.Scroll[(direction === ATTRIBUTE.FIRST) ? ATTRIBUTE.FIRST : ATTRIBUTE.LAST](element_id);
- }
- };
- return {
- create: create,
- append: append,
- prepend: prepend
- };
- })(LUNGO);/**
- * Wrapper of the third library iScroll
- *
- * @namespace LUNGO.View
- * @class Scroll
- * @requires iScroll
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.View.Scroll = (function(lng, undefined) {
- var CLASS = lng.Constants.CLASS;
- var ATTRIBUTE = lng.Constants.ATTRIBUTE;
- var ERROR = lng.Constants.ERROR;
- var DEFAULT_PROPERTIES = {
- hScroll: false,
- vScroll: false,
- useTransition: true,
- momentum: true,
- lockDirection: true,
- fixedScrollbar: true,
- fadeScrollbar: true,
- hideScrollbar: true
- };
- var CACHE_KEY = 'scrolls';
- var SCROLL_TIMEFRAME = 250;
- /**
- * Creates a new iScroll element.
- *
- * @method init
- *
- * @param {string} Id of the container scroll.
- * @param {object} [OPTIONAL] Properties
- */
- var init = function(id, properties) {
- if (id) {
- _render(id, properties);
- } else {
- lng.Core.log(3, ERROR.CREATE_SCROLL);
- }
- };
- /**
- * Update iScroll element with new <markup> content.
- *
- * @method html
- *
- * @param {string} Id of the container scroll.
- * @param {string} Markup content
- */
- var html = function(id, content) {
- var container = _getContainer(id);
- container.html(content);
- _render(id);
- };
- /**
- * Add <markup> content to iScroll instance
- *
- * @method append
- *
- * @param {string} Id of the container scroll.
- * @param {string} Markup content
- */
- var append = function(id, content) {
- var container = _getContainer(id);
- container.append(content);
- _render(id);
- };
- /**
- * Refresh iScroll instance.
- *
- * @method refresh
- *
- * @param {string} Id of the container scroll.
- * @param {object} [OPTIONAL] Properties
- */
- var refresh = function(id, properties) {
- _render(id, properties);
- };
- /**
- * Removes iScroll instance.
- *
- * @method remove
- *
- * @param {string} Id of the container scroll.
- */
- var remove = function(id) {
- if (lng.Data.Cache.exists(CACHE_KEY) && lng.Data.Cache.get(CACHE_KEY, id)) {
- lng.Data.Cache.get(CACHE_KEY, id).destroy();
- lng.Data.Cache.remove(CACHE_KEY, id);
- }
- };
- /**
- * Scrolls the wrapper contents to the minimum x/y coordinates
- *
- * @method first
- *
- * @param {string} Id of the <section>
- */
- var first = function(id) {
- var scroll = lng.Data.Cache.get(CACHE_KEY);
- if (scroll[id]) {
- scroll[id].scrollTo(0, 0, SCROLL_TIMEFRAME);
- }
- };
- /**
- * Scrolls the wrapper contents to the maximum x/y coordinate
- *
- * @method down
- *
- * @param {string} Id of the <section>
- */
- var last = function(id) {
- var scroll = lng.Data.Cache.get(CACHE_KEY, id);
- if (scroll) {
- var element = lng.dom('#' + id).first();
- var content_width = 0;
- var content_height = 0;
- if (_isHorizontal(element)) {
- content_width = -(_sizeProperty(element, ATTRIBUTE.WIDTH));
- } else {
- content_height = -(_sizeProperty(element, ATTRIBUTE.HEIGHT));
- }
- scroll.scrollTo(content_width, content_height, SCROLL_TIMEFRAME);
- }
- };
- var _getContainer = function(id) {
- var scroll = lng.dom('#' + id);
- var container = scroll.children().first();
- if (container.length === 0) {
- scroll.html('<div></div>');
- container = scroll.children().first();
- }
- return container;
- };
- var _sizeProperty = function(element, property) {
- var element_content = element.children().first();
- return element_content[property]() - element[property]();
- };
- var _render = function(id, properties) {
- var scroll = lng.dom('#' + id);
- if (_needScroll(scroll, properties)) {
- properties = _mixProperties(scroll, properties);
- _saveScrollInCache(id, properties);
- } else {
- remove(id);
- }
- };
- var _needScroll = function(scroll, properties) {
- var element = scroll[0];
- var is_horizontal = _isHorizontal(lng.dom(element));
- if (is_horizontal) {
- return (element.clientWidth < element.scrollWidth);
- } else {
- return (element.clientHeight < element.scrollHeight);
- }
- };
- var _saveScrollInCache = function(id, properties) {
- _createScrollIndexInCache();
- var scroll = lng.Data.Cache.get(CACHE_KEY);
- if (!scroll[id]) {
- scroll[id] = new iScroll(id, properties);
- } else {
- scroll[id].refresh();
- }
- lng.Data.Cache.set(CACHE_KEY, scroll);
- };
- var _createScrollIndexInCache = function() {
- if (!lng.Data.Cache.exists(CACHE_KEY)) {
- lng.Data.Cache.set(CACHE_KEY, {});
- }
- };
- var _mixProperties = function(scroll, properties) {
- var scroll_type = _isHorizontal(scroll) ? 'hScroll' : 'vScroll';
- properties || (properties = {});
- properties[scroll_type] = true;
- properties = lng.Core.mix(DEFAULT_PROPERTIES, properties);
- return properties;
- };
- var _isHorizontal = function(scroll) {
- return ( scroll.hasClass(CLASS.HORIZONTAL)) ? true : false;
- };
- return {
- init: init,
- remove: remove,
- refresh: refresh,
- html: html,
- append: append,
- first: first,
- last: last
- };
- })(LUNGO);/**
- * Initialize the <articles> layout of a certain <section>
- *
- * @namespace LUNGO.View
- * @class Aside
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.View.Aside = (function(lng, undefined) {
- var ELEMENT = lng.Constants.ELEMENT;
- var CLASS = lng.Constants.CLASS;
- var ATTRIBUTE = lng.Constants.ATTRIBUTE;
- /**
- * Display an aside element for a particular <section>
- *
- * @method show
- *
- * @param {string} Section id
- * @param {string} Aside id
- */
- var show = function(section_id, aside_id) {
- var aside = lng.dom(ELEMENT.ASIDE + aside_id);
- var aside_class = _asideClass(aside);
- var section = lng.dom(ELEMENT.SECTION + section_id);
- aside.addClass(CLASS.CURRENT);
- section.addClass(aside_class).addClass(CLASS.ASIDE);
- };
- /**
- * Hide an aside element for a particular section
- *
- * @method hide
- *
- * @param {string} Element query selector
- * @param {string} Value for counter
- */
- var hide = function(section_id, aside_id) {
- var aside = lng.dom(ELEMENT.ASIDE + aside_id);
- var aside_class = _asideClass(aside);
- var section = lng.dom(ELEMENT.SECTION + section_id);
- section.removeClass(CLASS.ASIDE).removeClass(aside_class);
- setTimeout(function() {
- aside.removeClass(CLASS.CURRENT);
- }, 300);
- };
- var _asideClass = function(aside) {
- var aside_class = aside.attr(ATTRIBUTE.CLASS);
- var classes = ''
- //@todo: Refactor
- if (aside_class) {
- classes += (aside_class.indexOf(CLASS.RIGHT) > -1) ? CLASS.RIGHT : '';
- classes += (aside_class.indexOf(CLASS.MINI) > -1) ? CLASS.MINI : '';
- }
- return classes;
- };
- return {
- show: show,
- hide: hide
- };
- })(LUNGO);/**
- * Initialize the <articles> layout of a certain <section>
- *
- * @namespace LUNGO.View
- * @class Element
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- */
- LUNGO.View.Element = (function(lng, undefined) {
- var ATTRIBUTE = lng.Constants.ATTRIBUTE;
- var BINDING = lng.Constants.BINDING;
- var SELECTORS = {
- BUBBLE: '.bubble.count',
- PROGRESS_VALUE: ' .value',
- PROGRESS_PERCENTAGE: ' .value .label'
- };
- /**
- * Set a counter to the element
- *
- * @method count
- *
- * @param {string} Element query selector
- * @param {number} Value for counter
- */
- var count = function(selector, count) {
- var element = lng.dom(selector);
- if (element) {
- if (count > 0) {
- _setBubble(element, count);
- } else {
- element.children(SELECTORS.BUBBLE).remove();
- }
- }
- };
- /**
- * Set a progress to the element
- *
- * @method progress
- *
- * @param {string} Element query selector
- * @param {number} Percentage
- * @param {boolean} Show the labels: description and current percentage
- * @param {string} Description
- */
- var progress = function(selector, percentage, with_label) {
- var element = lng.dom(selector);
- if (element) {
- percentage += ATTRIBUTE.PERCENT;
- lng.dom(selector + SELECTORS.PROGRESS_VALUE).style(ATTRIBUTE.WIDTH, percentage);
- lng.dom(selector + SELECTORS.PROGRESS_PERCENTAGE).html((with_label) ? percentage : ATTRIBUTE.EMPTY);
- }
- };
- /**
- * Set a progress to the element
- *
- * @method progress
- *
- * @param {string} Element query selector
- * @param {number} Percentage
- * @param {boolean} Show the labels: description and current percentage
- * @param {string} Description
- */
- var loading = function(selector, stylesheet) {
- var element = lng.dom(selector);
- if (element) {
- _bindAttribute(element, LUNGO.Attributes.Data.Loading, stylesheet);
- }
- };
- var _setBubble = function(element, count) {
- var bubbles = element.children(SELECTORS.BUBBLE);
- var total_bubbles = bubbles.length;
- if (total_bubbles > 0) {
- bubbles.html(count);
- } else {
- _bindAttribute(element, LUNGO.Attributes.Data.Count, count);
- }
- };
- var _bindAttribute = function(element, attribute, data) {
- var html_binded = attribute.html.replace(BINDING.START + BINDING.KEY + BINDING.END, data);
- element.append(html_binded);
- };
- return {
- count: count,
- progress: progress,
- loading: loading
- };
- })(LUNGO);/**
- * Object with data-attributes (HTML5) with a special <markup>
- *
- * @namespace LUNGO.Attributes
- * @class Data
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- 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>'
- },
- Count: {
- tag: 'count',
- selector: '*',
- html: '<span class="bubble count">{{value}}</span>'
- },
- Search: {
- tag: 'search',
- selector: '*',
- html: '<input type="search" placeholder="{{value}}"/><a href="#" class="button" data-icon="search"></a>'
- },
- Progress: {
- tag: 'progress',
- selector: '*',
- html: '<div class="progress">\
- <span class="bar"><span class="value" style="width:{{value}};"><span class="label"></span></span></span>\
- </div>'
- },
- Label: {
- tag: 'label',
- selector: 'a',
- html: '<abbr>{{value}}</abbr>'
- },
- Icon: {
- tag: 'icon',
- selector: '*',
- html: '<span class="icon {{value}}"></span>'
- },
- Image: {
- tag: 'image',
- selector: '*',
- html: '<img src="{{value}}" class="icon" />'
- },
- Title: {
- tag: 'title',
- selector: 'header, footer, article',
- html: '<span class="title centered">{{value}}</span>'
- },
- Loading: {
- tag: 'loading',
- selector: '*',
- html: '<div class="loading {{value}}">\
- <span class="top"></span>\
- <span class="right"></span>\
- <span class="bottom"></span>\
- <span class="left"></span>\
- </div>'
- },
- Back: {
- tag: 'back',
- selector: 'header, footer',
- html: '<a href="#back" data-target="section" class="onleft button default"><span class="icon {{value}}"></span></a>'
- }
- };/**
- * Temporary cache system
- *
- * @namespace LUNGO.Data
- * @class Cache
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Data.Cache = (function(lng, undefined) {
- var _cache = {};
- /**
- * Sets in the LungoJS cache system a new key/value
- *
- * @method set
- *
- * @param {string} Key for the new value
- * @param {object} Type of environment: DESKTOP_ENVIRONMENT or MOBILE_ENVIRONMENT
- */
- var set = function(key, value) {
- if (exists(key)) {
- _cache[key] = lng.Core.mix(get(key), value);
- } else {
- _cache[key] = value;
- }
- };
- /**
- * Returns the value of a given key.
- *
- * @method get
- *
- * @param {string} Key in LungoJS Cache System
- * @param {string} [OPTIONAL] Subkey in LungoJS Cache System
- * @return {object} Value
- */
- var get = function(key, value) {
- if (arguments.length === 1) {
- return _cache[key];
- } else {
- return (_cache[arguments[0]]) ? _cache[arguments[0]][arguments[1]] : undefined;
- }
- };
- /**
- * Removes the instance in LungoJs Cache System of a given key
- *
- * @method remove
- *
- * @param {string} Key in LungoJS Cache System
- * @param {string} [OPTIONAL] Subkey in LungoJS Cache System
- */
- var remove = function(key, value) {
- if (arguments.length === 1) {
- delete _cache[key];
- } else {
- delete _cache[arguments[0]][arguments[1]];
- }
- };
- /**
- * Returns the existence of a key in LungoJs Cache System
- *
- * @method exists
- *
- * @param {String} Key in LungoJS Cache System
- * @return {Boolean} true if exists, false if not
- */
- var exists = function(key) {
- return (_cache[key]) ? true : false;
- };
- return {
- set: set,
- get: get,
- remove: remove,
- exists: exists
- };
- })(LUNGO);/**
- * Wrapper for using WebSql (HTML5 feature)
- *
- * @namespace LUNGO.Data
- * @class Sql
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Data.Sql = (function(lng, undefined) {
- var ERROR = lng.Constants.ERROR;
- var CONFIG = {
- name: 'lungo_db',
- version: '1.0',
- size: 65536,
- schema: []
- };
- var db = null;
- /**
- * Initialize the SQLite storage (HTML5 Feature)
- *
- * @method init
- *
- * @param {object} Configuration for the Database
- */
- var init = function(db_config) {
- CONFIG = lng.Core.mix(CONFIG, db_config);
- db = openDatabase(CONFIG.name, CONFIG.version, CONFIG.name, CONFIG.size);
- if (db) {
- _createSchema();
- } else {
- lng.Core.log(3, ERROR.DATABASE);
- }
- };
- /**
- * Select a data set of a given table and based on a selection object
- *
- * @method select
- *
- * @param {string} Name of the table in the database
- * @param {object} [OPTIONAL] Object selection condition
- * @param {Function} Callback when the process is complete
- */
- var select = function(table, where_obj, callback) {
- var where = (where_obj) ? ' WHERE ' + _convertToSql(where_obj, 'AND') : '';
- execute('SELECT * FROM ' + table + where, function(rs) {
- var result = [];
- for (var i = 0, len = rs.rows.length; i < len; i++) {
- result.push(rs.rows.item(i));
- }
- _callbackResponse(callback, result);
- });
- };
- /**
- * Inserts a data set of a given table and based on a data object
- *
- * @method insert
- *
- * @param {string} Name of the table in the database
- * @param {object} Object (or Array of objects) to insert in table
- */
- var insert = function(table, data, callback) {
- if (lng.Core.toType(data) === 'object') {
- _insertRow(table, data);
- } else {
- for (row in data) {
- _insertRow(table, data[row]);
- }
- }
- };
- /**
- * Updates a data set of a given table and based on a data object and
- * an optional selection object
- *
- * @method update
- *
- * @param {string} Name of the table in the database
- * @param {object} Data object to update in table
- * @param {object} [OPTIONAL] Object selection condition
- */
- var update = function(table, data_obj, where_obj, callback) {
- var sql = 'UPDATE ' + table + ' SET ' + _convertToSql(data_obj, ',');
- if (where_obj) sql += ' WHERE ' + _convertToSql(where_obj, 'AND');
- execute(sql);
- };
- /**
- * Delete a data set of a given table and based on a selection object
- *
- * @method drop
- *
- * @param {string} Name of the table in the database
- * @param {object} [OPTIONAL] Object selection condition
- */
- var drop = function(table, where_obj, callback) {
- var where = (where_obj) ? ' WHERE ' + _convertToSql(where_obj, 'AND') : '';
- execute('DELETE FROM ' + table + where + ';');
- };
- /**
- * Executes a SQL statement in the SQLite storage
- *
- * @method execute
- *
- * @param {string} SQL statement
- * @param {Function} Callback when the process is complete
- */
- var execute = function(sql, callback) {
- lng.Core.log(1, 'lng.Data.Sql >> ' + sql);
- db.transaction( function(transaction) {
- transaction.executeSql(sql, [], function(transaction, rs) {
- _callbackResponse(callback, rs);
- }, function(transaction, error) {
- transaction.executedQuery = sql;
- _throwError.apply(null, arguments);
- });
- });
- };
- var _createSchema = function() {
- var schema = CONFIG.schema;
- var schema_len = schema.length;
- if (!schema_len) return;
- for (var i = 0; i < schema_len; i++) {
- var current = schema[i];
- _regenerateTable(current);
- _createTable(current.name, current.fields);
- }
- };
- var _createTable = function(table, fields) {
- var sql_fields = '';
- for (var field in fields) {
- if (lng.Core.isOwnProperty(fields, field)) {
- if (sql_fields) sql_fields += ', ';
- sql_fields += field + ' ' + fields[field];
- }
- }
- execute('CREATE TABLE IF NOT EXISTS ' + table + ' (' + sql_fields + ');');
- };
- var _regenerateTable = function(table) {
- if (table.drop === true) {
- _dropTable(table.name);
- }
- };
- var _dropTable = function(table) {
- execute('DROP TABLE IF EXISTS ' + table);
- };
- var _convertToSql = function(fields, separator) {
- var sql = '';
- for (var field in fields) {
- if (lng.Core.isOwnProperty(fields, field)) {
- var value = fields[field];
- if (sql) sql += ' ' + separator + ' ';
- sql += field + '=';
- sql += (isNaN(value)) ? '"' + value + '"' : value;
- }
- }
- return sql;
- };
- var _callbackResponse = function(callback, response) {
- if (lng.Core.toType(callback) === 'function') {
- setTimeout(callback, 100, response);
- }
- };
- var _insertRow = function(table, row) {
- var fields = '';
- var values = '';
- for (var field in row) {
- if (lng.Core.isOwnProperty(row, field)) {
- var value = row[field];
- fields += (fields) ? ', ' + field : field;
- if (values) values += ', ';
- values += (isNaN(value)) ? '"' + value + '"' : value;
- }
- }
- execute('INSERT INTO ' + table + ' (' + fields + ') VALUES (' + values + ')');
- };
- var _throwError = function(transaction, error) {
- lng.Core.log(3, 'lng.Data.Sql >> ' + error.code + ': ' + error.message + ' \n Executed query: ' + transaction.executedQuery);
- };
- return {
- init: init,
- select: select,
- insert: insert,
- update: update,
- drop: drop,
- execute: execute
- };
- })(LUNGO);/**
- * Wrapper for using LocalStorage & SessionStorage (HTML5 Feature)
- *
- * @namespace LUNGO.Data
- * @class Storage
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Data.Storage = (function(lng, undefined) {
- var STORAGE = {
- PERSISTENT: 'localStorage',
- SESSION: 'sessionStorage'
- };
- /**
- * Wrapper for SessionStorage
- *
- * @method persistent
- *
- * @param {string} Key
- * @param {object} Value
- * @return {string} If no value assigned returns the value of established key
- */
- var persistent = function(key, value) {
- return _handler(STORAGE.PERSISTENT, key, value);
- };
- /**
- * Wrapper for SessionStorage
- *
- * @method session
- *
- * @param {string} Key
- * @param {object} Value
- * @return {string} If no value assigned returns the value of established key
- */
- var session = function(key, value) {
- return _handler(STORAGE.SESSION, key, value);
- };
- var _handler = function(storage, key, value) {
- var storage = window[storage];
- if (value) {
- _saveKey(storage, key, value);
- } else {
- return _getKey(storage, key, value);
- }
- };
- var _saveKey = function(storage, key, value) {
- value = JSON.stringify(value);
- storage.setItem(key, value);
- };
- var _getKey = function(storage, key, value) {
- value = storage.getItem(key);
- return JSON.parse(value);
- };
- return {
- session: session,
- persistent: persistent
- };
- })(LUNGO);/**
- * Boot for a new LungoJS Application instance
- *
- * @namespace LUNGO
- * @class App
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Boot = (function(lng, undefined) {
- return function() {
- lng.Boot.Resources.start();
- lng.Boot.Layout.start();
- lng.Boot.Events.start();
- lng.Boot.Data.start();
- lng.Boot.Section.start();
- lng.Boot.Article.start();
- lng.Boot.Stats.start();
- };
- })(LUNGO);/**
- * Load Resources
- *
- * @namespace LUNGO.Boot
- * @class Resources
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- */
- LUNGO.Boot.Resources = (function(lng, $$, undefined) {
- var ELEMENT = lng.Constants.ELEMENT;
- var ERROR = lng.Constants.ERROR;
- var RESOURCE = {
- SECTION: 'sections',
- TEMPLATE: 'templates',
- SCRIPT: 'scripts'
- };
- /**
- * Start loading async sections (local & remote)
- *
- * @method start
- *
- */
- var start = function() {
- var resources = lng.App.get('resources');
- for (resource_key in resources) {
- _loadResources(resource_key, resources[resource_key]);
- }
- };
- var _loadResources = function(resource_key, resources, callback) {
- for (index in resources) {
- var url = _parseUrl(resources[index], resource_key);
- try {
- var response = _loadAsyncResource(url);
- _factoryResources(resource_key, response);
- } catch(error) {
- lng.Core.log(3, ERROR.LOADING_RESOURCE + ' ' + error);
- }
- }
- };
- var _parseUrl = function(section_url, folder) {
- return (/http/.test(section_url)) ? section_url : 'app/' + folder + '/' + section_url;
- };
- var _loadAsyncResource = function(url) {
- return $$.ajax({
- url: url,
- async: false,
- dataType: 'html',
- error: function() {
- console.error('[ERROR] Loading url', arguments);
- }
- });
- };
- var _factoryResources = function(resource_key, response) {
- switch(resource_key) {
- case RESOURCE.SECTION:
- _pushSectionInLayout(response);
- break;
- case RESOURCE.TEMPLATE:
- _createTemplate(response);
- break;
- case RESOURCE.SCRIPT:
- break;
- }
- };
- var _pushSectionInLayout = function(section) {
- if (lng.Core.toType(section) === 'string') {
- lng.dom(ELEMENT.BODY).append(section);
- }
- };
- var _createTemplate = function(markup) {
- var div = document.createElement(ELEMENT.DIV);
- div.innerHTML = markup;
- var template_id = lng.dom(div.firstChild).data('template');
- if (template_id) {
- lng.View.Template.create(template_id, markup);
- }
- };
- return {
- start: start
- };
- })(LUNGO, Quo);/**
- * Save in LungoJS.com the use of the service for further ranking
- *
- * @namespace LUNGO.Boot
- * @class Stats
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Boot.Stats = (function(lng, undefined) {
- /**
- * Analizing if it's run in Mobile Phone and changing the type of event to subscribe.
- *
- * @method start
- */
- var start = function() {
- if (lng.Core.isMobile()) {
- _saveStats();
- }
- };
- /**
- * Save in LungoJS.com the use of the service for further ranking
- *
- * @method _saveStatsInLungoJS
- */
- var _saveStats = function() {
- lng.Service.post( 'http://www.lungojs.com/stats/', {
- name: lng.App.get('name'),
- version: lng.App.get('version'),
- icon: lng.App.get('icon')
- }, function(response) {});
- };
- return {
- start: start
- };
- })(LUNGO);/**
- * Initialize the Layout of LungoJS (if it's a mobile environment)
- *
- * @namespace LUNGO.Boot
- * @class Layout
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- */
- LUNGO.Boot.Layout = (function(lng, undefined) {
- var _window = null;
- var _document = null;
- var ELEMENT = lng.Constants.ELEMENT;
- var ATTRIBUTE = lng.Constants.ATTRIBUTE;
- /**
- * Initializes the automatic subscription events by markup of the project.
- *
- * @method init
- *
- */
- var start = function() {
- if (lng.Core.isMobile()) {
- _window = window;
- _document = _window.document;
- _resizeLayout();
- }
- };
- var _resizeLayout = function() {
- if (_window.innerHeight == 356) {
- var _height = 416;
- lng.dom(ELEMENT.BODY).style(ATTRIBUTE.HEIGHT, _height + ATTRIBUTE.PIXEL);
- _hideNavigationBar();
- }
- };
- var _hideNavigationBar = function() {
- if( !location.hash || !_window.addEventListener ){
- _window.scrollTo( 0, 1 );
- var scrollTop = 1,
- //reset to 0 on bodyready, if needed
- bodycheck = setInterval(function(){
- if( _document.body ){
- clearInterval( bodycheck );
- scrollTop = 'scrollTop' in _document.body ? _document.body.scrollTop : 1;
- _window.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
- }
- }, 15 );
- _window.addEventListener('load', function(){
- setTimeout(function(){
- _window.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
- }, 0);
- }, false );
- }
- };
- return {
- start: start
- };
- })(LUNGO);/**
- * Initialize the <article> element
- *
- * @namespace LUNGO.Boot
- * @class Article
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Boot.Article = (function(lng, undefined) {
- var ATTRIBUTE = lng.Constants.ATTRIBUTE;
- var ELEMENT = lng.Constants.ELEMENT;
- var SELECTORS = {
- LIST_IN_ARTICLE: 'article.list, aside.list',
- SCROLL_IN_ARTICLE: '.scrollable',
- CHECKBOX_IN_ARTICLE: '.checkbox, .radio'
- };
- /**
- * Initializes the markup elements of an article
- *
- * @method init
- */
- var start = function() {
- _initElement(SELECTORS.LIST_IN_ARTICLE, _createListElement);
- _initElement(SELECTORS.SCROLL_IN_ARTICLE, _createScrollElement);
- _initElement(SELECTORS.CHECKBOX_IN_ARTICLE, _createCheckboxElement);
- };
- var _initElement = function(selector, callback) {
- var found_elements = lng.dom(selector);
- for (var i = 0, len = found_elements.length; i < len; i++) {
- var element = lng.dom(found_elements[i]);
- lng.Core.execute(callback, element);
- }
- };
- var _createListElement = function(article) {
- if (article.children().length === 0) {
- var article_id = article.attr(ATTRIBUTE.ID);
- article.append(ELEMENT.LIST);
- }
- };
- var _createScrollElement = function(scroll) {
- var scroll_id = scroll.attr(ATTRIBUTE.ID);
- lng.View.Scroll.init(scroll_id);
- };
- var _createCheckboxElement = function(checkbox) {
- checkbox.append(ELEMENT.SPAN);
- };
- return {
- start: start
- };
- })(LUNGO);/**
- * Make an analysis of Data attributes in HTML elements and creates a <markup>
- * based on each data type.
- *
- * @namespace LUNGO.Boot
- * @class Data
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Boot.Data = (function(lng, undefined) {
- /**
- * Initialize the <markup> data-attributes analisys
- *
- * @method init
- *
- *
- */
- var start = function() {
- var attributes = lng.Attributes.Data;
- for (var attribute in attributes) {
- if (lng.Core.isOwnProperty(attributes, attribute)) {
- _findElements(attributes[attribute]);
- }
- }
- };
- var _findElements = function(attribute) {
- var elements = lng.dom(attribute.selector);
- for (var i = 0, len = elements.length; i < len; i++) {
- var element = lng.dom(elements[i]);
- lng.View.Template.Binding.dataAttribute(element, attribute);
- }
- };
- return {
- start: start
- };
- })(LUNGO);/**
- * Initialize the automatic DOM UI events
- *
- * @namespace LUNGO.Boot
- * @class Events
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Boot.Events = (function(lng, undefined) {
- var ATTRIBUTE = lng.Constants.ATTRIBUTE;
- var CLASS = lng.Constants.CLASS;
- var ELEMENT = lng.Constants.ELEMENT;
- var SELECTORS = {
- DOCUMENT: document,
- WINDOW: window,
- HREF_TARGET: 'a[href][data-target]',
- HREF_TARGET_FROM_ASIDE: 'aside a[href][data-target]',
- CURRENT_SECTION: 'section.aside, section.current'
- };
- /**
- * Initializes the automatic subscription events by markup of the project.
- *
- * @method init
- *
- */
- var start = function() {
- var touch_move_event = 'touchmove';
- var resize = 'resize';
- //@ToDo: Error with input type="range"
- lng.dom(SELECTORS.DOCUMENT).on(touch_move_event, _iScroll);
- lng.dom(SELECTORS.WINDOW).on(resize, _changeOrientation);
- lng.dom(SELECTORS.HREF_TARGET).tap(_loadTarget);
- lng.dom(SELECTORS.HREF_TARGET_FROM_ASIDE).touch(_asideVisibility);
- };
- var _iScroll = function(event) {
- event.preventDefault();
- };
- var _changeOrientation = function(event) {
- lng.View.Resize.toolbars();
- event.preventDefault();
- };
- var _loadTarget = function(event) {
- var link = lng.dom(this);
- _selectTarget(link);
- event.preventDefault();
- };
- var _selectTarget = function(link) {
- var target_type = link.data(ATTRIBUTE.TARGET);
- switch(target_type) {
- case ELEMENT.SECTION:
- var target_id = link.attr(ATTRIBUTE.HREF);
- _goSection(target_id);
- break;
- case ELEMENT.ARTICLE:
- _goArticle(link);
- break;
- case ELEMENT.ASIDE:
- _goAside(link);
- break;
- }
- };
- var _asideVisibility = function(event) {
- var link = lng.dom(this);
- var target = lng.dom(link.data(ATTRIBUTE.TARGET) + link.attr(ATTRIBUTE.HREF));
- if (target.length > 0) {
- var aside_id = '#' + link.parent(ELEMENT.ASIDE).attr(ATTRIBUTE.ID);
- var section_id = '#' + lng.dom(SELECTORS.CURRENT_SECTION).first().attr(ATTRIBUTE.ID);
- if (link.data(ATTRIBUTE.TARGET) === ELEMENT.ARTICLE) {
- lng.dom(ELEMENT.ASIDE + aside_id + ' ' + SELECTORS.HREF_TARGET).removeClass(CLASS.CURRENT);
- link.addClass(CLASS.CURRENT);
- }
- _hideAsideIfNecesary(section_id, aside_id);
- }
- event.preventDefault();
- };
- var _goSection = function(id) {
- id = lng.Core.parseUrl(id);
- if (id === '#back') {
- lng.Router.back();
- } else {
- lng.Router.section(id);
- }
- };
- var _goArticle = function(element) {
- var section_id = lng.Router.History.current();
- var article_id = element.attr(ATTRIBUTE.HREF);
- lng.Router.article(section_id, article_id);
- };
- var _goAside = function(element) {
- var section_id = lng.Router.History.current();
- var aside_id = element.attr(ATTRIBUTE.HREF);
- lng.Router.aside(section_id, aside_id);
- };
- var _hideAsideIfNecesary = function(section_id, aside_id) {
- if (window.innerWidth < 768) {
- lng.View.Aside.hide(section_id, aside_id);
- }
- };
- return {
- start: start
- };
- })(LUNGO);/**
- * Initialize the <section> element
- *
- * @namespace LUNGO.Boot
- * @class Section
- *
- * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
- * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
- */
- LUNGO.Boot.Section = (function(lng, undefined) {
- var ELEMENT = lng.Constants.ELEMENT;
- var CLASS = lng.Constants.CLASS;
- var ATTRIBUTE = lng.Constants.ATTRIBUTE;
- /**
- * Initializes all <section>s of the project
- *
- * @method init
- */
- var start = function() {
- var sections = lng.dom(ELEMENT.SECTION);
- _initFirstSection(sections);
- _initAllSections(sections);
- lng.View.Resize.toolbars();
- };
- var _initFirstSection = function(sections) {
- var first_section = sections.first();
- var first_section_id = '#' + first_section.attr(ATTRIBUTE.ID);
- first_section.addClass(CLASS.CURRENT);
- lng.Router.History.add(first_section_id);
- };
- var _initAllSections = function(sections) {
- lng.Fallback.positionFixed(sections);
- for (var i = 0, len = sections.length; i < len; i++) {
- var section = lng.dom(sections[i]);
- _initArticles(section);
- }
- };
- var _initArticles = function(section) {
- var first_article = section.children(ELEMENT.ARTICLE).first();
- first_article.addClass(CLASS.CURRENT);
- var first_article_id = first_article.attr(ATTRIBUTE.ID);
- var section_id = '#' + section.attr(ATTRIBUTE.ID);
- lng.View.Article.showReferenceLinks(section_id, first_article_id);
- };
- return {
- start: start
- };
- })(LUNGO);
|