-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
74 lines (65 loc) · 2.46 KB
/
main.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
/**
* A module to render tiled walls of Content
* @module streamhub-sdk/views/media-wall-view
*/
define([
'jquery',
'streamhub-sdk/view',
'streamhub-sdk/content/views/content-view',
'streamhub-sdk/util'
], function($, View, ContentView, Util) {
/**
* A view that displays Content in a media wall.
* @alias module:streamhub-sdk/views/media-wall-view
* @param opts {Object} A set of options to config the view with
* @param opts.el {HTMLElement} The element in which to render the streamed content
* @constructor
*/
var PackeryView = function(opts) {
var self = this;
opts = opts || {};
opts.el = opts.el || document.createElement('div');
Packery.call(this, opts.el, opts);
View.call(this, opts);
this.contentIsDraggable = opts.contentIsDraggable || false;
this._addedElementsToLayout = [];
this._addTimeout = null;
$(this.el).addClass('streamhub-packery');
};
PackeryView.prototype = $.extend(new View(), Packery.prototype);
/**
* Add a piece of Content to the MediaWallView
* @param content {Content} A Content model to add to the MediaWallView
* @return the newly created ContentView
*/
PackeryView.prototype.add = function(content, stream) {
var self = this,
contentView = this.createContentView(content),
$contentViewEl = $(contentView.el);
contentView.render();
if (this.contentIsDraggable) {
var draggie = new Draggabilly(contentView.el);
draggie.on('dragMove', function () {
$contentViewEl.addClass('was-dragged');
});
self.on('dragItemPositioned', function (packery, draggedItem) {
if (draggedItem.element == contentView.el) {
$contentViewEl.removeClass('was-dragged');
}
});
this.bindDraggabillyEvents(draggie);
}
$(this.el).prepend(contentView.el);
this._addedElementsToLayout.push(contentView.el);
// When .add hasn't been called for 200ms, then tell Packery
// to .layout() via .prepended(elems)
if (this._addTimeout) {
this._addTimeout = clearTimeout(this._addTimeout);
}
this._addTimeout = setTimeout(function () {
self.prepended(self._addedElementsToLayout);
self._addedElementsToLayout = [];
}, 200);
};
return PackeryView;
});