Commit 30ffbe916d66f42ec31f64688a037bce37c04b95
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.
| | | | 11 | }); | 11 | }); |
---|
12 | | 12 | |
---|
13 | var Text = BaseType.extend({ | 13 | var Text = BaseType.extend({ |
---|
14 | defaults: { | | defaults: { |
---|
| | 14 | defaults: _.extend(BaseType.prototype.defaults, { | 15 | data: "", | 15 | data: "", |
---|
16 | }, | | }, |
---|
| | 16 | }), | 17 | initialize: function() { | 17 | initialize: function() { |
---|
| | 18 | BaseType.prototype.initialize.call(this, arguments); |
---|
18 | } | 19 | } |
---|
19 | }); | 20 | }); |
---|
20 | | 21 | |
---|
21 | var Table = BaseType.extend({ | 22 | var Table = BaseType.extend({ |
---|
22 | defaults: { | | defaults: { |
---|
| | 23 | defaults: _.extend(BaseType.prototype.defaults, { | 23 | data : { | 24 | data : { |
---|
24 | th: [], | 25 | th: [], |
---|
25 | tr:[] | 26 | tr:[] |
---|
26 | } | 27 | } |
---|
27 | }, | | }, |
---|
| | 28 | }), | 28 | initialize: function() { | 29 | initialize: function() { |
---|
| | 30 | BaseType.prototype.initialize.call(this, arguments); |
---|
29 | } | 31 | } |
---|
30 | }); | 32 | }); |
---|
31 | | 33 | |
---|
32 | var Image = BaseType.extend({ | 34 | var Image = BaseType.extend({ |
---|
33 | defaults: { | | defaults: { |
---|
| | 35 | defaults: _.extend(BaseType.prototype.defaults, { | 34 | src: "" | 36 | src: "" |
---|
35 | }, | | }, |
---|
| | 37 | }), | 36 | initialize:function() { | 38 | initialize:function() { |
---|
| | 39 | BaseType.prototype.initialize.call(this, arguments); |
---|
37 | } | 40 | } |
---|
38 | }); | 41 | }); |
---|
39 | | 42 | |
---|
40 | var Video = BaseType.extend({ | 43 | var Video = BaseType.extend({ |
---|
41 | defaults: { | | defaults: { |
---|
| | 44 | defaults: _.extend(BaseType.prototype.defaults, { | 42 | src: "" | 45 | src: "" |
---|
43 | }, | | }, |
---|
| | 46 | }), | 44 | initialize:function() { | 47 | initialize:function() { |
---|
| | 48 | BaseType.prototype.initialize.call(this, arguments); |
---|
45 | } | 49 | } |
---|
46 | }); | 50 | }); |
---|
47 | | 51 | |
---|
48 | var RSS = BaseType.extend({ | 52 | var RSS = BaseType.extend({ |
---|
49 | defaults: { | | defaults: { |
---|
| | 53 | defaults: _.extend(BaseType.prototype.defaults, { | 50 | src: "" | 54 | src: "" |
---|
51 | }, | | }, |
---|
| | 55 | }), | 52 | initialize:function() { | 56 | initialize:function() { |
---|
| | 57 | BaseType.prototype.initialize.call(this, arguments); |
---|
53 | } | 58 | } |
---|
54 | }); | 59 | }); |
---|
55 | | 60 | |
---|
… | | … | |
---|
63 | // Also the website can be styled by using external CSS files, | 63 | // Also the website can be styled by using external CSS files, |
---|
64 | // which can also be loaded via this plugin model. | 64 | // which can also be loaded via this plugin model. |
---|
65 | var Plugin = BaseType.extend({ | 65 | var Plugin = BaseType.extend({ |
---|
66 | defaults: { | | defaults: { |
---|
| | 66 | defaults: _.extend(BaseType.prototype.defaults, { | 67 | src: "", | 67 | src: "", |
---|
68 | data: {}, | 68 | data: {}, |
---|
69 | callback: "" | 69 | callback: "" |
---|
70 | }, | | }, |
---|
| | 70 | }), | 71 | initialize: function() { | 71 | initialize: function() { |
---|
| | 72 | BaseType.prototype.initialize.call(this, arguments); |
---|
| | 73 | |
---|
72 | if(this.get('src').match(/\.js/)) { | 74 | if(this.get('src').match(/\.js/)) { |
---|
73 | var script = document.createElement('script'); | 75 | var script = document.createElement('script'); |
---|
74 | var callback = this.get('callback'); | 76 | var callback = this.get('callback'); |
---|