Start parsing boards, threads, and posts.

This commit is contained in:
Nicolas Stepien 2012-08-27 02:59:32 +02:00
parent 62076648c3
commit 93f4b4e7d5
2 changed files with 134 additions and 7 deletions

View File

@ -73,7 +73,7 @@
*/
(function() {
var $, $$, Conf, Config, UI, d, g;
var $, $$, Board, Conf, Config, Main, Post, Thread, UI, d, g;
Config = {
main: {
@ -284,6 +284,13 @@
return root.querySelector(selector);
};
$$ = function(selector, root) {
if (root == null) {
root = d.body;
}
return Array.prototype.slice.call(root.querySelectorAll(selector));
};
$.extend = function(object, properties) {
var key, val;
for (key in properties) {
@ -592,11 +599,86 @@
}
});
$$ = function(selector, root) {
if (root == null) {
root = d.body;
g.boards = {};
Board = (function() {
function Board(ID) {
this.ID = ID;
this.threads = {};
this.posts = {};
g.boards[this.ID] = this;
}
return Board;
})();
g.threads = {};
Thread = (function() {
function Thread(root, board) {
this.root = root;
this.board = board;
this.ID = +root.id.slice(1);
this.hr = root.nextElementSibling;
this.posts = {};
g.threads[this.ID] = board.threads[this.ID] = this;
}
return Thread;
})();
g.posts = {};
Post = (function() {
function Post(root, thread, board) {
this.root = root;
this.thread = thread;
this.board = board;
this.ID = +root.id.slice(2);
this.el = $('.post', root);
g.posts[this.ID] = thread.posts[this.ID] = board.posts[this.ID] = this;
}
return Post;
})();
Main = {
init: function() {
var pathname;
pathname = location.pathname.split('/');
g.BOARD = new Board(pathname[1]);
if (g.REPLY = pathname[2] === 'res') {
g.THREAD = +pathname[3];
}
return $.ready(Main.ready);
},
ready: function() {
var board, child, thread, _i, _j, _len, _len1, _ref, _ref1;
board = $('.board');
_ref = board.children;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
if (child.className === 'thread') {
thread = new Thread(child, g.BOARD);
_ref1 = thread.root.children;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
child = _ref1[_j];
if ($.hasClass(child, 'postContainer')) {
new Post(child, thread, g.BOARD);
}
}
}
}
return $.log(g);
}
return Array.prototype.slice.call(root.querySelectorAll(selector));
};
Main.init();
}).call(this);

View File

@ -243,6 +243,8 @@ not chainable
###
$ = (selector, root=d.body) ->
root.querySelector selector
$$ = (selector, root=d.body) ->
Array::slice.call root.querySelectorAll selector
$.extend = (object, properties) ->
for key, val of properties
@ -468,5 +470,48 @@ $.extend $,
set: (name, value) ->
localStorage.setItem $.NAMESPACE + name, JSON.stringify value
$$ = (selector, root=d.body) ->
Array::slice.call root.querySelectorAll selector
g.boards = {}
class Board
constructor: (@ID) ->
@threads = {}
@posts = {}
g.boards[@ID] = @
g.threads = {}
class Thread
constructor: (@root, @board) ->
@ID = +root.id[1..]
@hr = root.nextElementSibling
@posts = {}
g.threads[@ID] = board.threads[@ID] = @
g.posts = {}
class Post
constructor: (@root, @thread, @board) ->
@ID = +root.id[2..]
@el = $ '.post', root
g.posts[@ID] = thread.posts[@ID] = board.posts[@ID] = @
Main =
init: ->
pathname = location.pathname.split '/'
g.BOARD = new Board pathname[1]
if g.REPLY = pathname[2] is 'res'
g.THREAD = +pathname[3]
$.ready Main.ready
ready: ->
board = $ '.board'
for child in board.children
if child.className is 'thread'
thread = new Thread child, g.BOARD
for child in thread.root.children
if $.hasClass child, 'postContainer'
new Post child, thread, g.BOARD
$.log g
Main.init()