ソースを参照

New namespace Lungo.Events

soyjavi 14 年 前
コミット
718ce89e92

+ 1 - 3
examples/test/app/app.js

@@ -3,12 +3,10 @@ var App = (function(lng, undefined) {
 
     lng.App.init({
         name: 'Kitchen Sink',
-        version: '1.2',
+        version: '2.0',
         resources: {
-
             sections: [
                 'aside.html', 'aside-profiles.html']
-
         }
     });
 

+ 14 - 1
examples/test/app/events.js

@@ -1,3 +1,9 @@
+LUNGO.Events.init({
+    'section#sec-1 header #btn-toggle-loading tap': App.View.toggleLoading,
+    'a': App.View.toggleLoading
+});
+
+/*
 App.Events = (function(lng, undefined) {
 
     lng.ready(function() {
@@ -13,6 +19,7 @@ App.Events = (function(lng, undefined) {
     });
 
 
+
     $$('section#sec-1 header #btn-toggle-loading').tap(function(event) {
         var el = lng.dom(this);
 
@@ -51,4 +58,10 @@ App.Events = (function(lng, undefined) {
         console.error('article#nav-1 unloaded', event);
     });
 
-})(LUNGO);
+
+    return {
+        a: a
+    };
+
+})(LUNGO);
+*/

+ 17 - 0
examples/test/app/view.js

@@ -1,3 +1,20 @@
 App.View = (function(lng, App, undefined) {
 
+    toggleLoading = function(event) {
+        var el = lng.dom(this);
+
+        if (el.children('.loading').length > 0) {
+            el.children('.icon').show();
+            lng.View.Element.loading(this);
+        } else {
+            el.children('.icon').hide();
+            lng.View.Element.loading(this, 'white');
+        }
+    };
+
+    return {
+        toggleLoading: toggleLoading
+    };
+
+
 })(LUNGO, App);

+ 2 - 1
examples/test/index.html

@@ -295,6 +295,7 @@
     <script src="../../src/Lungo.Service.js"></script>
     <script src="../../src/Lungo.Constants.js"></script>
     <script src="../../src/Lungo.Element.js"></script>
+    <script src="../../src/Lungo.Events.js"></script>
     <script src="../../src/router/Lungo.Router.js"></script>
     <script src="../../src/router/Lungo.Router.History.js" ></script>
     <script src="../../src/view/Lungo.View.Resize.js"></script>
@@ -320,9 +321,9 @@
 
     <!-- LungoJS - Sandbox App -->
     <script src="app/app.js"></script>
-    <script src="app/events.js"></script>
     <script src="app/view.js"></script>
     <script src="app/data.js"></script>
     <script src="app/services.js"></script>
+    <script src="app/events.js"></script>
 </body>
 </html>

+ 30 - 0
src/Lungo.Events.js

@@ -0,0 +1,30 @@
+/**
+ * ?
+ *
+ * @namespace LUNGO
+ * @class Fallback
+ *
+ * @author Javier Jimenez Villar <javi@tapquo.com> || @soyjavi
+ */
+
+LUNGO.Events = (function(lng, undefined) {
+
+    var SPACE_CHAR = ' ';
+
+    var init = function(events) {
+        for (event in events) {
+            var index_of = event.lastIndexOf(SPACE_CHAR);
+            if (index_of > 0) {
+                var element = event.substring(0, index_of);
+                var event_name = event.substring(index_of + 1);
+
+                lng.dom(element).on(event_name, events[event]);
+            }
+        }
+    };
+
+    return {
+        init: init
+    };
+
+})(LUNGO);