Browse Source

Minor refactoring

JC Brand 7 years ago
parent
commit
fc631e7f8c
1 changed files with 9 additions and 3 deletions
  1. 9 3
      src/converse-bookmarks.js

+ 9 - 3
src/converse-bookmarks.js

@@ -386,7 +386,6 @@
             });
             });
 
 
             _converse.BookmarkView = Backbone.VDOMView.extend({
             _converse.BookmarkView = Backbone.VDOMView.extend({
-
                 initialize () {
                 initialize () {
                     this.model.on('destroy', this.remove.bind(this));
                     this.model.on('destroy', this.remove.bind(this));
                 },
                 },
@@ -422,6 +421,8 @@
                 initialize () {
                 initialize () {
                     Backbone.OrderedListView.prototype.initialize.apply(this, arguments);
                     Backbone.OrderedListView.prototype.initialize.apply(this, arguments);
 
 
+                    this.toggleBookmarksList = _.debounce(this._toggleBookmarksList, 600, {'leading': true});
+
                     this.model.on('remove', this.hideListIfEmpty, this);
                     this.model.on('remove', this.hideListIfEmpty, this);
                     _converse.chatboxes.on('add', this.renderBookmarkListElement, this);
                     _converse.chatboxes.on('add', this.renderBookmarkListElement, this);
                     _converse.chatboxes.on('remove', this.renderBookmarkListElement, this);
                     _converse.chatboxes.on('remove', this.renderBookmarkListElement, this);
@@ -444,12 +445,17 @@
                         'label_bookmarks': __('Bookmarks'),
                         'label_bookmarks': __('Bookmarks'),
                         '_converse': _converse
                         '_converse': _converse
                     });
                     });
+                    this.hideListIfEmpty();
+                    this.insertIntoControlBox();
+                    return this;
+                },
+
+                insertIntoControlBox () {
                     const controlboxview = _converse.chatboxviews.get('controlbox');
                     const controlboxview = _converse.chatboxviews.get('controlbox');
                     if (!_.isUndefined(controlboxview)) {
                     if (!_.isUndefined(controlboxview)) {
                         const chatrooms_el = controlboxview.el.querySelector('#chatrooms');
                         const chatrooms_el = controlboxview.el.querySelector('#chatrooms');
                         chatrooms_el.insertAdjacentElement('afterbegin', this.el);
                         chatrooms_el.insertAdjacentElement('afterbegin', this.el);
                     }
                     }
-                    return this;
                 },
                 },
 
 
                 removeBookmark: _converse.removeBookmarkViaEvent,
                 removeBookmark: _converse.removeBookmarkViaEvent,
@@ -473,7 +479,7 @@
                     }
                     }
                 },
                 },
 
 
-                toggleBookmarksList (ev) {
+                _toggleBookmarksList (ev) {
                     if (ev && ev.preventDefault) { ev.preventDefault(); }
                     if (ev && ev.preventDefault) { ev.preventDefault(); }
                     if (u.hasClass('icon-opened', ev.target)) {
                     if (u.hasClass('icon-opened', ev.target)) {
                         u.slideIn(this.el.querySelector('.bookmarks'));
                         u.slideIn(this.el.querySelector('.bookmarks'));