Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

refactor notifier methods; shorter urls

  • Loading branch information...
commit 86007acaf9a96d6d861aa3acca8636f4b569ba5d 1 parent 1ad57e2
Matt Sherman authored February 26, 2012
4  src/background.html
@@ -56,8 +56,8 @@
56 56
         columnswitch: true,
57 57
         columnwide: true,
58 58
         font: false,
59  
-        hidewho: false,
60  
-        hidetrends: false
  59
+        hidewho: true,
  60
+        hidetrends: true
61 61
     },
62 62
     collapse: {
63 63
         options: false,
65  src/js/contentscript.js
@@ -82,7 +82,7 @@
82 82
 	  };
83 83
 
84 84
 	  $.fn.addNotifier = function() {
85  
-	  	return this.after(newNotifier());
  85
+	  	return this.append(newNotifier());
86 86
 	  };
87 87
 
88 88
 	  $.fn.appendNotifier = function() {
@@ -101,6 +101,9 @@
101 101
 	  };
102 102
 
103 103
 	  $.fn.getNotifier = function() {
  104
+	  	if (this.isNotifier()) {
  105
+  	  		return this;
  106
+  	  	}
104 107
 	  	var selector = "small." + bb_classnames.notify;
105 108
 	  	var find = this.find(selector);
106 109
 	  	if (find.length) {
@@ -114,6 +117,28 @@
114 117
 	  	return this.getNotifier().data(bb_datanames.count);
115 118
 	  };
116 119
 
  120
+  	  $.fn.updateNotifier = function(count, isincrement) {
  121
+  	  	var n = this.getNotifier();
  122
+  	  	if (isincrement) {
  123
+  	  		count += n.getNotifierCount();
  124
+  	  	}
  125
+  	  	if (n.length) {
  126
+	  	  	if (count > 0) {
  127
+	  	  		return n.data(bb_datanames.count, count).text(count + " new");
  128
+	  	  	}
  129
+  	  		return n.data(bb_datanames.count, count).text("");
  130
+  	  	}
  131
+	  	return this;
  132
+	  };
  133
+
  134
+  	  $.fn.incrementNotifier = function(count) {
  135
+  	  	return this.updateNotifier(count, true);
  136
+	  };
  137
+
  138
+  	  $.fn.isNotifier = function() {
  139
+	  	return this.hasClass(bb_classnames.notify);
  140
+	  };
  141
+
117 142
   	  $.fn.hasNotifier = function() {
118 143
 	  	return this.getNotifier().length > 0;
119 144
 	  };
@@ -129,6 +154,7 @@
129 154
 
130 155
 	String.prototype.remove = function(r) { return this.replace(r, ''); };
131 156
 	String.prototype.removePrefix = function(r) { return this.remove(/^bb\-/); };
  157
+	String.prototype.last = function() { return this[this.length - 1]; };
132 158
 
133 159
 	var body = $(document.body);
134 160
 	var wrapper = $("div.wrapper");
@@ -137,7 +163,7 @@
137 163
 
138 164
 	var regex = {
139 165
 		scheme: /^http[s]?:\/\/(www\.)*/,
140  
-		trailingid: /\/[\d\/]+$/g,
  166
+		trailingid: /\/[A-Z]*[\d\/]+$/gi,
141 167
 		trailing: /[\/\-\.\s]$/,
142 168
 		fileext: /(.html|.php|.aspx)/i,
143 169
 		querystring: /\?.*$/,
@@ -153,21 +179,22 @@
153 179
 			bb_classnames[key] = "bb-" + key;
154 180
 			body.toggleClass(bb_classnames[key], options.styles[key]);
155 181
 		}
156  
-		wrapper.show();
  182
+		$("div#page-node-home").show();
157 183
 	};
158 184
 
159 185
 	var abbrevUrl = function(url) {
160 186
 		var parts = decodeURIComponent(url
161 187
 			.remove(regex.scheme)
162 188
 			.remove(regex.querystring)
163  
-			.remove(regex.trailingid)
164 189
 			.remove(regex.fileext)
  190
+			.remove(regex.trailingid)
165 191
 			.remove(regex.trailing)
166 192
 			).split('/');
167 193
 		if (parts.length <= 2) {
168 194
 			return parts.join('/');
169 195
 		}
170 196
 		parts.splice(1, parts.length - 2, "…");
  197
+		parts[this.length] = parts[this.length].split('-').slice(0, 6).join("-");
171 198
 		return parts.join('/');
172 199
 	};
173 200
 
@@ -189,7 +216,7 @@
189 216
 	var bb_modules = [];
