forked from mikaelbr/SocialFeed.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socialfeed.js
1194 lines (1000 loc) · 37.4 KB
/
socialfeed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(e){if("function"==typeof bootstrap)bootstrap("socialfeed",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeSocialFeed=e}else"undefined"!=typeof window?window.SocialFeed=e():global.SocialFeed=e()})(function(){var define,ses,bootstrap,module,exports;
return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){
var API = require('./api')
, Controller = require('./controller')
, SocialBase = require('./basemodule')
, _ = require('./utils')
;
var SocialFeed = function (options) {
if ( !(this instanceof SocialFeed) ) return new SocialFeed();
if (!options.el) {
options = {
el: options
};
}
this.c = new Controller(options);
};
// Expose public API.
_.inherits(SocialFeed, API);
// Make modules available:
SocialFeed.Modules = {
Disqus: require('./modules/disqus')
, Github: require('./modules/github')
, YouTubeUploads: require('./modules/youtubeuploads')
, Delicious: require('./modules/delicious')
, RSS: require('./modules/rss')
, Vimeo: require('./modules/vimeo')
, Tumblr: require('./modules/tumblr')
, SocialBase: SocialBase
, extend: function (module) {
return SocialBase.extend(module);
}
};
module.exports = SocialFeed;
},{"./api":2,"./controller":3,"./basemodule":4,"./utils":5,"./modules/disqus":6,"./modules/github":7,"./modules/youtubeuploads":8,"./modules/delicious":9,"./modules/rss":10,"./modules/vimeo":11,"./modules/tumblr":12}],2:[function(require,module,exports){
var API = module.exports = function (controller) {
};
API.prototype = {
start: function () {
this.c.emit('start');
return this;
}
, reload: function () {
this.c.emit('reload');
return this;
}
, addModule: function (module) {
this.c.emit('addModule', module);
return this;
}
, nextBulk: function () {
this.c.emit('nextBulk');
return this;
}
, loadNumEntries: function (num) {
this.c.emit('loadNumEntries', num);
return this;
}
, on: function (eventType, cb) {
this.c.on(eventType, cb);
return this;
}
};
},{}],5:[function(require,module,exports){
exports.timesince = function (date) {
date = new Date(date);
var seconds = Math.floor((new Date() - date) / 1000);
var interval = Math.floor(seconds / 31536000);
if (interval > 1) {
return interval + " years ago";
}
interval = Math.floor(seconds / 2592000);
if (interval > 1) {
return interval + " months ago";
}
interval = Math.floor(seconds / 86400);
if (interval > 1) {
return interval + " days ago";
}
interval = Math.floor(seconds / 3600);
if (interval > 1) {
return interval + " hours ago";
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
return interval + " minutes ago";
}
return Math.floor(seconds) + " seconds ago";
};
var isFunc = exports.isFunc = function (obj) {
return Object.prototype.toString.call(obj) == '[object Function]';
};
var isString = exports.isString = function (obj) {
return Object.prototype.toString.call(obj) == "[object String]";
};
exports.result = function (object, property) {
if (object == null) return;
var value = object[property];
return isFunc(value) ? value.call(object) : value;
};
exports.bind = function( fn, context ) {
var args = [].slice.call( arguments, 2 );
return function() {
return fn.apply( context || this, args.concat( [].slice.call( arguments ) ) );
};
};
exports.has = function (object, key) {
return Object.prototype.hasOwnProperty.call(object, key);
}
exports.extend = function (obj) {
[].slice.call(arguments, 1).forEach(function(source) {
if (source) {
for (var prop in source) {
obj[prop] = source[prop];
}
}
});
return obj;
};
exports.template = function (template, o) {
// From douglas crockfords
return template.replace(/{([^{}]*)}/g,
function (a, b) {
var r = o[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
}
);
}
// From Node util lib
/**
* Inherit the prototype methods from one constructor into another.
*
* The Function.prototype.inherits from lang.js rewritten as a standalone
* function (not on Function.prototype). NOTE: If this file is to be loaded
* during bootstrapping this function needs to be rewritten using some native
* functions as prototype setup using normal JavaScript does not work as
* expected during bootstrapping (see mirror.js in r114903).
*
* @param {function} ctor Constructor function which needs to inherit the
* prototype.
* @param {function} superCtor Constructor function to inherit prototype from.
*/
exports.inherits = function(ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
};
/*
* ECMAScript 5 Shims.
* Copyright 2009, 2010 Kristopher Michael Kowal. All rights reserved.
*/
// ES5 9.9
// http://es5.github.com/#x9.9
var toObject = function (o) {
if (o == null) { // this matches both null and undefined
throw new TypeError("can't convert "+o+" to object");
}
return Object(o);
};
// ES5 15.4.4.18
// http://es5.github.com/#x15.4.4.18
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/forEach
// Check failure of by-index access of string characters (IE < 9)
// and failure of `0 in boxedString` (Rhino)
var boxedString = Object("a"),
splitString = boxedString[0] != "a" || !(0 in boxedString);
if (!Array.prototype.forEach) {
Array.prototype.forEach = function forEach(fun /*, thisp*/) {
var object = toObject(this),
self = splitString && isString(this) ?
this.split("") :
object,
thisp = arguments[1],
i = -1,
length = self.length >>> 0;
// If no callback function or if callback is not a callable function
if (!isFunc(fun)) {
throw new TypeError(); // TODO message
}
while (++i < length) {
if (i in self) {
// Invoke the callback function with call, passing arguments:
// context, property value, property key, thisArg object
// context
fun.call(thisp, self[i], i, object);
}
}
};
}
// ES5 15.4.4.19
// http://es5.github.com/#x15.4.4.19
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
if (!Array.prototype.map) {
Array.prototype.map = function map(fun /*, thisp*/) {
var object = toObject(this),
self = splitString && _toString(this) == "[object String]" ?
this.split("") :
object,
length = self.length >>> 0,
result = Array(length),
thisp = arguments[1];
// If no callback function or if callback is not a callable function
if (_toString(fun) != "[object Function]") {
throw new TypeError(fun + " is not a function");
}
for (var i = 0; i < length; i++) {
if (i in self)
result[i] = fun.call(thisp, self[i], i, object);
}
return result;
};
}
// ES5 15.4.4.20
// http://es5.github.com/#x15.4.4.20
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/filter
if (!Array.prototype.filter) {
Array.prototype.filter = function filter(fun /*, thisp */) {
var object = toObject(this),
self = splitString && _toString(this) == "[object String]" ?
this.split("") :
object,
length = self.length >>> 0,
result = [],
value,
thisp = arguments[1];
// If no callback function or if callback is not a callable function
if (_toString(fun) != "[object Function]") {
throw new TypeError(fun + " is not a function");
}
for (var i = 0; i < length; i++) {
if (i in self) {
value = self[i];
if (fun.call(thisp, value, i, object)) {
result.push(value);
}
}
}
return result;
};
}
},{}],13:[function(require,module,exports){
// shim for using process in browser
var process = module.exports = {};
process.nextTick = (function () {
var canSetImmediate = typeof window !== 'undefined'
&& window.setImmediate;
var canPost = typeof window !== 'undefined'
&& window.postMessage && window.addEventListener
;
if (canSetImmediate) {
return function (f) { return window.setImmediate(f) };
}
if (canPost) {
var queue = [];
window.addEventListener('message', function (ev) {
var source = ev.source;
if ((source === window || source === null) && ev.data === 'process-tick') {
ev.stopPropagation();
if (queue.length > 0) {
var fn = queue.shift();
fn();
}
}
}, true);
return function nextTick(fn) {
queue.push(fn);
window.postMessage('process-tick', '*');
};
}
return function nextTick(fn) {
setTimeout(fn, 0);
};
})();
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.binding = function (name) {
throw new Error('process.binding is not supported');
}
// TODO(shtylman)
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
},{}],14:[function(require,module,exports){
(function(process){if (!process.EventEmitter) process.EventEmitter = function () {};
var EventEmitter = exports.EventEmitter = process.EventEmitter;
var isArray = typeof Array.isArray === 'function'
? Array.isArray
: function (xs) {
return Object.prototype.toString.call(xs) === '[object Array]'
}
;
function indexOf (xs, x) {
if (xs.indexOf) return xs.indexOf(x);
for (var i = 0; i < xs.length; i++) {
if (x === xs[i]) return i;
}
return -1;
}
// By default EventEmitters will print a warning if more than
// 10 listeners are added to it. This is a useful default which
// helps finding memory leaks.
//
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
var defaultMaxListeners = 10;
EventEmitter.prototype.setMaxListeners = function(n) {
if (!this._events) this._events = {};
this._events.maxListeners = n;
};
EventEmitter.prototype.emit = function(type) {
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events || !this._events.error ||
(isArray(this._events.error) && !this._events.error.length))
{
if (arguments[1] instanceof Error) {
throw arguments[1]; // Unhandled 'error' event
} else {
throw new Error("Uncaught, unspecified 'error' event.");
}
return false;
}
}
if (!this._events) return false;
var handler = this._events[type];
if (!handler) return false;
if (typeof handler == 'function') {
switch (arguments.length) {
// fast cases
case 1:
handler.call(this);
break;
case 2:
handler.call(this, arguments[1]);
break;
case 3:
handler.call(this, arguments[1], arguments[2]);
break;
// slower
default:
var args = Array.prototype.slice.call(arguments, 1);
handler.apply(this, args);
}
return true;
} else if (isArray(handler)) {
var args = Array.prototype.slice.call(arguments, 1);
var listeners = handler.slice();
for (var i = 0, l = listeners.length; i < l; i++) {
listeners[i].apply(this, args);
}
return true;
} else {
return false;
}
};
// EventEmitter is defined in src/node_events.cc
// EventEmitter.prototype.emit() is also defined there.
EventEmitter.prototype.addListener = function(type, listener) {
if ('function' !== typeof listener) {
throw new Error('addListener only takes instances of Function');
}
if (!this._events) this._events = {};
// To avoid recursion in the case that type == "newListeners"! Before
// adding it to the listeners, first emit "newListeners".
this.emit('newListener', type, listener);
if (!this._events[type]) {
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
} else if (isArray(this._events[type])) {
// Check for listener leak
if (!this._events[type].warned) {
var m;
if (this._events.maxListeners !== undefined) {
m = this._events.maxListeners;
} else {
m = defaultMaxListeners;
}
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
console.error('(node) warning: possible EventEmitter memory ' +
'leak detected. %d listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
this._events[type].length);
console.trace();
}
}
// If we've already got an array, just append.
this._events[type].push(listener);
} else {
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
}
return this;
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function(type, listener) {
var self = this;
self.on(type, function g() {
self.removeListener(type, g);
listener.apply(this, arguments);
});
return this;
};
EventEmitter.prototype.removeListener = function(type, listener) {
if ('function' !== typeof listener) {
throw new Error('removeListener only takes instances of Function');
}
// does not use listeners(), so no side effect of creating _events[type]
if (!this._events || !this._events[type]) return this;
var list = this._events[type];
if (isArray(list)) {
var i = indexOf(list, listener);
if (i < 0) return this;
list.splice(i, 1);
if (list.length == 0)
delete this._events[type];
} else if (this._events[type] === listener) {
delete this._events[type];
}
return this;
};
EventEmitter.prototype.removeAllListeners = function(type) {
if (arguments.length === 0) {
this._events = {};
return this;
}
// does not use listeners(), so no side effect of creating _events[type]
if (type && this._events && this._events[type]) this._events[type] = null;
return this;
};
EventEmitter.prototype.listeners = function(type) {
if (!this._events) this._events = {};
if (!this._events[type]) this._events[type] = [];
if (!isArray(this._events[type])) {
this._events[type] = [this._events[type]];
}
return this._events[type];
};
})(require("__browserify_process"))
},{"__browserify_process":13}],4:[function(require,module,exports){
var EventEmitter = require('events').EventEmitter
, _ = require('./utils')
;
var root = window;
var $;
var SocialBase = module.exports = function () {
this.collection = [];
this.init.apply(this, arguments);
$ = SocialBase.$ || root.jQuery || root.Zepto || root.$;
if (!$) throw "jQuery or Zepto is required to use SocialFeed.";
};
_.inherits(SocialBase, EventEmitter);
/**
Extend from Backbone
(Copyright (c) 2010-2013 Jeremy Ashkenas, DocumentCloud)
*/
SocialBase.extend = function (protoProps) {
var parent = this
, child = function(){
return parent.apply(this, arguments);
}
;
_.extend(child, parent);
var Surrogate = function () {
this.constructor = child;
};
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate;
if (protoProps) {
_.extend(child.prototype, protoProps);
}
child.__super__ = parent.prototype;
return child;
};
/** // From Backbone */
SocialBase.fetch = function (options) {
if (options.dataType.toLowerCase() === 'jsonp') {
options.callback = options.callbackParameter || "callback";
}
return $.ajax(options);
};
_.extend(SocialBase.prototype, {
ajaxSettings: {
dataType: 'jsonp',
type: 'GET'
}
, init: function (ident) {
this.ident = ident;
}
, fetch: function (options) {
options = options ? _.clone(options) : {};
var url = _.result(this, 'url')
, module = this
, success = options.success
;
options.url = url;
options.success = function(resp) {
var parsed = module.parse(resp);
module.collection = parsed;
if (success) success(module, parsed, options);
module.emit('fetched', module, parsed, options);
};
var error = options.error;
options.error = function(xOptions, textStatus) {
if (error) error(module, textStatus, xOptions);
module.emit('error', module, textStatus, xOptions);
};
if (!url && this.data) {
options.success(_.result(this, 'data'));
return void 0;
}
return SocialBase.fetch(_.extend(this.ajaxSettings, options));
}
, parse: function (resp) {
return resp;
}
, orderBy: function (item) { }
, render: function (item) { }
});
},{"events":14,"./utils":5}],3:[function(require,module,exports){
var EventEmitter = require('events').EventEmitter
, _ = require('./utils')
, SocialBase = require('./basemodule')
;
var $ = SocialBase.$ || window.jQuery || window.Zepto || window.$;
var Controller = module.exports = function (options) {
this.modules = [];
this.feedRendered = null;
this.$el = $(options.el) || $('#socialfeed');
this.count = options.count || 1000;
this._offset = options.offset || 0;
this.on('start', _.bind(this.start, this));
this.on('reload', _.bind(this.reload));
this.on('addModule', _.bind(this.addModule));
this.on('postFetch', _.bind(this.render));
// Paging
this.on('nextBulk', _.bind(this.nextBulk));
this.on('loadNumEntries', _.bind(this.loadNumEntries));
};
_.inherits(Controller, EventEmitter);
_.extend(Controller.prototype, {
_sync_count: 0
, addModule: function (module) {
var controller = this;
this.modules.push(module);
module.on('fetched', _.bind(controller.moduleFetched, controller));
module.on('error', function () {
if (controller.listeners('error').length > 0) {
controller.emit.apply(controller, ['error'].concat(arguments));
}
controller.moduleFetched();
});
}
, start: function () {
var controller = this;
controller.emit('preFetch');
controller.modules.forEach(function (module) {
module.fetch();
});
}
, moduleFetched: function (module, b, c) {
this.emit('moduleAdded', module);
if (++this._sync_count === this.modules.length) {
// all done
this.emit('postFetch', this.modules);
this._sync_count = 0;
}
}
, reload: function () {
this.$el.empty();
this._offset = 0;
this.feedRendered = null;
this.start();
}
, nextBulk: function () {
return this.loadNumEntries(this.count);
}
, loadNumEntries: function (num) {
if (this._offset >= this.feedRendered.length) {
return this;
}
var tmp = this.count;
this.count = num;
this.render();
this.count = tmp;
return this;
}
, render: function () {
var $el = this.$el;
if (this.feedRendered === null) {
this.feedRendered = this._generateOrderedList();
this.emit('dataReady', this.feedRendered, this.modules);
}
var list = this.feedRendered.slice(this._offset, (this._offset + this.count));
list.forEach(function (item) {
$el.append(item.html);
});
this._offset += this.count;
this.emit('rendered', list);
return this;
}
, _generateOrderedList: function () {
var list = [];
this.modules.forEach(function (module) {
if (!module || !module.collection) {
return;
}
var collectionlist = module.collection.map(function (item) {
var html = module.render(item);
if (!html) {
return null;
}
return {
orderBy: module.orderBy(item),
html: html
};
});
collectionlist = collectionlist.filter(function (item) {
return item !== null;
});
list = list.concat(collectionlist);
});
return this._orderList(list);
}
, _orderList: function (list) {
return list.sort(function (x, y) {
var a = x.orderBy;
var b = y.orderBy;
if (a > b || a === void 0) return 1;
if (a <= b || b === void 0) return -1;
});
}
});
},{"events":14,"./utils":5,"./basemodule":4}],6:[function(require,module,exports){
var SocialBase = require('../basemodule')
, templateHtml = require('../resources').disqus
, _ = require('../utils')
;
module.exports = SocialBase.extend({
init: function(ident, apikey) {
this.ident = ident;
this.apikey = apikey;
}
, url: function () {
return 'https://disqus.com/api/3.0/users/listPosts.json?api_key=' + this.apikey + '&user:username=' + this.ident;
}
, parse: function (resp) {
return resp.response;
}
, orderBy: function (item) {
return -(new Date(item.createdAt)).getTime();
}
, render: function (item) {
return _.template(templateHtml, {
profile_url: item.author.profileUrl,
author_name: item.author.name,
created_at: item.createdAt,
time_since: _.timesince(item.createdAt),
message: item.message
});
}
});
},{"../basemodule":4,"../resources":15,"../utils":5}],7:[function(require,module,exports){
var SocialBase = require('../basemodule')
, resources = require('../resources')
, _ = require('../utils')
, tmpl = {
create: resources.github_create
, createbranch: resources.github_createbranch
, watch: resources.github_watch
, push: resources.github_push
, pullrequest: resources.github_pullrequest
, fork: resources.github_fork
, issue: resources.github_issue
};
var getRepoURL = function (item) {
return 'https://github.com/' + item.repo.name;
}
, getUserURL = function (item) {
return 'https://github.com/' + item.actor.login;
}
, templateHelper = function (template, item) {
return _.template(tmpl[template], {
profile_url: getUserURL(item)
, username: item.actor.login
, repo_name: item.repo.name
, repo_url: getRepoURL(item)
, time_since: _.timesince(item.created_at)
, created_at: item.created_at
});
}
;
var defaultVisibility = {
'CreateEvent': true
, 'WatchEvent': true
, 'PushEvent': true
, 'PullRequestEvent': true
, 'ForkEvent': true
, 'IssuesEvent': true
};
module.exports = SocialBase.extend({
init: function (ident, showEntities) {
this.ident = ident;
this.show = _.extend(defaultVisibility, showEntities);
}
, url: function () {
return 'https://api.github.com/users/' + this.ident + '/events';
}
, orderBy: function (item) {
return -(new Date(item.created_at)).getTime();
}
, renderMethods: {
'CreateEvent': function (item) {
if (item.payload.ref === null) {
return templateHelper('create', item);
}
return _.template(templateHelper('createbranch', item), {
branch_url: getRepoURL(item) + '/tree/' + item.payload.ref
, branch_name: item.payload.ref
});
}
, 'WatchEvent': function (item) {
return templateHelper('watch', item);
}
, 'PushEvent': function (item) {
var $html = $(templateHelper('push', item));
// Add commits:
var $ul = $html.find('.socialfeed-commit-list')
, $li = $ul.find('li:first');
item.payload.commits.forEach(function(commit) {
var $it = $li.clone();
$it.find('a')
.attr('href', getRepoURL(item) + '/commit/' + commit.sha)
.text(commit.sha.substr(0, 7))
$it.find('span').text(commit.message);
$ul.prepend($it);
});
$li.remove();
return $html;
}
, 'PullRequestEvent': function (item) {
return _.template(templateHelper('pullrequest', item), {
"action": item.payload.action
, "title": item.payload.pull_request.title
, "pullrequest_url": item.payload.pull_request.html_url
, "pullrequest_name": item.repo.name + '#' + item.payload.number
});
}
, 'ForkEvent': function (item) {
return _.template(templateHelper('fork', item), {
"forkee_url": item.payload.forkee.html_url
, "forkee_name": item.payload.forkee.full_name
});
}
, 'IssuesEvent': function (item) {
return _.template(templateHelper('issue', item), {
"action": item.payload.action
, "title": item.payload.issue.title
, "issue_url": item.payload.issue.html_url
, "issue_name": item.repo.name + '#' + item.payload.number
});
}
}
, parse: function (resp) {
return resp.data;
}
, render: function (item) {
if (item.type && this.renderMethods[item.type] && !!this.show[item.type]) {
return this.renderMethods[item.type].apply(this, [item]);
}
return null;
}
});
},{"../basemodule":4,"../utils":5,"../resources":15}],8:[function(require,module,exports){
var SocialBase = require('../basemodule')
, templateHtml = require('../resources').youtubeuploads
, _ = require('../utils')
;
module.exports = SocialBase.extend({
ajaxSettings: {
cache: true,
dataType: 'jsonp'
}
, init: function (ident, maxCount) {
this.ident = ident;
this.maxCount = maxCount || 10;
}
, url: function () {
return 'http://gdata.youtube.com/feeds/users/' + this.ident + '/uploads?alt=json-in-script&format=5&max-results=' + this.maxCount;
}
, parse: function (resp) {
var feed = resp.feed;
return feed.entry || [];
}
, orderBy: function (item) {
return -(new Date(item.updated.$t)).getTime();
}
, hideAndMakeYoutubeClickable: function (item, html) {
var $html = $(html)
, $iframe = $html.find('iframe')
, thumbnail = item['media$group']['media$thumbnail'][0].url
;
var $img = $('<img />', {
src: thumbnail,
'class': 'youtube-preview'
}).insertAfter($iframe).on('click', function () {
$iframe.insertAfter($img);
$img.remove();
});
$iframe.remove();
return $html;
}
, render: function (item) {
var html = _.template(templateHtml, {
profile_url: item.author[0].uri.$t
, username: item.author[0].name.$t
, video_url: item.link[0].href
, video_name: item.title.$t
, created_at: item.updated.$t
, time_since: _.timesince(item.updated.$t)
, entry_id: item.id.$t.substring(38)
, desc: item['media$group']['media$description'].$t
});
return this.hideAndMakeYoutubeClickable(item, html);
}
});