From 1977a99c596485d2e42e544b2b0ecd0625395775 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 3 Aug 2015 22:33:34 -0400 Subject: app skeleton --- public/js/lib/parser.js | 286 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 public/js/lib/parser.js (limited to 'public/js/lib/parser.js') diff --git a/public/js/lib/parser.js b/public/js/lib/parser.js new file mode 100644 index 0000000..20c5306 --- /dev/null +++ b/public/js/lib/parser.js @@ -0,0 +1,286 @@ +var Parser = (function(){ + var Parser = {} + Parser.integrations = [{ + type: 'image', + regex: /\.(jpeg|jpg|gif|png|svg)(\?.*)?$/i, + fetch: function(url, done) { + var img = new Image () + img.onload = function(){ + if (!img) return + var width = img.naturalWidth, height = img.naturalHeight + img = null + done({ + url: url, + type: "image", + token: "", + thumbnail: "", + title: "", + width: width, + height: height, + }) + } + img.src = url + if (img.complete) { + img.onload() + } + }, + tag: function (media) { + return ''; + } + }, { + type: 'video', + regex: /\.(mp4|webm)(\?.*)?$/i, + fetch: function(url, done) { + var video = document.createElement("video") + video.addEventListener("loadedmetadata", function(){ + var width = video.videoWidth, height = video.videoHeight + video = null + done({ + url: url, + type: "video", + token: "", + thumbnail: "", + title: "", + width: width, + height: height, + }) + }) + video.src = url + video.load() + }, + tag: function (media) { + return '