endlich!!!
authorMarcin Koziej <marcin@lolownia.org>
Thu, 12 Jul 2012 07:31:08 +0000 (09:31 +0200)
committerMarcin Koziej <marcin@lolownia.org>
Thu, 12 Jul 2012 07:31:08 +0000 (09:31 +0200)
categories.html [new file with mode: 0644]
index.html [deleted file]
js/app/Controller.coffee
js/app/Controller.js
js/app/TagList.coffee
js/app/TagList.js
js/app/app.coffee
js/app/app.js
js/app/reader.coffee [new file with mode: 0644]
js/app/reader.js [new file with mode: 0644]
tags.html [new file with mode: 0644]

diff --git a/categories.html b/categories.html
new file mode 100644 (file)
index 0000000..4a3d7d2
--- /dev/null
@@ -0,0 +1,82 @@
+<!--
+       jQuery Mobile Boilerplate
+       index.html
+-->
+<!doctype html>
+<html>
+<head>
+       <title> jQuery Mobile Boilerplate </title>
+
+       <meta charset="utf-8">
+       <meta name="viewport" content="width=device-width, initial-scale=1">
+       <meta name="apple-mobile-web-app-capable" content="yes">
+       <meta name="apple-mobile-web-app-status-bar-style" content="black">
+       <meta name="HandheldFriendly" content="True">
+       <meta name="MobileOptimized" content="320">
+
+<!-- Home screen icon  Mathias Bynens mathiasbynens.be/notes/touch-icons -->
+       <!-- For iPhone 4 with high-resolution Retina display: -->
+       <link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon.png">
+       <!-- For first-generation iPad: -->
+       <link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon.png">
+       <!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
+       <link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png">
+       <!-- For nokia devices and desktop browsers : -->
+       <link rel="shortcut icon" href="favicon.ico" />
+       
+       <!-- Mobile IE allows us to activate ClearType technology for smoothing fonts for easy reading -->
+       <meta http-equiv="cleartype" content="on">
+
+       <!-- 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" />
+
+       <!-- Javascript includes -->
+<!--   <script
+       src="http://code.jquery.com/jquery-1.7.1.min.js"></script>-->
+       <script src="js/jquery-1.7.2.js"></script>
+
+       <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/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 src="js/jquery.cookie.js"></script>
+       <!-- Startup Images for iDevices -->
+       <script>(function(){var a;if(navigator.platform==="iPad"){a=window.orientation!==90||window.orientation===-90?"images/startup-tablet-landscape.png":"images/startup-tablet-portrait.png"}else{a=window.devicePixelRatio===2?"images/startup-retina.png":"images/startup.png"}document.write('<link rel="apple-touch-startup-image" href="'+a+'"/>')})()</script>
+       <!-- The script prevents links from opening in mobile safari. https://gist.github.com/1042026 -->
+       <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> 
+  <!-- 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>
+
+
+</body>
+</html>
diff --git a/index.html b/index.html
deleted file mode 100644 (file)
index 518af86..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-<!--
-       jQuery Mobile Boilerplate
-       index.html
--->
-<!doctype html>
-<html>
-<head>
-       <title> jQuery Mobile Boilerplate </title>
-
-       <meta charset="utf-8">
-       <meta name="viewport" content="width=device-width, initial-scale=1">
-       <meta name="apple-mobile-web-app-capable" content="yes">
-       <meta name="apple-mobile-web-app-status-bar-style" content="black">
-       <meta name="HandheldFriendly" content="True">
-       <meta name="MobileOptimized" content="320">
-
-<!-- Home screen icon  Mathias Bynens mathiasbynens.be/notes/touch-icons -->
-       <!-- For iPhone 4 with high-resolution Retina display: -->
-       <link rel="apple-touch-icon-precomposed" sizes="114x114" href="apple-touch-icon.png">
-       <!-- For first-generation iPad: -->
-       <link rel="apple-touch-icon-precomposed" sizes="72x72" href="apple-touch-icon.png">
-       <!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
-       <link rel="apple-touch-icon-precomposed" href="apple-touch-icon-precomposed.png">
-       <!-- For nokia devices and desktop browsers : -->
-       <link rel="shortcut icon" href="favicon.ico" />
-       
-       <!-- Mobile IE allows us to activate ClearType technology for smoothing fonts for easy reading -->
-       <meta http-equiv="cleartype" content="on">
-
-       <!-- 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" />
-
-       <!-- Javascript includes -->
-       <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
-       <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/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 src="js/jquery.cookie.js"></script>
-       <!-- Startup Images for iDevices -->
-       <script>(function(){var a;if(navigator.platform==="iPad"){a=window.orientation!==90||window.orientation===-90?"images/startup-tablet-landscape.png":"images/startup-tablet-portrait.png"}else{a=window.devicePixelRatio===2?"images/startup-retina.png":"images/startup.png"}document.write('<link rel="apple-touch-startup-image" href="'+a+'"/>')})()</script>
-       <!-- The script prevents links from opening in mobile safari. https://gist.github.com/1042026 -->
-       <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> 
-  <!-- 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>
-
-  <!-- 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>
-
-</body>
-</html>
index b5db24c..d2b6d36 100644 (file)
@@ -1,7 +1,16 @@
 # main controller
 
