Giter Club home page Giter Club logo

embed-js's Introduction

Build Status npm Twitter

A lightweight JavaScript plugin to embed emojis, media, maps, tweets, code and services.

This is the documentation for v5. If you are looking for docs of v4 you can get them here.

Edit embed.js - demo

Features

  • Supported: supports IE8+ (assuming Promise is polyfilled)
  • Plugin Based: only load what you want.
  • Isomorphic: Can be used both on server and client side.
  • Customizable: So much that creating a custom plugin is also few lines of code.
  • Modern: written in ES2015

Contents

Installation

To install the stable version:

npm install --save embed-js

CDN

https://unpkg.com/embed-js

Basic Usage

You need to use plugins or presets to do anything. By default embed-js does nothing.

Let's assume that the HTML structure is as written below

<div id="element">
   <!--===== your string here =======-->
</div>

Creating an instance of embed.js

import EmbedJS from 'embed-js'
import url from 'embed-plugin-url'
import emoji from 'embed-plugin-emoji'

const x = new EmbedJS({
  input: document.getElementById('element'),
  plugins: [
    url(),
    emoji()
  ]
})

Next step is replacing the original text with the processed text.

//Render the result
x.render();

There may be cases where you just want the processed string to use it according to your need. You can get it by the following method. This can be used on the server side to get the string. Still if the plugin involves interactions, you will have to load it on the client side.

//Get the resulting string
x.text().then(({ result }) => {
  console.log(result); //The resulting string
})

If you wan't to destroy the instance. It will also replace the processed string with the original string.

//Destroy the instance
x.destroy()

Options

option default Description
plugins [] Accepts an array of plugins.
preset null Accepts a preset. Currently accpets only one preset. It can be combined with plugins.
inlineEmbed true If case you want to to embed contents at the end of texts, turn this to false.
replaceUrl false Useful when inlineEmbed is set to true. Replace text with the embed.
fetch window.fetch or window.unfetch If you are willing to use the library on both server and client side you need to pass an isomorphic fetch library like isomorphic-unfetch or isomorphic-fetch. This is only needed if you are using a plugin that has to make a HTTP request.

Development

  1. Fork the repo
  2. clone the repo then cd embed.js
  3. create a new branch
  4. Then npm install && yarn build:watch
  5. Create a PR

Note: This projects adheres to a Code of Conduct.

License

MIT © Ritesh Kumar

embed-js's People

Contributors

ritz078 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

embed-js's Issues

Error message on .render()

Hello,

I've been trying to get your plugin to work, but every time I attempt to render I get this error message;

Uncaught (in promise) ReferenceError: hljs is not defined()                 embed.min.js:10

I've installed via npm and loading the minified version from /dist
I've also tried a CDN and I tried to load from /src but the same error keeps coming back.

Please do not pollute Array/String prototype

Please, don't do it, just never. This causes terrible issues when having to deal with 3rd party "authority" JS libraries which are not beyond our control (tons of libraries that iterate an array in the bad way for (item in array)).

I will make a PR soon.

Bug found link

When i enable the link option, the parameter

linkTarget : '_blank',

does not work

new update: missing options?

In the previous versios there where some other options, in the latest they are gone..
Did i miss something?

              codepenEmbed      :true,
              codepenHeight     :300,
              jsfiddleEmbed     :true,
              jsfiddleHeight    :300,
              jsbinEmbed        :true,
              jsbinHeight       :300,
              ideoneEmbed       :true,
              ideoneHeight      :300,
              plunkerEmbed      :true,
              plunkerHeight     :300,


              twitchtvEmbed     :true,
              dotsubEmbed       :true,
              dailymotionEmbed  :true,
              vineEmbed        : true,

              tedEmbed         :true,
              liveleakEmbed     :true,

Hiding original source

It would be nice to if i could hide/mask the original location/link and show only the new output

Video Support

Can you build in video support for the following:

Twitch.TV
LiveLeak
Dotsub
Dailymotion
Vine
TED

Multiple YouTube Videos

Hey there,

first of all, embed.js is awesome und super easy to use. Thanks for that.

I have come across one issue though. Whenever I have multiple YouTube video embeds, and I click one to view the video, all the others stop working. What I mean is that you can't click another video to view right in the browser.

Is this supposed to be like this? Is there any way around this, or is this a bug?

You can see what I mean in this example:
http://codepen.io/ritz078/pen/JYmJML

Click the first video, and then click the second video. In my case at least, the second video won't play.

Thanks for your effort.

Kind regards

Optional: css for small devices.

