From 30ffbe916d66f42ec31f64688a037bce37c04b95 Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Thu, 1 Aug 2013 18:56:09 +0530 Subject: [PATCH] Add inheritance support in models.js Previously BaseType was written to have inheritance, but derived classes were not inheriting some properties, and the super classes constructor was also not called. Appropriate fixes. --- mouchak/static/js/models.js | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/mouchak/static/js/models.js b/mouchak/static/js/models.js index 944cc07..2eb3de1 100644 --- a/mouchak/static/js/models.js +++ b/mouchak/static/js/models.js @@ -11,45 +11,50 @@ }); var Text = BaseType.extend({ - defaults: { + defaults: _.extend(BaseType.prototype.defaults, { data: "", - }, + }), initialize: function() { + BaseType.prototype.initialize.call(this, arguments); } }); var Table = BaseType.extend({ - defaults: { + defaults: _.extend(BaseType.prototype.defaults, { data : { th: [], tr:[] } - }, + }), initialize: function() { + BaseType.prototype.initialize.call(this, arguments); } }); var Image = BaseType.extend({ - defaults: { + defaults: _.extend(BaseType.prototype.defaults, { src: "" - }, + }), initialize:function() { + BaseType.prototype.initialize.call(this, arguments); } }); var Video = BaseType.extend({ - defaults: { + defaults: _.extend(BaseType.prototype.defaults, { src: "" - }, + }), initialize:function() { + BaseType.prototype.initialize.call(this, arguments); } }); var RSS = BaseType.extend({ - defaults: { + defaults: _.extend(BaseType.prototype.defaults, { src: "" - }, + }), initialize:function() { + BaseType.prototype.initialize.call(this, arguments); } }); @@ -58,12 +63,14 @@ // Also the website can be styled by using external CSS files, // which can also be loaded via this plugin model. var Plugin = BaseType.extend({ - defaults: { + defaults: _.extend(BaseType.prototype.defaults, { src: "", data: {}, callback: "" - }, + }), initialize: function() { + BaseType.prototype.initialize.call(this, arguments); + if(this.get('src').match(/\.js/)) { var script = document.createElement('script'); var callback = this.get('callback'); -- 1.7.10.4