mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-15 01:09:57 +09:00
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@4968 201d5d3c-b55e-5fd7-737f-ddc643e51545
52 lines
No EOL
1.3 KiB
JavaScript
52 lines
No EOL
1.3 KiB
JavaScript
/**
|
|
* @requires Xquared.js
|
|
* @requires macro/Base.js
|
|
*/
|
|
xq.macro.Factory = xq.Class(/** @lends xq.macro.Factory.prototype */{
|
|
/**
|
|
* @constructs
|
|
*
|
|
* @param {String} URL to place holder image.
|
|
*/
|
|
initialize: function(placeHolderImgSrc) {
|
|
this.placeHolderImgSrc = placeHolderImgSrc;
|
|
this.macroClazzes = {};
|
|
},
|
|
/**
|
|
* Registers new macro by ID.
|
|
*
|
|
* @param {String} id Macro id.
|
|
*/
|
|
register: function(id) {
|
|
var clazz = xq.macro[id + "Macro"];
|
|
if(!clazz) throw "Unknown macro id: [" + id + "]";
|
|
|
|
this.macroClazzes[id] = clazz;
|
|
},
|
|
/**
|
|
* Creates macro instance by given HTML fragment.
|
|
*
|
|
* @param {String} html HTML fragment.
|
|
* @returns {xq.macro.Base} Macro instance or null if recognization of the HTML fragment fails.
|
|
*/
|
|
createMacroFromHtml: function(html) {
|
|
for(var id in this.macroClazzes) {
|
|
var clazz = this.macroClazzes[id];
|
|
if(clazz.recognize(html)) return new clazz(id, html, this.placeHolderImgSrc);
|
|
}
|
|
return null;
|
|
},
|
|
/**
|
|
* Creates macro instance by given macro definition.
|
|
*
|
|
* @param {Object} def Macro definition.
|
|
* @returns {xq.macro.Base} Macro instance
|
|
* @throws If macro not found by def[id].
|
|
*/
|
|
createMacroFromDefinition: function(def) {
|
|
var clazz = this.macroClazzes[def.id];
|
|
if(!clazz) return null;
|
|
|
|
return new clazz(def.id, def.params, this.placeHolderImgSrc);
|
|
}
|
|
}) |