/* * embed-js - v4.0.2 * A JavaScript plugin that analyses the string and embeds emojis, media, tweets, code and services. * http://riteshkr.com/embed.js * * Made by Ritesh Kumar * Under MIT License */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.EmbedJS = factory()); }(this, function () { 'use strict'; var __commonjs_global = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this; function __commonjs(fn, module) { return module = { exports: {} }, fn(module, module.exports, __commonjs_global), module.exports; } var babelHelpers = {}; babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; babelHelpers.classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; babelHelpers.createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); babelHelpers.slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); babelHelpers; /** * Trucates the string and adds ellipsis at the end. * @param string The string to be truncated * @param n Length to which it should be truncated * @returns {string} The truncated string */ function truncate(string, n) { return string.substr(0, n - 1) + (string.length > n ? '...' : ''); } /** * Converts a string into legitimate url. * @param string */ function toUrl(string) { return string.indexOf('//') === -1 ? '//' + string : string; } /** * Extends an Object * @param destination * @param source * @returns {*} */ function deepExtend(destination, source) { for (var property in source) { if (source.hasOwnProperty(property) && source[property] && source[property].constructor === Object) { destination[property] = destination[property] || {}; deepExtend(destination[property], source[property]); } else { destination[property] = source[property]; } } return destination; } function escapeRegExp(str) { return str.replace(/[\-\[\]\/\{}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); } /** * Sort an array of objects based on the index value * @param {Array} arr Array to be sorted * @return {Array} Sorted array */ function sortObject(arr) { return arr.sort(function (a, b) { return a.index - b.index; }); } /** * Creates the string of the iframes after sorting them and finally returning a string * @param {string} str String to which the created text has to be added * @param {object} embeds Sorted array of iframe html * @return {string} String to be rendered */ function createText(str, embeds) { var sortedEmbeds = sortObject(embeds); for (var i = 0; i < sortedEmbeds.length; i++) { str += ' ' + sortedEmbeds[i].text; } return str; } /** * Matches the string and finds the substrings matching to the provided regex pattern * @param {object} regex Regex pattern * @param {string} input The string to be analyzed * @return {object} Returns the matched substring with their corresponding positions */ function matches(regex, input) { return regex.exec(input); } /** * Checks whether a particular service should be embedded or not based on * the setting provided by the user * @param {object} options The options provided by the user * @param {string} service Name of the service for which the condition is to be analyzed * @return {boolean} True if it should be embedded */ function ifEmbed(options, service) { if (options.singleEmbed && options.served.length) return; return options.excludeEmbed.indexOf(service) == -1 && !(options.excludeEmbed === 'all'); } function ifInline(options, service) { return options.inlineEmbed.indexOf(service) >= 0 || options.inlineEmbed === 'all'; } /** * Calculates the dimensions for the elements based on a aspect ratio * @param {object} options Plugin options * @return {object} The width and height of the elements */ function setDimensions(options) { options.videoWidth = options.videoWidth || options.videoHeight / 3 * 4 || 800; options.videoHeight = options.videoHeight || options.videoWidth / 4 * 3 || 600; return options; } /** * Returns a cloned object * @param {object} obj * @return {object} cloned object */ function cloneObject(obj) { if (obj === null || (typeof obj === 'undefined' ? 'undefined' : babelHelpers.typeof(obj)) !== 'object') return obj; var temp = obj.constructor(); // give temp the original obj's constructor for (var key in obj) { temp[key] = cloneObject(obj[key]); } return temp; } function urlRegex() { return (/((href|src)=["']|)(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])|(?:https?:\/\/)?(?:(?:0rz\.tw)|(?:1link\.in)|(?:1url\.com)|(?:2\.gp)|(?:2big\.at)|(?:2tu\.us)|(?:3\.ly)|(?:307\.to)|(?:4ms\.me)|(?:4sq\.com)|(?:4url\.cc)|(?:6url\.com)|(?:7\.ly)|(?:a\.gg)|(?:a\.nf)|(?:aa\.cx)|(?:abcurl\.net)|(?:ad\.vu)|(?:adf\.ly)|(?:adjix\.com)|(?:afx\.cc)|(?:all\.fuseurl.com)|(?:alturl\.com)|(?:amzn\.to)|(?:ar\.gy)|(?:arst\.ch)|(?:atu\.ca)|(?:azc\.cc)|(?:b23\.ru)|(?:b2l\.me)|(?:bacn\.me)|(?:bcool\.bz)|(?:binged\.it)|(?:bit\.ly)|(?:buff\.ly)|(?:bizj\.us)|(?:bloat\.me)|(?:bravo\.ly)|(?:bsa\.ly)|(?:budurl\.com)|(?:canurl\.com)|(?:chilp\.it)|(?:chzb\.gr)|(?:cl\.lk)|(?:cl\.ly)|(?:clck\.ru)|(?:cli\.gs)|(?:cliccami\.info)|(?:clickthru\.ca)|(?:clop\.in)|(?:conta\.cc)|(?:cort\.as)|(?:cot\.ag)|(?:crks\.me)|(?:ctvr\.us)|(?:cutt\.us)|(?:dai\.ly)|(?:decenturl\.com)|(?:dfl8\.me)|(?:digbig\.com)|(?:digg\.com)|(?:disq\.us)|(?:dld\.bz)|(?:dlvr\.it)|(?:do\.my)|(?:doiop\.com)|(?:dopen\.us)|(?:easyuri\.com)|(?:easyurl\.net)|(?:eepurl\.com)|(?:eweri\.com)|(?:fa\.by)|(?:fav\.me)|(?:fb\.me)|(?:fbshare\.me)|(?:ff\.im)|(?:fff\.to)|(?:fire\.to)|(?:firsturl\.de)|(?:firsturl\.net)|(?:flic\.kr)|(?:flq\.us)|(?:fly2\.ws)|(?:fon\.gs)|(?:freak\.to)|(?:fuseurl\.com)|(?:fuzzy\.to)|(?:fwd4\.me)|(?:fwib\.net)|(?:g\.ro.lt)|(?:gizmo\.do)|(?:gl\.am)|(?:go\.9nl.com)|(?:go\.ign.com)|(?:go\.usa.gov)|(?:goo\.gl)|(?:goshrink\.com)|(?:gurl\.es)|(?:hex\.io)|(?:hiderefer\.com)|(?:hmm\.ph)|(?:href\.in)|(?:hsblinks\.com)|(?:htxt\.it)|(?:huff\.to)|(?:hulu\.com)|(?:hurl\.me)|(?:hurl\.ws)|(?:icanhaz\.com)|(?:idek\.net)|(?:ilix\.in)|(?:is\.gd)|(?:its\.my)|(?:ix\.lt)|(?:j\.mp)|(?:jijr\.com)|(?:kl\.am)|(?:klck\.me)|(?:korta\.nu)|(?:krunchd\.com)|(?:l9k\.net)|(?:lat\.ms)|(?:liip\.to)|(?:liltext\.com)|(?:linkbee\.com)|(?:linkbun\.ch)|(?:liurl\.cn)|(?:ln-s\.net)|(?:ln-s\.ru)|(?:lnk\.gd)|(?:lnk\.ms)|(?:lnkd\.in)|(?:lnkurl\.com)|(?:lru\.jp)|(?:lt\.tl)|(?:lurl\.no)|(?:macte\.ch)|(?:mash\.to)|(?:merky\.de)|(?:migre\.me)|(?:miniurl\.com)|(?:minurl\.fr)|(?:mke\.me)|(?:moby\.to)|(?:moourl\.com)|(?:mrte\.ch)|(?:myloc\.me)|(?:myurl\.in)|(?:n\.pr)|(?:nbc\.co)|(?:nblo\.gs)|(?:nn\.nf)|(?:not\.my)|(?:notlong\.com)|(?:nsfw\.in)|(?:nutshellurl\.com)|(?:nxy\.in)|(?:nyti\.ms)|(?:o-x\.fr)|(?:oc1\.us)|(?:om\.ly)|(?:omf\.gd)|(?:omoikane\.net)|(?:on\.cnn.com)|(?:on\.mktw.net)|(?:onforb\.es)|(?:orz\.se)|(?:ow\.ly)|(?:ping\.fm)|(?:pli\.gs)|(?:pnt\.me)|(?:politi\.co)|(?:post\.ly)|(?:pp\.gg)|(?:profile\.to)|(?:ptiturl\.com)|(?:pub\.vitrue.com)|(?:qlnk\.net)|(?:qte\.me)|(?:qu\.tc)|(?:qy\.fi)|(?:r\.im)|(?:rb6\.me)|(?:read\.bi)|(?:readthis\.ca)|(?:reallytinyurl\.com)|(?:redir\.ec)|(?:redirects\.ca)|(?:redirx\.com)|(?:retwt\.me)|(?:ri\.ms)|(?:rickroll\.it)|(?:riz\.gd)|(?:rt\.nu)|(?:ru\.ly)|(?:rubyurl\.com)|(?:rurl\.org)|(?:rww\.tw)|(?:s4c\.in)|(?:s7y\.us)|(?:safe\.mn)|(?:sameurl\.com)|(?:sdut\.us)|(?:shar\.es)|(?:shink\.de)|(?:shorl\.com)|(?:short\.ie)|(?:short\.to)|(?:shortlinks\.co.uk)|(?:shorturl\.com)|(?:shout\.to)|(?:show\.my)|(?:shrinkify\.com)|(?:shrinkr\.com)|(?:shrt\.fr)|(?:shrt\.st)|(?:shrten\.com)|(?:shrunkin\.com)|(?:simurl\.com)|(?:slate\.me)|(?:smallr\.com)|(?:smsh\.me)|(?:smurl\.name)|(?:sn\.im)|(?:snipr\.com)|(?:snipurl\.com)|(?:snurl\.com)|(?:sp2\.ro)|(?:spedr\.com)|(?:srnk\.net)|(?:srs\.li)|(?:starturl\.com)|(?:su\.pr)|(?:surl\.co.uk)|(?:surl\.hu)|(?:t\.cn)|(?:t\.co)|(?:t\.lh.com)|(?:ta\.gd)|(?:tbd\.ly)|(?:tcrn\.ch)|(?:tgr\.me)|(?:tgr\.ph)|(?:tighturl\.com)|(?:tiniuri\.com)|(?:tiny\.cc)|(?:tiny\.ly)|(?:tiny\.pl)|(?:tinylink\.in)|(?:tinyuri\.ca)|(?:tinyurl\.com)|(?:tl\.gd)|(?:tmi\.me)|(?:tnij\.org)|(?:tnw\.to)|(?:tny\.com)|(?:to\.ly)|(?:togoto\.us)|(?:totc\.us)|(?:toysr\.us)|(?:tpm\.ly)|(?:tr\.im)|(?:tra\.kz)|(?:trunc\.it)|(?:twhub\.com)|(?:twirl\.at)|(?:twitclicks\.com)|(?:twitterurl\.net)|(?:twitterurl\.org)|(?:twiturl\.de)|(?:twurl\.cc)|(?:twurl\.nl)|(?:u\.mavrev.com)|(?:u\.nu)|(?:u76\.org)|(?:ub0\.cc)|(?:ulu\.lu)|(?:updating\.me)|(?:ur1\.ca)|(?:url\.az)|(?:url\.co.uk)|(?:url\.ie)|(?:url360\.me)|(?:url4\.eu)|(?:urlborg\.com)|(?:urlbrief\.com)|(?:urlcover\.com)|(?:urlcut\.com)|(?:urlenco\.de)|(?:urli\.nl)|(?:urls\.im)|(?:urlshorteningservicefortwitter\.com)|(?:urlx\.ie)|(?:urlzen\.com)|(?:usat\.ly)|(?:use\.my)|(?:vb\.ly)|(?:vgn\.am)|(?:vl\.am)|(?:vm\.lc)|(?:w55\.de)|(?:wapo\.st)|(?:wapurl\.co.uk)|(?:wipi\.es)|(?:wp\.me)|(?:x\.vu)|(?:xr\.com)|(?:xrl\.in)|(?:xrl\.us)|(?:xurl\.es)|(?:xurl\.jp)|(?:y\.ahoo.it)|(?:yatuc\.com)|(?:ye\.pe)|(?:yep\.it)|(?:yfrog\.com)|(?:yhoo\.it)|(?:yiyd\.com)|(?:youtu\.be)|(?:yuarel\.com)|(?:z0p\.de)|(?:zi\.ma)|(?:zi\.mu)|(?:zipmyurl\.com)|(?:zud\.me)|(?:zurl\.ws)|(?:zz\.gd)|(?:zzang\.kr)|(?:›\.ws)|(?:✩\.ws)|(?:✿\.ws)|(?:❥\.ws)|(?:➔\.ws)|(?:➞\.ws)|(?:➡\.ws)|(?:➨\.ws)|(?:➯\.ws)|(?:➹\.ws)|(?:➽\.ws))\/[a-z0-9]*/gi ); } function arrayLowercase(options, property) { if (typeof options[property] !== 'string') { options[property] = options[property].map(function (elem) { return elem.toLowerCase(); }); } return options; } /** * Sets the dimensions and converts options values' Array into lowercase. * @param options * @returns {Object|*} */ function processOptions(options) { options = setDimensions(options); options = arrayLowercase(options, 'excludeEmbed'); options = arrayLowercase(options, 'inlineEmbed'); return arrayLowercase(options, 'openGraphExclude'); } /** * Get the last element of an array or string * @param elem [String|Array] * @returns last element of the Array or String */ function lastElement(elem) { return elem[elem.length - 1]; } var Renderer = function () { function Renderer(options) { babelHelpers.classCallCheck(this, Renderer); this.options = options || {}; } babelHelpers.createClass(Renderer, [{ key: 'url', value: function url(match, options) { var config = options.linkOptions; return '' + match + ''; } }, { key: 'smiley', value: function smiley(text, pre, code) { return '' + pre + code + ''; } }, { key: 'emoji', value: function emoji(text) { return ''; } }, { key: 'audio', value: function audio(match) { return '
'; } }, { key: 'soundcloud', value: function soundcloud(match, options) { var config = options.soundCloudOptions; return ''; } }, { key: 'spotify', value: function spotify(match) { var id = lastElement(match.split('/')); return ''; } }, { key: 'codepen', value: function codepen(id, options) { return ''; } }, { key: 'ideone', value: function ideone(match, options) { return ''; } }, { key: 'jsbin', value: function jsbin(id, options) { return ''; } }, { key: 'jsfiddle', value: function jsfiddle(id, options) { id = lastElement(id) == '/' ? id.slice(0, -1) : id; id = id.indexOf('//') !== -1 ? id : '//' + id; return ''; } }, { key: 'plunker', value: function plunker(id, options) { return ''; } }, { key: 'image', value: function image(match) { return ''; } }, { key: 'flickr', value: function flickr(match, options) { return ''; } }, { key: 'instagram', value: function instagram(match, options) { return ''; } }, { key: 'slideShare', value: function slideShare(html) { return ''; } }, { key: 'video', value: function video(match) { return ''; } }, { key: 'dailymotion', value: function dailymotion(match, options) { var id = lastElement(match.split('/')); return ''; } }, { key: 'liveleak', value: function liveleak(match, options) { return ''; } }, { key: 'ted', value: function ted(match, options) { var a = match.split('/'); var id = a[a.length - 1]; return ''; } }, { key: 'ustream', value: function ustream(match, options) { var id = match.split('/'); id.splice(1, 0, 'embed'); return ''; } }, { key: 'detailsVimeo', value: function detailsVimeo(data, fullData, embedUrl) { return ''; } }, { key: 'detailsYoutube', value: function detailsYoutube(data, fullData, embedUrl) { return ''; } }, { key: 'vine', value: function vine(match, options) { var id = lastElement(match.split('/')); var config = options.vineOptions; return ''; } }, { key: 'vimeo', value: function vimeo(url, options) { return ''; } }, { key: 'youtube', value: function youtube(url, options) { return ''; } }, { key: 'openGraph', value: function openGraph(data, options) { return ''; } }, { key: 'github', value: function github(data, options) { return ''; } }]); return Renderer; }(); var regex = { basicAudio: /((?:https?):\/\/\S*\.(?:wav|mp3|ogg))/gi, soundCloud: /(soundcloud.com)\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+/gi, spotify: /spotify.com\/track\/[a-zA-Z0-9_]+/gi, codepen: /http:\/\/codepen.io\/([A-Za-z0-9_]+)\/pen\/([A-Za-z0-9_]+)/gi, gist: /gist.github.com\/[a-zA-Z0-9_-]+\/([a-zA-Z0-9]+)/gi, highlightCode: /(`{3})(\s|[a-z]+)\s*([\s\S]*?[^`])\s*\1(?!`)/gm, inlineCode: /(`)\s*([\s\S]*?[^`])\s*\1(?!`)/gm, ideone: /ideone.com\/[a-zA-Z0-9]{6}/gi, jsbin: /jsbin.com\/[a-zA-Z0-9_]+\/[0-9_]+/gi, jsfiddle: /jsfiddle.net\/[a-zA-Z0-9_]+\/[a-zA-Z0-9_\/]+/gi, plunker: /plnkr.co\/edit\/[a-zA-Z0-9\?=]+/gi, basicImage: /((?:https?):\/\/\S*\.(?:gif|jpg|jpeg|tiff|png|svg|webp))/gi, flickr: /flickr.com\/[a-z]+\/[a-zA-Z@_$!\d\-\]+\/[\d]+/gi, instagram: /instagram.com\/p\/[a-zA-Z0-9_\/\?\-\=]+/gi, slideShare: /slideshare.net\/[a-zA-Z0-9_-]*\/[a-zA-Z0-9_-]*/gi, github: /[^\.]github.com\/([\w\.\-]+)\/([\w\.\-]+)/gi, basicVideo: /(?:https?):\/\/\S*\.(?:ogv|webm|mp4)/gi, dailymotion: /dailymotion.com\/video\/[a-zA-Z0-9-_]+/gi, liveleak: /liveleak.com\/view\?i=[a-zA-Z0-9_]+/gi, ted: /ted.com\/talks\/[a-zA-Z0-9_]+/gi, ustream: /ustream.tv\/[a-z\/0-9]*/gi, vimeo: /https?:\/\/(?:www\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)*/gi, vine: /vine.co\/v\/[a-zA-Z0-9]+/gi, youtube: /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[?=&+%\w-]*/gi, gmap: /@\((.+)\)/gi, twitter: /https:\/\/twitter\.com\/\w+\/\w+\/\d+/gi, smileys: /(\:\w+\:|\<[\/\\]?3|[\(\)\\\D|\*\$][\-\^]?[\:\;\=]|[\:\;\=B8][\-\^]?[3DOPp\@\$\*\\\)\(\/\|])(?=\s|[\!\.\?]|$)/gi }; var Emoji = function () { function Emoji(output, options) { babelHelpers.classCallCheck(this, Emoji); this.output = output; this.options = options; this.emojiRegex = regex.smileys; } babelHelpers.createClass(Emoji, [{ key: 'process', value: function process() { var _this = this; return this.output.replace(this.emojiRegex, function (match) { var emoji = Emoji.getEmoji(match); if (emoji) { return _this.options.template.emoji(emoji, _this.options); } return match; }); } }], [{ key: 'getEmoji', value: function getEmoji(match) { return match[0] === ':' && match[match.length - 1] === ':' && match.substring(1, match.length - 1); } }]); return Emoji; }(); var Smiley = function () { function Smiley(input, options) { babelHelpers.classCallCheck(this, Smiley); this.input = input; this.options = options; var defaultIcons = [{ 'text': ':)', 'code': '' }, { 'text': ':D', 'code': '' }, { 'text': ':d', 'code': '' }, { 'text': ':(', 'code': '' }, { 'text': ':/', 'code': '' }, { 'text': ':P', 'code': '' }, { 'text': ':p', 'code': '' }, { 'text': '3:)', 'code': '' }, { 'text': '(^)', 'code': '' }, { 'text': ';)', 'code': '' }, { 'text': ':o', 'code': '' }, { 'text': '-_-', 'code': '' }, { 'text': '(y)', 'code': '' }, { 'text': ':*', 'code': '' }, { 'text': '<3', 'code': '' }, { 'text': '<3', 'code': '' }, { 'text': '</3', 'code': '' }, { 'text': '3', 'code': '' }, { 'text': '^_^', 'code': '' }, { 'text': '8-)', 'code': '' }, { 'text': '8|', 'code': '' }, { 'text': ':S', 'code': '' }, { 'text': ':s', 'code': '' }]; this.icons = options.customFontIcons.length ? options.customFontIcons : defaultIcons; this.escapedSymbols = this.icons.map(function (val) { return escapeRegExp(val.text); }); this.smileyRegex = new RegExp('(^|\\s)(' + this.escapedSymbols.join('|') + ')(?=\\s|$)', 'gi'); } babelHelpers.createClass(Smiley, [{ key: 'process', value: function process() { var _this = this; return this.input.replace(this.smileyRegex, function (match, pre, text) { var index = _this.escapedSymbols.indexOf(escapeRegExp(text)); var code = _this.icons[index].code; return _this.options.template.smiley(text, pre, code, _this.options); }); } }]); return Smiley; }(); var Url = function () { function Url(input, options) { babelHelpers.classCallCheck(this, Url); this.input = input; this.options = options; this.urlRegex = urlRegex(); } babelHelpers.createClass(Url, [{ key: 'process', value: function process() { var _this = this; var config = this.options.linkOptions; return this.input.replace(this.urlRegex, function (match) { var extension = lastElement(match.split('.')); if (lastElement(match) === '/') match = match.slice(0, -1); if (config.exclude.indexOf(extension) === -1) return _this.options.template.url(match, _this.options); return match; }); } }]); return Url; }(); var fetchJsonp = __commonjs(function (module, exports, global) { (function (global, factory) { if (typeof define === 'function' && define.amd) { define(['exports', 'module'], factory); } else if (typeof exports !== 'undefined' && typeof module !== 'undefined') { factory(exports, module); } else { var mod = { exports: {} }; factory(mod.exports, mod); global.fetchJsonp = mod.exports; } })(__commonjs_global, function (exports, module) { 'use strict'; var defaultOptions = { timeout: 5000, jsonpCallback: 'callback', jsonpCallbackFunction: null }; function generateCallbackFunction() { return 'jsonp_' + Date.now() + '_' + Math.ceil(Math.random() * 100000); } // Known issue: Will throw 'Uncaught ReferenceError: callback_*** is not defined' error if request timeout function clearFunction(functionName) { // IE8 throws an exception when you try to delete a property on window // http://stackoverflow.com/a/1824228/751089 try { delete window[functionName]; } catch (e) { window[functionName] = undefined; } } function removeScript(scriptId) { var script = document.getElementById(scriptId); document.getElementsByTagName('head')[0].removeChild(script); } var fetchJsonp = function fetchJsonp(url) { var options = arguments[1] === undefined ? {} : arguments[1]; var timeout = options.timeout != null ? options.timeout : defaultOptions.timeout; var jsonpCallback = options.jsonpCallback != null ? options.jsonpCallback : defaultOptions.jsonpCallback; var timeoutId = undefined; return new Promise(function (resolve, reject) { var callbackFunction = options.jsonpCallbackFunction || generateCallbackFunction(); window[callbackFunction] = function (response) { resolve({ ok: true, // keep consistent with fetch API json: function json() { return Promise.resolve(response); } }); if (timeoutId) clearTimeout(timeoutId); removeScript(jsonpCallback + '_' + callbackFunction); clearFunction(callbackFunction); }; // Check if the user set their own params, and if not add a ? to start a list of params url += url.indexOf('?') === -1 ? '?' : '&'; var jsonpScript = document.createElement('script'); jsonpScript.setAttribute('src', url + jsonpCallback + '=' + callbackFunction); jsonpScript.id = jsonpCallback + '_' + callbackFunction; document.getElementsByTagName('head')[0].appendChild(jsonpScript); timeoutId = setTimeout(function () { reject(new Error('JSONP request to ' + url + ' timed out')); clearFunction(callbackFunction); removeScript(jsonpCallback + '_' + callbackFunction); }, timeout); }); }; // export as global function /* let local; if (typeof global !== 'undefined') { local = global; } else if (typeof self !== 'undefined') { local = self; } else { try { local = Function('return this')(); } catch (e) { throw new Error('polyfill failed because global object is unavailable in this environment'); } } local.fetchJsonp = fetchJsonp; */ module.exports = fetchJsonp; }); }); var fetchJsonp$1 = fetchJsonp && (typeof fetchJsonp === 'undefined' ? 'undefined' : babelHelpers.typeof(fetchJsonp)) === 'object' && 'default' in fetchJsonp ? fetchJsonp['default'] : fetchJsonp; /** * Common template for vimeo and youtube iframes * @param {string} url URL of the embedding video * @param {object} options Options object * @return {string} compiled template with variables replaced */ function template(url, options) { return options.template.vimeo(url, options) || options.template.youtube(url, options); } /** * Plays the video after clicking on the thumbnail * @param {object} options Options object * @return {null} */ function playVideo(options) { /** Execute the customVideoClickHandler if the user wants to handle it on his own. */ if (options.customVideoClickHandler) return options.videoClickHandler(options, template); var classes = document.getElementsByClassName(options.videoClickClass); for (var i = 0; i < classes.length; i++) { classes[i].onclick = function () { options.onVideoShow(); var url = this.getAttribute('data-ejs-url') + "?autoplay=true"; this.parentNode.parentNode.innerHTML = template(url, options); }; } } function getDetailsTemplate(data, fullData, embedUrl, options) { if (data.host === 'vimeo') { return options.template.detailsVimeo(data, fullData, embedUrl, options); } else if (data.host === 'youtube') { return options.template.detailsYoutube(data, fullData, embedUrl, options); } } /** * Applies video.js to all audio and video dynamically * @param {object} options Options object * @return {null} */ function applyVideoJS(options) { options.videojsOptions.width = options.videoWidth; options.videojsOptions.height = options.videoHeight; if (options.videoJS) { if (!options.plugins.videojs) throw new ReferenceError("You have enabled videojs but you haven't loaded the library.Find it at http://videojs.com/"); var VideoJS = options.plugins.videojs; var elements = options.input.getElementsByClassName('ejs-video-js'); for (var i = 0; i < elements.length; i++) { VideoJS(elements[i], options.videojsOptions, function () { return options.videojsCallback(); }); } } } /** * Destroys the onclick event for opening the video template from the details template * @param {className} className * @return {null} */ function destroyVideos(className) { var classes = document.getElementsByClassName(className); for (var i = 0; i < classes.length; i++) { classes[i].onclick = null; } } function inlineEmbed(_) { var regexInline = _.options.link ? new RegExp('([^>]*' + _.regex.source + ')', 'gm') : new RegExp('([^\\s]*' + _.regex.source + ')', 'gm'); _.output = _.output.replace(regexInline, function (match) { var url = _.options.link ? match.slice(0, -4) : match; if (_.options.served.indexOf(url) === -1) { _.options.served.push(url); if (_.options.link) { return !_.options.inlineText ? _.template(match.slice(0, -4)) + '' : match + _.template(match.slice(0, -4)); } else { return !_.options.inlineText ? _.template(match) : match + _.template(match); } } else { return match; //TODO : check whether this should be `match` } }); return [_.output, _.embeds]; } function normalEmbed(_) { var match = void 0; while ((match = matches(_.regex, _.input)) !== null) { var url = match[0]; if (!(_.options.served.indexOf(url) === -1) || _.options.served.length && _.options.singleEmbed) continue; _.options.served.push(url); var text = _.template(url); _.embeds.push({ text: text, index: match.index }); } return [_.output, _.embeds]; } function embed(_) { return ifInline(_.options, _.service) ? inlineEmbed(_) : normalEmbed(_); } var Base = function () { function Base(input, output, embeds, options, regex, service) { babelHelpers.classCallCheck(this, Base); this.input = input; this.output = output; this.options = options; this.embeds = embeds; this.regex = regex; this.service = service; } babelHelpers.createClass(Base, [{ key: 'template', value: function template(match) { return this.options.template[this.service](match, this.options); } }, { key: 'process', value: function process() { return embed(this); } }]); return Base; }(); function baseEmbed(input, output, embeds, options, regex, service, flag) { return ifEmbed(options, service) || ifEmbed(options, service) && flag ? new Base(input, output, embeds, options, regex, service).process() : [output, embeds]; } /** * This is a private function which is used to get the actual text to be replaced for * a particular url in inline embedding. This returns a promise * @param {object} _ reference to this * @param {function} urlToText The function that converts url to replaceable text * @param {object} match object containing info of matching string * @return {Promise} resolves to the text */ function getInlineData(_, urlToText, match) { var url = (_.options.link ? match[0].slice(0, -4) : match[0]) || match[1]; if (_.options.served.indexOf(url) >= 0) return Promise.resolve(null); return new Promise(function (resolve) { urlToText(_, match, url).then(function (text) { if (!text) return resolve(); _.options.served.push(url); resolve(text); }); }); } /** * A helper function for inline embedding * @param _ * @param urlToText * @returns Promise */ function inlineAsyncEmbed(_, urlToText) { var regexInline = _.options.link ? new RegExp('([^>]*' + _.regex.source + ')', 'gi') : new RegExp('([^\\s]*' + _.regex.source + ')', 'gi'); var match = void 0, promises = []; while ((match = matches(regexInline, _.output)) !== null) { promises.push(getInlineData(_, urlToText, match)); }return new Promise(function (resolve) { if (matches.length) Promise.all(promises).then(function (data) { var i = 0; _.output = _.output.replace(regexInline, function (match) { if (_.options.link) return !_.options.inlineText ? data[i] + '' : match + data[i++];else return !_.options.inlineText ? data[i] : match + data[i++]; }); resolve(_.output); });else resolve(_.output); }); } function getNormalData(_, urlToText, match) { var url = match[0]; if (_.options.served.indexOf(url) >= 0) return; return new Promise(function (resolve) { urlToText(_, match, url, true).then(function (text) { if (!text) resolve(); _.options.served.push(url); _.embeds.push({ text: text, index: match.index }); resolve(); }); }); } /** * A helper function for normal embedding * @param {object} _ * @param {function} urlToText * @return {Promise} */ function normalAsyncEmbed(_, urlToText) { var match = void 0, promises = []; while ((match = matches(_.regex, _.input)) !== null) { promises.push(getNormalData(_, urlToText, match)); }return new Promise(function (resolve) { Promise.all(promises).then(function () { resolve(_.embeds); }); }); } function asyncEmbed(_, urlToText) { return new Promise(function (resolve) { if (ifInline(_.options, _.service)) inlineAsyncEmbed(_, urlToText).then(function (output) { return resolve([output, _.embeds]); });else normalAsyncEmbed(_, urlToText).then(function (embeds) { return resolve([_.output, embeds]); }); }); } var Twitter = function () { function Twitter(input, output, options, embeds) { babelHelpers.classCallCheck(this, Twitter); this.input = input; this.output = output; this.options = options; this.embeds = embeds; this.regex = regex.twitter; this.service = 'twitter'; this.load = this.load.bind(this); this.options.input.addEventListener('rendered', this.load, false); } /** * Fetches the data from twitter's oEmbed API * @param {string} url URL of the tweet * @return {object} data containing the tweet info */ babelHelpers.createClass(Twitter, [{ key: 'tweetData', value: function tweetData(url) { var config = this.options.tweetOptions; var apiUrl = 'https://api.twitter.com/1/statuses/oembed.json?omit_script=true&url=' + url + '&maxwidth=' + config.maxWidth + '&hide_media=' + config.hideMedia + '&hide_thread=' + config.hideThread + '&align=' + config.align + '&lang=' + config.lang; return new Promise(function (resolve) { fetchJsonp$1(apiUrl, { credentials: 'include' }).then(function (data) { return data.json(); }).then(function (json) { return resolve(json); }); }); } /** * Load twitter widgets * @return null */ }, { key: 'load', value: function load() { var twitter = this.options.plugins.twitter; twitter.widgets.load(this.options.element); //here this refers to the element //Execute the function after the widget is loaded twitter.events.bind('loaded', this.options.onTweetsLoad); } }, { key: 'process', value: function process() { var _this2 = this; return new Promise(function (resolve) { return asyncEmbed(_this2, Twitter.urlToText).then(function (data) { return resolve(data); }); }); } }], [{ key: 'urlToText', value: function urlToText(_this, match, url) { return new Promise(function (resolve) { return _this.tweetData(url).then(function (data) { return resolve(data.html); }); }); } }]); return Twitter; }(); (function (self) { 'use strict'; if (self.fetch) { return; } function normalizeName(name) { if (typeof name !== 'string') { name = String(name); } if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) { throw new TypeError('Invalid character in header field name'); } return name.toLowerCase(); } function normalizeValue(value) { if (typeof value !== 'string') { value = String(value); } return value; } function Headers(headers) { this.map = {}; if (headers instanceof Headers) { headers.forEach(function (value, name) { this.append(name, value); }, this); } else if (headers) { Object.getOwnPropertyNames(headers).forEach(function (name) { this.append(name, headers[name]); }, this); } } Headers.prototype.append = function (name, value) { name = normalizeName(name); value = normalizeValue(value); var list = this.map[name]; if (!list) { list = []; this.map[name] = list; } list.push(value); }; Headers.prototype['delete'] = function (name) { delete this.map[normalizeName(name)]; }; Headers.prototype.get = function (name) { var values = this.map[normalizeName(name)]; return values ? values[0] : null; }; Headers.prototype.getAll = function (name) { return this.map[normalizeName(name)] || []; }; Headers.prototype.has = function (name) { return this.map.hasOwnProperty(normalizeName(name)); }; Headers.prototype.set = function (name, value) { this.map[normalizeName(name)] = [normalizeValue(value)]; }; Headers.prototype.forEach = function (callback, thisArg) { Object.getOwnPropertyNames(this.map).forEach(function (name) { this.map[name].forEach(function (value) { callback.call(thisArg, value, name, this); }, this); }, this); }; function consumed(body) { if (body.bodyUsed) { return Promise.reject(new TypeError('Already read')); } body.bodyUsed = true; } function fileReaderReady(reader) { return new Promise(function (resolve, reject) { reader.onload = function () { resolve(reader.result); }; reader.onerror = function () { reject(reader.error); }; }); } function readBlobAsArrayBuffer(blob) { var reader = new FileReader(); reader.readAsArrayBuffer(blob); return fileReaderReady(reader); } function readBlobAsText(blob) { var reader = new FileReader(); reader.readAsText(blob); return fileReaderReady(reader); } var support = { blob: 'FileReader' in self && 'Blob' in self && function () { try { new Blob(); return true; } catch (e) { return false; } }(), formData: 'FormData' in self, arrayBuffer: 'ArrayBuffer' in self }; function Body() { this.bodyUsed = false; this._initBody = function (body) { this._bodyInit = body; if (typeof body === 'string') { this._bodyText = body; } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { this._bodyBlob = body; } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { this._bodyFormData = body; } else if (!body) { this._bodyText = ''; } else if (support.arrayBuffer && ArrayBuffer.prototype.isPrototypeOf(body)) { // Only support ArrayBuffers for POST method. // Receiving ArrayBuffers happens via Blobs, instead. } else { throw new Error('unsupported BodyInit type'); } if (!this.headers.get('content-type')) { if (typeof body === 'string') { this.headers.set('content-type', 'text/plain;charset=UTF-8'); } else if (this._bodyBlob && this._bodyBlob.type) { this.headers.set('content-type', this._bodyBlob.type); } } }; if (support.blob) { this.blob = function () { var rejected = consumed(this); if (rejected) { return rejected; } if (this._bodyBlob) { return Promise.resolve(this._bodyBlob); } else if (this._bodyFormData) { throw new Error('could not read FormData body as blob'); } else { return Promise.resolve(new Blob([this._bodyText])); } }; this.arrayBuffer = function () { return this.blob().then(readBlobAsArrayBuffer); }; this.text = function () { var rejected = consumed(this); if (rejected) { return rejected; } if (this._bodyBlob) { return readBlobAsText(this._bodyBlob); } else if (this._bodyFormData) { throw new Error('could not read FormData body as text'); } else { return Promise.resolve(this._bodyText); } }; } else { this.text = function () { var rejected = consumed(this); return rejected ? rejected : Promise.resolve(this._bodyText); }; } if (support.formData) { this.formData = function () { return this.text().then(decode); }; } this.json = function () { return this.text().then(JSON.parse); }; return this; } // HTTP methods whose capitalization should be normalized var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']; function normalizeMethod(method) { var upcased = method.toUpperCase(); return methods.indexOf(upcased) > -1 ? upcased : method; } function Request(input, options) { options = options || {}; var body = options.body; if (Request.prototype.isPrototypeOf(input)) { if (input.bodyUsed) { throw new TypeError('Already read'); } this.url = input.url; this.credentials = input.credentials; if (!options.headers) { this.headers = new Headers(input.headers); } this.method = input.method; this.mode = input.mode; if (!body) { body = input._bodyInit; input.bodyUsed = true; } } else { this.url = input; } this.credentials = options.credentials || this.credentials || 'omit'; if (options.headers || !this.headers) { this.headers = new Headers(options.headers); } this.method = normalizeMethod(options.method || this.method || 'GET'); this.mode = options.mode || this.mode || null; this.referrer = null; if ((this.method === 'GET' || this.method === 'HEAD') && body) { throw new TypeError('Body not allowed for GET or HEAD requests'); } this._initBody(body); } Request.prototype.clone = function () { return new Request(this); }; function decode(body) { var form = new FormData(); body.trim().split('&').forEach(function (bytes) { if (bytes) { var split = bytes.split('='); var name = split.shift().replace(/\+/g, ' '); var value = split.join('=').replace(/\+/g, ' '); form.append(decodeURIComponent(name), decodeURIComponent(value)); } }); return form; } function headers(xhr) { var head = new Headers(); var pairs = xhr.getAllResponseHeaders().trim().split('\n'); pairs.forEach(function (header) { var split = header.trim().split(':'); var key = split.shift().trim(); var value = split.join(':').trim(); head.append(key, value); }); return head; } Body.call(Request.prototype); function Response(bodyInit, options) { if (!options) { options = {}; } this.type = 'default'; this.status = options.status; this.ok = this.status >= 200 && this.status < 300; this.statusText = options.statusText; this.headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers); this.url = options.url || ''; this._initBody(bodyInit); } Body.call(Response.prototype); Response.prototype.clone = function () { return new Response(this._bodyInit, { status: this.status, statusText: this.statusText, headers: new Headers(this.headers), url: this.url }); }; Response.error = function () { var response = new Response(null, { status: 0, statusText: '' }); response.type = 'error'; return response; }; var redirectStatuses = [301, 302, 303, 307, 308]; Response.redirect = function (url, status) { if (redirectStatuses.indexOf(status) === -1) { throw new RangeError('Invalid status code'); } return new Response(null, { status: status, headers: { location: url } }); }; self.Headers = Headers; self.Request = Request; self.Response = Response; self.fetch = function (input, init) { return new Promise(function (resolve, reject) { var request; if (Request.prototype.isPrototypeOf(input) && !init) { request = input; } else { request = new Request(input, init); } var xhr = new XMLHttpRequest(); function responseURL() { if ('responseURL' in xhr) { return xhr.responseURL; } // Avoid security warnings on getResponseHeader when not allowed by CORS if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) { return xhr.getResponseHeader('X-Request-URL'); } return; } xhr.onload = function () { var status = xhr.status === 1223 ? 204 : xhr.status; if (status < 100 || status > 599) { reject(new TypeError('Network request failed')); return; } var options = { status: status, statusText: xhr.statusText, headers: headers(xhr), url: responseURL() }; var body = 'response' in xhr ? xhr.response : xhr.responseText; resolve(new Response(body, options)); }; xhr.onerror = function () { reject(new TypeError('Network request failed')); }; xhr.open(request.method, request.url, true); if (request.credentials === 'include') { xhr.withCredentials = true; } if ('responseType' in xhr && support.blob) { xhr.responseType = 'blob'; } request.headers.forEach(function (value, name) { xhr.setRequestHeader(name, value); }); xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit); }); }; self.fetch.polyfill = true; })(typeof self !== 'undefined' ? self : this); var Gmap = function () { function Gmap(input, output, options, embeds) { babelHelpers.classCallCheck(this, Gmap); this.input = input; this.output = output; this.options = options; this.embeds = embeds; this.service = 'map'; this.regex = regex.gmap; } /** * Takes the location name and returns the coordinates of that location using the Google * Map API v3. This is an async function so it will return a promise. * @param {string} location The name of any location * @return {array} Returns an array in the form [latitude, longitude] */ babelHelpers.createClass(Gmap, [{ key: 'process', value: function process() { var _this = this; var match = void 0, promises = [], allMatches = []; while ((match = matches(this.regex, this.output)) !== null) { this.options.served.push(match); var promise = this.options.mapOptions.mode !== 'place' ? Gmap.getCoordinate(match[0]) : Promise.resolve([null, null]); promises.push(promise); allMatches.push(match); } return new Promise(function (resolve) { Promise.all(promises).then(function (coordinatesArr) { var _loop = function _loop() { var _coordinatesArr$i = babelHelpers.slicedToArray(coordinatesArr[i], 2); var latitude = _coordinatesArr$i[0]; var longitude = _coordinatesArr$i[1]; var text = Gmap.template(allMatches[i][0], latitude, longitude, _this.options); if (ifInline(_this.options, _this.service)) { _this.output = _this.output.replace(_this.regex, function (regexMatch) { return '' + Gmap.locationText(regexMatch) + '' + text; }); } else { _this.embeds.push({ text: text, index: allMatches[i][0].index }); _this.output = _this.output.replace(_this.regex, function (regexMatch) { return '' + Gmap.locationText(regexMatch) + ''; }); } }; for (var i in promises) { _loop(); } resolve([_this.output, _this.embeds]); }); }); } }], [{ key: 'getCoordinate', value: function getCoordinate(location) { var url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' + location + '&sensor=false'; return new Promise(function (resolve) { fetch(url).then(function (data) { return data.json(); }).then(function (json) { return resolve([json.results[0].geometry.location.lat, json.results[0].geometry.location.lng]); }); }); } /** * Returns the template of the Map widget. The source of the iframe is based on whether the * mode set in options is 'place', 'streetview' or 'view'. * @param {string} match The matching string in the form of @(location name). * @param {number} latitude Latitude of the location * @param {number} longitude Longitude of the location * @param {object} options plugin options * @return {string} Template of the map widget. */ }, { key: 'template', value: function template(match, latitude, longitude, options) { var location = Gmap.locationText(match); var config = options.mapOptions; if (config.mode === 'place') { return ''; } else if (config.mode === 'streetview') { return ''; } else if (config.mode === 'view') { return ''; } } /** * Extracts out the location name from the format @(locationName) * @param {string} match The string in the supported format. Eg : @(Delhi) * @return {string} Only the location name removing @ and brackets. Eg: Delhi */ }, { key: 'locationText', value: function locationText(match) { return match.split('(')[1].split(')')[0]; } }]); return Gmap; }(); var Markdown = function () { function Markdown(output, options) { babelHelpers.classCallCheck(this, Markdown); if (!options.plugins.marked) throw new ReferenceError('marked.js is not loaded.'); this.output = output; this.options = options; } babelHelpers.createClass(Markdown, [{ key: 'process', value: function process() { var _this = this; var Marked = this.options.plugins.marked; var renderer = new Marked.Renderer(); renderer.link = function (href, title, text) { if (href.indexOf('</a') === -1) return href; if (href.match(/>(.+)<\/a/gi)) { if (!title) title = ''; return '' + text + ''; } }; renderer.image = function (href, title, text) { if (href.indexOf('</a') === -1) return href; if (href.match(/>(.+)<\/a/gi)) { if (!title) title = ''; return ''; } }; renderer.paragraph = function (text) { return '' + text + '
'; }; //for font smiley in end. //Fix for heading that should be actually present in marked.js //if gfm is true the `## Heading` is acceptable but `##Heading` is not Marked.Lexer.rules.gfm.heading = Marked.Lexer.rules.normal.heading; Marked.Lexer.rules.tables.heading = Marked.Lexer.rules.normal.heading; this.options.markedOptions.renderer = renderer; this.options.markedOptions.highlight = false; return Marked(this.output, this.options.markedOptions); } }]); return Markdown; }(); var Highlight = function () { function Highlight(output, options) { babelHelpers.classCallCheck(this, Highlight); if (!options.plugins.highlightjs && !this.isPrism()) { throw new ReferenceError('\'hljs is not defined. HighlightJS library is needed to highlight code. Visit https://highlightjs.org/\''); } this.output = output; this.options = options; this.regex = regex.highlightCode; this.inlineCodeRegex = regex.inlineCode; } /** * Encodes the characters like <, > and space and replaces them with * <, > and > respectively. * @param {string} code The string that has to be encoded. * @return {string} The encoded string */ babelHelpers.createClass(Highlight, [{ key: 'process', /** * Replaces the code block with the pre tags and returns a string having the code * formatting using Highlight.js. * => Matches the string with the regex and finds the code written in three back-ticks ``` * => Detects whether any language has been provided by the user. * The format supported by embed.js is * ```[language-name] * var a = 2; * ``` * => Trims all the unnecessary spaces and newlines from the code. * => Passes the code to `hljs.highlightAuto(code, language)` which returns a formatted string * having the html tags for styling. The `language` here is optional. In case we don't pass the * language, it tries to detect the language itself. * => Replaces the code string in the template with the formatted string * @return {string} The string in which the code is formatted */ value: function process() { var _this = this; this.output = this.output.replace(this.inlineCodeRegex, function (match, group1, group2) { return '' + group2 + '';
});
return this.output.replace(this.regex, function (match, group1, group2, group3) {
var code = group3;
code = Highlight.trimSpace(code);
code = Highlight.encode(code);
// to prevent auto-linking. Not necessary in code
// *blocks*, but in code spans. Will be converted
// back after the auto-linker runs.
code = code.replace(/:\/\//g, '~P');
var language = group2.split('\n')[0];
var highlightedCode = void 0;
var HighlightJS = _this.options.plugins.highlightjs;
if (language) {
highlightedCode = HighlightJS.highlightAuto(code, [language]);
} else {
highlightedCode = HighlightJS.highlightAuto(code);
language = highlightedCode.language;
}
return Highlight.addTemplate(highlightedCode, language);
});
}
}], [{
key: 'encode',
value: function encode(code) {
code = code.replace(/&/gm, '');
code = code.replace(/</g, '<');
code = code.replace(/>/g, '>');
return code;
}
/**
* removes whitespace characters
* @param {string} code The string from which the whitespace has to be removed
* @return {string}
*/
}, {
key: 'trimSpace',
value: function trimSpace(code) {
code = code.replace(/^([ \t]*)/g, ''); // leading whitespace
code = code.replace(/[ \t]*$/g, ''); // trailing whitespace
return code;
}
/**
* Places the code and the language name in the required template
* @param {string} processedCode
* @param {string} language
* @return {string}
*/
}, {
key: 'addTemplate',
value: function addTemplate(processedCode, language) {
return '' + (processedCode.value || processedCode) + '';
}
}]);
return Highlight;
}();
var Gist = function () {
function Gist(input, output, options, embeds) {
var _this = this;
babelHelpers.classCallCheck(this, Gist);
this.input = input;
this.output = output;
this.options = options;
this.embeds = embeds;
this.regex = regex.gist;
this.service = 'gist';
this.options.input.addEventListener('rendered', function () {
_this.load();
});
}
babelHelpers.createClass(Gist, [{
key: 'template',
value: function template(match) {
return '';
}
}, {
key: 'load',
value: function load() {
var gists = this.options.input.getElementsByClassName('ejs-gist');
for (var i = 0; i < gists.length; i++) {
var gistFrame = document.createElement("iframe");
gistFrame.setAttribute("width", "100%");
gistFrame.id = 'ejs-gist-' + i;
var zone = gists[i];
zone.innerHTML = "";
zone.appendChild(gistFrame);
// Create the iframe's document
var url = gists[i].getAttribute('data-src');
url = url.indexOf('http') === -1 ? 'https://' + url : url;
var gistFrameHTML = '