Merge branch 'master' of github.com:psychobunny/node-forum
Conflicts: src/webserver.jsv1.18.x
commit
71e410d571
@ -1,70 +0,0 @@
|
||||
// https://gist.github.com/balupton/858093/raw/187833dc344a576e404fbdd40ef96de1f944b33b/ajaxify-html4.js
|
||||
console.log('derp2');
|
||||
(function(window,undefined){
|
||||
|
||||
// Prepare our Variables
|
||||
var
|
||||
document = window.document,
|
||||
$ = window.jQuery;
|
||||
|
||||
// Wait for Document
|
||||
$(document).ready(function(){
|
||||
// Prepare Variables
|
||||
var
|
||||
$content = $('#content'),
|
||||
$body = $(document.body),
|
||||
rootUrl = document.location.protocol+'//'+(document.location.hostname||document.location.host);
|
||||
console.log('derp');
|
||||
// Ajaxify our Internal Links
|
||||
$.fn.ajaxify = function(){
|
||||
|
||||
|
||||
// Ajaxify internal links
|
||||
$(this).find('a[href^="/"],a[href^="'+rootUrl+'"]').unbind('click').bind('click',function(event){
|
||||
var $this = $(this), url = $this.attr('href'), title = $this.attr('title')||null, relativeUrl = $(this).attr('href').replace(rootUrl,'');
|
||||
document.location.hash = '!' + relativeUrl;
|
||||
event.preventDefault();
|
||||
return false;
|
||||
});
|
||||
|
||||
// Chain
|
||||
return this;
|
||||
};
|
||||
|
||||
// Ajaxify Page
|
||||
$body.ajaxify();
|
||||
|
||||
// Hook into State Changes
|
||||
$(window).bind('hashchange',function(){
|
||||
// Prepare
|
||||
var
|
||||
relativeUrl = document.location.hash.replace(/^\//,'').replace(/^#!/,''),
|
||||
fullUrl = rootUrl+relativeUrl;
|
||||
|
||||
// Set Loading
|
||||
$body.addClass('loading');
|
||||
|
||||
// Start Fade Out
|
||||
$content.fadeOut(800);
|
||||
|
||||
// Ajax Request the Traditional Page
|
||||
$.get(fullUrl,function(data){
|
||||
console.log('here');
|
||||
// Find the content in the page's html, and apply it to our current page's content
|
||||
$content.stop(true,true).show();
|
||||
$content.html(data).ajaxify();
|
||||
//$content.html($(data).find('#content')).ajaxify();
|
||||
if ( $content.ScrollTo||false ) $content.ScrollTo(); // http://balupton.com/projects/jquery-scrollto
|
||||
$body.removeClass('loading');
|
||||
|
||||
// Inform Google Analytics of the change
|
||||
if ( typeof pageTracker !== 'undefined' ) {
|
||||
pageTracker._trackPageview(relativeUrl);
|
||||
}
|
||||
}); // end get
|
||||
|
||||
}); // end onStateChange
|
||||
|
||||
}); // end onDomLoad
|
||||
|
||||
})(window); // end closure
|
@ -0,0 +1,40 @@
|
||||
var RDB = require('./redis.js');
|
||||
|
||||
(function(Posts) {
|
||||
//data structure
|
||||
//*global:next_post_id
|
||||
// *pid:1:content
|
||||
// *pid:1:uid
|
||||
// *pid:1:timestamp
|
||||
// ***pid:1:replies
|
||||
// *uid:1:posts
|
||||
|
||||
|
||||
|
||||
Posts.get = function(topic) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Posts.reply = function() {
|
||||
|
||||
};
|
||||
|
||||
Posts.create = function(content, callback) {
|
||||
if (global.uid === null) return;
|
||||
|
||||
RDB.incr('global:next_post_id', function(pid) {
|
||||
// Posts Info
|
||||
RDB.set('pid:' + pid + ':content', content);
|
||||
RDB.set('pid:' + pid + ':uid', global.uid);
|
||||
RDB.set('pid:' + pid + ':timestamp', new Date().getTime());
|
||||
|
||||
// User Details - move this out later
|
||||
RDB.lpush('uid:' + uid + ':posts', pid);
|
||||
|
||||
if (callback) callback(pid);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}(exports));
|
@ -0,0 +1,111 @@
|
||||
var RDB = require('./redis.js'),
|
||||
posts = require('./posts.js');
|
||||
|
||||
|
||||
|
||||
|
||||
(function(Topics) {
|
||||
//data structure
|
||||
|
||||
//*global:next_topic_id
|
||||
// *tid:1:title
|
||||
// *tid:1:uid
|
||||
// *tid:1:posts (array of pid)
|
||||
// *tid:1:timestamp
|
||||
// *uid:1:topics
|
||||
// *topic:slug:how-to-eat-chicken:tid
|
||||
|
||||
|
||||
|
||||
Topics.get_by_category = function(category, start, end) {
|
||||
|
||||
}
|
||||
|
||||
Topics.get = function(start, end) {
|
||||
if (start == null) start = 0;
|
||||
if (end == null) end = start + 10;
|
||||
|
||||
|
||||
RDB.lrange('topics:tid', start, end, function() {
|
||||
global.socket.emit
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Topics.post = function(title, content, category) {
|
||||
if (global.uid === null) {
|
||||
global.socket.emit('event:alert', {
|
||||
title: 'Thank you for posting',
|
||||
message: 'Since you are unregistered, your post is awaiting approval. Click here to register now.',
|
||||
type: 'warning',
|
||||
timeout: 7500,
|
||||
clickfn: function() {
|
||||
ajaxify.go('register');
|
||||
}
|
||||
});
|
||||
return; // for now, until anon code is written.
|
||||
}
|
||||
|
||||
RDB.incr('global:next_topic_id', function(tid) {
|
||||
// Global Topics
|
||||
if (global.uid !== null) {
|
||||
RDB.lpush('topics:tid', tid);
|
||||
} else {
|
||||
// need to add some unique key sent by client so we can update this with the real uid later
|
||||
RDB.lpush('topics:queued:tid', tid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (category) {
|
||||
RDB.lpush('topics:' + category + ':tid', tid);
|
||||
}
|
||||
|
||||
// Topic Info
|
||||
RDB.set('tid:' + tid + ':title', title);
|
||||
RDB.set('tid:' + tid + ':uid', global.uid);
|
||||
RDB.set('tid:' + tid + ':timestamp', new Date().getTime());
|
||||
|
||||
RDB.set('topic:slug:' + slugify(title) + ':tid', tid);
|
||||
|
||||
// Posts
|
||||
posts.create(content, function(pid) {
|
||||
RDB.lpush('tid:' + tid + ':posts', pid);
|
||||
});
|
||||
|
||||
// User Details - move this out later
|
||||
RDB.lpush('uid:' + uid + ':topics', tid);
|
||||
|
||||
|
||||
global.socket.emit('event:alert', {
|
||||
title: 'Thank you for registering',
|
||||
message: 'You have successfully registered - welcome to nodebb!',
|
||||
type: 'notify',
|
||||
timeout: 2000
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
}(exports));
|
||||
|
||||
|
||||
//http://dense13.com/blog/2009/05/03/converting-string-to-slug-javascript/
|
||||
function slugify(str) {
|
||||
str = str.replace(/^\s+|\s+$/g, ''); // trim
|
||||
str = str.toLowerCase();
|
||||
|
||||
// remove accents, swap ñ for n, etc
|
||||
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
|
||||
var to = "aaaaeeeeiiiioooouuuunc------";
|
||||
for (var i=0, l=from.length ; i<l ; i++) {
|
||||
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
|
||||
}
|
||||
|
||||
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
|
||||
.replace(/\s+/g, '-') // collapse whitespace and replace by -
|
||||
.replace(/-+/g, '-'); // collapse dashes
|
||||
|
||||
return str;
|
||||
}
|
Loading…
Reference in New Issue