@media only screen and (min-width: 480px) and (max-width: 767px) {
.ejs-doc-icon {
border-right: 0px solid #eee;
height: 110px;
width: 200px;
}
.ejs-doc-icon i {
margin: 15px 148px;
}
.ejs-doc-view{
height: 65px;
width: 366px;
text-align: center;
}
.ejs-doc-view button {
float: none;
margin: 10px 10px 0;
padding: 6px 15px;
}
.ejs-doc-viewer {
height:320px;
}
.ejs-doc-title {
display: none;
}
.ejs-doc-detail {
padding-left: 0px;
width: 180px;
}
.ejs-doc {
margin: 20px 0;
overflow: auto;
}
.ejs-video-detail {
display: none;
}
.ejs-video-title {
display;none;
}
.ejs-video-desc {
display: none;
}
.ejs-stats {
display: none;
}
.ejs-video-stats span {
display: none;
}
.ejs-video-stats span i {
display: none;
}
.ejs-video-preview img {
height: 224px;
width: 348px;
}
.ejs-video-thumb {
float: none;
width: 348px;
}
.ejs-video-thumb i {
margin-left: 160px;
margin-top: -128px;
}
}

@media only screen and (max-width: 479px) {
.ejs-doc-icon {
border-right: 0px solid #eee;
height: 110px;
width: 228px;
}
.ejs-doc-icon i {
margin: 15px 78px;
}
.ejs-doc-view{
height: 100px;
width: 228px;
text-align: center;
}
.ejs-doc-view button {
float: none;
margin: 10px 10px 0;
padding: 6px 15px;
}
.ejs-doc-viewer {
height:320px;
}
.ejs-doc-title {
display: none;
}
.ejs-doc-detail {
padding-left: 0px;
width: 180px;
}
.ejs-doc {
margin: 20px 0;
overflow: auto;
/*
overflow-y:hidden;
overflow-x:hidden;
*/
}
.ejs-video-detail {
display: none;
}
.ejs-video-title {
display;none;
}
.ejs-video-desc {
display: none;
}
.ejs-stats {
display: none;
}
.ejs-video-stats span {
display: none;
}
.ejs-video-stats span i {
display: none;
}
.ejs-video-player {
width: 208px;
overflow:auto;
}
.ejs-video-player iframe {
width: 208px;
}
.ejs-video-preview img {
height: 138px;
width: 208px;
}
.ejs-video-thumb {
float: none;
width: 208px;
}
}

Bower install failing?

am having this message when im attempting to install with bower:

bower embed-js#*
EMALFORMED Failed to read /var/folders/xh/mzwpjt1d3bgg6wmsvkwsq9f40000gn/T/user/bower/264d16b7d819bc21408de67ee21d81bb-15037-5F7sQ7/bower.json

Additional error details:
Unexpected token ]

Any ideas?

Button text

Option for labeling the buttons in Embed.js (example : view/download button for PDF)
or option to include a special embed_language_en.js file or something.

english can be default language if nothing is included

function request

Hi, thnx for this nice plugin.

Can you add an option for an action after hitting the button to play/listen or view a mediafile?

responsive css

The display of PDF/Video is not nicely displayed on small devcies phones The PDF/Video becomes a box with sliders .

@media only screen and (min-width: 480px) and (max-width: 767px) { }
@media only screen and (max-width: 479px) { }

Improvement

Hi Ritesh,

I would like to suggest you the modifications below :
jquery.embed.css

  1. Add
 .emoticon {
    background : transparent url(../resources/images/emojis.png) 0 0 no-repeat;
}

before @media all and (-webkit-min-device-pixel-ratio : 1), .....
for browsers not support media queries

jquery.embed.js :

  1. Replace :
icons.forEach(function (icon) {
                for (var i = 0; i < a.length; i++) {
                    if (a[i] === icon.text) {
                        a[i] = '<span class="icon-emoticon" title="' + icon.text + '">' + '&#x' + icon.code + '</span>';
                    }
                }
            });

by

jQuery.each(icons, function(index, icon) {
                for (var i = 0; i < a.length; i++) {
if (a[i] === icon.text) {
    a[i] = '<span class="icon-emoticon" title="' + icon.text + '">' + '&#x' + icon.code + ';</span>';
}
                }
            });

2 reasons : for browser not support forEach and the missing ';' after icon.code

  1. Replace :
var lat = d.results[0].geometry.location.lat;
var long = d.results[0].geometry.location.lng;

if (opts.mapOptions.mode === 'streetview') {
    template = '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/streetview?key=' + opts.gdevAuthKey + '&location=' + lat + ',' + long + '&heading=210&pitch=10&fov=35"></iframe>';
}

else {
    template = '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/view?key=' + opts.gdevAuthKey + '&center=' + lat + ',' + long + '&zoom=18&maptype=satellite"></iframe>';
}

by

var latitude = d.results[0].geometry.location.lat;
var longitude = d.results[0].geometry.location.lng;

if (opts.mapOptions.mode === 'streetview') {
    template = '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/streetview?key=' + opts.gdevAuthKey + '&location=' + latitude + ',' + longitude + '&heading=210&pitch=10&fov=35"></iframe>';
} else {
    template = '<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/view?key=' + opts.gdevAuthKey + '&center=' + latitude + ',' + longitude + '&zoom=18&maptype=satellite"></iframe>';
}

