nodebb-plugin-group-gallery 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/.editorconfig +8 -0
  2. package/.gitattributes +22 -0
  3. package/LICENSE +8 -0
  4. package/README.md +3 -0
  5. package/lib/comments.js +178 -0
  6. package/lib/config.js +47 -0
  7. package/lib/gallery.js +206 -0
  8. package/lib/nodebb.js +19 -0
  9. package/lib/sockets.js +113 -0
  10. package/lib/upgrade.js +101 -0
  11. package/library.js +258 -0
  12. package/package.json +34 -0
  13. package/plugin.json +30 -0
  14. package/static/js/lib/comments.js +163 -0
  15. package/static/js/lib/modal.js +111 -0
  16. package/static/js/lib/overview.js +15 -0
  17. package/static/js/lib/single.js +64 -0
  18. package/static/js/lib/uploader.js +37 -0
  19. package/static/js/main.js +147 -0
  20. package/static/less/style.less +145 -0
  21. package/static/templates/group-gallery/comments.tpl +15 -0
  22. package/static/templates/group-gallery/gallery.tpl +30 -0
  23. package/static/templates/group-gallery/modal/wrap.tpl +25 -0
  24. package/static/templates/group-gallery/single.tpl +75 -0
  25. package/static/templates/group-gallery/widget.tpl +18 -0
  26. package/static/vendor/fancybox/blank.gif +0 -0
  27. package/static/vendor/fancybox/fancybox_loading.gif +0 -0
  28. package/static/vendor/fancybox/fancybox_loading@2x.gif +0 -0
  29. package/static/vendor/fancybox/fancybox_overlay.png +0 -0
  30. package/static/vendor/fancybox/fancybox_sprite.png +0 -0
  31. package/static/vendor/fancybox/fancybox_sprite@2x.png +0 -0
  32. package/static/vendor/fancybox/jquery.fancybox-thumbs.css +55 -0
  33. package/static/vendor/fancybox/jquery.fancybox-thumbs.js +162 -0
  34. package/static/vendor/fancybox/jquery.fancybox.css +274 -0
  35. package/static/vendor/fancybox/jquery.fancybox.pack.js +46 -0
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ (function(GroupGallery) {
4
+
5
+ var Overview = {};
6
+
7
+ Overview.init = function() {
8
+ require(['forum/pagination'], function(pagination) {
9
+ pagination.init(ajaxify.variables.get('currentPage'), ajaxify.variables.get('pageCount'));
10
+ });
11
+ };
12
+
13
+ GroupGallery.overview = Overview;
14
+
15
+ })(GroupGallery);
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ (function(GroupGallery) {
4
+
5
+ var Single = {},
6
+ currentImageId;
7
+
8
+ Single.init = function() {
9
+ var imageId = parseInt(ajaxify.variables.get('image_id'), 10);
10
+ if (!isNaN(imageId)) {
11
+ if (currentImageId !== imageId) {
12
+ GroupGallery.comments.clear();
13
+ GroupGallery.comments.unbindEvents();
14
+ unbindEvents();
15
+ }
16
+
17
+ GroupGallery.comments.load(imageId);
18
+ GroupGallery.comments.bindEvents();
19
+ currentImageId = imageId;
20
+
21
+ bindEvents();
22
+ }
23
+ };
24
+
25
+ function bindEvents() {
26
+ var removeImageButton = $('[data-func="group-gallery.remove"]');
27
+
28
+ if (parseInt(ajaxify.variables.get('image_uid'), 10) === parseInt(app.user.uid, 10) || app.user.isAdmin) {
29
+ removeImageButton.removeClass('hidden');
30
+ } else {
31
+ removeImageButton.addClass('hidden');
32
+ }
33
+
34
+ removeImageButton.on('click.group-gallery', function(e) {
35
+ removeImage(currentImageId);
36
+
37
+ e.preventDefault();
38
+ return false;
39
+ });
40
+
41
+ socket.on('event:group-gallery.removeImage', function(imageId) {
42
+ if (parseInt(imageId, 10) === currentImageId) {
43
+ ajaxify.go('groups/' + ajaxify.variables.get('group_slug') + '/gallery');
44
+ }
45
+ });
46
+ }
47
+
48
+ function unbindEvents() {
49
+ var removeImageButton = $('[data-func="group-gallery.remove"]');
50
+
51
+ removeImageButton.off('click.group-gallery');
52
+
53
+ socket.off('event:group-gallery.removeImage');
54
+ }
55
+
56
+ function removeImage(id) {
57
+ if (!isNaN(id)) {
58
+ socket.emit('plugins.group-gallery.removeImage', {imageId: id});
59
+ }
60
+ }
61
+
62
+ GroupGallery.single = Single;
63
+
64
+ })(GroupGallery);
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ (function(GroupGallery) {
4
+
5
+ var Uploader = {},
6
+ uploaderModule = null;
7
+
8
+ Uploader.open = function() {
9
+ console.log(GroupGallery.vars);
10
+ if (GroupGallery.vars.groupName) {
11
+ if (uploaderModule === null) {
12
+ loadUploaderModule();
13
+ } else {
14
+ if ($.fancybox.current !== null) {
15
+ $.fancybox.close();
16
+ }
17
+
18
+ var route = '/groups/' + GroupGallery.vars.groupName + '/gallery/upload';
19
+ bootbox.prompt('Image caption', function(caption) {
20
+ if (caption !== null) {
21
+ uploaderModule.open(route, {caption: caption}, null, function(image) {});
22
+ }
23
+ });
24
+ }
25
+ }
26
+ };
27
+
28
+ function loadUploaderModule() {
29
+ require(['uploader'], function(module) {
30
+ uploaderModule = module;
31
+ Uploader.open();
32
+ });
33
+ }
34
+
35
+ GroupGallery.uploader = Uploader;
36
+
37
+ })(GroupGallery);
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ (function(window) {
4
+
5
+ $(window).on('action:ajaxify.end', function(event, data) {
6
+ var groupName = ajaxify.variables.get('group_name');
7
+ if (groupName && groupName.length) {
8
+ GroupGallery.init(utils.slugify(groupName));
9
+ }
10
+ });
11
+
12
+ var GroupGallery = {};
13
+
14
+ GroupGallery.vars = {
15
+ page: '',
16
+ groupName: null,
17
+ groupImages: null,
18
+ indexLookup: {},
19
+ idLookup: [],
20
+ lightboxImages: null,
21
+ lightboxOptions: {
22
+ index: 0,
23
+ tpl: null,
24
+ mouseWheel: false,
25
+ helpers: {
26
+ title: null
27
+ }
28
+ }
29
+ };
30
+
31
+ GroupGallery.init = function(groupName, callback) {
32
+ var self = this;
33
+
34
+ function load() {
35
+ self.vars.page = ajaxify.variables.get('group_gallery_page') || 'group';
36
+
37
+ if (self.vars.page === 'group' && !self.vars.lightboxOptions.tpl) {
38
+ loadTemplate();
39
+ return;
40
+ }
41
+
42
+ if (groupName !== self.vars.groupName) {
43
+ self.vars.groupName = groupName;
44
+
45
+ if (self.vars.page === 'group' || !self.vars.groupImages) {
46
+ loadImages();
47
+ return;
48
+ }
49
+ }
50
+
51
+ self.bindEvents();
52
+ self.checkPage();
53
+
54
+ if (callback) callback();
55
+ }
56
+
57
+ function loadTemplate() {
58
+ templates.parse('group-gallery/modal/wrap', {}, function(wrapHtml) {
59
+ self.vars.lightboxOptions.tpl = {
60
+ wrap: wrapHtml
61
+ };
62
+ load();
63
+ });
64
+ }
65
+
66
+ function loadImages() {
67
+ if (!self.vars.groupName) {
68
+ self.vars.groupImages = [];
69
+ return;
70
+ }
71
+
72
+ $.ajax({
73
+ url: '/api/groups/' + self.vars.groupName + '/gallery',
74
+ success: function(result) {
75
+ self.addImages(result.images);
76
+ },
77
+ error: function() {
78
+ self.vars.groupImages = [];
79
+ },
80
+ complete: function() {
81
+ load();
82
+ }
83
+ });
84
+ }
85
+
86
+ load();
87
+ };
88
+
89
+ GroupGallery.addImages = function(images) {
90
+ if (!Array.isArray(this.vars.groupImages)) {
91
+ this.vars.groupImages = [];
92
+ }
93
+
94
+ this.vars.groupImages = this.vars.groupImages.concat(images);
95
+ this.indexImages();
96
+ };
97
+
98
+ GroupGallery.indexImages = function() {
99
+ var self = this;
100
+
101
+ this.vars.indexLookup = {};
102
+ this.vars.idLookup = [];
103
+ this.vars.lightboxImages = this.vars.groupImages.map(function(el, index) {
104
+ self.vars.indexLookup[el.id] = index;
105
+ self.vars.idLookup[index] = el.id;
106
+ return {
107
+ href: el.url,
108
+ title: ''
109
+ };
110
+ });
111
+ };
112
+
113
+ GroupGallery.bindEvents = function() {
114
+ var event = 'event:group-gallery.newImage';
115
+ socket.off(event).on(event, function(image) {
116
+ // Image is an array of length one
117
+ GroupGallery.addImages(image);
118
+ var index = GroupGallery.vars.indexLookup[image[0].id];
119
+
120
+ if (GroupGallery.vars.page === 'group') {
121
+ if (parseInt(image[0].uid, 10) === parseInt(app.user.uid, 10)) {
122
+ GroupGallery.modal.openOnIndex(index);
123
+ } else if ($.fancybox.current !== null) {
124
+ $.fancybox.current.group.push(GroupGallery.vars.lightboxImages[index]);
125
+ }
126
+ } else {
127
+ ajaxify.go('groups/' + GroupGallery.vars.groupName + '/gallery/' + image[0].id);
128
+ }
129
+ });
130
+
131
+ var clickEvent = 'click.group-gallery';
132
+ $(document.body)
133
+ .off(clickEvent, '[data-func="group-gallery.modal.open"]')
134
+ .off(clickEvent, '[data-func="group-gallery.upload"]')
135
+ .on(clickEvent, '[data-func="group-gallery.modal.open"]', GroupGallery.modal.open)
136
+ .on(clickEvent, '[data-func="group-gallery.upload"]', GroupGallery.uploader.open);
137
+ };
138
+
139
+ GroupGallery.checkPage = function() {
140
+ if (this.vars.page && this.vars.page.length && this[this.vars.page]) {
141
+ this[this.vars.page].init();
142
+ }
143
+ };
144
+
145
+ window.GroupGallery = GroupGallery;
146
+
147
+ })(window);
@@ -0,0 +1,145 @@
1
+ @imageHeight: 100px;
2
+
3
+ .group-gallery-widget {
4
+ margin: 0;
5
+
6
+ .col-xs-3 {
7
+ padding: 5px;
8
+ }
9
+ }
10
+
11
+ .group-gallery-widget-image {
12
+
13
+ }
14
+
15
+ .group-gallery-image-crop {
16
+ display: inline-block;
17
+ position: relative;
18
+ width: 100%;
19
+ overflow: hidden;
20
+ padding-top: 100%;
21
+ background-position: center;
22
+ background-size: cover;
23
+ }
24
+
25
+ .group-gallery-modal {
26
+ .panel-body {
27
+ padding: 0px;
28
+ }
29
+ }
30
+
31
+ .group-gallery-comment {
32
+ margin: 5px 0 5px 0;
33
+ .group-gallery-comment-user {
34
+ .group-gallery-comment-userimage {
35
+ width: 20px;
36
+ height: 20px;
37
+ }
38
+
39
+ .group-gallery-comment-username {
40
+ font-weight: bold;
41
+ }
42
+ }
43
+ }
44
+
45
+ // Fix for small images
46
+ .fancybox-wrap {
47
+ min-width: 400px;
48
+ }
49
+
50
+ // Center images smaller than the modal width
51
+ .fancybox-inner {
52
+ margin: 0 auto;
53
+ }
54
+
55
+ //------------ Gallery overview page ------------//
56
+ .group-gallery-overview {
57
+
58
+ }
59
+
60
+ .group-gallery-overview-pagination {
61
+ text-align: center;
62
+
63
+ .pagination {
64
+ margin: 5px 0;
65
+ }
66
+ }
67
+
68
+ .group-gallery-overview-item, .group-gallery-single-item {
69
+ padding: 0 20px;
70
+ text-align: center;
71
+
72
+ & > a {
73
+ display: block;
74
+ }
75
+
76
+ img {
77
+ width: 100%;
78
+ }
79
+ }
80
+
81
+ .group-gallery-image-details p {
82
+ margin: 0;
83
+ }
84
+
85
+ .group-gallery-image-details-views, .group-gallery-image-details-comments {
86
+ margin: 0 10px;
87
+ }
88
+
89
+ //------------ Gallery single page ------------//
90
+ .group-gallery-single {
91
+
92
+ }
93
+
94
+ .group-gallery-single .panel-body {
95
+ padding: 0;
96
+ position: relative;
97
+ }
98
+
99
+ .group-gallery-single-left {
100
+ float: left;
101
+ height: 100%;
102
+ width: 25%;
103
+ border-right: 1px solid @gray-lighter;
104
+ }
105
+
106
+ .group-gallery-single-left-more {
107
+ padding: 20px;
108
+ border-bottom: 1px solid @gray-lighter;
109
+ text-align: center;
110
+ }
111
+
112
+ .group-gallery-single-left-thumbs {
113
+ text-align: center;
114
+ }
115
+
116
+ .group-gallery-single-thumb {
117
+ padding: 20px 20px;
118
+ }
119
+
120
+ .group-gallery-single-left-nav {
121
+ bottom: 0;
122
+ width: 100%;
123
+ border-top: 1px solid @gray-lighter;
124
+ }
125
+
126
+ .group-gallery-single-right {
127
+ float: right;
128
+ width: 75%;
129
+ padding: 50px 100px;
130
+ }
131
+
132
+ .group-gallery-single-item {
133
+ padding: 0;
134
+
135
+ img {
136
+ width: auto;
137
+ height: auto;
138
+ max-width: 100%;
139
+ max-height: 60vh;
140
+ }
141
+ }
142
+
143
+ .group-gallery-single-buttons {
144
+ margin: 10px 0;
145
+ }
@@ -0,0 +1,15 @@
1
+ <!-- BEGIN comments -->
2
+ <div class="group-gallery-comment" data-comment-id="{comments.id}">
3
+ <div class="group-gallery-comment-user" data-uid="{comments.user.uid}">
4
+ <img src="{comments.user.picture}" class="group-gallery-comment-userimage"/>
5
+ <a href="/user/{comments.user.slug}" class="group-gallery-comment-username">{comments.user.username}</a>
6
+ </div>
7
+ <!-- IF comments.isMod -->
8
+ <div class="pull-right group-gallery-comment-options">
9
+ <a href="#" class="fa fa-pencil" data-func="group-gallery.comment.edit"></a>
10
+ <a href="#" class="fa fa-times" data-func="group-gallery.comment.remove"></a>
11
+ </div>
12
+ <!-- ENDIF comments.isMod -->
13
+ <span class="group-gallery-comment-content">{comments.content}</span>
14
+ </div>
15
+ <!-- END comments -->
@@ -0,0 +1,30 @@
1
+ <input type="hidden" template-variable="group_name" value="{group.name}" />
2
+ <input type="hidden" template-variable="group_slug" value="{group.slug}" />
3
+ <input type="hidden" template-variable="group_gallery_page" value="overview" />
4
+ <input type="hidden" template-variable="currentPage" value="{currentPage}" />
5
+ <input type="hidden" template-variable="pageCount" value="{pageCount}" />
6
+
7
+ <h1>{group.name} - Photo gallery <button data-func="group-gallery.upload" class="btn btn-default pull-right" type="button">Upload</button></h1>
8
+
9
+ <div class="panel panel-default">
10
+ <div class="panel-body">
11
+ <div class="group-gallery-overview-pagination">
12
+ <!-- IMPORT partials/paginator.tpl -->
13
+ </div>
14
+
15
+ <div class="group-gallery-overview row">
16
+ <!-- BEGIN images -->
17
+ <div class="col-sm-3 group-gallery-overview-item">
18
+ <a href="/groups/{group.slug}/gallery/{images.id}">
19
+ <div class="group-gallery-image-crop" style="background-image: url({images.url})"></div>
20
+ <h4 class="group-gallery-image-caption">{images.caption}</h4>
21
+ </a>
22
+ <div class="group-gallery-image-details">
23
+ <p>Uploaded by <a href="/user/{images.author.userslug}" class="group-gallery-image-details-author">{images.author.username}</a></p>
24
+ <p><span class="group-gallery-image-details-views">{images.viewcount} Views</span> | <span class="group-gallery-image-details-comments">{images.commentcount} Comments</span></p>
25
+ </div>
26
+ </div>
27
+ <!-- END images -->
28
+ </div>
29
+ </div>
30
+ </div>
@@ -0,0 +1,25 @@
1
+ <div class="fancybox-wrap group-gallery-modal" tabIndex="-1">
2
+ <div class="panel panel-default fancybox-skin">
3
+ <div class="panel-body">
4
+ <div class="fancybox-outer">
5
+ <div class="fancybox-inner">
6
+
7
+ </div>
8
+ </div>
9
+ <br>
10
+ <button data-func="group-gallery.remove" class="btn btn-danger hidden" type="button">Remove</button>
11
+ <button data-func="group-gallery.upload" class="btn btn-default" type="button">Upload</button>
12
+ <h2>Comments</h2>
13
+ <div class="input-group">
14
+ <input id="group-gallery-comment-input" type="text" class="form-control" placeholder="Enter a comment...">
15
+ <span class="input-group-btn">
16
+ <button class="btn btn-default" type="button" data-func="group-gallery.comment">Submit</button>
17
+ </span>
18
+ </div>
19
+ <hr>
20
+ <div class="group-gallery-comments">
21
+
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </div>
@@ -0,0 +1,75 @@
1
+ <input type="hidden" template-variable="group_name" value="{group.name}" />
2
+ <input type="hidden" template-variable="group_slug" value="{group.slug}" />
3
+ <input type="hidden" template-variable="group_gallery_page" value="single" />
4
+ <input type="hidden" template-variable="image_id" value="{image.id}" />
5
+ <input type="hidden" template-variable="image_uid" value="{image.author.uid}" />
6
+
7
+ <h1>{group.name} - Photo gallery <button data-func="group-gallery.upload" class="btn btn-default pull-right" type="button">Upload</button></h1>
8
+
9
+ <div class="panel panel-default group-gallery-single">
10
+ <div class="panel-body">
11
+ <div class="group-gallery-single-left">
12
+ <div class="group-gallery-single-left-more">
13
+ <a href="/groups/{group.slug}/gallery?uid={image.author.uid}">
14
+ More from this user
15
+ </a>
16
+ </div>
17
+ <div class="group-gallery-single-left-thumbs">
18
+ <!-- IF !nextImages.length -->
19
+ <div class="group-gallery-single-thumb">
20
+ No more next images
21
+ </div>
22
+ <!-- ENDIF !nextImages.length -->
23
+ <!-- BEGIN nextImages -->
24
+ <div class="group-gallery-single-thumb">
25
+ <a href="/groups/{group.slug}/gallery/{nextImages.id}">
26
+ <div class="group-gallery-image-crop" style="background-image: url({nextImages.url})"></div>
27
+ <h4 class="group-gallery-image-caption">{nextImages.caption}</h4>
28
+ </a>
29
+ <div class="group-gallery-image-details">
30
+ <p>Uploaded by <a href="/user/{nextImages.author.userslug}" class="group-gallery-image-details-author">{nextImages.author.username}</a></p>
31
+ <p><span class="group-gallery-image-details-views">{nextImages.viewcount} Views</span> | <span class="group-gallery-image-details-comments">{nextImages.commentcount} Comments</span></p>
32
+ </div>
33
+ </div>
34
+ <!-- END nextImages -->
35
+ </div>
36
+ <div class="group-gallery-single-left-nav">
37
+ <nav>
38
+ <ul class="pager">
39
+ <!-- IF prevId -->
40
+ <li><a href="/groups/{group.slug}/gallery/{prevId}">Previous</a></li>
41
+ <!-- ENDIF prevId -->
42
+ <!-- IF nextId -->
43
+ <li><a href="/groups/{group.slug}/gallery/{nextId}">Next</a></li>
44
+ <!-- ENDIF nextId -->
45
+ </ul>
46
+ </nav>
47
+ </div>
48
+ </div>
49
+ <div class="group-gallery-single-right">
50
+ <div class="group-gallery-single-item">
51
+ <img src="{image.url}"/>
52
+ <h4 class="group-gallery-image-caption">{image.caption}</h4>
53
+ <div class="group-gallery-image-details">
54
+ <p>Uploaded by <a href="/user/{image.author.userslug}" class="group-gallery-image-details-author">{image.author.username}</a></p>
55
+ <p><span class="group-gallery-image-details-views">{image.viewcount} Views</span> | <span class="group-gallery-image-details-comments">{image.commentcount} Comments</span></p>
56
+ </div>
57
+ </div>
58
+ <div class="group-gallery-single-buttons">
59
+ <button data-func="group-gallery.remove" class="btn btn-danger hidden" type="button">Remove</button>
60
+ </div>
61
+ <hr>
62
+ <h2>Comments</h2>
63
+ <div class="input-group">
64
+ <input id="group-gallery-comment-input" type="text" class="form-control" placeholder="Enter a comment...">
65
+ <span class="input-group-btn">
66
+ <button class="btn btn-default" type="button" data-func="group-gallery.comment">Submit</button>
67
+ </span>
68
+ </div>
69
+ <hr>
70
+ <div class="group-gallery-comments">
71
+
72
+ </div>
73
+ </div>
74
+ </div>
75
+ </div>
@@ -0,0 +1,18 @@
1
+ <!-- IF images.length -->
2
+ <button data-func="group-gallery.modal.open" class="btn btn-default" type="button">Open</button>
3
+ <!-- ENDIF images.length -->
4
+ <button data-func="group-gallery.upload" class="btn btn-default" type="button">Upload</button>
5
+ <hr>
6
+ <div class="row group-gallery-widget">
7
+ <!-- IF !images.length -->
8
+ There are no images in the gallery yet.
9
+ <!-- ENDIF !images.length -->
10
+ <!-- BEGIN images -->
11
+ <div class="col-xs-3">
12
+ <a class="group-gallery-widget-image" href="{images.url}"
13
+ data-group-gallery-id="{images.id}" data-func="group-gallery.modal.open">
14
+ <div class="group-gallery-image-crop" style="background-image: url({images.url})"></div>
15
+ </a>
16
+ </div>
17
+ <!-- END images -->
18
+ </div>
Binary file
@@ -0,0 +1,55 @@
1
+ #fancybox-thumbs {
2
+ position: fixed;
3
+ left: 0;
4
+ width: 100%;
5
+ overflow: hidden;
6
+ z-index: 8050;
7
+ }
8
+
9
+ #fancybox-thumbs.bottom {
10
+ bottom: 2px;
11
+ }
12
+
13
+ #fancybox-thumbs.top {
14
+ top: 2px;
15
+ }
16
+
17
+ #fancybox-thumbs ul {
18
+ position: relative;
19
+ list-style: none;
20
+ margin: 0;
21
+ padding: 0;
22
+ }
23
+
24
+ #fancybox-thumbs ul li {
25
+ float: left;
26
+ padding: 1px;
27
+ opacity: 0.5;
28
+ }
29
+
30
+ #fancybox-thumbs ul li.active {
31
+ opacity: 0.75;
32
+ padding: 0;
33
+ border: 1px solid #fff;
34
+ }
35
+
36
+ #fancybox-thumbs ul li:hover {
37
+ opacity: 1;
38
+ }
39
+
40
+ #fancybox-thumbs ul li a {
41
+ display: block;
42
+ position: relative;
43
+ overflow: hidden;
44
+ border: 1px solid #222;
45
+ background: #111;
46
+ outline: none;
47
+ }
48
+
49
+ #fancybox-thumbs ul li img {
50
+ display: block;
51
+ position: relative;
52
+ border: 0;
53
+ padding: 0;
54
+ max-width: none;
55
+ }