From c956fba7332f45e9abab07b2b8ac417b0f6514c8 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Thu, 12 Jul 2012 09:31:08 +0200 Subject: [PATCH 1/1] endlich!!! --- index.html => categories.html | 28 +++++++---------------- js/app/Controller.coffee | 15 +++++++++--- js/app/Controller.js | 9 +++++--- js/app/TagList.coffee | 43 +++++++++++++---------------------- js/app/TagList.js | 38 +++++++------------------------ js/app/app.coffee | 25 +++++++++++++++++--- js/app/app.js | 36 ++++++++++++++++++++++++++--- js/app/reader.coffee | 28 +++++++++++++++++++++++ js/app/reader.js | 35 ++++++++++++++++++++++++++++ tags.html | 21 +++++++++++++++++ 10 files changed, 189 insertions(+), 89 deletions(-) rename index.html => categories.html (79%) create mode 100644 js/app/reader.coffee create mode 100644 js/app/reader.js create mode 100644 tags.html diff --git a/index.html b/categories.html similarity index 79% rename from index.html rename to categories.html index 518af86..4a3d7d2 100644 --- a/index.html +++ b/categories.html @@ -28,18 +28,21 @@ - - + + - + + + - - + + @@ -74,21 +77,6 @@ - -
-
- -
-
diff --git a/js/app/Controller.coffee b/js/app/Controller.coffee index b5db24c..d2b6d36 100644 --- a/js/app/Controller.coffee +++ b/js/app/Controller.coffee @@ -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 "
  • #{labelname}
  • " - list.listview 'refresh' \ No newline at end of file + list.append "
  • #{labelname}
  • " + # $('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' diff --git a/js/app/Controller.js b/js/app/Controller.js index 9222b13..cb37c6f 100644 --- a/js/app/Controller.js +++ b/js/app/Controller.js @@ -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("
  • " + labelname + "
  • "); + list.append("
  • " + labelname + "
  • "); } + console.log("category list updte"); return list.listview('refresh'); }; diff --git a/js/app/TagList.coffee b/js/app/TagList.coffee index a481284..3c745c8 100644 --- a/js/app/TagList.coffee +++ b/js/app/TagList.coffee @@ -6,34 +6,23 @@ class Readings.Tag #@url = record.url @slug = $.grep(@href.split('/'), (e) -> e != "") - render: -> - "#{@name}" $.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' diff --git a/js/app/TagList.js b/js/app/TagList.js index 35dd0e5..cecadcf 100644 --- a/js/app/TagList.js +++ b/js/app/TagList.js @@ -1,3 +1,4 @@ +// Generated by CoffeeScript 1.3.3 (function() { Readings.Tag = (function() { @@ -11,7 +12,7 @@ } Tag.prototype.render = function() { - return "" + this.name + ""; }; return Tag; @@ -21,49 +22,26 @@ $.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); diff --git a/js/app/app.coffee b/js/app/app.coffee index 390729a..0ca151c 100644 --- a/js/app/app.coffee +++ b/js/app/app.coffee @@ -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] diff --git a/js/app/app.js b/js/app/app.js index 79aa20c..c5a9521 100644 --- a/js/app/app.js +++ b/js/app/app.js @@ -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: { @@ -15,7 +30,22 @@ '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 index 0000000..d106ac1 --- /dev/null +++ b/js/app/reader.coffee @@ -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 index 0000000..a978e54 --- /dev/null +++ b/js/app/reader.js @@ -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 index 0000000..e7347a6 --- /dev/null +++ b/tags.html @@ -0,0 +1,21 @@ + + + + Readings + + + + + +
    +
    + Back +

    Loading

    +
    +
    +
      +
    +
    +
    + + -- 2.20.1