From c2abff6e6d7c793c175f9a7dd461099bc07dbe9e Mon Sep 17 00:00:00 2001
From: Denis Wolf <dear.mr.dw@gmail.com>
Date: Mon, 28 Oct 2013 23:33:37 +0200
Subject: [PATCH 1/3] utils.js - strict mode, missing semicolon, braces etc

---
 public/src/utils.js | 59 +++++++++++++++++++++++++++++++++------------
 1 file changed, 43 insertions(+), 16 deletions(-)

diff --git a/public/src/utils.js b/public/src/utils.js
index 71d695fffa..296cca3e1f 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -1,4 +1,5 @@
 (function(module) {
+	'use strict';
 
 	var utils, fs;
 
@@ -23,20 +24,28 @@
 				main_dir = path.join(__dirname, '..', 'templates');
 
 			fs.readdir(dir, function(err, list) {
-				if (err) return done(err);
+				if (err) {
+					return done(err);
+				}
 				var pending = list.length;
-				if (!pending) return done(null, results);
+				if (!pending) {
+					return done(null, results);
+				}
 				list.forEach(function(file) {
 					file = dir + '/' + file;
 					fs.stat(file, function(err, stat) {
 						if (stat && stat.isDirectory()) {
 							utils.walk(file, function(err, res) {
 								results = results.concat(res);
-								if (!--pending) done(null, results);
+								if (!--pending) {
+									done(null, results);
+								}
 							});
 						} else {
 							results.push(file.replace(main_dir + '/', '').replace('.tpl', ''));
-							if (!--pending) done(null, results);
+							if (!--pending) {
+								done(null, results);
+							}
 						}
 					});
 				});
@@ -49,19 +58,29 @@
 
 			difference = Math.floor(difference / 1000);
 
-			if (difference < 60) return difference + (min ? 's' : ' second') + (difference !== 1 && !min ? 's' : '');
+			if (difference < 60) {
+				return difference + (min ? 's' : ' second') + (difference !== 1 && !min ? 's' : '');
+			}
 
 			difference = Math.floor(difference / 60);
-			if (difference < 60) return difference + (min ? 'm' : ' minute') + (difference !== 1 && !min ? 's' : '');
+			if (difference < 60) {
+				return difference + (min ? 'm' : ' minute') + (difference !== 1 && !min ? 's' : '');
+			}
 
 			difference = Math.floor(difference / 60);
-			if (difference < 24) return difference + (min ? 'h' : ' hour') + (difference !== 1 && !min ? 's' : '');
+			if (difference < 24) {
+				return difference + (min ? 'h' : ' hour') + (difference !== 1 && !min ? 's' : '');
+			}
 
 			difference = Math.floor(difference / 24);
-			if (difference < 30) return difference + (min ? 'd' : ' day') + (difference !== 1 && !min ? 's' : '');
+			if (difference < 30) {
+				return difference + (min ? 'd' : ' day') + (difference !== 1 && !min ? 's' : '');
+			}
 
 			difference = Math.floor(difference / 30);
-			if (difference < 12) return difference + (min ? 'mon' : ' month') + (difference !== 1 && !min ? 's' : '');
+			if (difference < 12) {
+				return difference + (min ? 'mon' : ' month') + (difference !== 1 && !min ? 's' : '');
+			}
 
 			difference = Math.floor(difference / 12);
 			return difference + (min ? 'y' : ' year') + (difference !== 1 && !min ? 's' : '');
@@ -116,8 +135,11 @@
 			var tags = '',
 				tag;
 			for (var x = 0, numTags = tagsArr.length; x < numTags; x++) {
-				if (tags.length > 0) tags += "\n\t";
+				if (tags.length > 0) {
+					tags += "\n\t";
+				}
 				tag = '<meta';
+				var y;
 				for (y in tagsArr[x]) {
 					tag += ' ' + y + '="' + tagsArr[x][y] + '"';
 				}
@@ -135,6 +157,7 @@
 			for (var x = 0, numTags = tagsArr.length; x < numTags; x++) {
 				if (tags.length > 0) tags += "\n\t";
 				tag = '<link';
+				var y;
 				for (y in tagsArr[x]) {
 					tag += ' ' + y + '="' + tagsArr[x][y] + '"';
 				}
@@ -157,7 +180,9 @@
 			socket.emit('api:meta.buildTitle', url, function(title, numNotifications) {
 				document.title = (numNotifications > 0 ? '(' + numNotifications + ') ' : '') + title;
 				notificationIcon = notificationIcon || document.querySelector('.notifications a i');
-				if (numNotifications > 0 && notificationIcon) notificationIcon.className = 'icon-circle active';
+				if (numNotifications > 0 && notificationIcon) {
+					notificationIcon.className = 'icon-circle active';
+				}
 			});
 
 			jQuery.getJSON(RELATIVE_PATH + '/api/unread/total', function(data) {
@@ -167,11 +192,11 @@
 				if (data.count > 0) {
 					badge
 						.removeClass('badge-inverse')
-						.addClass('badge-important')
+						.addClass('badge-important');
 				} else {
 					badge
 						.removeClass('badge-important')
-						.addClass('badge-inverse')
+						.addClass('badge-inverse');
 				}
 			});
 		},
@@ -183,13 +208,15 @@
 
 		makeNumberHumanReadable: function(num) {
 			num = parseInt(num, 10);
-			if (num > 999999)
+			if (num > 999999) {
 				return (num / 1000000).toFixed(1) + 'm';
-			else if(num > 999)
+			}
+			else if(num > 999) {
 				return (num / 1000).toFixed(1) + 'k';
+			}
 			return num;
 		}
-	}
+	};
 
 
 	if (!String.prototype.trim) {

From c614af2cd98c0aea49a8085cba2539373a7f655b Mon Sep 17 00:00:00 2001
From: Denis Wolf <dear.mr.dw@gmail.com>
Date: Mon, 28 Oct 2013 23:41:11 +0200
Subject: [PATCH 2/3] utils.js - removed unused *trim shims - it's better to
 bring them when and if needed

---
 public/src/utils.js | 19 -------------------
 1 file changed, 19 deletions(-)

diff --git a/public/src/utils.js b/public/src/utils.js
index 296cca3e1f..885ab3f765 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -225,25 +225,6 @@
 		};
 	}
 
-	if (!String.prototype.ltrim) {
-		String.prototype.ltrim = function() {
-			return this.replace(/^\s+/, '');
-		};
-	}
-
-	if (!String.prototype.rtrim) {
-		String.prototype.rtrim = function() {
-			return this.replace(/\s+$/, '');
-		};
-	}
-
-	if (!String.prototype.fulltrim) {
-		String.prototype.fulltrim = function() {
-			return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ');
-		};
-	}
-
-
 	if ('undefined' !== typeof window) {
 		window.utils = module.exports;
 	}

From a127fcd05647ac45af6f7334da951afbe17e4ced Mon Sep 17 00:00:00 2001
From: Denis Wolf <dear.mr.dw@gmail.com>
Date: Mon, 28 Oct 2013 23:55:45 +0200
Subject: [PATCH 3/3] utils.js - detect node/browser with IF, not silent
 TRY/CATCH

---
 public/src/utils.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/public/src/utils.js b/public/src/utils.js
index 885ab3f765..c6cf66d80a 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -3,9 +3,9 @@
 
 	var utils, fs;
 
-	try {
+	if ('undefined' === typeof window) {
 		fs = require('fs');
-	} catch (e) {}
+	}
 
 
 	module.exports = utils = {