Преглед изворни кода

Refactor code out into backbone.overview

JC Brand пре 11 година
родитељ
комит
81f3814e32
5 измењених фајлова са 13 додато и 30 уклоњено
  1. 5 4
      bower.json
  2. 5 26
      converse.js
  3. 1 0
      main.js
  4. 1 0
      src/deps-full.js
  5. 1 0
      src/deps-no-otr.js

+ 5 - 4
bower.json

@@ -17,16 +17,17 @@
     "backbone.localStorage": "1.1.7",
     "backbone.localStorage": "1.1.7",
     "strophe": "git@github.com:strophe/strophejs-bower.git#v1.1.3",
     "strophe": "git@github.com:strophe/strophejs-bower.git#v1.1.3",
     "strophe.roster": "https://raw.github.com/strophe/strophejs-plugins/b1f364eb6e854ffe844c57add38e885cfeb9b498/roster/strophe.roster.js",
     "strophe.roster": "https://raw.github.com/strophe/strophejs-plugins/b1f364eb6e854ffe844c57add38e885cfeb9b498/roster/strophe.roster.js",
-    "strophe.vcard":  "https://raw.github.com/strophe/strophejs-plugins/f5c9e16b463610d501591452cded0359f53aae48/vcard/strophe.vcard.js",
-    "strophe.disco":  "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/disco/strophe.disco.js",
-    "strophe.muc":    "https://raw.github.com/strophe/strophejs-plugins/02310ad1b8da2962cd05b0f4bceaecca134efed4/muc/strophe.muc.js",
+    "strophe.vcard": "https://raw.github.com/strophe/strophejs-plugins/f5c9e16b463610d501591452cded0359f53aae48/vcard/strophe.vcard.js",
+    "strophe.disco": "https://raw.github.com/jcbrand/strophejs-plugins/75c8693992bc357c699b6d615eeb396e799f5c02/disco/strophe.disco.js",
+    "strophe.muc": "https://raw.github.com/strophe/strophejs-plugins/02310ad1b8da2962cd05b0f4bceaecca134efed4/muc/strophe.muc.js",
     "otr": "0.2.12",
     "otr": "0.2.12",
     "crypto-js-evanvosberg": "~3.1.2",
     "crypto-js-evanvosberg": "~3.1.2",
     "almond": "~0.2.9",
     "almond": "~0.2.9",
     "requirejs-text": "~2.0.12",
     "requirejs-text": "~2.0.12",
     "requirejs-tpl-jcbrand": "*",
     "requirejs-tpl-jcbrand": "*",
     "momentjs": "~2.6.0",
     "momentjs": "~2.6.0",
-    "jquery.browser": "~0.0.6"
+    "jquery.browser": "~0.0.6",
+    "backbone.overview": "*"
   },
   },
   "exportsOverride": {}
   "exportsOverride": {}
 }
 }

+ 5 - 26
converse.js

@@ -3,7 +3,7 @@
  * http://conversejs.org
  * http://conversejs.org
  *
  *
  * Copyright (c) 2012, Jan-Carel Brand <jc@opkode.com>
  * Copyright (c) 2012, Jan-Carel Brand <jc@opkode.com>
- * Dual licensed under the MIT and GPL Licenses
+ * Licensed under the Mozilla Public License (MPL) 
  */
  */
 
 
 // AMD/global registrations
 // AMD/global registrations
@@ -1339,6 +1339,7 @@
                 // the opposite of trim, i.e. restoring a trimmed chat box
                 // the opposite of trim, i.e. restoring a trimmed chat box
                 this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el).show();
                 this.$el.insertAfter(converse.chatboxviews.get("controlbox").$el).show();
                 this.focus();
                 this.focus();
+                converse.refreshWebkit();
                 this.model.trigger('grow', this.model);
                 this.model.trigger('grow', this.model);
             },
             },
 
 
@@ -2512,17 +2513,11 @@
             }
             }
         });
         });
 
 
