From 14d7453a2326f61c344076e34fd31353225b08b1 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 2 Mar 2014 13:28:09 -0500 Subject: [PATCH 01/13] bundling socket.io client library into minfile, minfile always used from this point forward, even in development mode. Development mode will not compress the scripts, but will just concatenate. --- public/templates/header.tpl | 1 - src/meta.js | 34 +++++++++++++++++++++++++++------- src/plugins.js | 1 + src/routes/meta.js | 18 ++++++++++++++---- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/public/templates/header.tpl b/public/templates/header.tpl index decbae43da..56bfc48638 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -28,7 +28,6 @@ - diff --git a/src/meta.js b/src/meta.js index b8c12a0721..2108cc277c 100644 --- a/src/meta.js +++ b/src/meta.js @@ -250,6 +250,7 @@ var fs = require('fs'), jsPaths = scripts.map(function (jsPath) { jsPath = path.normalize(jsPath); + // The filter:scripts.get plugin will be deprecated as of v0.5.0, specify scripts in plugin.json instead if (jsPath.substring(0, 7) === 'plugins') { var matches = _.map(plugins.staticDirs, function(realPath, mappedPath) { if (jsPath.match(mappedPath)) { @@ -271,15 +272,18 @@ var fs = require('fs'), } }); + // Remove scripts that could not be found (remove this line at v0.5.0) Meta.js.scripts = jsPaths.filter(function(path) { return path !== null }); - if (process.env.NODE_ENV !== 'development') { - callback(null, [ - Meta.js.minFile - ]); - } else { - callback(null, scripts); - } + // Add socket.io client library + Meta.js.scripts.push(path.join(__dirname, '../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js')); + + // Add plugin scripts + Meta.js.scripts = Meta.js.scripts.concat(plugins.clientScripts); + + callback(null, [ + Meta.js.minFile + ]); }); }, minify: function (callback) { @@ -294,6 +298,22 @@ var fs = require('fs'), minified = uglifyjs.minify(jsPaths); this.cache = minified.code; callback(); + }, + compress: function(callback) { + var uglifyjs = require('uglify-js'), + jsPaths = this.scripts, + compressed; + + if (process.env.NODE_ENV === 'development') { + winston.info('Compressing client-side libraries into one file'); + } + + minified = uglifyjs.minify(jsPaths, { + mangle: false, + compress: false + }); + this.cache = minified.code; + callback(); } }; diff --git a/src/plugins.js b/src/plugins.js index f334d8b0da..c704049641 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -17,6 +17,7 @@ var fs = require('fs'), Plugins.staticDirs = {}; Plugins.cssFiles = []; Plugins.lessFiles = []; + Plugins.clientScripts = []; Plugins.initialized = false; diff --git a/src/routes/meta.js b/src/routes/meta.js index 0900ca07d8..0a09074b2c 100644 --- a/src/routes/meta.js +++ b/src/routes/meta.js @@ -45,12 +45,22 @@ var path = require('path'), }); app.get('/nodebb.min.js', function(req, res) { + var sendCached = function() { + return res.type('text/javascript').send(meta.js.cache); + } if (meta.js.cache) { - res.type('text/javascript').send(meta.js.cache); + sendCached(); } else { - meta.js.minify(function() { - res.type('text/javascript').send(meta.js.cache); - }); + if (app.enabled('minification')) { + meta.js.minify(function() { + sendCached(); + }); + } else { + // Compress only + meta.js.compress(function() { + sendCached(); + }); + } } }); }; From 3860abdc24ec02cb5be49a6b055f9511b5b2c291 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 2 Mar 2014 13:31:13 -0500 Subject: [PATCH 02/13] plugins can now pass in scripts in plugin.json, and they will be bundled into nodebb.min.js --- src/plugins.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/plugins.js b/src/plugins.js index c704049641..35d05fe5e3 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -223,6 +223,20 @@ var fs = require('fs'), })); } + next(); + }, + function(next) { + // Client-side scripts + if (pluginData.scripts && pluginData.scripts instanceof Array) { + if (global.env === 'development') { + winston.info('[plugins] Found ' + pluginData.scripts.length + ' js file(s) for plugin ' + pluginData.id); + } + + Plugins.clientScripts = Plugins.clientScripts.concat(pluginData.scripts.map(function(file) { + return path.join(pluginData.id, file); + })); + } + next(); } ], function(err) { From 4c2a6953f188a2ae151e5b2151ba0044e7fed330 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 2 Mar 2014 15:34:12 -0500 Subject: [PATCH 03/13] concatenating the client scripts, instead of compressing, in development mode --- src/meta.js | 25 ++++++++++++++----------- src/routes/meta.js | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/meta.js b/src/meta.js index 2108cc277c..2c3b6c66f3 100644 --- a/src/meta.js +++ b/src/meta.js @@ -299,21 +299,24 @@ var fs = require('fs'), this.cache = minified.code; callback(); }, - compress: function(callback) { - var uglifyjs = require('uglify-js'), - jsPaths = this.scripts, - compressed; - + concatenate: function(callback) { if (process.env.NODE_ENV === 'development') { - winston.info('Compressing client-side libraries into one file'); + winston.info('Concatenating client-side libraries into one file'); } - minified = uglifyjs.minify(jsPaths, { - mangle: false, - compress: false + async.map(this.scripts, function(path, next) { + fs.readFile(path, { encoding: 'utf-8' }, next); + }, function(err, contents) { + if (err) { + winston.error('[meta.js.concatenate] Could not minify javascript! Error: ' + err.message); + process.exit(); + } + + Meta.js.cache = contents.reduce(function(output, src) { + return output.length ? output + ';\n' + src : src; + }, ''); + callback(); }); - this.cache = minified.code; - callback(); } }; diff --git a/src/routes/meta.js b/src/routes/meta.js index 0a09074b2c..cc5683b924 100644 --- a/src/routes/meta.js +++ b/src/routes/meta.js @@ -57,7 +57,7 @@ var path = require('path'), }); } else { // Compress only - meta.js.compress(function() { + meta.js.concatenate(function() { sendCached(); }); } From 5553e07bbd9e686f4f7ee99cb3cfd2f6294ed9ce Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 2 Mar 2014 16:29:21 -0500 Subject: [PATCH 04/13] moving socket.IO client lib to top of file, just in case --- src/meta.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/meta.js b/src/meta.js index 2c3b6c66f3..5520cc4a58 100644 --- a/src/meta.js +++ b/src/meta.js @@ -276,7 +276,7 @@ var fs = require('fs'), Meta.js.scripts = jsPaths.filter(function(path) { return path !== null }); // Add socket.io client library - Meta.js.scripts.push(path.join(__dirname, '../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js')); + Meta.js.scripts.unshift(path.join(__dirname, '../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js')); // Add plugin scripts Meta.js.scripts = Meta.js.scripts.concat(plugins.clientScripts); From e70bc9f163a3b2e653694194268a8aeb19ccafca Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 2 Mar 2014 16:33:45 -0500 Subject: [PATCH 05/13] added deprecation warning for plugins using filter:scripts.get --- src/meta.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/meta.js b/src/meta.js index 5520cc4a58..07e9255065 100644 --- a/src/meta.js +++ b/src/meta.js @@ -261,7 +261,10 @@ var fs = require('fs'), }).filter(function(a) { return a; }); if (matches.length) { - var relPath = jsPath.slice(new String('plugins/' + matches[0]).length); + var relPath = jsPath.slice(new String('plugins/' + matches[0]).length), + pluginId = matches[0].split(path.sep)[0]; + + winston.warn('[meta.scripts.get (' + pluginId + ')] filter:scripts.get is deprecated, consider using "scripts" in plugin.json'); return plugins.staticDirs[matches[0]] + relPath; } else { winston.warn('[meta.scripts.get] Could not resolve mapped path: ' + jsPath + '. Are you sure it is defined by a plugin?'); From a8d2b46911c0f5ff45dec95cb3541492ab9addc7 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 2 Mar 2014 16:44:41 -0500 Subject: [PATCH 06/13] fixed incorrect path in plugin script inclusion --- src/plugins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins.js b/src/plugins.js index 35d05fe5e3..688184f81a 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -233,7 +233,7 @@ var fs = require('fs'), } Plugins.clientScripts = Plugins.clientScripts.concat(pluginData.scripts.map(function(file) { - return path.join(pluginData.id, file); + return path.join(__dirname, '../node_modules/', pluginData.id, file); })); } From e4b6d0e1ff0bd2559dd26fe73a956e592fba961a Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sun, 2 Mar 2014 16:58:49 -0500 Subject: [PATCH 07/13] closes #1096 --- public/src/forum/pagination.js | 8 ++++--- public/src/forum/topic.js | 39 +++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/public/src/forum/pagination.js b/public/src/forum/pagination.js index 3b19fce4c1..afd4bf3fb8 100644 --- a/public/src/forum/pagination.js +++ b/public/src/forum/pagination.js @@ -17,8 +17,6 @@ define(function() { return pagination.loadPage(pagination.currentPage - 1); }).on('click', '.next', function() { return pagination.loadPage(pagination.currentPage + 1); - }).on('click', '.page', function() { - return pagination.loadPage($(this).attr('data-page')); }).on('click', '.select_page', function(e) { e.preventDefault(); bootbox.prompt('Enter page number:', function(pageNum) { @@ -77,7 +75,11 @@ define(function() { return false; } - ajaxify.go(window.location.pathname.slice(1) + '?page=' + page); + ajaxify.go(window.location.pathname.slice(1) + '?page=' + page, function() { + if (typeof callback === 'function') { + callback(); + } + }); return true; } diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 6a697f5849..a74c3d18fe 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -309,7 +309,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { var bookmark = localStorage.getItem('topic:' + tid + ':bookmark'); if (window.location.hash) { Topic.scrollToPost(window.location.hash.substr(1), true); - } else if (bookmark) { + } else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1))) { app.alert({ alert_id: 'bookmark', message: '[[topic:bookmark_instructions]]', @@ -324,7 +324,9 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { }); } - updateHeader(); + if (!window.location.hash && !config.usePagination) { + updateHeader(); + } $('#post-container').on('mouseenter', '.favourite-tooltip', function(e) { if (!$(this).data('users-loaded')) { @@ -1037,26 +1039,29 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { if(index > Topic.postCount) { index = Topic.postCount; } + $('#pagination').html(index + ' out of ' + Topic.postCount); $('.progress-bar').width((index / Topic.postCount * 100) + '%'); - if(!parseInt(el.attr('data-index'), 10)) { - localStorage.removeItem('topic:' + templates.get('topic_id') + ':bookmark'); - } else { + var currentBookmark = localStorage.getItem('topic:' + templates.get('topic_id') + ':bookmark'); + if (!currentBookmark || parseInt(el.attr('data-pid'), 10) > parseInt(currentBookmark, 10)) { localStorage.setItem('topic:' + templates.get('topic_id') + ':bookmark', el.attr('data-pid')); + } - if (!scrollingToPost) { - var newUrl = window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + el.attr('data-pid') - if (newUrl !== currentUrl) { - if (history.replaceState) { - history.replaceState({ - url: window.location.pathname.slice(1) + '#' + el.attr('data-pid') - }, null, newUrl); - } - currentUrl = newUrl; + if (!scrollingToPost) { + + var newUrl = window.location.href.replace(window.location.hash, '') + '#' + el.attr('data-pid'); + + if (newUrl !== currentUrl) { + if (history.replaceState) { + history.replaceState({ + url: window.location.pathname.slice(1) + (window.location.search ? window.location.search : '' ) + '#' + el.attr('data-pid') + }, null, newUrl); } + currentUrl = newUrl; } } + return false; } }); @@ -1090,7 +1095,9 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { return; } if(parseInt(page, 10) !== pagination.currentPage) { - pagination.loadPage(page); + pagination.loadPage(page, function() { + scrollToPid(pid); + }); } else { scrollToPid(pid); } @@ -1106,6 +1113,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { if(after < 0) { after = 0; } + loadMorePosts(tid, after, function() { scrollToPid(pid); }); @@ -1123,6 +1131,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + "px" }, duration !== undefined ? duration : 400, function() { scrollingToPost = false; + updateHeader(); if (highlight) { scrollTo.parent().find('.topic-item').addClass('highlight'); setTimeout(function() { From 98fa8c419db5a4b7ea72fe5e9b53ef318f09c82e Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sun, 2 Mar 2014 19:55:26 -0500 Subject: [PATCH 08/13] closes #1152 --- public/src/forum/admin/groups.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/forum/admin/groups.js b/public/src/forum/admin/groups.js index c5b69e8743..970822fa73 100644 --- a/public/src/forum/admin/groups.js +++ b/public/src/forum/admin/groups.js @@ -127,7 +127,7 @@ define(function() { .append($('').attr('src', results.users[x].picture)) .append($('').html(results.users[x].username)); - resultsEl.appendChild(foundUser); + resultsEl.append(foundUser); } } else { resultsEl.html('
  • No Users Found
  • '); From 1837a8443c2a7d59b259b68cf1dc00be1c2109d6 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 2 Mar 2014 19:55:50 -0500 Subject: [PATCH 09/13] shifting socket.io back to the end :\ --- src/meta.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/meta.js b/src/meta.js index 07e9255065..385e89e054 100644 --- a/src/meta.js +++ b/src/meta.js @@ -279,7 +279,7 @@ var fs = require('fs'), Meta.js.scripts = jsPaths.filter(function(path) { return path !== null }); // Add socket.io client library - Meta.js.scripts.unshift(path.join(__dirname, '../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js')); + Meta.js.scripts.push(path.join(__dirname, '../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js')); // Add plugin scripts Meta.js.scripts = Meta.js.scripts.concat(plugins.clientScripts); @@ -291,14 +291,13 @@ var fs = require('fs'), }, minify: function (callback) { var uglifyjs = require('uglify-js'), - jsPaths = this.scripts, minified; if (process.env.NODE_ENV === 'development') { winston.info('Minifying client-side libraries'); } - minified = uglifyjs.minify(jsPaths); + minified = uglifyjs.minify(this.scripts); this.cache = minified.code; callback(); }, From 016642bc16be74d8a87d242c79a42ec0d7fda01c Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sun, 2 Mar 2014 20:00:54 -0500 Subject: [PATCH 10/13] show 1 ip per line --- public/templates/account.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/templates/account.tpl b/public/templates/account.tpl index d099d68767..7b660a185d 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -115,7 +115,7 @@
    - {ips.ip} +
    {ips.ip}
    From 28832a2540521a542bbffa1e33b3ae8f522b0785 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 2 Mar 2014 20:37:57 -0500 Subject: [PATCH 11/13] fixing bug where sometimes a pidfile was left over, and nodebb would refuse to start a daemon again. --- loader.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/loader.js b/loader.js index 2effb4ffa0..2ab9be2715 100644 --- a/loader.js +++ b/loader.js @@ -44,11 +44,18 @@ var nconf = require('nconf'), nconf.argv(); +// Start the daemon! if (nconf.get('d')) { // Check for a still-active NodeBB process if (fs.existsSync(pidFilePath)) { - console.log('\n Error: Another NodeBB is already running!'); - process.exit(); + try { + var pid = fs.readFileSync(pidFilePath, { encoding: 'utf-8' }); + process.kill(pid, 0); + console.log('\n Error: Another NodeBB is already running!'); + process.exit(); + } catch (e) { + fs.unlinkSync(pidFilePath); + } } // Initialise logging streams From 044347ebca2db18b6d1b527e164c332899325979 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 2 Mar 2014 22:02:55 -0500 Subject: [PATCH 12/13] hotfix for vanilla missing socket.io lib --- public/templates/header.tpl | 1 + 1 file changed, 1 insertion(+) diff --git a/public/templates/header.tpl b/public/templates/header.tpl index 56bfc48638..decbae43da 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -28,6 +28,7 @@ + From fc53385ede4e24e0960d7c5eba2a38a134bd4e04 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 2 Mar 2014 22:34:57 -0500 Subject: [PATCH 13/13] removing socket.io library from minfile --- src/meta.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/meta.js b/src/meta.js index 385e89e054..ce1cd70990 100644 --- a/src/meta.js +++ b/src/meta.js @@ -278,9 +278,6 @@ var fs = require('fs'), // Remove scripts that could not be found (remove this line at v0.5.0) Meta.js.scripts = jsPaths.filter(function(path) { return path !== null }); - // Add socket.io client library - Meta.js.scripts.push(path.join(__dirname, '../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js')); - // Add plugin scripts Meta.js.scripts = Meta.js.scripts.concat(plugins.clientScripts);