-Readings.category_list = (list) ->
+$.fn.Readings.CategoryList = ->
+  list = $(this)
   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
+    list.append "<li><a href=\"tags.html?category=#{cat}\" data-category=\"#{cat}\">#{labelname}</a></li>"
+  # $('a', list).on 'tap', (ev) ->
+  #   ev.preventDefault()
+  #   $i = $(this)
+  #   category = $i.data 'category'
+  #   false
+#    $.mobile.changePage '#page-tags',
+#      category: category
+  console.log("category list updte")
+  list.listview 'refresh'
index 9222b13..cb37c6f 100644 (file)
@@ -1,13 +1,16 @@
+// Generated by CoffeeScript 1.3.3
 (function() {
 
-  Readings.category_list = function(list) {
-    var cat, labelname, _ref;
+  $.fn.Readings.CategoryList = function() {
+    var cat, labelname, list, _ref;
+    list = $(this);
     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>");
+      list.append("<li><a href=\"tags.html?category=" + cat + "\" data-category=\"" + cat + "\">" + labelname + "</a></li>");
     }
+    console.log("category list updte");
     return list.listview('refresh');
   };
 
index a481284..3c745c8 100644 (file)
@@ -6,34 +6,23 @@ class Readings.Tag
     #@url = record.url
     @slug = $.grep(@href.split('/'), (e) -> e != "")
 
-
   render: ->
-    "<li"
+    "<li><a href=\"#\">#{@name}</a></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: ->
+#  dont_filter = ['kinds']
+  this.each ->
+    $('[data-role=header] h1').text Readings.config.get('categories')[category]
+    list = $('[data-role=listview]', this)
+#    list.listview
+#      filter: dont_filter.indexOf(category) < 0
     $.ajax
-      url: Readings.config.get('wlurl') + "/api/#{@category}"
-      success: ->
-        true
+      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()
+        list.listview 'refresh'
index 35dd0e5..cecadcf 100644 (file)
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
 (function() {
 
   Readings.Tag = (function() {
@@ -11,7 +12,7 @@
     }
 
     Tag.prototype.render = function() {
-      return "<li";
+      return "<li><a href=\"#\">" + this.name + "</a></li>";
     };
 
     return Tag;
   $.fn.Readings.TagList = function(category) {
     return this.each(function() {
       var list;
-      list = $(this);
+      $('[data-role=header] h1').text(Readings.config.get('categories')[category]);
+      list = $('[data-role=listview]', this);
       return $.ajax({
-        url: Readings.config.get('wlurl') + ("/api/" + this.category),
+        url: Readings.config.get('wlurl') + ("/api/" + category),
         contentType: "json",
         success: function(data) {
-          var t, tags, _i, _len, _results;
+          var t, tags, _i, _len;
           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()));
+            list.append(t.render());
           }
-          return _results;
+          return list.listview('refresh');
         }
       });
     });
   };
 
-  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);
index 390729a..0ca151c 100644 (file)
@@ -1,9 +1,19 @@
 
 window.Readings = {}
-$.fn.Readings = {}
 
+# Readings jquery plugin dispatcher.
+$.fn.Readings =  ->
+  meth = arguments[0]
+  args = []
+  for a in arguments
+    args.push a
+  args.shift()
+  $.fn.Readings[meth].apply(this, args)
 
-$(document).on 'pageinit', (ev) ->
+
+Readings.init = ->
+  if Readings.initialized?
+    return
   Readings.config = new Readings.Config
     wlurl: 'http://readings.local'
     categories:
@@ -12,5 +22,14 @@ $(document).on 'pageinit', (ev) ->
       'genres': 'gatunek',
       'kinds': 'rodzaj',
       'themes': 'motyw'
+  Readings.initialized = true
+
+$(document).on 'pageinit', '#page-categories' , (ev) ->
+  Readings.init()
+  $('#list-categories').Readings 'CategoryList'
 
-  Readings.category_list $('#list-categories')
\ No newline at end of file
+rcategory = /category=(\w+)/
+$(document).on 'pageshow', "#page-tags", (ev, ui) ->
+  category = rcategory.exec($(this).attr('data-url'))
+  if category? and category[1]?
+    $(this).Readings 'TagList', category[1]
index 79aa20c..c5a9521 100644 (file)
@@ -1,10 +1,25 @@
+// Generated by CoffeeScript 1.3.3
 (function() {
+  var rcategory;
 
   window.Readings = {};
 
-  $.fn.Readings = {};
+  $.fn.Readings = function() {
+    var a, args, meth, _i, _len;
+    meth = arguments[0];
+    args = [];
+    for (_i = 0, _len = arguments.length; _i < _len; _i++) {
+      a = arguments[_i];
+      args.push(a);
+    }
+    args.shift();
+    return $.fn.Readings[meth].apply(this, args);
+  };
 
-  $(document).on('pageinit', function(ev) {
+  Readings.init = function() {
+    if (Readings.initialized != null) {
+      return;
+    }
     Readings.config = new Readings.Config({
       wlurl: 'http://readings.local',
       categories: {
         'themes': 'motyw'
       }
     });
-    return Readings.category_list($('#list-categories'));
+    return Readings.initialized = true;
+  };
+
+  $(document).on('pageinit', '#page-categories', function(ev) {
+    Readings.init();
+    return $('#list-categories').Readings('CategoryList');
+  });
+
+  rcategory = /category=(\w+)/;
+
+  $(document).on('pageshow', "#page-tags", function(ev, ui) {
+    var category;
+    category = rcategory.exec($(this).attr('data-url'));
+    if ((category != null) && (category[1] != null)) {
+      return $(this).Readings('TagList', category[1]);
+    }
   });
 
 }).call(this);
diff --git a/js/app/reader.coffee b/js/app/reader.coffee
new file mode 100644 (file)
index 0000000..d106ac1
--- /dev/null
@@ -0,0 +1,28 @@
+
+
+$.fn.extend
+  load_book: (slug) ->
+    this.each ->
+      $.ajax
+        type: 'GET',
+        contentType: 'html',
+        url: '/fixtures/katalog_lektura_lord-jim.html',
+        error: (e) ->
+          console.log "Error #{e}"
+        success: (page) =>
+          $page = $(page)
+          $text = $page.find '#book-text'
+          $toc = $text.find '#toc'
+
+          this.toc = $toc.find('a').map (_i, link) =>
+            {
+              anchor: link.href,
+              label: $(link).text()
+            }
+
+          $toc.remove()
+          this.text = $text
+
+          $('[data-role=header] h1', this).text(
+            this.text.find('h1 .title').text()
+            )
diff --git a/js/app/reader.js b/js/app/reader.js
new file mode 100644 (file)
index 0000000..a978e54
--- /dev/null
@@ -0,0 +1,35 @@
+// Generated by CoffeeScript 1.3.3
+(function() {
+
+  $.fn.extend({
+    load_book: function(slug) {
+      return this.each(function() {
+        var _this = this;
+        return $.ajax({
+          type: 'GET',
+          contentType: 'html',
+          url: '/fixtures/katalog_lektura_lord-jim.html',
+          error: function(e) {
+            return console.log("Error " + e);
+          },
+          success: function(page) {
+            var $page, $text, $toc;
+            $page = $(page);
+            $text = $page.find('#book-text');
+            $toc = $text.find('#toc');
+            _this.toc = $toc.find('a').map(function(_i, link) {
+              return {
+                anchor: link.href,
+                label: $(link).text()
+              };
+            });
+            $toc.remove();
+            _this.text = $text;
+            return $('[data-role=header] h1', _this).text(_this.text.find('h1 .title').text());
+          }
+        });
+      });
+    }
+  });
+
+}).call(this);
diff --git a/tags.html b/tags.html
new file mode 100644 (file)
index 0000000..e7347a6
--- /dev/null
+++ b/tags.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<html>
+<head>
+       <title>Readings</title>
+       <meta charset="utf-8">
+       <meta name="viewport" content="width=device-width, initial-scale=1"> 
+</head> 
+<body>
+  <!-- Tag List -->
+  <div data-role="page" id="page-tags">
+    <div data-role="header">
+      <a data-rel="back" href="#">Back</a>
+      <h1>Loading</h1>
+    </div>
+    <div data-role="content" style="padding: 15px">
+      <ul data-role="listview" data-filter="true" data-filter-placeholder="Search..." data-divider-theme="b" data-inset="false" id="list-tags">
+      </ul>
+    </div>
+  </div>
+</body>
+</html>