first take
authorMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Sun, 8 Jul 2012 18:14:51 +0000 (20:14 +0200)
committerMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Sun, 8 Jul 2012 18:14:51 +0000 (20:14 +0200)
index.html
js/app/AjaxList.js [new file with mode: 0644]
js/app/Config.coffee [new file with mode: 0644]
js/app/Config.js [new file with mode: 0644]
js/app/Controller.coffee [new file with mode: 0644]
js/app/Controller.js [new file with mode: 0644]
js/app/TagList.coffee [new file with mode: 0644]
js/app/TagList.js [new file with mode: 0644]
js/app/app.coffee [new file with mode: 0644]
js/app/app.js [new file with mode: 0644]

index a8ec171..518af86 100644 (file)
@@ -29,6 +29,7 @@
 
        <!-- jQuery Mobile CSS bits -->
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
+<!--   <link rel="stylesheet" href="css/jquery.mobile-1.1.0.min.css" />-->
 
        <!-- Custom css -->
        <link rel="stylesheet" href="css/custom.css" />
        <script src="js/mobileinit.js"></script>
        <script src="js/ios-orientationchange-fix.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
-       <script src="js/application.js"></script>
+<!--   <script src="js/jquery.mobile-1.1.0.min.js"></script>-->
+
+       <!-- app -->
+       <script src="js/app/app.js"></script>
+       <script src="js/app/Config.js"></script>
+       <script src="js/app/Controller.js"></script>
+       <script src="js/app/TagList.js"></script>
+       <!-- /app -->
+
        <!-- Add a Bookmark Bubble for iDevices, and adds a cookie if already shown -->
        <script type="text/javascript" src="js/bookmark_bubble.js"></script>
        <script type="text/javascript" src="js/example.js"></script>
        <script>(function(a,b,c){if(c in b&&b[c]){var d,e=a.location,f=/^(a|html)$/i;a.addEventListener("click",function(a){d=a.target;while(!f.test(d.nodeName))d=d.parentNode;"href"in d&&(d.href.indexOf("http")||~d.href.indexOf(e.host))&&(a.preventDefault(),e.href=d.href)},!1)}})(document,window.navigator,"standalone")</script>
 </head> 
 <body> 
-       <div data-role="page">
-
-               <div data-role="header">
-                       <h1>jQuery Mobile Boilerplate 1.1</h1>
-               </div>
+  <!-- Categories -->
+  <div data-role="page" id="page-categories">
+    <div data-role="content" style="padding: 15px">
+      <ul data-role="listview" data-divider-theme="b" data-inset="false" id="list-categories">
+        <li data-role="list-divider" role="heading">
+          Divider
+        </li>
+        <li data-theme="c">
+          <a href="#" data-transition="slide">
+            Button
+          </a>
+        </li>
+      </ul>
+    </div>
+  </div>
 
-               <div data-role="content">
-               
-                       <ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b">
-                               <li data-role="list-divider">Snippet Pages</li>
-                               <li><a href="snippets/buttons.html">Buttons</a></li>
-                               <li><a href="snippets/grids.html">Grids</a></li>
-                               <li><a href="snippets/collapsibles.html">Collapsible Boxes</a></li>
-                               <li><a href="snippets/collapsible-sets.html">Collapsible Sets</a></li>
-                               <li><a href="snippets/forms.html">Form Elements</a></li>
-                               <li><a href="snippets/lists.html">List Views</a></li>
-                       </ul>
+  <!-- Tag List -->
+  <div data-role="page" id="page-tags">
+    <div data-role="content" style="padding: 15px">
+      <ul data-role="listview" data-divider-theme="b" data-inset="false" id="list-tags">
+        <li data-role="list-divider" role="heading">
+          Divider
+        </li>
+        <li data-theme="c">
+          <a href="#" data-transition="slide">
+            Button
+          </a>
+        </li>
+      </ul>
+    </div>
+  </div>
 
-               </div>
-               
-               <div data-role="footer" data-theme="c">
-                       <p>&copy; 2012 - jQuery Mobile Boilerplate</p>
-               </div>  
-               
-       </div>
 </body>
