From b2dcc4cec0edb145ed13c26537c94b593691954f Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Sun, 8 Jul 2012 20:14:51 +0200 Subject: [PATCH] first take --- index.html | 66 +++++++++++++++++++++++--------------- js/app/AjaxList.js | 25 +++++++++++++++ js/app/Config.coffee | 6 ++++ js/app/Config.js | 17 ++++++++++ js/app/Controller.coffee | 7 ++++ js/app/Controller.js | 14 ++++++++ js/app/TagList.coffee | 39 +++++++++++++++++++++++ js/app/TagList.js | 69 ++++++++++++++++++++++++++++++++++++++++ js/app/app.coffee | 16 ++++++++++ js/app/app.js | 21 ++++++++++++ 10 files changed, 255 insertions(+), 25 deletions(-) create mode 100644 js/app/AjaxList.js create mode 100644 js/app/Config.coffee create mode 100644 js/app/Config.js create mode 100644 js/app/Controller.coffee create mode 100644 js/app/Controller.js create mode 100644 js/app/TagList.coffee create mode 100644 js/app/TagList.js create mode 100644 js/app/app.coffee create mode 100644 js/app/app.js diff --git a/index.html b/index.html index a8ec171..518af86 100644 --- a/index.html +++ b/index.html @@ -29,6 +29,7 @@ + @@ -38,7 +39,15 @@ - + + + + + + + + + @@ -49,30 +58,37 @@ -
- -
-

jQuery Mobile Boilerplate 1.1

-
+ +
+
+ +
+
-
- - + +
+
+ +
+
-
- -
-

© 2012 - jQuery Mobile Boilerplate

-
- -
- \ No newline at end of file + diff --git a/js/app/AjaxList.js b/js/app/AjaxList.js new file mode 100644 index 0000000..d2d0897 --- /dev/null +++ b/js/app/AjaxList.js @@ -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 index 0000000..00df4a1 --- /dev/null +++ b/js/app/Config.coffee @@ -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 index 0000000..87a99b7 --- /dev/null +++ b/js/app/Config.js @@ -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 index 0000000..b5db24c --- /dev/null +++ b/js/app/Controller.coffee @@ -0,0 +1,7 @@ +# main controller + +Readings.category_list = (list) -> + list.empty() + for cat, labelname of Readings.config.get 'categories' + list.append "
  • #{labelname}
  • " + 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 index 0000000..9222b13 --- /dev/null +++ b/js/app/Controller.js @@ -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("
  • " + labelname + "
  • "); + } + return list.listview('refresh'); + }; + +}).call(this); diff --git a/js/app/TagList.coffee b/js/app/TagList.coffee new file mode 100644 index 0000000..a481284 --- /dev/null +++ b/js/app/TagList.coffee @@ -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: -> + " + 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 index 0000000..35dd0e5 --- /dev/null +++ b/js/app/TagList.js @@ -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 " + 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 index 0000000..79aa20c --- /dev/null +++ b/js/app/app.js @@ -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); -- 2.20.1