190 217
 
191 218
 	var createModule = function(classname, title, iconurl) {
192  
-		var h = $("<h3>").text(title).title("Click to expand or hide");
  219
+		var h = $("<h3>").text(title).title("Hover to expand");
193 220
 
194 221
 		var d = $("<div>").addClass(bb_classnames.content).toggle(!options.collapse[classname.removePrefix()]);
195 222
 		var f = $("<div class='flex-module' />").append(h).append(d);
@@ -206,9 +233,7 @@
206 233
 		m.icon = img;
207 234
 
208 235
 		m.clearAllNotifiers = function() {
209  
-			m.content.findByClass(bb_classnames.notify)
210  
-				.text("")
211  
-				.data(bb_datanames.count, 0);
  236
+			m.content.findByClass(bb_classnames.notify).updateNotifier(0);
212 237
 			updateTitleNotifier(m);
213 238
 		};
214 239
 
@@ -246,7 +271,7 @@
246 271
 		var total = 0;
247 272
 		bb_modules.forEach(function(module) {
248 273
 			module.title.getNotifier().each(function() {
249  
-				total += $(this).data(bb_datanames.count);
  274
+				total += $(this).getNotifierCount();
250 275
 			});
251 276
 		});
252 277
 		chrome.extension.sendRequest({ type: "set-icon", notify: clear || total > 0 });
@@ -256,7 +281,7 @@
256 281
 		bb_modules.forEach(function(module) {
257 282
 			var notifier = module.title.getNotifier().first();
258 283
 			if (notifier.length && !(module.is(":hover"))) {
259  
-				if (notifier.data(bb_datanames.count) > 0) {
  284
+				if (notifier.getNotifierCount() > 0) {
260 285
 					module.content.slideDown();
261 286
 				} else {
262 287
 					module.content.slideUp();
@@ -270,16 +295,16 @@
270 295
 		var notifiers = m.content.findByClass(bb_classnames.notify);
271 296
 		var total = 0;
272 297
 		notifiers.each(function(){
273  
-			total += $(this).data(bb_datanames.count);
  298
+			total += $(this).getNotifierCount();
274 299
 		});
275 300
 		var notifier = m.title.getNotifier();
276 301
 		if (total > 0) {
277  
-			notifier.text(total + " new").data(bb_datanames.count, total)
  302
+			notifier.updateNotifier(total)
278 303
 				.appendClear(m.clearAllNotifiers)
279 304
 				.fadeIn("fast");
280 305
 			m.icon.addClass(bb_classnames.notify).src(iconUrls.notify);
281 306
 		} else {
282  
-			notifier.fadeOut("fast").html("").data(bb_datanames.count, 0);
  307
+			notifier.fadeOut("fast").updateNotifier(0);
283 308
 			m.icon.removeClass(bb_classnames.notify).src(iconUrls.default);
284 309
 		}
285 310
 		return total;
@@ -303,14 +328,10 @@
303 328
 					.click(function(){
304 329
 						$(this).clearNotifier();
305 330
 						updateTitleNotifier(searchModule);
306  
-					});					
  331
+					});
307 332
 				searchModule.content.append($("<p>").append(a));
308 333
 			}
309  
-			var notifier = a.getNotifier().incrementData(bb_datanames.count, count);
310  
-			var newcount = notifier.data(bb_datanames.count);
311  
-			if (newcount > 0) {
312  
-				notifier.text(newcount + " new");
313  
-			}
  334
+			a.incrementNotifier(count);
314 335
 			updateTitleNotifier(searchModule);
315 336
 		};
316 337
 
@@ -348,11 +369,7 @@
348 369
 					});
349 370
 				mentionsModule.content.append($("<p>").append(a));
350 371
 			}
351  
-			var notifier = a.getNotifier().incrementData(bb_datanames.count, count);
352  
-			var newcount = notifier.data(bb_datanames.count);
353  
-			if (newcount > 0) {
354  
-				notifier.text(newcount + " new");
355  
-			}
  372
+			a.incrementNotifier(count);
356 373
 			updateTitleNotifier(mentionsModule);
357 374
 		};
358 375
 
3  src/styles.css
... ...
@@ -1,8 +1,7 @@
1  
-div.logged-in div.wrapper {
  1
+div#page-node-home {
2 2
 	display: none;
3 3
 }
4 4
 
5  
-
6 5
 body.bb-columnswitch div.content-main {
7 6
 	float:left;
8 7
 }

0 notes on commit 86007ac

Please sign in to comment.
Something went wrong with that request. Please try again.