1 define(function(require) {
4 var _ = require('libs/underscore'),
5 wlxml = require('wlxml/wlxml');
8 var ElementsRegister = function(basePrototype, defaultPrototype) {
10 this.basePrototype = basePrototype;
11 this.DefaultType = this.createCanvasElementType(defaultPrototype);
14 _.extend(ElementsRegister.prototype, {
15 createCanvasElementType: function(elementPrototype, extending) {
16 var inheritFrom = this.basePrototype;
17 if(extending && extending.tag) {
18 inheritFrom = this.getElement(extending);
20 var Constructor = function() {
22 this.super = inheritFrom.prototype;
24 inheritFrom.apply(this, Array.prototype.slice.call(arguments, 0));
27 Constructor.prototype = Object.create(inheritFrom.prototype);
28 _.extend(Constructor.prototype, elementPrototype);
31 register: function(params) {
32 params.klass = params.klass || '';
33 params.prototype = params.prototype || Object.create({});
35 this._register[params.tag] = this._register[params.tag] || {};
36 this._register[params.tag][params.klass] = this.createCanvasElementType(params.prototype, params.extending);
38 getElement: function(params) {
39 params.klass = params.klass || '';
41 if(this._register[params.tag]) {
42 wlxml.getClassHierarchy(params.klass).reverse().some(function(klass) {
43 Factory = this._register[params.tag][klass];
50 Factory = this.DefaultType;
57 return ElementsRegister;