From 9beaf2708b012b9533ca3088fbddd542a3c6c076 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 15 Nov 2016 17:26:44 -0500 Subject: dumping color codes to irc --- public/assets/js/vendor/parser.js | 290 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 public/assets/js/vendor/parser.js (limited to 'public/assets/js/vendor/parser.js') diff --git a/public/assets/js/vendor/parser.js b/public/assets/js/vendor/parser.js new file mode 100644 index 0000000..464cbbf --- /dev/null +++ b/public/assets/js/vendor/parser.js @@ -0,0 +1,290 @@ +var Parser = { + integrations: [{ + type: 'image', + regex: /\.(jpeg|jpg|gif|png|svg)(\?.*)?$/i, + tokenize: function(url){ + return { + text: "" + } + }, + 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") + var url_parts = url.replace(/\?.*$/, "").split("/") + var filename = url_parts[ url_parts.length-1 ] + video.addEventListener("loadedmetadata", function(){ + var width = video.videoWidth, height = video.videoHeight + video = null + done({ + url: url, + type: "video", + token: url, + thumbnail: "http://okfocus.s3.amazonaws.com/misc/okcms/video.png", + title: filename, + width: width, + height: height, + }) + }) + video.src = url + video.load() + }, + tag: function (media) { + return '