-        this.ChatBoxViews = Backbone.View.extend({
+        this.ChatBoxViews = Backbone.Overview.extend({
 
 
             initialize: function () {
             initialize: function () {
-                var views = {};
-                this.get = function (id) { return views[id]; };
-                this.add = function (id, view) { views[id] = view; };
-                this.getAll = function () { return views; };
-
                 this.trimmed_chatboxes_view = new converse.TrimmedChatBoxesView({model: this.model});
                 this.trimmed_chatboxes_view = new converse.TrimmedChatBoxesView({model: this.model});
                 this.render();
                 this.render();
-
                 this.model.on("add", this.onChatAdded, this);
                 this.model.on("add", this.onChatAdded, this);
                 this.model.on("grow", function (item) {
                 this.model.on("grow", function (item) {
                     this.trimChats(this.get(item.get('id')));
                     this.trimChats(this.get(item.get('id')));
@@ -2667,20 +2662,9 @@
             }
             }
         });
         });
 
 
-        this.TrimmedChatBoxesView = Backbone.View.extend({
+        this.TrimmedChatBoxesView = Backbone.Overview.extend({
 
 
             initialize: function () {
             initialize: function () {
-                var views = {};
-                this.get = function (id) { return views[id]; };
-                this.add = function (id, view) { views[id] = view; };
-                this.remove = function (id) {
-                    var view = views[id];
-                    if (view) {
-                        view.remove();
-                        delete views[id];
-                    }
-                };
-
                 this.model.on("change:trimmed", function (item) {
                 this.model.on("change:trimmed", function (item) {
                     var view;
                     var view;
                     if (item.get('trimmed')) {
                     if (item.get('trimmed')) {
@@ -3125,15 +3109,11 @@
             }
             }
         });
         });
 
 
-        this.RosterView = Backbone.View.extend({
+        this.RosterView = Backbone.Overview.extend({
             tagName: 'dl',
             tagName: 'dl',
             id: 'converse-roster',
             id: 'converse-roster',
 
 
             initialize: function () {
             initialize: function () {
-                var views = {};
-                this.get = function (id) { return views[id]; };
-                this.add = function (id, view) { views[id] = view; };
-
                 this.model.on("add", function (item) {
                 this.model.on("add", function (item) {
                     this.addRosterItemView(item).render(item);
                     this.addRosterItemView(item).render(item);
                     if (!item.get('vcard_updated')) {
                     if (!item.get('vcard_updated')) {
@@ -3167,7 +3147,6 @@
                         });
                         });
                 }
                 }
                 this.$el.hide().html(roster_markup);
                 this.$el.hide().html(roster_markup);
-
                 this.model.fetch({add: true}); // Get the cached roster items from localstorage
                 this.model.fetch({add: true}); // Get the cached roster items from localstorage
             },
             },
 
 

+ 1 - 0
main.js

@@ -8,6 +8,7 @@ config = {
         "underscore": "components/underscore/underscore",
         "underscore": "components/underscore/underscore",
         "backbone": "components/backbone/backbone",
         "backbone": "components/backbone/backbone",
         "backbone.localStorage": "components/backbone.localStorage/backbone.localStorage",
         "backbone.localStorage": "components/backbone.localStorage/backbone.localStorage",
+        "backbone.overview": "components/backbone.overview/backbone.overview",
         "text": 'components/requirejs-text/text',
         "text": 'components/requirejs-text/text',
         "tpl": 'components/requirejs-tpl-jcbrand/tpl',
         "tpl": 'components/requirejs-tpl-jcbrand/tpl',
         "converse-templates": "src/templates",
         "converse-templates": "src/templates",

+ 1 - 0
src/deps-full.js

@@ -3,6 +3,7 @@ define("converse-dependencies", [
     "moment",
     "moment",
     "locales",
     "locales",
     "backbone.localStorage",
     "backbone.localStorage",
+    "backbone.overview",
     "jquery.tinysort",
     "jquery.tinysort",
     "jquery.browser",
     "jquery.browser",
     "strophe",
     "strophe",

+ 1 - 0
src/deps-no-otr.js

@@ -2,6 +2,7 @@ define("converse-dependencies", [
     "moment",
     "moment",
     "locales",
     "locales",
     "backbone.localStorage",
     "backbone.localStorage",
+    "backbone.overview",
     "jquery.tinysort",
     "jquery.tinysort",
     "jquery.browser",
     "jquery.browser",
     "strophe",
     "strophe",