lungo-2.0.js 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489
  1. /**
  2. *
  3. * /$$
  4. * | $$
  5. * | $$ /$$ /$$ /$$$$$$$ /$$$$$$ /$$$$$$
  6. * | $$ | $$ | $$| $$__ $$ /$$__ $$ /$$__ $$
  7. * | $$ | $$ | $$| $$ \ $$| $$ \ $$| $$ \ $$
  8. * | $$ | $$ | $$| $$ | $$| $$ | $$| $$ | $$
  9. * | $$$$$$$$| $$$$$$/| $$ | $$| $$$$$$$| $$$$$$/
  10. * |________/ \______/ |__/ |__/ \____ $$ \______/
  11. * /$$ \ $$
  12. * | $$$$$$/
  13. * \______/
  14. *
  15. * @copyright 2011 TapQuo Inc (c)
  16. * @license http://www.github.com/tapquo/lungo/blob/master/LICENSE.txt
  17. * @version 1.2
  18. * @link https://github.com/TapQuo/Lungo.js
  19. *
  20. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  21. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  22. */
  23. var LUNGO = LUNGO || {};
  24. LUNGO.VERSION = '1.2';
  25. LUNGO.Attributes || (LUNGO.Attributes = {});
  26. LUNGO.Data || (LUNGO.Data = {});
  27. LUNGO.Sugar || (LUNGO.Sugar = {});
  28. LUNGO.View || (LUNGO.View = {});
  29. LUNGO.Device || (LUNGO.Device = {});
  30. LUNGO.ready || (LUNGO.ready = Quo().ready);/**
  31. * Object with data-attributes (HTML5) with a special <markup>
  32. *
  33. * @namespace LUNGO
  34. * @class Constants
  35. *
  36. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  37. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  38. */
  39. LUNGO.Constants = {
  40. ELEMENT: {
  41. SECTION: 'section',
  42. ARTICLE: 'article',
  43. ASIDE: 'aside',
  44. BODY: 'body',
  45. DIV: 'div',
  46. LIST: '<ul></ul>',
  47. SPAN: '<span>&nbsp;</span>'
  48. },
  49. CLASS: {
  50. ACTIVE: 'active',
  51. ASIDE: 'aside',
  52. SHOW: 'show',
  53. HIDE: 'hide',
  54. CURRENT: 'current',
  55. RIGHT: 'onright',
  56. LEFT: 'onleft',
  57. HORIZONTAL: 'horizontal',
  58. MINI: 'mini'
  59. },
  60. TRIGGER: {
  61. LOAD: 'load',
  62. UNLOAD: 'unload'
  63. },
  64. ATTRIBUTE: {
  65. ID: 'id',
  66. HREF: 'href',
  67. TITLE: 'title',
  68. ARTICLE: 'article',
  69. CLASS: 'class',
  70. WIDTH: 'width',
  71. HEIGHT: 'height',
  72. PIXEL: 'px',
  73. PERCENT: '%',
  74. TARGET: 'target',
  75. FIRST: 'first',
  76. LAST: 'last',
  77. EMPTY: ''
  78. },
  79. BINDING: {
  80. START: '{{',
  81. END: '}}',
  82. KEY: 'value',
  83. PARSER: /\{{.*?\}}/gi
  84. },
  85. ERROR: {
  86. CREATE_SCROLL: 'ERROR: Impossible to create a <scroll> without ID.',
  87. BINDING_DATA_TYPE: 'ERROR: Processing the type of binding data.',
  88. BINDING_TEMPLATE: 'ERROR: Binding Template not exists >> ',
  89. BINDING_LIST: 'ERROR: Processing parameters for list binding.',
  90. DATABASE: 'ERROR: Connecting to Data.Sql.',
  91. ROUTER: 'ERROR: The target does not exists >>',
  92. LOADING_RESOURCE: 'ERROR: Loading resource.'
  93. }
  94. };/**
  95. * Lungo sandbox APP initialization
  96. *
  97. * @namespace LUNGO
  98. * @class App
  99. *
  100. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  101. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  102. */
  103. LUNGO.App = (function(lng, undefined) {
  104. var default_config = {
  105. id: 1,
  106. name: 'lungo_app',
  107. version: 1.0,
  108. icon: ''
  109. };
  110. /**
  111. * Initializes all LungoJS system: setting properties for the application,
  112. * subscribing to automatic events, initializing sections & articles
  113. * and stating the title.
  114. *
  115. * @method init
  116. *
  117. * @param {object} Application configuration properties
  118. */
  119. var init = function(app_config) {
  120. default_config = lng.Core.mix(default_config, app_config);
  121. lng.Boot();
  122. };
  123. var get = function(property) {
  124. return default_config[property];
  125. };
  126. return {
  127. init: init,
  128. get: get
  129. };
  130. })(LUNGO);/**
  131. * Contains all the common functions used in Lungo.
  132. *
  133. * @namespace LUNGO
  134. * @class Core
  135. *
  136. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  137. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  138. */
  139. LUNGO.Core = (function(lng, $$, undefined) {
  140. var ARRAY_PROTO = Array.prototype;
  141. var HASHTAG_CHARACTER = '#';
  142. /**
  143. * Console system to display messages when you are in debug mode.
  144. *
  145. * @method log
  146. *
  147. * @param {number} Severity based in (1)Log, (2)Warn, (>2)Error
  148. * @param {string} Message to show in console
  149. */
  150. var log = function(severity, message) {
  151. if (!lng.Core.isMobile()) {
  152. console[(severity === 1) ? 'log' : (severity === 2) ? 'warn' : 'error'](message);
  153. } else {
  154. // @todo : send to the server
  155. }
  156. };
  157. /**
  158. * Executes callbacks based on the parameters received.
  159. *
  160. * @method execute
  161. *
  162. * @param {Function} callback to execute
  163. */
  164. var execute = function() {
  165. var args = toArray(arguments);
  166. var callback = args.shift();
  167. if (toType(callback) === 'function') {
  168. callback.apply(null, args);
  169. }
  170. };
  171. /**
  172. * Creates a new function that, when called, itself calls this function in
  173. * the context of the provided this value, with a given sequence of arguments
  174. * preceding any provided when the new function was called.
  175. *
  176. * @method bind
  177. *
  178. * @param {object} object to which the 'this' can refer in the new function when the new function is called.
  179. * @param {Function} method A function object.
  180. */
  181. var bind = function(object, method) {
  182. return function() {
  183. return method.apply(object, toArray(arguments));
  184. };
  185. };
  186. /**
  187. * Copy from any number of objects and mix them all into a new object.
  188. * The implementation is simple; just loop through arguments and
  189. * copy every property of every object passed to the function.
  190. *
  191. * @method mix
  192. *
  193. * @param {object} arguments to mix them all into a new object.
  194. * @return {object} child a new object with all the objects from the arguments mixed.
  195. */
  196. var mix = function() {
  197. var child = child || {};
  198. for (var arg = 0, len = arguments.length; arg < len; arg++) {
  199. var argument = arguments[arg];
  200. for (var prop in argument) {
  201. if (isOwnProperty(argument, prop)) {
  202. child[prop] = argument[prop];
  203. }
  204. }
  205. }
  206. return child;
  207. };
  208. /**
  209. * Every object descended from Object inherits the hasOwnProperty method.
  210. * This method can be used to determine whether an object has the specified property
  211. * as a direct property of that object.
  212. *
  213. * @param {object} object to test for a property's existence inside itself.
  214. * @param {string} property the name of the property to test.
  215. * @return {boolean} indicating whether the object has the specified property.
  216. */
  217. var isOwnProperty = function(object, property) {
  218. return $$.isOwnProperty(object, property);
  219. };
  220. /**
  221. * Determine the internal JavaScript [[Class]] of an object.
  222. *
  223. * @param {object} obj to get the real type of itself.
  224. * @return {string} with the internal JavaScript [[Class]] of itself.
  225. */
  226. var toType = function(obj) {
  227. return $$.toType(obj);
  228. };
  229. /**
  230. * Convert an array-like object into a true JavaScript array.
  231. *
  232. * @param {object} obj Any object to turn into a native Array.
  233. * @return {object} The object is now a plain array.
  234. */
  235. var toArray = function(obj) {
  236. return ARRAY_PROTO.slice.call(obj, 0);
  237. };
  238. /**
  239. * Determine if the current environment is a mobile environment
  240. *
  241. * @method isMobile
  242. *
  243. * @return {boolean} true if is mobile environment, false if not.
  244. */
  245. var isMobile = function() {
  246. return $$.isMobile();
  247. };
  248. /**
  249. * Returns information of execute environment
  250. *
  251. * @method environment
  252. *
  253. * @return {object} Environment information
  254. */
  255. var environment = function() {
  256. return $$.environment();
  257. };
  258. /**
  259. * Returns a ordered list of objects by a property
  260. *
  261. * @method orderByProperty
  262. *
  263. * @param {list} List of objects
  264. * @param {string} Name of property
  265. * @param {string} Type of order: asc (ascendent) or desc (descendent)
  266. * @return {list} Ordered list
  267. */
  268. var orderByProperty = function(data, property, order) {
  269. var order_operator = (order === 'desc') ? -1 : 1;
  270. return data.sort(function(a, b) {
  271. return (a[property] < b[property]) ? - order_operator :
  272. (a[property] > b[property])
  273. ?
  274. order_operator : 0;
  275. }
  276. );
  277. };
  278. /**
  279. * Returns a correct URL using hashtag character
  280. *
  281. * @method parseUrl
  282. *
  283. * @param {string} Url
  284. * @return {string} Url parsed
  285. */
  286. var parseUrl = function(href) {
  287. var href_hashtag = href.lastIndexOf(HASHTAG_CHARACTER);
  288. if (href_hashtag > 0) {
  289. href = href.substring(href_hashtag);
  290. } else if (href_hashtag === -1) {
  291. href = HASHTAG_CHARACTER + href ;
  292. }
  293. return href;
  294. };
  295. /**
  296. * Returns a Object in a list by a property value
  297. *
  298. * @method objectInListByProperty
  299. *
  300. * @param {list} List of objects
  301. * @param {string} Name of property
  302. * @param {var} Value for comparision
  303. * @return {object} Instance of object founded (if exists)
  304. */
  305. var findByProperty = function(list, property, value) {
  306. var search = null;
  307. for (var i = 0, len = list.length; i < len; i++) {
  308. var element = list[i];
  309. if (element[property] == value) {
  310. search = element;
  311. break;
  312. }
  313. };
  314. return search;
  315. };
  316. return {
  317. log: log,
  318. execute: execute,
  319. bind: bind,
  320. mix: mix,
  321. isOwnProperty: isOwnProperty,
  322. toType: toType,
  323. toArray: toArray,
  324. isMobile: isMobile,
  325. environment: environment,
  326. orderByProperty: orderByProperty,
  327. parseUrl: parseUrl,
  328. findByProperty: findByProperty
  329. };
  330. })(LUNGO, Quo);/**
  331. * LungoJS Dom Handler
  332. *
  333. * @namespace LUNGO
  334. * @class Dom
  335. *
  336. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  337. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  338. */
  339. /**
  340. * Add an event listener
  341. *
  342. * @method dom
  343. *
  344. * @param {string} <Markup> element selector
  345. * @return {Object} QuoJS <element> instance
  346. */
  347. LUNGO.dom = function(selector) {
  348. return $$(selector);
  349. };/**
  350. * External Data & Services Manager
  351. *
  352. * @namespace LUNGO
  353. * @class Service
  354. * @requires QuoJS
  355. *
  356. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  357. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  358. */
  359. LUNGO.Service = (function(lng, $$, undefined) {
  360. var URL_CACHE_INDEX_KEY = 'lungojs_service_cache';
  361. var DATE_PATTERN = {
  362. MINUTE: 'minute',
  363. HOUR: 'hour',
  364. DAY: 'day'
  365. };
  366. /**
  367. * Load data from the server using a HTTP GET request.
  368. *
  369. * @method get
  370. *
  371. * @param {string} Containing the URL to which the request is sent
  372. * @param {object} A map or string that is sent to the server with the request
  373. * @param {Function} Callback function after the request [OPTIONAL]
  374. * @param {string} Mime-Type: json, xml, html, or text [OPTIONAL]
  375. */
  376. var get = function(url, data, success, dataType) {
  377. return $$.get(url, data, success, dataType);
  378. };
  379. /**
  380. * Load data from the server using a HTTP POST request.
  381. *
  382. * @method post
  383. *
  384. * @param {string} Containing the URL to which the request is sent
  385. * @param {object} A map or string that is sent to the server with the request
  386. * @param {Function} Callback function after the request [OPTIONAL]
  387. * @param {string} Mime-Type: json, xml, html, or text [OPTIONAL]
  388. */
  389. var post = function(url, data, success, dataType) {
  390. return $$.post(url, data, success, dataType);
  391. };
  392. /**
  393. * Load data from the server using a HTTP GET request.
  394. *
  395. * @method json
  396. *
  397. * @param {string} Containing the URL to which the request is sent
  398. * @param {object} A map or string that is sent to the server with the request
  399. * @param {Function} [OPTIONAL] Callback function after the request
  400. */
  401. var json = function(url, data, success) {
  402. return $$.json(url, data, success);
  403. };
  404. /**
  405. * Auto-caching system with date pattern.
  406. *
  407. * @method cache
  408. *
  409. * @param {string} Containing the URL to which the request is sent
  410. * @param {object} A map or string that is sent to the server with the request
  411. * @param {string} Date pattern (example: 15 minutes, 1 hour, 3 days)
  412. * @param {Function} [OPTIONAL] Callback function after the request
  413. * @param {string} Mime-Type: json, xml, html, or text [OPTIONAL]
  414. */
  415. var cache = function(url, data, date_pattern, callback, dataType) {
  416. var url_key = url + $$.serializeParameters(data);
  417. if (_urlCached(url_key, date_pattern)) {
  418. var value = lng.Data.Storage.persistent(url_key);
  419. if (value) {
  420. return callback.call(callback, value);
  421. }
  422. } else {
  423. return $$.get(url, data, function(result) {
  424. _saveServiceInCache(url_key, result);
  425. callback.call(callback, result);
  426. }, dataType);
  427. }
  428. };
  429. var _urlCached = function(url, date_pattern) {
  430. var in_cache = false;
  431. var url_cache_index = lng.Data.Storage.persistent(URL_CACHE_INDEX_KEY);
  432. if (url_cache_index) {
  433. var time_between = _calculateTimeSpent(url_cache_index[url]);
  434. in_cache = _checkIsValidPattern(time_between, date_pattern);
  435. }
  436. return in_cache;
  437. };
  438. var _calculateTimeSpent = function(url_last_access) {
  439. var now = new Date().getTime();
  440. var service_last_access = new Date(url_last_access).getTime();
  441. return now - service_last_access;
  442. };
  443. var _checkIsValidPattern = function(time_between, date_pattern) {
  444. var pattern = date_pattern.split(' ');
  445. var diference_time = _calculateDiferenceTime(pattern[1], time_between);
  446. return (diference_time < pattern[0]) ? true : false;
  447. };
  448. var _calculateDiferenceTime = function(pattern_name, time_between) {
  449. var diference = (time_between / 1000) / 60;
  450. if (pattern_name.indexOf(DATE_PATTERN.HOUR) >= 0) {
  451. diference = diference / 60;
  452. } else if (pattern_name.indexOf(DATE_PATTERN.DAY) >= 0) {
  453. diference = (diference / 60) / 24;
  454. }
  455. return diference;
  456. };
  457. var _saveServiceInCache = function(url, result) {
  458. var service_cache_index = lng.Data.Storage.persistent(URL_CACHE_INDEX_KEY) || {};
  459. service_cache_index[url] = new Date();
  460. lng.Data.Storage.persistent(URL_CACHE_INDEX_KEY, service_cache_index);
  461. lng.Data.Storage.persistent(url, result);
  462. };
  463. return {
  464. get: get,
  465. post: post,
  466. json: json,
  467. cache: cache,
  468. Settings: $$.ajaxSettings
  469. };
  470. })(LUNGO, Quo);/**
  471. * ?
  472. *
  473. * @namespace LUNGO
  474. * @class Fallback
  475. *
  476. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  477. */
  478. LUNGO.Fallback = (function(lng, undefined) {
  479. var androidInputs = function(article_id, active) {
  480. environment = lng.Core.environment();
  481. if (environment.isMobile && environment.os.name === 'android' && environment.os.version < '4') {
  482. var selector = article_id + ' input, ' + article_id + ' textarea, ' + article_id + ' select';
  483. var input_elements = lng.dom(selector);
  484. for (var i = 0, len = input_elements.length; i < len; i++) {
  485. (active) ? _enableAndroidInput(input_elements[i]) : _disableAndroidInput(input_elements[i]);
  486. }
  487. }
  488. };
  489. var positionFixed = function(sections) {
  490. environment = lng.Core.environment();
  491. if (environment.isMobile && environment.os.name === 'ios' && environment.os.version >= '4.2') {
  492. sections.style('position', 'fixed');
  493. }
  494. };
  495. var _enableAndroidInput = function(input) {
  496. input.removeAttribute('disabled');
  497. };
  498. var _disableAndroidInput = function(input) {
  499. input.setAttribute('disabled', 'disabled');
  500. };
  501. return {
  502. androidInputs: androidInputs,
  503. positionFixed: positionFixed
  504. }
  505. })(LUNGO);/**
  506. * Handles the <sections> and <articles> to show
  507. *
  508. * @namespace LUNGO
  509. * @class Router
  510. *
  511. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  512. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  513. */
  514. LUNGO.Router = (function(lng, undefined) {
  515. var CLASS = lng.Constants.CLASS;
  516. var ELEMENT = lng.Constants.ELEMENT;
  517. var ERROR = lng.Constants.ERROR;
  518. var TRIGGER = lng.Constants.TRIGGER;
  519. /**
  520. * Navigate to a <section>.
  521. *
  522. * @method section
  523. *
  524. * @param {string} Id of the <section>
  525. */
  526. var section = function(section_id) {
  527. var section_id = lng.Core.parseUrl(section_id);
  528. var current = _getHistoryCurrent();
  529. var target = ELEMENT.SECTION + section_id;
  530. if (_exists(target) && _notCurrentTarget(target)) {
  531. lng.dom(current).removeClass(CLASS.SHOW).addClass(CLASS.HIDE);
  532. lng.dom(target).addClass(CLASS.SHOW).trigger(TRIGGER.LOAD);
  533. lng.Router.History.add(section_id);
  534. }
  535. };
  536. /**
  537. * Displays the <article> in a particular <section>.
  538. *
  539. * @method article
  540. *
  541. * @param {string} <section> Id
  542. * @param {string} <article> Id
  543. */
  544. var article = function(section_id, article_id) {
  545. var section_id = lng.Core.parseUrl(section_id);
  546. var article_id = lng.Core.parseUrl(article_id);
  547. var target = ELEMENT.SECTION + section_id + ' ' + ELEMENT.ARTICLE + article_id;
  548. if (_exists(target) && _notCurrentTarget(target)) {
  549. lng.dom(target).trigger(TRIGGER.LOAD);
  550. lng.View.Article.show(section_id, article_id);
  551. }
  552. };
  553. /**
  554. * Displays the <aside> in a particular <section>.
  555. *
  556. * @method aside
  557. *
  558. * @param {string} <section> Id
  559. * @param {string} <aside> Id
  560. */
  561. var aside = function(section_id, aside_id) {
  562. var section_id = lng.Core.parseUrl(section_id);
  563. var aside_id = lng.Core.parseUrl(aside_id);
  564. var target = ELEMENT.ASIDE + aside_id;
  565. if (_exists(target)) {
  566. var is_visible = lng.dom(target).hasClass(CLASS.CURRENT);
  567. if (is_visible) {
  568. lng.View.Aside.hide(section_id, aside_id);
  569. } else {
  570. lng.View.Aside.show(section_id, aside_id);
  571. }
  572. }
  573. };
  574. /**
  575. * Return to previous section.
  576. *
  577. * @method back
  578. */
  579. var back = function() {
  580. var current_section = ELEMENT.SECTION + _getHistoryCurrent();
  581. lng.dom(current_section).removeClass(CLASS.SHOW).trigger(TRIGGER.UNLOAD);
  582. lng.Router.History.removeLast();
  583. lng.dom(_getHistoryCurrent()).removeClass(CLASS.HIDE).addClass(CLASS.SHOW);
  584. };
  585. var _notCurrentTarget = function(target) {
  586. return lng.dom(target).hasClass(CLASS.CURRENT) ? false : true;
  587. };
  588. var _exists = function(target) {
  589. var exists = false;
  590. if (lng.dom(target).length > 0) {
  591. exists = true;
  592. } else {
  593. lng.Core.log(3, ERROR.ROUTER + target);
  594. }
  595. return exists;
  596. };
  597. var _getHistoryCurrent = function() {
  598. return lng.Router.History.current();
  599. };
  600. return {
  601. section: section,
  602. article: article,
  603. aside: aside,
  604. back: back
  605. };
  606. })(LUNGO);/**
  607. * Stores the displayed <sections> as a historical.
  608. *
  609. * @namespace LUNGO.Router
  610. * @class History
  611. *
  612. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  613. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  614. */
  615. LUNGO.Router.History = (function(undefined) {
  616. var _history = [];
  617. /**
  618. * Create a new element to the browsing history based on the current section id.
  619. *
  620. * @method add
  621. *
  622. * @param {string} Id of the section
  623. */
  624. var add = function(section_id) {
  625. if (section_id !== current()) {
  626. _history.push(section_id);
  627. }
  628. };
  629. /**
  630. * Returns the current browsing history section id.
  631. *
  632. * @method current
  633. *
  634. * @return {string} Current section id
  635. */
  636. var current = function() {
  637. return _history[_history.length - 1];
  638. };
  639. /**
  640. * Removes the current item browsing history.
  641. *
  642. * @method removeLast
  643. */
  644. var removeLast = function() {
  645. _history.length -= 1;
  646. };
  647. return {
  648. add: add,
  649. current: current,
  650. removeLast: removeLast
  651. };
  652. })();/**
  653. * Initialize the <articles> layout of a certain <section>
  654. *
  655. * @namespace LUNGO.View
  656. * @class Article
  657. *
  658. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  659. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  660. */
  661. LUNGO.View.Article = (function(lng, undefined) {
  662. var ELEMENT = lng.Constants.ELEMENT;
  663. var CLASS = lng.Constants.CLASS;
  664. var ATTRIBUTE = lng.Constants.ATTRIBUTE;
  665. var TRIGGER = lng.Constants.TRIGGER;
  666. var SELECTORS = {
  667. NAVIGATION_ITEM: 'a[href][data-target="article"]',
  668. REFERENCE_LINK: ' a[href][data-article]'
  669. };
  670. /**
  671. * ?
  672. *
  673. * @method show
  674. */
  675. var show = function(section_id, article_id) {
  676. _toggleNavItems(section_id, article_id);
  677. showReferenceLinks(section_id, article_id.replace('#', ''));
  678. _showContainer(section_id, article_id);
  679. };
  680. /**
  681. * ?
  682. *
  683. * @method showReferenceLinks
  684. */
  685. var showReferenceLinks = function(section_id, article_id) {
  686. var links = lng.dom(ELEMENT.SECTION + section_id + SELECTORS.REFERENCE_LINK);
  687. for (var i = 0, len = links.length; i < len; i++) {
  688. var link = lng.dom(links[i]);
  689. (link.data(ATTRIBUTE.ARTICLE) === article_id) ? link.show() : link.hide();
  690. }
  691. };
  692. var _toggleNavItems = function(section_id, article_id) {
  693. var nav_items = lng.dom(section_id + ' ' + SELECTORS.NAVIGATION_ITEM);
  694. nav_items.removeClass(CLASS.CURRENT);
  695. for (var i = 0, len = nav_items.length; i < len; i++) {
  696. var nav_item = lng.dom(nav_items[i]);
  697. var nav_item_parsed_url = lng.Core.parseUrl(nav_item.attr(ATTRIBUTE.HREF));
  698. if (nav_item_parsed_url === article_id) {
  699. nav_item.addClass(CLASS.CURRENT);
  700. _setTitle(section_id, nav_item);
  701. }
  702. }
  703. };
  704. var _showContainer = function(section_id, article_id) {
  705. var section_articles = section_id + ' ' + ELEMENT.ARTICLE + '.' + CLASS.CURRENT;
  706. var current_active_article_id = '#' + lng.dom(section_articles).attr(ATTRIBUTE.ID);
  707. lng.dom(section_articles).removeClass(CLASS.CURRENT).trigger(TRIGGER.UNLOAD);
  708. lng.Fallback.androidInputs(current_active_article_id, false);
  709. lng.dom(article_id).addClass(CLASS.CURRENT);
  710. lng.Fallback.androidInputs(article_id, true);
  711. };
  712. var _setTitle = function(id, item) {
  713. var title = item.data(ATTRIBUTE.TITLE);
  714. if (title) {
  715. var section_title = id + ' header .title, ' + id + ' footer .title';
  716. lng.dom(section_title).text(title);
  717. }
  718. };
  719. return {
  720. show: show,
  721. showReferenceLinks: showReferenceLinks
  722. };
  723. })(LUNGO);/**
  724. *
  725. *
  726. * @namespace LUNGO.View
  727. * @class Resize
  728. *
  729. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  730. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  731. */
  732. LUNGO.View.Resize = (function(lng, undefined) {
  733. var ATTRIBUTE = lng.Constants.ATTRIBUTE;
  734. /**
  735. * Sets toolbars width, using total screen width
  736. *
  737. * @method toolbars
  738. */
  739. var toolbars = function() {
  740. var toolbar = '.toolbar nav, .groupbar';
  741. var all_toolbars = lng.dom(toolbar);
  742. for (var i = 0, len = all_toolbars.length; i < len; i++) {
  743. var toolbar = lng.dom(all_toolbars[i]);
  744. var toolbar_children = toolbar.children();
  745. var toolbar_children_percent = 100 / toolbar.children().length;
  746. toolbar_children.style(ATTRIBUTE.WIDTH, toolbar_children_percent + ATTRIBUTE.PERCENT);
  747. }
  748. };
  749. return {
  750. toolbars: toolbars
  751. };
  752. })(LUNGO);/**
  753. * Lungo Template system
  754. *
  755. * @namespace LUNGO.View
  756. * @class Template
  757. *
  758. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  759. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  760. */
  761. LUNGO.View.Template = (function(lng, undefined) {
  762. var ERROR = lng.Constants.ERROR;
  763. var _templates = {};
  764. /**
  765. * Create a new databinding template based on a <markup>
  766. *
  767. * @method create
  768. *
  769. * @param {String} Id of the new databinding template
  770. * @param {String} <markup> of the new databinding template
  771. */
  772. var create = function(id, markup) {
  773. _templates[id] = markup;
  774. };
  775. /**
  776. * Returns the existence of a certain Id databinding template
  777. *
  778. * @method exists
  779. *
  780. * @param {String} Id of the databinding template
  781. * @return {Boolean} true if exists, false if not.
  782. */
  783. var exists = function(id) {
  784. return (_templates[id]) ? true : false;
  785. };
  786. /**
  787. * Returns the instance of a certain Id databinding template
  788. *
  789. * @method get
  790. *
  791. * @param {String} Id of the databinding template
  792. * @return {String} Markup of template
  793. */
  794. var get = function(id) {
  795. return _templates[id];
  796. };
  797. /**
  798. * Performs databinding process for a data set and a given template
  799. *
  800. * @method render
  801. *
  802. * @param {String} Element selector for showing the result of databinding
  803. * @param {String} Databinding Template Id
  804. * @param {Object} Data for binding
  805. * @param {Function} Callback when the process is complete
  806. */
  807. var render = function(element, template_id, data, callback) {
  808. if (lng.View.Template.exists(template_id)) {
  809. var container = lng.dom(element);
  810. var markup = this.markup(template_id, data);
  811. container.html(markup);
  812. lng.Core.execute(callback);
  813. } else {
  814. lng.Core.log(3, ERROR.BINDING_TEMPLATE + template_id);
  815. }
  816. };
  817. /**
  818. * Performs databinding process for a data set and a given template
  819. *
  820. * @method markup
  821. *
  822. * @param {String} Databinding Template Id
  823. * @param {Object} Data for binding
  824. */
  825. var markup = function(template_id, data) {
  826. return lng.View.Template.Binding.create(template_id, data);
  827. };
  828. return {
  829. create: create,
  830. exists: exists,
  831. get: get,
  832. render: render,
  833. markup: markup
  834. };
  835. })(LUNGO);/**
  836. * Lungo Data-Binding system
  837. *
  838. * @namespace LUNGO.View.Template
  839. * @class Binding
  840. *
  841. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  842. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  843. */
  844. LUNGO.View.Template.Binding = (function(lng, undefined) {
  845. var BINDING = lng.Constants.BINDING;
  846. var ERROR = lng.Constants.ERROR;
  847. /**
  848. * Performs databinding process for a data set and a given template
  849. *
  850. * @method create
  851. *
  852. * @param {String} Databinding Template Id
  853. * @param {Object} Data for binding
  854. */
  855. var create = function(template_id, data) {
  856. var template = lng.View.Template.get(template_id);
  857. return _processData(data, template);
  858. };
  859. var dataAttribute = function(element, attribute) {
  860. var data = element.data(attribute.tag);
  861. if (data) {
  862. var html_binded = attribute.html.replace(BINDING.START + BINDING.KEY + BINDING.END, data);
  863. element.prepend(html_binded);
  864. }
  865. };
  866. var _processData = function(data, template) {
  867. var data_type = lng.Core.toType(data);
  868. if (data_type === 'array') {
  869. return _bindPropertiesInMultiplesElements(data, template);
  870. } else if (data_type === 'object') {
  871. return _bindProperties(data, template);
  872. } else {
  873. lng.Core.log(3, ERROR.BINDING_DATA_TYPE);
  874. }
  875. };
  876. var _bindPropertiesInMultiplesElements = function(elements, template) {
  877. var markup = '';
  878. for (var i = 0, len = elements.length; i < len; i++) {
  879. markup += _bindProperties(elements[i], template);
  880. }
  881. return markup;
  882. };
  883. var _bindProperties = function(element, template) {
  884. var binding_field;
  885. for (var property in element) {
  886. if (lng.Core.isOwnProperty(element, property) && element[property] !== null) {
  887. binding_field = new RegExp(BINDING.START + property + BINDING.END, 'g');
  888. template = template.replace(binding_field, element[property]);
  889. }
  890. }
  891. return _removeNoBindedProperties(template);
  892. };
  893. var _removeNoBindedProperties = function(template) {
  894. return template.replace(BINDING.PARSER, '');
  895. };
  896. return {
  897. create: create,
  898. dataAttribute: dataAttribute
  899. };
  900. })(LUNGO);/**
  901. * Auto generate lists based on Template and Data-Binding system
  902. *
  903. * @namespace LUNGO.View.Template
  904. * @class List
  905. *
  906. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  907. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  908. */
  909. LUNGO.View.Template.List = (function(lng, undefined) {
  910. var ERROR = lng.Constants.ERROR;
  911. var ATTRIBUTE = lng.Constants.ATTRIBUTE;
  912. /**
  913. * Create a list based DataBind with a configuration object for an element <article>
  914. * if the config has a 'norecords' property it will display the norecords markup rather than nothing.
  915. *
  916. * @method create
  917. *
  918. * @param {object} Id of the container showing the result of databinding
  919. */
  920. var create = function(config) {
  921. config.container = _getContainer(config.el);
  922. if (_validateConfig(config)) {
  923. config.data = _order(config);
  924. _render(config);
  925. _scroll(config.el);
  926. }
  927. };
  928. /**
  929. * Append a list based DataBind with a configuration object for an element <article>
  930. * if the config has a 'norecords' property it will display the norecords markup rather than nothing.
  931. *
  932. * @method append
  933. *
  934. * @param {object} Id of the container showing the result of databinding
  935. */
  936. var append = function(config) {
  937. var markup = lng.View.Template.markup(config.template, config.data);
  938. var container = _getContainer(config.el);
  939. container.append(markup);
  940. _scroll(config.el, ATTRIBUTE.LAST);
  941. };
  942. /**
  943. * Prepend a list based DataBind with a configuration object for an element <article>
  944. * if the config has a 'norecords' property it will display the norecords markup rather than nothing.
  945. *
  946. * @method prepend
  947. *
  948. * @param {object} Id of the container showing the result of databinding
  949. */
  950. var prepend = function(config) {
  951. var markup = lng.View.Template.markup(config.template, config.data);
  952. var container = _getContainer(config.el);
  953. container.prepend(markup);
  954. _scroll(config.el, ATTRIBUTE.FIRST);
  955. };
  956. var _validateConfig = function(config) {
  957. var checked = false;
  958. var container_exists = !! config.container.length > 0;
  959. var template_exists = lng.View.Template.exists(config.template);
  960. if (container_exists && template_exists) {
  961. var type = lng.Core.toType(config.data);
  962. if (type === 'array' || type === 'object') {
  963. checked = true;
  964. }
  965. } else {
  966. lng.Core.log(3, ERROR.BINDING_LIST);
  967. }
  968. return checked;
  969. };
  970. var _getContainer = function(element) {
  971. return lng.dom(element).children().first();
  972. }
  973. var _order = function(config) {
  974. if (config.order && config.order.field && config.order.type) {
  975. config.data = lng.Core.orderByProperty(config.data, config.order.field, config.order.type);
  976. }
  977. return config.data;
  978. };
  979. var _render = function(config) {
  980. lng.View.Template.render(config.container.selector, config.template, config.data);
  981. };
  982. var _scroll = function(element, direction) {
  983. var element_id = lng.dom(element).attr(ATTRIBUTE.ID);
  984. lng.View.Scroll.init(element_id);
  985. if (direction) {
  986. lng.View.Scroll[(direction === ATTRIBUTE.FIRST) ? ATTRIBUTE.FIRST : ATTRIBUTE.LAST](element_id);
  987. }
  988. };
  989. return {
  990. create: create,
  991. append: append,
  992. prepend: prepend
  993. };
  994. })(LUNGO);/**
  995. * Wrapper of the third library iScroll
  996. *
  997. * @namespace LUNGO.View
  998. * @class Scroll
  999. * @requires iScroll
  1000. *
  1001. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1002. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  1003. */
  1004. LUNGO.View.Scroll = (function(lng, undefined) {
  1005. var CLASS = lng.Constants.CLASS;
  1006. var ATTRIBUTE = lng.Constants.ATTRIBUTE;
  1007. var ERROR = lng.Constants.ERROR;
  1008. var DEFAULT_PROPERTIES = {
  1009. hScroll: false,
  1010. vScroll: false,
  1011. useTransition: true,
  1012. momentum: true,
  1013. lockDirection: true,
  1014. fixedScrollbar: true,
  1015. fadeScrollbar: true,
  1016. hideScrollbar: true
  1017. };
  1018. var CACHE_KEY = 'scrolls';
  1019. var SCROLL_TIMEFRAME = 250;
  1020. /**
  1021. * Creates a new iScroll element.
  1022. *
  1023. * @method init
  1024. *
  1025. * @param {string} Id of the container scroll.
  1026. * @param {object} [OPTIONAL] Properties
  1027. */
  1028. var init = function(id, properties) {
  1029. if (id) {
  1030. _render(id, properties);
  1031. } else {
  1032. lng.Core.log(3, ERROR.CREATE_SCROLL);
  1033. }
  1034. };
  1035. /**
  1036. * Update iScroll element with new <markup> content.
  1037. *
  1038. * @method html
  1039. *
  1040. * @param {string} Id of the container scroll.
  1041. * @param {string} Markup content
  1042. */
  1043. var html = function(id, content) {
  1044. var container = _getContainer(id);
  1045. container.html(content);
  1046. _render(id);
  1047. };
  1048. /**
  1049. * Add <markup> content to iScroll instance
  1050. *
  1051. * @method append
  1052. *
  1053. * @param {string} Id of the container scroll.
  1054. * @param {string} Markup content
  1055. */
  1056. var append = function(id, content) {
  1057. var container = _getContainer(id);
  1058. container.append(content);
  1059. _render(id);
  1060. };
  1061. /**
  1062. * Refresh iScroll instance.
  1063. *
  1064. * @method refresh
  1065. *
  1066. * @param {string} Id of the container scroll.
  1067. * @param {object} [OPTIONAL] Properties
  1068. */
  1069. var refresh = function(id, properties) {
  1070. _render(id, properties);
  1071. };
  1072. /**
  1073. * Removes iScroll instance.
  1074. *
  1075. * @method remove
  1076. *
  1077. * @param {string} Id of the container scroll.
  1078. */
  1079. var remove = function(id) {
  1080. if (lng.Data.Cache.exists(CACHE_KEY) && lng.Data.Cache.get(CACHE_KEY, id)) {
  1081. lng.Data.Cache.get(CACHE_KEY, id).destroy();
  1082. lng.Data.Cache.remove(CACHE_KEY, id);
  1083. }
  1084. };
  1085. /**
  1086. * Scrolls the wrapper contents to the minimum x/y coordinates
  1087. *
  1088. * @method first
  1089. *
  1090. * @param {string} Id of the <section>
  1091. */
  1092. var first = function(id) {
  1093. var scroll = lng.Data.Cache.get(CACHE_KEY);
  1094. if (scroll[id]) {
  1095. scroll[id].scrollTo(0, 0, SCROLL_TIMEFRAME);
  1096. }
  1097. };
  1098. /**
  1099. * Scrolls the wrapper contents to the maximum x/y coordinate
  1100. *
  1101. * @method down
  1102. *
  1103. * @param {string} Id of the <section>
  1104. */
  1105. var last = function(id) {
  1106. var scroll = lng.Data.Cache.get(CACHE_KEY, id);
  1107. if (scroll) {
  1108. var element = lng.dom('#' + id).first();
  1109. var content_width = 0;
  1110. var content_height = 0;
  1111. if (_isHorizontal(element)) {
  1112. content_width = -(_sizeProperty(element, ATTRIBUTE.WIDTH));
  1113. } else {
  1114. content_height = -(_sizeProperty(element, ATTRIBUTE.HEIGHT));
  1115. }
  1116. scroll.scrollTo(content_width, content_height, SCROLL_TIMEFRAME);
  1117. }
  1118. };
  1119. var _getContainer = function(id) {
  1120. var scroll = lng.dom('#' + id);
  1121. var container = scroll.children().first();
  1122. if (container.length === 0) {
  1123. scroll.html('<div></div>');
  1124. container = scroll.children().first();
  1125. }
  1126. return container;
  1127. };
  1128. var _sizeProperty = function(element, property) {
  1129. var element_content = element.children().first();
  1130. return element_content[property]() - element[property]();
  1131. };
  1132. var _render = function(id, properties) {
  1133. var scroll = lng.dom('#' + id);
  1134. if (_needScroll(scroll, properties)) {
  1135. properties = _mixProperties(scroll, properties);
  1136. _saveScrollInCache(id, properties);
  1137. } else {
  1138. remove(id);
  1139. }
  1140. };
  1141. var _needScroll = function(scroll, properties) {
  1142. var element = scroll[0];
  1143. var is_horizontal = _isHorizontal(lng.dom(element));
  1144. if (is_horizontal) {
  1145. return (element.clientWidth < element.scrollWidth);
  1146. } else {
  1147. return (element.clientHeight < element.scrollHeight);
  1148. }
  1149. };
  1150. var _saveScrollInCache = function(id, properties) {
  1151. _createScrollIndexInCache();
  1152. var scroll = lng.Data.Cache.get(CACHE_KEY);
  1153. if (!scroll[id]) {
  1154. scroll[id] = new iScroll(id, properties);
  1155. } else {
  1156. scroll[id].refresh();
  1157. }
  1158. lng.Data.Cache.set(CACHE_KEY, scroll);
  1159. };
  1160. var _createScrollIndexInCache = function() {
  1161. if (!lng.Data.Cache.exists(CACHE_KEY)) {
  1162. lng.Data.Cache.set(CACHE_KEY, {});
  1163. }
  1164. };
  1165. var _mixProperties = function(scroll, properties) {
  1166. var scroll_type = _isHorizontal(scroll) ? 'hScroll' : 'vScroll';
  1167. properties || (properties = {});
  1168. properties[scroll_type] = true;
  1169. properties = lng.Core.mix(DEFAULT_PROPERTIES, properties);
  1170. return properties;
  1171. };
  1172. var _isHorizontal = function(scroll) {
  1173. return ( scroll.hasClass(CLASS.HORIZONTAL)) ? true : false;
  1174. };
  1175. return {
  1176. init: init,
  1177. remove: remove,
  1178. refresh: refresh,
  1179. html: html,
  1180. append: append,
  1181. first: first,
  1182. last: last
  1183. };
  1184. })(LUNGO);/**
  1185. * Initialize the <articles> layout of a certain <section>
  1186. *
  1187. * @namespace LUNGO.View
  1188. * @class Aside
  1189. *
  1190. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1191. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  1192. */
  1193. LUNGO.View.Aside = (function(lng, undefined) {
  1194. var ELEMENT = lng.Constants.ELEMENT;
  1195. var CLASS = lng.Constants.CLASS;
  1196. var ATTRIBUTE = lng.Constants.ATTRIBUTE;
  1197. /**
  1198. * Display an aside element for a particular <section>
  1199. *
  1200. * @method show
  1201. *
  1202. * @param {string} Section id
  1203. * @param {string} Aside id
  1204. */
  1205. var show = function(section_id, aside_id) {
  1206. var aside = lng.dom(ELEMENT.ASIDE + aside_id);
  1207. var aside_class = _asideClass(aside);
  1208. var section = lng.dom(ELEMENT.SECTION + section_id);
  1209. aside.addClass(CLASS.CURRENT);
  1210. section.addClass(aside_class).addClass(CLASS.ASIDE);
  1211. };
  1212. /**
  1213. * Hide an aside element for a particular section
  1214. *
  1215. * @method hide
  1216. *
  1217. * @param {string} Element query selector
  1218. * @param {string} Value for counter
  1219. */
  1220. var hide = function(section_id, aside_id) {
  1221. var aside = lng.dom(ELEMENT.ASIDE + aside_id);
  1222. var aside_class = _asideClass(aside);
  1223. var section = lng.dom(ELEMENT.SECTION + section_id);
  1224. section.removeClass(CLASS.ASIDE).removeClass(aside_class);
  1225. setTimeout(function() {
  1226. aside.removeClass(CLASS.CURRENT);
  1227. }, 300);
  1228. };
  1229. var _asideClass = function(aside) {
  1230. var aside_class = aside.attr(ATTRIBUTE.CLASS);
  1231. var classes = ''
  1232. //@todo: Refactor
  1233. if (aside_class) {
  1234. classes += (aside_class.indexOf(CLASS.RIGHT) > -1) ? CLASS.RIGHT : '';
  1235. classes += (aside_class.indexOf(CLASS.MINI) > -1) ? CLASS.MINI : '';
  1236. }
  1237. return classes;
  1238. };
  1239. return {
  1240. show: show,
  1241. hide: hide
  1242. };
  1243. })(LUNGO);/**
  1244. * Initialize the <articles> layout of a certain <section>
  1245. *
  1246. * @namespace LUNGO.View
  1247. * @class Element
  1248. *
  1249. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1250. */
  1251. LUNGO.View.Element = (function(lng, undefined) {
  1252. var ATTRIBUTE = lng.Constants.ATTRIBUTE;
  1253. var BINDING = lng.Constants.BINDING;
  1254. var SELECTORS = {
  1255. BUBBLE: '.bubble.count',
  1256. PROGRESS_VALUE: ' .value',
  1257. PROGRESS_PERCENTAGE: ' .value .label'
  1258. };
  1259. /**
  1260. * Set a counter to the element
  1261. *
  1262. * @method count
  1263. *
  1264. * @param {string} Element query selector
  1265. * @param {number} Value for counter
  1266. */
  1267. var count = function(selector, count) {
  1268. var element = lng.dom(selector);
  1269. if (element) {
  1270. if (count > 0) {
  1271. _setBubble(element, count);
  1272. } else {
  1273. element.children(SELECTORS.BUBBLE).remove();
  1274. }
  1275. }
  1276. };
  1277. /**
  1278. * Set a progress to the element
  1279. *
  1280. * @method progress
  1281. *
  1282. * @param {string} Element query selector
  1283. * @param {number} Percentage
  1284. * @param {boolean} Show the labels: description and current percentage
  1285. * @param {string} Description
  1286. */
  1287. var progress = function(selector, percentage, with_label) {
  1288. var element = lng.dom(selector);
  1289. if (element) {
  1290. percentage += ATTRIBUTE.PERCENT;
  1291. lng.dom(selector + SELECTORS.PROGRESS_VALUE).style(ATTRIBUTE.WIDTH, percentage);
  1292. lng.dom(selector + SELECTORS.PROGRESS_PERCENTAGE).html((with_label) ? percentage : ATTRIBUTE.EMPTY);
  1293. }
  1294. };
  1295. /**
  1296. * Set a progress to the element
  1297. *
  1298. * @method progress
  1299. *
  1300. * @param {string} Element query selector
  1301. * @param {number} Percentage
  1302. * @param {boolean} Show the labels: description and current percentage
  1303. * @param {string} Description
  1304. */
  1305. var loading = function(selector, stylesheet) {
  1306. var element = lng.dom(selector);
  1307. if (element) {
  1308. _bindAttribute(element, LUNGO.Attributes.Data.Loading, stylesheet);
  1309. }
  1310. };
  1311. var _setBubble = function(element, count) {
  1312. var bubbles = element.children(SELECTORS.BUBBLE);
  1313. var total_bubbles = bubbles.length;
  1314. if (total_bubbles > 0) {
  1315. bubbles.html(count);
  1316. } else {
  1317. _bindAttribute(element, LUNGO.Attributes.Data.Count, count);
  1318. }
  1319. };
  1320. var _bindAttribute = function(element, attribute, data) {
  1321. var html_binded = attribute.html.replace(BINDING.START + BINDING.KEY + BINDING.END, data);
  1322. element.append(html_binded);
  1323. };
  1324. return {
  1325. count: count,
  1326. progress: progress,
  1327. loading: loading
  1328. };
  1329. })(LUNGO);/**
  1330. * Object with data-attributes (HTML5) with a special <markup>
  1331. *
  1332. * @namespace LUNGO.Attributes
  1333. * @class Data
  1334. *
  1335. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1336. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  1337. */
  1338. LUNGO.Attributes.Data = {
  1339. Search: {
  1340. tag: 'search',
  1341. selector: '.list',
  1342. html: '<li class="search {{value}}"><input type="search" placeholder="Search..."><a href="#" class="button" data-icon="search"></a></li>'
  1343. },
  1344. Count: {
  1345. tag: 'count',
  1346. selector: '*',
  1347. html: '<span class="bubble count">{{value}}</span>'
  1348. },
  1349. Search: {
  1350. tag: 'search',
  1351. selector: '*',
  1352. html: '<input type="search" placeholder="{{value}}"/><a href="#" class="button" data-icon="search"></a>'
  1353. },
  1354. Progress: {
  1355. tag: 'progress',
  1356. selector: '*',
  1357. html: '<div class="progress">\
  1358. <span class="bar"><span class="value" style="width:{{value}};"><span class="label"></span></span></span>\
  1359. </div>'
  1360. },
  1361. Label: {
  1362. tag: 'label',
  1363. selector: 'a',
  1364. html: '<abbr>{{value}}</abbr>'
  1365. },
  1366. Icon: {
  1367. tag: 'icon',
  1368. selector: '*',
  1369. html: '<span class="icon {{value}}"></span>'
  1370. },
  1371. Image: {
  1372. tag: 'image',
  1373. selector: '*',
  1374. html: '<img src="{{value}}" class="icon" />'
  1375. },
  1376. Title: {
  1377. tag: 'title',
  1378. selector: 'header, footer, article',
  1379. html: '<span class="title centered">{{value}}</span>'
  1380. },
  1381. Loading: {
  1382. tag: 'loading',
  1383. selector: '*',
  1384. html: '<div class="loading {{value}}">\
  1385. <span class="top"></span>\
  1386. <span class="right"></span>\
  1387. <span class="bottom"></span>\
  1388. <span class="left"></span>\
  1389. </div>'
  1390. },
  1391. Back: {
  1392. tag: 'back',
  1393. selector: 'header, footer',
  1394. html: '<a href="#back" data-target="section" class="onleft button default"><span class="icon {{value}}"></span></a>'
  1395. }
  1396. };/**
  1397. * Temporary cache system
  1398. *
  1399. * @namespace LUNGO.Data
  1400. * @class Cache
  1401. *
  1402. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1403. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  1404. */
  1405. LUNGO.Data.Cache = (function(lng, undefined) {
  1406. var _cache = {};
  1407. /**
  1408. * Sets in the LungoJS cache system a new key/value
  1409. *
  1410. * @method set
  1411. *
  1412. * @param {string} Key for the new value
  1413. * @param {object} Type of environment: DESKTOP_ENVIRONMENT or MOBILE_ENVIRONMENT
  1414. */
  1415. var set = function(key, value) {
  1416. if (exists(key)) {
  1417. _cache[key] = lng.Core.mix(get(key), value);
  1418. } else {
  1419. _cache[key] = value;
  1420. }
  1421. };
  1422. /**
  1423. * Returns the value of a given key.
  1424. *
  1425. * @method get
  1426. *
  1427. * @param {string} Key in LungoJS Cache System
  1428. * @param {string} [OPTIONAL] Subkey in LungoJS Cache System
  1429. * @return {object} Value
  1430. */
  1431. var get = function(key, value) {
  1432. if (arguments.length === 1) {
  1433. return _cache[key];
  1434. } else {
  1435. return (_cache[arguments[0]]) ? _cache[arguments[0]][arguments[1]] : undefined;
  1436. }
  1437. };
  1438. /**
  1439. * Removes the instance in LungoJs Cache System of a given key
  1440. *
  1441. * @method remove
  1442. *
  1443. * @param {string} Key in LungoJS Cache System
  1444. * @param {string} [OPTIONAL] Subkey in LungoJS Cache System
  1445. */
  1446. var remove = function(key, value) {
  1447. if (arguments.length === 1) {
  1448. delete _cache[key];
  1449. } else {
  1450. delete _cache[arguments[0]][arguments[1]];
  1451. }
  1452. };
  1453. /**
  1454. * Returns the existence of a key in LungoJs Cache System
  1455. *
  1456. * @method exists
  1457. *
  1458. * @param {String} Key in LungoJS Cache System
  1459. * @return {Boolean} true if exists, false if not
  1460. */
  1461. var exists = function(key) {
  1462. return (_cache[key]) ? true : false;
  1463. };
  1464. return {
  1465. set: set,
  1466. get: get,
  1467. remove: remove,
  1468. exists: exists
  1469. };
  1470. })(LUNGO);/**
  1471. * Wrapper for using WebSql (HTML5 feature)
  1472. *
  1473. * @namespace LUNGO.Data
  1474. * @class Sql
  1475. *
  1476. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1477. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  1478. */
  1479. LUNGO.Data.Sql = (function(lng, undefined) {
  1480. var ERROR = lng.Constants.ERROR;
  1481. var CONFIG = {
  1482. name: 'lungo_db',
  1483. version: '1.0',
  1484. size: 65536,
  1485. schema: []
  1486. };
  1487. var db = null;
  1488. /**
  1489. * Initialize the SQLite storage (HTML5 Feature)
  1490. *
  1491. * @method init
  1492. *
  1493. * @param {object} Configuration for the Database
  1494. */
  1495. var init = function(db_config) {
  1496. CONFIG = lng.Core.mix(CONFIG, db_config);
  1497. db = openDatabase(CONFIG.name, CONFIG.version, CONFIG.name, CONFIG.size);
  1498. if (db) {
  1499. _createSchema();
  1500. } else {
  1501. lng.Core.log(3, ERROR.DATABASE);
  1502. }
  1503. };
  1504. /**
  1505. * Select a data set of a given table and based on a selection object
  1506. *
  1507. * @method select
  1508. *
  1509. * @param {string} Name of the table in the database
  1510. * @param {object} [OPTIONAL] Object selection condition
  1511. * @param {Function} Callback when the process is complete
  1512. */
  1513. var select = function(table, where_obj, callback) {
  1514. var where = (where_obj) ? ' WHERE ' + _convertToSql(where_obj, 'AND') : '';
  1515. execute('SELECT * FROM ' + table + where, function(rs) {
  1516. var result = [];
  1517. for (var i = 0, len = rs.rows.length; i < len; i++) {
  1518. result.push(rs.rows.item(i));
  1519. }
  1520. _callbackResponse(callback, result);
  1521. });
  1522. };
  1523. /**
  1524. * Inserts a data set of a given table and based on a data object
  1525. *
  1526. * @method insert
  1527. *
  1528. * @param {string} Name of the table in the database
  1529. * @param {object} Object (or Array of objects) to insert in table
  1530. */
  1531. var insert = function(table, data, callback) {
  1532. if (lng.Core.toType(data) === 'object') {
  1533. _insertRow(table, data);
  1534. } else {
  1535. for (row in data) {
  1536. _insertRow(table, data[row]);
  1537. }
  1538. }
  1539. };
  1540. /**
  1541. * Updates a data set of a given table and based on a data object and
  1542. * an optional selection object
  1543. *
  1544. * @method update
  1545. *
  1546. * @param {string} Name of the table in the database
  1547. * @param {object} Data object to update in table
  1548. * @param {object} [OPTIONAL] Object selection condition
  1549. */
  1550. var update = function(table, data_obj, where_obj, callback) {
  1551. var sql = 'UPDATE ' + table + ' SET ' + _convertToSql(data_obj, ',');
  1552. if (where_obj) sql += ' WHERE ' + _convertToSql(where_obj, 'AND');
  1553. execute(sql);
  1554. };
  1555. /**
  1556. * Delete a data set of a given table and based on a selection object
  1557. *
  1558. * @method drop
  1559. *
  1560. * @param {string} Name of the table in the database
  1561. * @param {object} [OPTIONAL] Object selection condition
  1562. */
  1563. var drop = function(table, where_obj, callback) {
  1564. var where = (where_obj) ? ' WHERE ' + _convertToSql(where_obj, 'AND') : '';
  1565. execute('DELETE FROM ' + table + where + ';');
  1566. };
  1567. /**
  1568. * Executes a SQL statement in the SQLite storage
  1569. *
  1570. * @method execute
  1571. *
  1572. * @param {string} SQL statement
  1573. * @param {Function} Callback when the process is complete
  1574. */
  1575. var execute = function(sql, callback) {
  1576. lng.Core.log(1, 'lng.Data.Sql >> ' + sql);
  1577. db.transaction( function(transaction) {
  1578. transaction.executeSql(sql, [], function(transaction, rs) {
  1579. _callbackResponse(callback, rs);
  1580. }, function(transaction, error) {
  1581. transaction.executedQuery = sql;
  1582. _throwError.apply(null, arguments);
  1583. });
  1584. });
  1585. };
  1586. var _createSchema = function() {
  1587. var schema = CONFIG.schema;
  1588. var schema_len = schema.length;
  1589. if (!schema_len) return;
  1590. for (var i = 0; i < schema_len; i++) {
  1591. var current = schema[i];
  1592. _regenerateTable(current);
  1593. _createTable(current.name, current.fields);
  1594. }
  1595. };
  1596. var _createTable = function(table, fields) {
  1597. var sql_fields = '';
  1598. for (var field in fields) {
  1599. if (lng.Core.isOwnProperty(fields, field)) {
  1600. if (sql_fields) sql_fields += ', ';
  1601. sql_fields += field + ' ' + fields[field];
  1602. }
  1603. }
  1604. execute('CREATE TABLE IF NOT EXISTS ' + table + ' (' + sql_fields + ');');
  1605. };
  1606. var _regenerateTable = function(table) {
  1607. if (table.drop === true) {
  1608. _dropTable(table.name);
  1609. }
  1610. };
  1611. var _dropTable = function(table) {
  1612. execute('DROP TABLE IF EXISTS ' + table);
  1613. };
  1614. var _convertToSql = function(fields, separator) {
  1615. var sql = '';
  1616. for (var field in fields) {
  1617. if (lng.Core.isOwnProperty(fields, field)) {
  1618. var value = fields[field];
  1619. if (sql) sql += ' ' + separator + ' ';
  1620. sql += field + '=';
  1621. sql += (isNaN(value)) ? '"' + value + '"' : value;
  1622. }
  1623. }
  1624. return sql;
  1625. };
  1626. var _callbackResponse = function(callback, response) {
  1627. if (lng.Core.toType(callback) === 'function') {
  1628. setTimeout(callback, 100, response);
  1629. }
  1630. };
  1631. var _insertRow = function(table, row) {
  1632. var fields = '';
  1633. var values = '';
  1634. for (var field in row) {
  1635. if (lng.Core.isOwnProperty(row, field)) {
  1636. var value = row[field];
  1637. fields += (fields) ? ', ' + field : field;
  1638. if (values) values += ', ';
  1639. values += (isNaN(value)) ? '"' + value + '"' : value;
  1640. }
  1641. }
  1642. execute('INSERT INTO ' + table + ' (' + fields + ') VALUES (' + values + ')');
  1643. };
  1644. var _throwError = function(transaction, error) {
  1645. lng.Core.log(3, 'lng.Data.Sql >> ' + error.code + ': ' + error.message + ' \n Executed query: ' + transaction.executedQuery);
  1646. };
  1647. return {
  1648. init: init,
  1649. select: select,
  1650. insert: insert,
  1651. update: update,
  1652. drop: drop,
  1653. execute: execute
  1654. };
  1655. })(LUNGO);/**
  1656. * Wrapper for using LocalStorage & SessionStorage (HTML5 Feature)
  1657. *
  1658. * @namespace LUNGO.Data
  1659. * @class Storage
  1660. *
  1661. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1662. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  1663. */
  1664. LUNGO.Data.Storage = (function(lng, undefined) {
  1665. var STORAGE = {
  1666. PERSISTENT: 'localStorage',
  1667. SESSION: 'sessionStorage'
  1668. };
  1669. /**
  1670. * Wrapper for SessionStorage
  1671. *
  1672. * @method persistent
  1673. *
  1674. * @param {string} Key
  1675. * @param {object} Value
  1676. * @return {string} If no value assigned returns the value of established key
  1677. */
  1678. var persistent = function(key, value) {
  1679. return _handler(STORAGE.PERSISTENT, key, value);
  1680. };
  1681. /**
  1682. * Wrapper for SessionStorage
  1683. *
  1684. * @method session
  1685. *
  1686. * @param {string} Key
  1687. * @param {object} Value
  1688. * @return {string} If no value assigned returns the value of established key
  1689. */
  1690. var session = function(key, value) {
  1691. return _handler(STORAGE.SESSION, key, value);
  1692. };
  1693. var _handler = function(storage, key, value) {
  1694. var storage = window[storage];
  1695. if (value) {
  1696. _saveKey(storage, key, value);
  1697. } else {
  1698. return _getKey(storage, key, value);
  1699. }
  1700. };
  1701. var _saveKey = function(storage, key, value) {
  1702. value = JSON.stringify(value);
  1703. storage.setItem(key, value);
  1704. };
  1705. var _getKey = function(storage, key, value) {
  1706. value = storage.getItem(key);
  1707. return JSON.parse(value);
  1708. };
  1709. return {
  1710. session: session,
  1711. persistent: persistent
  1712. };
  1713. })(LUNGO);/**
  1714. * Boot for a new LungoJS Application instance
  1715. *
  1716. * @namespace LUNGO
  1717. * @class App
  1718. *
  1719. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1720. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  1721. */
  1722. LUNGO.Boot = (function(lng, undefined) {
  1723. return function() {
  1724. lng.Boot.Resources.start();
  1725. lng.Boot.Layout.start();
  1726. lng.Boot.Events.start();
  1727. lng.Boot.Data.start();
  1728. lng.Boot.Section.start();
  1729. lng.Boot.Article.start();
  1730. lng.Boot.Stats.start();
  1731. };
  1732. })(LUNGO);/**
  1733. * Load Resources
  1734. *
  1735. * @namespace LUNGO.Boot
  1736. * @class Resources
  1737. *
  1738. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1739. */
  1740. LUNGO.Boot.Resources = (function(lng, $$, undefined) {
  1741. var ELEMENT = lng.Constants.ELEMENT;
  1742. var ERROR = lng.Constants.ERROR;
  1743. var RESOURCE = {
  1744. SECTION: 'sections',
  1745. TEMPLATE: 'templates',
  1746. SCRIPT: 'scripts'
  1747. };
  1748. /**
  1749. * Start loading async sections (local & remote)
  1750. *
  1751. * @method start
  1752. *
  1753. */
  1754. var start = function() {
  1755. var resources = lng.App.get('resources');
  1756. for (resource_key in resources) {
  1757. _loadResources(resource_key, resources[resource_key]);
  1758. }
  1759. };
  1760. var _loadResources = function(resource_key, resources, callback) {
  1761. for (index in resources) {
  1762. var url = _parseUrl(resources[index], resource_key);
  1763. try {
  1764. var response = _loadAsyncResource(url);
  1765. _factoryResources(resource_key, response);
  1766. } catch(error) {
  1767. lng.Core.log(3, ERROR.LOADING_RESOURCE + ' ' + error);
  1768. }
  1769. }
  1770. };
  1771. var _parseUrl = function(section_url, folder) {
  1772. return (/http/.test(section_url)) ? section_url : 'app/' + folder + '/' + section_url;
  1773. };
  1774. var _loadAsyncResource = function(url) {
  1775. return $$.ajax({
  1776. url: url,
  1777. async: false,
  1778. dataType: 'html',
  1779. error: function() {
  1780. console.error('[ERROR] Loading url', arguments);
  1781. }
  1782. });
  1783. };
  1784. var _factoryResources = function(resource_key, response) {
  1785. switch(resource_key) {
  1786. case RESOURCE.SECTION:
  1787. _pushSectionInLayout(response);
  1788. break;
  1789. case RESOURCE.TEMPLATE:
  1790. _createTemplate(response);
  1791. break;
  1792. case RESOURCE.SCRIPT:
  1793. break;
  1794. }
  1795. };
  1796. var _pushSectionInLayout = function(section) {
  1797. if (lng.Core.toType(section) === 'string') {
  1798. lng.dom(ELEMENT.BODY).append(section);
  1799. }
  1800. };
  1801. var _createTemplate = function(markup) {
  1802. var div = document.createElement(ELEMENT.DIV);
  1803. div.innerHTML = markup;
  1804. var template_id = lng.dom(div.firstChild).data('template');
  1805. if (template_id) {
  1806. lng.View.Template.create(template_id, markup);
  1807. }
  1808. };
  1809. return {
  1810. start: start
  1811. };
  1812. })(LUNGO, Quo);/**
  1813. * Save in LungoJS.com the use of the service for further ranking
  1814. *
  1815. * @namespace LUNGO.Boot
  1816. * @class Stats
  1817. *
  1818. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1819. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  1820. */
  1821. LUNGO.Boot.Stats = (function(lng, undefined) {
  1822. /**
  1823. * Analizing if it's run in Mobile Phone and changing the type of event to subscribe.
  1824. *
  1825. * @method start
  1826. */
  1827. var start = function() {
  1828. if (lng.Core.isMobile()) {
  1829. _saveStats();
  1830. }
  1831. };
  1832. /**
  1833. * Save in LungoJS.com the use of the service for further ranking
  1834. *
  1835. * @method _saveStatsInLungoJS
  1836. */
  1837. var _saveStats = function() {
  1838. lng.Service.post( 'http://www.lungojs.com/stats/', {
  1839. name: lng.App.get('name'),
  1840. version: lng.App.get('version'),
  1841. icon: lng.App.get('icon')
  1842. }, function(response) {});
  1843. };
  1844. return {
  1845. start: start
  1846. };
  1847. })(LUNGO);/**
  1848. * Initialize the Layout of LungoJS (if it's a mobile environment)
  1849. *
  1850. * @namespace LUNGO.Boot
  1851. * @class Layout
  1852. *
  1853. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1854. */
  1855. LUNGO.Boot.Layout = (function(lng, undefined) {
  1856. var _window = null;
  1857. var _document = null;
  1858. var ELEMENT = lng.Constants.ELEMENT;
  1859. var ATTRIBUTE = lng.Constants.ATTRIBUTE;
  1860. /**
  1861. * Initializes the automatic subscription events by markup of the project.
  1862. *
  1863. * @method init
  1864. *
  1865. */
  1866. var start = function() {
  1867. if (lng.Core.isMobile()) {
  1868. _window = window;
  1869. _document = _window.document;
  1870. _resizeLayout();
  1871. }
  1872. };
  1873. var _resizeLayout = function() {
  1874. if (_window.innerHeight == 356) {
  1875. var _height = 416;
  1876. lng.dom(ELEMENT.BODY).style(ATTRIBUTE.HEIGHT, _height + ATTRIBUTE.PIXEL);
  1877. _hideNavigationBar();
  1878. }
  1879. };
  1880. var _hideNavigationBar = function() {
  1881. if( !location.hash || !_window.addEventListener ){
  1882. _window.scrollTo( 0, 1 );
  1883. var scrollTop = 1,
  1884. //reset to 0 on bodyready, if needed
  1885. bodycheck = setInterval(function(){
  1886. if( _document.body ){
  1887. clearInterval( bodycheck );
  1888. scrollTop = 'scrollTop' in _document.body ? _document.body.scrollTop : 1;
  1889. _window.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
  1890. }
  1891. }, 15 );
  1892. _window.addEventListener('load', function(){
  1893. setTimeout(function(){
  1894. _window.scrollTo( 0, scrollTop === 1 ? 0 : 1 );
  1895. }, 0);
  1896. }, false );
  1897. }
  1898. };
  1899. return {
  1900. start: start
  1901. };
  1902. })(LUNGO);/**
  1903. * Initialize the <article> element
  1904. *
  1905. * @namespace LUNGO.Boot
  1906. * @class Article
  1907. *
  1908. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1909. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  1910. */
  1911. LUNGO.Boot.Article = (function(lng, undefined) {
  1912. var ATTRIBUTE = lng.Constants.ATTRIBUTE;
  1913. var ELEMENT = lng.Constants.ELEMENT;
  1914. var SELECTORS = {
  1915. LIST_IN_ARTICLE: 'article.list, aside.list',
  1916. SCROLL_IN_ARTICLE: '.scrollable',
  1917. CHECKBOX_IN_ARTICLE: '.checkbox, .radio'
  1918. };
  1919. /**
  1920. * Initializes the markup elements of an article
  1921. *
  1922. * @method init
  1923. */
  1924. var start = function() {
  1925. _initElement(SELECTORS.LIST_IN_ARTICLE, _createListElement);
  1926. _initElement(SELECTORS.SCROLL_IN_ARTICLE, _createScrollElement);
  1927. _initElement(SELECTORS.CHECKBOX_IN_ARTICLE, _createCheckboxElement);
  1928. };
  1929. var _initElement = function(selector, callback) {
  1930. var found_elements = lng.dom(selector);
  1931. for (var i = 0, len = found_elements.length; i < len; i++) {
  1932. var element = lng.dom(found_elements[i]);
  1933. lng.Core.execute(callback, element);
  1934. }
  1935. };
  1936. var _createListElement = function(article) {
  1937. if (article.children().length === 0) {
  1938. var article_id = article.attr(ATTRIBUTE.ID);
  1939. article.append(ELEMENT.LIST);
  1940. }
  1941. };
  1942. var _createScrollElement = function(scroll) {
  1943. var scroll_id = scroll.attr(ATTRIBUTE.ID);
  1944. lng.View.Scroll.init(scroll_id);
  1945. };
  1946. var _createCheckboxElement = function(checkbox) {
  1947. checkbox.append(ELEMENT.SPAN);
  1948. };
  1949. return {
  1950. start: start
  1951. };
  1952. })(LUNGO);/**
  1953. * Make an analysis of Data attributes in HTML elements and creates a <markup>
  1954. * based on each data type.
  1955. *
  1956. * @namespace LUNGO.Boot
  1957. * @class Data
  1958. *
  1959. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1960. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  1961. */
  1962. LUNGO.Boot.Data = (function(lng, undefined) {
  1963. /**
  1964. * Initialize the <markup> data-attributes analisys
  1965. *
  1966. * @method init
  1967. *
  1968. *
  1969. */
  1970. var start = function() {
  1971. var attributes = lng.Attributes.Data;
  1972. for (var attribute in attributes) {
  1973. if (lng.Core.isOwnProperty(attributes, attribute)) {
  1974. _findElements(attributes[attribute]);
  1975. }
  1976. }
  1977. };
  1978. var _findElements = function(attribute) {
  1979. var elements = lng.dom(attribute.selector);
  1980. for (var i = 0, len = elements.length; i < len; i++) {
  1981. var element = lng.dom(elements[i]);
  1982. lng.View.Template.Binding.dataAttribute(element, attribute);
  1983. }
  1984. };
  1985. return {
  1986. start: start
  1987. };
  1988. })(LUNGO);/**
  1989. * Initialize the automatic DOM UI events
  1990. *
  1991. * @namespace LUNGO.Boot
  1992. * @class Events
  1993. *
  1994. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  1995. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  1996. */
  1997. LUNGO.Boot.Events = (function(lng, undefined) {
  1998. var ATTRIBUTE = lng.Constants.ATTRIBUTE;
  1999. var CLASS = lng.Constants.CLASS;
  2000. var ELEMENT = lng.Constants.ELEMENT;
  2001. var SELECTORS = {
  2002. DOCUMENT: document,
  2003. WINDOW: window,
  2004. HREF_TARGET: 'a[href][data-target]',
  2005. HREF_TARGET_FROM_ASIDE: 'aside a[href][data-target]',
  2006. CURRENT_SECTION: 'section.aside, section.current'
  2007. };
  2008. /**
  2009. * Initializes the automatic subscription events by markup of the project.
  2010. *
  2011. * @method init
  2012. *
  2013. */
  2014. var start = function() {
  2015. var touch_move_event = 'touchmove';
  2016. var resize = 'resize';
  2017. //@ToDo: Error with input type="range"
  2018. lng.dom(SELECTORS.DOCUMENT).on(touch_move_event, _iScroll);
  2019. lng.dom(SELECTORS.WINDOW).on(resize, _changeOrientation);
  2020. lng.dom(SELECTORS.HREF_TARGET).tap(_loadTarget);
  2021. lng.dom(SELECTORS.HREF_TARGET_FROM_ASIDE).touch(_asideVisibility);
  2022. };
  2023. var _iScroll = function(event) {
  2024. event.preventDefault();
  2025. };
  2026. var _changeOrientation = function(event) {
  2027. lng.View.Resize.toolbars();
  2028. event.preventDefault();
  2029. };
  2030. var _loadTarget = function(event) {
  2031. var link = lng.dom(this);
  2032. _selectTarget(link);
  2033. event.preventDefault();
  2034. };
  2035. var _selectTarget = function(link) {
  2036. var target_type = link.data(ATTRIBUTE.TARGET);
  2037. switch(target_type) {
  2038. case ELEMENT.SECTION:
  2039. var target_id = link.attr(ATTRIBUTE.HREF);
  2040. _goSection(target_id);
  2041. break;
  2042. case ELEMENT.ARTICLE:
  2043. _goArticle(link);
  2044. break;
  2045. case ELEMENT.ASIDE:
  2046. _goAside(link);
  2047. break;
  2048. }
  2049. };
  2050. var _asideVisibility = function(event) {
  2051. var link = lng.dom(this);
  2052. var target = lng.dom(link.data(ATTRIBUTE.TARGET) + link.attr(ATTRIBUTE.HREF));
  2053. if (target.length > 0) {
  2054. var aside_id = '#' + link.parent(ELEMENT.ASIDE).attr(ATTRIBUTE.ID);
  2055. var section_id = '#' + lng.dom(SELECTORS.CURRENT_SECTION).first().attr(ATTRIBUTE.ID);
  2056. if (link.data(ATTRIBUTE.TARGET) === ELEMENT.ARTICLE) {
  2057. lng.dom(ELEMENT.ASIDE + aside_id + ' ' + SELECTORS.HREF_TARGET).removeClass(CLASS.CURRENT);
  2058. link.addClass(CLASS.CURRENT);
  2059. }
  2060. _hideAsideIfNecesary(section_id, aside_id);
  2061. }
  2062. event.preventDefault();
  2063. };
  2064. var _goSection = function(id) {
  2065. id = lng.Core.parseUrl(id);
  2066. if (id === '#back') {
  2067. lng.Router.back();
  2068. } else {
  2069. lng.Router.section(id);
  2070. }
  2071. };
  2072. var _goArticle = function(element) {
  2073. var section_id = lng.Router.History.current();
  2074. var article_id = element.attr(ATTRIBUTE.HREF);
  2075. lng.Router.article(section_id, article_id);
  2076. };
  2077. var _goAside = function(element) {
  2078. var section_id = lng.Router.History.current();
  2079. var aside_id = element.attr(ATTRIBUTE.HREF);
  2080. lng.Router.aside(section_id, aside_id);
  2081. };
  2082. var _hideAsideIfNecesary = function(section_id, aside_id) {
  2083. if (window.innerWidth < 768) {
  2084. lng.View.Aside.hide(section_id, aside_id);
  2085. }
  2086. };
  2087. return {
  2088. start: start
  2089. };
  2090. })(LUNGO);/**
  2091. * Initialize the <section> element
  2092. *
  2093. * @namespace LUNGO.Boot
  2094. * @class Section
  2095. *
  2096. * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
  2097. * @author Guillermo Pascual <pasku@tapquo.com> || @pasku1
  2098. */
  2099. LUNGO.Boot.Section = (function(lng, undefined) {
  2100. var ELEMENT = lng.Constants.ELEMENT;
  2101. var CLASS = lng.Constants.CLASS;
  2102. var ATTRIBUTE = lng.Constants.ATTRIBUTE;
  2103. /**
  2104. * Initializes all <section>s of the project
  2105. *
  2106. * @method init
  2107. */
  2108. var start = function() {
  2109. var sections = lng.dom(ELEMENT.SECTION);
  2110. _initFirstSection(sections);
  2111. _initAllSections(sections);
  2112. lng.View.Resize.toolbars();
  2113. };
  2114. var _initFirstSection = function(sections) {
  2115. var first_section = sections.first();
  2116. var first_section_id = '#' + first_section.attr(ATTRIBUTE.ID);
  2117. first_section.addClass(CLASS.CURRENT);
  2118. lng.Router.History.add(first_section_id);
  2119. };
  2120. var _initAllSections = function(sections) {
  2121. lng.Fallback.positionFixed(sections);
  2122. for (var i = 0, len = sections.length; i < len; i++) {
  2123. var section = lng.dom(sections[i]);
  2124. _initArticles(section);
  2125. }
  2126. };
  2127. var _initArticles = function(section) {
  2128. var first_article = section.children(ELEMENT.ARTICLE).first();
  2129. first_article.addClass(CLASS.CURRENT);
  2130. var first_article_id = first_article.attr(ATTRIBUTE.ID);
  2131. var section_id = '#' + section.attr(ATTRIBUTE.ID);
  2132. lng.View.Article.showReferenceLinks(section_id, first_article_id);
  2133. };
  2134. return {
  2135. start: start
  2136. };
  2137. })(LUNGO);