2012-01-24 18:08:59 +00:00
|
|
|
/*\
|
|
|
|
title: js/ImageParser.js
|
|
|
|
|
|
|
|
Compiles images into JavaScript functions that render them in HTML
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
2012-02-11 20:12:25 +00:00
|
|
|
var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
|
2012-02-16 20:38:10 +00:00
|
|
|
Renderer = require("./Renderer.js").Renderer,
|
2012-02-17 14:11:25 +00:00
|
|
|
Dependencies = require("./Dependencies.js").Dependencies,
|
2012-02-11 20:12:25 +00:00
|
|
|
utils = require("./Utils.js");
|
2012-01-24 18:08:59 +00:00
|
|
|
|
2012-02-11 20:12:25 +00:00
|
|
|
var ImageParser = function(options) {
|
|
|
|
this.store = options.store;
|
2012-01-24 18:08:59 +00:00
|
|
|
};
|
|
|
|
|
2012-02-11 20:12:25 +00:00
|
|
|
ImageParser.prototype.parse = function(type,text) {
|
|
|
|
var src;
|
2012-02-16 20:38:10 +00:00
|
|
|
if(type === "image/svg+xml") {
|
2012-02-11 20:12:25 +00:00
|
|
|
src = "data:" + type + "," + encodeURIComponent(text);
|
2012-01-24 18:08:59 +00:00
|
|
|
} else {
|
2012-02-11 20:12:25 +00:00
|
|
|
src = "data:" + type + ";base64," + text;
|
2012-01-24 18:08:59 +00:00
|
|
|
}
|
2012-02-17 14:11:25 +00:00
|
|
|
return new WikiTextParseTree([Renderer.ElementNode("img",{src: src})],new Dependencies(),this.store);
|
2012-01-24 18:08:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.ImageParser = ImageParser;
|
|
|
|
|
|
|
|
})();
|