Browse Source

New feature: Async Sections (Local & Remote server)

@soyjavi 14 years ago
parent
commit
60befe4721
2 changed files with 56 additions and 0 deletions
  1. 55 0
      src/boot/Lungo.Boot.Async.js
  2. 1 0
      src/boot/Lungo.Boot.js

+ 55 - 0
src/boot/Lungo.Boot.Async.js

@@ -0,0 +1,55 @@
+/**
+ * Load Async sections
+ *
+ * @namespace LUNGO
+ * @class App
+ *
+ * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
+ */
+
+LUNGO.Boot.Async = (function(lng, $$, undefined) {
+
+    /**
+     * Start loading async sections (local & remote)
+     *
+     * @method start
+     *
+     */
+    var start = function() {
+        var async_sections = lng.App.get('sections');
+
+        if (async_sections) {
+            for (section in async_sections) {
+                var url = _parseUrl(async_sections[section])
+                var response = _loadAsyncSection(url);
+                _pushSectionInLayout(response);
+            }
+        }
+    };
+
+    var _parseUrl = function(section_url) {
+        return (/http/.test(section_url)) ? section_url : 'app/sections/' + section_url;
+    };
+
+    var _loadAsyncSection = function(url) {
+        return $$.ajax({
+            url: url,
+            async: false,
+            dataType: 'html',
+            error: function() {
+                console.error('[ERROR] Loading url', arguments);
+            }
+        });
+    };
+
+    var _pushSectionInLayout = function(section) {
+        if (lng.Core.toType(section) === 'string') {
+            lng.dom('body').append(section);
+        }
+    };
+
+    return {
+        start: start
+    };
+
+})(LUNGO, Quo);

+ 1 - 0
src/boot/Lungo.Boot.js

@@ -11,6 +11,7 @@
 LUNGO.Boot = (function(lng, undefined) {
 LUNGO.Boot = (function(lng, undefined) {
 
 
     return function() {
     return function() {
+        lng.Boot.Async.start();
         lng.Boot.Layout.start();
         lng.Boot.Layout.start();
         lng.Boot.Events.start();
         lng.Boot.Events.start();
         lng.Boot.Data.start();
         lng.Boot.Data.start();