| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | /** | 
|  | 2 | * | 
|  | 3 | * Alternatively pass a string as <tt>base/s=span</tt> | 
|  | 4 | * | 
|  | 5 | * @param foundry | 
|  | 6 | */ | 
|  | 7 | define(function () { | 
|  | 8 | var _AvailableRE = new RegExp("^([^\/]+?)\/([^=]+?)(?:=(spans|rels|tokens))?$"); | 
|  | 9 |  | 
|  | 10 | return { | 
|  | 11 | create : function (foundry, layer, type) { | 
|  | 12 | return Object.create(this)._init(foundry, layer, type); | 
|  | 13 | }, | 
|  | 14 | _init : function (foundry, layer, type) { | 
|  | 15 | if (foundry === undefined) | 
|  | 16 | throw new Error("Missing parameters"); | 
|  | 17 |  | 
|  | 18 | if (layer === undefined) { | 
|  | 19 | if (_AvailableRE.exec(foundry)) { | 
|  | 20 | this.foundry = RegExp.$1; | 
|  | 21 | this.layer = RegExp.$2; | 
|  | 22 | this.type = RegExp.$3; | 
|  | 23 | } | 
|  | 24 | else { | 
|  | 25 | throw new Error("Missing parameters"); | 
|  | 26 | }; | 
|  | 27 | } | 
|  | 28 | else { | 
|  | 29 | this.foundry = foundry; | 
|  | 30 | this.layer = layer; | 
|  | 31 | this.type = type; | 
|  | 32 | }; | 
|  | 33 |  | 
|  | 34 | if (this.type === undefined) | 
|  | 35 | this.type = 'tokens'; | 
|  | 36 |  | 
|  | 37 | return this; | 
|  | 38 | } | 
|  | 39 | }; | 
|  | 40 | }); | 
|  | 41 |  |