long is a reserved word

JF

Url shortener

Future suggestion for short websitelinks using:

goo.gl
bitly
tinyurl
ow.ly

Using Embed.js with input forms (and live preview)

Hi Ritesh,

Awesome work on this plugin, it seems very promising. I was wondering if you could add an example or some directions on how to initialise embed.js on a input form. Think of a Status Update ala Facebook or any form that takes direct input.

In an ideal situation embed.js would be attached to a input form and would show a live preview as the user types/pastes media/links/videos.

Thanks in advance for your help :-)

Customizing Video Templates

Hello Ritesh,

I'm at the process of making a custom template for the different video embeds for my application.

While changing the template it self turned out to be pretty easy (example below with youtube):

ejs.template.detailsYoutube = function(data, fullData, embedUrl){
  return '<div>' + embedUrl  + '</div>'; // this template only shows the embed link as an example
}

Now I am struggling to get the right functionality with clicking the video thumbnail and letting it play.

The code responsible for this should be these two parts:

(embed.js around line 300)

play: function play(className, options) {
    var _this = this;

    var classes = document.getElementsByClassName(className);

    var _loop = function _loop(i) {
        classes[i].onclick = function () {
            options.onVideoShow();
            var url = classes[i].getAttribute('data-ejs-url') + "?autoplay=true";
            classes[i].parentNode.parentNode.innerHTML = _this.template(url, options);
        };
    };

    for (var i = 0; i < classes.length; i++) {
        _loop(i);
    }
},

And at line 3304 the function is called. But in order for it to work I would have to use the 'ejs-video-thumb' class:

helper.play('ejs-video-thumb', this.options);

So here are my questions:

  1. How can I initialize the play function with another class name, without changing the source file?
  2. And how can I customize the play function? Because in the default case, it goes up two levels, whereas in my case I need it to go up two more levels, before it can replace the content with the actual iframe.

Once again, thank you for your effort.

Kind regards,
Enes Emini

Can't get ejs method working with .applyEmbedJS()

I want to embed some code highlighting on a style guide I'm building.

I've got these in my head:

<link rel="stylesheet" type="text/css" href="https://rawgit.com/ritz078/embed.js/es6/dist/embed.min.css" />
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css" />
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" />

and this after my body:

<script src="http://platform.twitter.com/widgets.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.5/highlight.min.js"></script>
<script src="https://rawgit.com/ritz078/embed.js/master/dist/embed.min.js"></script>
<script type="text/javascript">
    ejs.setOptions({
        highlightCode: true
    });

    ejs.applyEmbedJS('.u-ui-pre');
</script>

But I'm not getting the highlighting rendering.

Am I using it wrong? This should be in the examples section I feel.

ImageEmbed

When setting imageEmbed to false, the image is not showing at is original notation.
I use a IMG tag in my resources. Maybey you can make a option to convert the img tag or only urls and enable/disable the function complete.

Google dev key

Hi, could you please show how create the Google keys? I only can get it working using the ones included in the demo. With mines I only get a forbidden message.

Thanks in advance :)

Code comments (cosmetic issue)

lines 526 and 537 are about PDF.

//calling the function before pdf is shown
//calling the function after the pdf is shown.

Videowidth/heigt

It would be nice if the video width can be px or % and the height can be auto-calculated.

CSS

When i include the css file, the following give conflicts in my website becouse the parameter does run on al tags.

  • (asterix) (
    box-sizing : border-box;
    }

I changed it to the name of the div container where EmbedJS is running on.
Is it an suggestion that you change it in one of your next releases so its on the div container?
Maybey more people can have problems with this...

Image stretching

If there are images smaller than the element width they are stretched. This is not nice. My pictures are blown up.

Twitter feeds

can you build in support for displaying twitter feed post?

knipsel

Function request: LightBox

Requestion for a function to add an Lightbox function to images. (Click on image to view an large version)

OnTwitterShow funtion

Can you add an option field for actions after twitter shows up?
Is it also posible to ad this option before & after the embedJS has started? (before apply/ after apply)

          onTwitterShow:function(){
              $('.column').matchHeight();
          },
          onEmbedJSLoad:function(){
              $('.column').matchHeight();
          },
          onEmbedJSLoaded:function(){
              $('.column').matchHeight();
          },

Instagram support

Any plans to add Instagram support? I see there is Instagram mentioned in the code but not in the official support

More plugins support?

Sincere thanks for making this plugin. Its awesome.
Are you planning on including following plugins?

  1. Instagram
  2. Slideshares
  3. TED

How to unset/unload Embed.js

I want to enable/disable the Embed.js function on a div (by clicking a button) for use in a box to show source or preview output.

Is there a way to unload/disable the function ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.