-</html>
\ No newline at end of file
+</html>
diff --git a/js/app/AjaxList.js b/js/app/AjaxList.js
new file mode 100644 (file)
index 0000000..d2d0897
--- /dev/null
@@ -0,0 +1,25 @@
+(function() {
+
+  Readings.TagList = (function() {
+
+    TagList.prototype.defaults = null;
+
+    function TagList(list, category, options) {
+      this.category = category;
+      this.options = $.extend(this.defaults, options);
+    }
+
+    TagList.prototype.load = function() {
+      return $.ajax({
+        url: Readings.config.get('wlurl') + ("/api/" + this.category),
+        success: function() {
+          return true;
+        }
+      });
+    };
+
+    return TagList;
+
+  })();
+
+}).call(this);
diff --git a/js/app/Config.coffee b/js/app/Config.coffee
new file mode 100644 (file)
index 0000000..00df4a1
--- /dev/null
@@ -0,0 +1,6 @@
+
+class Readings.Config
+  constructor: (@opts) ->
+
+  get: (name) ->
+    @opts[name]
diff --git a/js/app/Config.js b/js/app/Config.js
new file mode 100644 (file)
index 0000000..87a99b7
--- /dev/null
@@ -0,0 +1,17 @@
+(function() {
+
+  Readings.Config = (function() {
+
+    function Config(opts) {
+      this.opts = opts;
+    }
+
+    Config.prototype.get = function(name) {
+      return this.opts[name];
+    };
+
+    return Config;
+
+  })();
+
+}).call(this);
diff --git a/js/app/Controller.coffee b/js/app/Controller.coffee
new file mode 100644 (file)
index 0000000..b5db24c
--- /dev/null
@@ -0,0 +1,7 @@
+# main controller
+
+Readings.category_list = (list) ->
+  list.empty()
+  for cat, labelname of Readings.config.get 'categories'
+    list.append "<li><a href=\"#page-tags?category=#{cat}\">#{labelname}</a></li>"
+  list.listview 'refresh'
\ No newline at end of file
diff --git a/js/app/Controller.js b/js/app/Controller.js
new file mode 100644 (file)
index 0000000..9222b13
--- /dev/null
@@ -0,0 +1,14 @@
+(function() {
+
+  Readings.category_list = function(list) {
+    var cat, labelname, _ref;
+    list.empty();
+    _ref = Readings.config.get('categories');
+    for (cat in _ref) {
+      labelname = _ref[cat];
+      list.append("<li><a href=\"#page-tags?category=" + cat + "\">" + labelname + "</a></li>");
+    }
+    return list.listview('refresh');
+  };
+
+}).call(this);
diff --git a/js/app/TagList.coffee b/js/app/TagList.coffee
new file mode 100644 (file)
index 0000000..a481284
--- /dev/null
@@ -0,0 +1,39 @@
+
+class Readings.Tag
+  constructor: (record) ->
+    @href = record.href
+    @name = record.name
+    #@url = record.url
+    @slug = $.grep(@href.split('/'), (e) -> e != "")
+
+
+  render: ->
+    "<li"
+
+$.fn.Readings.TagList = (category) ->
+    this.each ->
+      list = $(this)
+      $.ajax
+        url: Readings.config.get('wlurl') + "/api/#{@category}"
+        contentType: "json"
+        success: (data) ->
+          console.log(data)
+          tags = $.map data, (rec) -> new Readings.Tag(rec)
+          list.empty()
+          for t in tags
+            list.append t.render()
+
+
+class Readings.TagList
+  defaults: null
+  constructor: (list, options) ->
+    @options = $.extend @defaults, options
+    if not list.tag_list?
+      list.tag_list = this
+    list.tag_list
+
+  load: ->
+    $.ajax
+      url: Readings.config.get('wlurl') + "/api/#{@category}"
+      success: ->
+        true
diff --git a/js/app/TagList.js b/js/app/TagList.js
new file mode 100644 (file)
index 0000000..35dd0e5
--- /dev/null
@@ -0,0 +1,69 @@
+(function() {
+
+  Readings.Tag = (function() {
+
+    function Tag(record) {
+      this.href = record.href;
+      this.name = record.name;
+      this.slug = $.grep(this.href.split('/'), function(e) {
+        return e !== "";
+      });
+    }
+
+    Tag.prototype.render = function() {
+      return "<li";
+    };
+
+    return Tag;
+
+  })();
+
+  $.fn.Readings.TagList = function(category) {
+    return this.each(function() {
+      var list;
+      list = $(this);
+      return $.ajax({
+        url: Readings.config.get('wlurl') + ("/api/" + this.category),
+        contentType: "json",
+        success: function(data) {
+          var t, tags, _i, _len, _results;
+          console.log(data);
+          tags = $.map(data, function(rec) {
+            return new Readings.Tag(rec);
+          });
+          list.empty();
+          _results = [];
+          for (_i = 0, _len = tags.length; _i < _len; _i++) {
+            t = tags[_i];
+            _results.push(list.append(t.render()));
+          }
+          return _results;
+        }
+      });
+    });
+  };
+
+  Readings.TagList = (function() {
+
+    TagList.prototype.defaults = null;
+
+    function TagList(list, options) {
+      this.options = $.extend(this.defaults, options);
+      if (!(list.tag_list != null)) list.tag_list = this;
+      list.tag_list;
+    }
+
+    TagList.prototype.load = function() {
+      return $.ajax({
+        url: Readings.config.get('wlurl') + ("/api/" + this.category),
+        success: function() {
+          return true;
+        }
+      });
+    };
+
+    return TagList;
+
+  })();
+
+}).call(this);
diff --git a/js/app/app.coffee b/js/app/app.coffee
new file mode 100644 (file)
index 0000000..390729a
--- /dev/null
@@ -0,0 +1,16 @@
+
+window.Readings = {}
+$.fn.Readings = {}
+
+
+$(document).on 'pageinit', (ev) ->
+  Readings.config = new Readings.Config
+    wlurl: 'http://readings.local'
+    categories:
+      'authors': 'autor',
+      'epochs': 'epoka',
+      'genres': 'gatunek',
+      'kinds': 'rodzaj',
+      'themes': 'motyw'
+
+  Readings.category_list $('#list-categories')
\ No newline at end of file
diff --git a/js/app/app.js b/js/app/app.js
new file mode 100644 (file)
index 0000000..79aa20c
--- /dev/null
@@ -0,0 +1,21 @@
+(function() {
+
+  window.Readings = {};
+
+  $.fn.Readings = {};
+
+  $(document).on('pageinit', function(ev) {
+    Readings.config = new Readings.Config({
+      wlurl: 'http://readings.local',
+      categories: {
+        'authors': 'autor',
+        'epochs': 'epoka',
+        'genres': 'gatunek',
+        'kinds': 'rodzaj',
+        'themes': 'motyw'
+      }
+    });
+    return Readings.category_list($('#list-categories'));
+  });
+
+}).call(this);