Giter Site home page Giter Site logo

jquery.oembed's Introduction

jquery.oEmbed.js

Summary

URL とoEmbed APIのkey(プロパティ名) から、 値を取得するプラグインです。

This Plugin can get the value form URL and key of oEmbed API(property name).

This Plugin is es6.

About oEmbed API

Access Endpooint_URL?url=Permalink in Browser,

then view Permalink informaition(following).

{
  "title": "Title",
  "html": "<iframe src=\\"\\"><\/iframe>",
  "url": "http://example.com",
  "author_name": "hoge",
  "author_url": "http://example.com/user",
  "provider_name": "example",
  "type": "rich",
  etc...  
}

detail of oEmbed API oembed.com


Sample Page


Support Providers


How to use

Note: This MUST use jquery.xdomanajax.js.

jquery.xdomainajax.js

add following in <body> or <head>.

HTML

<body>
  ~
  <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
  <script src="jquery.xdomainajax.js"></script>
  <script src="jquery.oEmbed.js"></script>
</body>

JS

var url = 'http://example.com';
var key = 'html';
$.when (
  $.oEmbed(url, key)
)
.done(function(value){
  console.log(value);
});

Example

Get embed link from youtube

var url = "https://www.youtube.com/watch?v=ekK7peRxKGc";
$.when(
  $.oEmbed(url, 'html')
)
.done(function(iframe_data){
  $('.hoge').html(iframe_data);
});

Add customProviders

if add Provider without above, can add settings.customProviders property.

var settings = {
  customProviders: [
    {
      name: 'provider_name',
      endpoint: 'endpoint_URL',
      schemelink: ['regexp_string1', ...],
      apiDataFormat: "xml" or 'json',
      queries: /*option*/{format: 'xml',... etc}
    },...
  ]
};

var url = 'http://example.com/article';
$.when(  
  $.oEmbed(url, 'html', settings)
)
.done(function(iframe){
  $('.hoge').html(iframe);
});

example of youtube Provider:

{
  name: 'youtube',
  endpoint: 'http://www.youtube.com/oembed',
  schemelink:  ['https?://www\\.youtube\\.com/watch.*'],
  queries: {'format': 'xml'},
  apiDataFormat: 'xml'
}

Get hatenaBlogCard

if parmalink page not provided oEmbed API, can get embed link(hatenaBlogCard).

hatenaBlogCard sample is following:
http://hatenablog-parts.com/embed?url=https://www.youtube.com/watch?v=Jc-LEG0T_4c

JS

var url = "http://example.com/article";
$.when(
  $.oEmbed(url, 'hatenablogcard')
)
.done(function(hatenaBlogCard){
  $('.hoge').html(hatenaBlogCard);
});

then, can get iframe data is <iframe src="http://hatenablog-parts.com/embed?url=<Permalink> width="100%">.

Get hatenaBlogCard info

can view got info of hatenaBlogCard, use dev tool in Browser.

http://hatenablog-parts.com/embed?url=https://www.youtube.com/watch?v=Jc-LEG0T_4c

<div class="embed-wrapper">

  <div class="embed-wrapper-inner">

    <div class="embed-content with-thumb">

      <div class="thumb-wrapper">
        <a href="https://www.">
        <img src="http://.jpg" class="thumb">
        </a>
      </div>

      <div class="entry-body">
        <h2 class="entry-title">
          <a href="https://">entry-title</a>
        </h2>

        <div class="entry-content">
          entry-content
        </div>
      </div>

    </div>

    <div class="embed-footer">
      <a href="https://www">
        <img src="https://.ico" class="favicon">
      </a>

      <img src="http://" alt="" class="star-count">

      <a href="http://">
        <img src="http://" class="bookmark-count">
      </a>
    </div>

  </div>

</div>

uses class name above, gets value of elements.

Example Get entry-title
var url = 'http://wwww.example.com';
$.when(
  $.oEmbed(url, **'.entry-title'**, {hatenaBlogCard: 'text'}) // innerHTML
)
.done(function(entry_title){
  $('.hoge').text(entry-title); // entry-title
});
Example Get thumbnail
var url = 'http://wwww.example.com';
$.when(
  $.oEmbed(url, '.thumb-wrapper', {hatenaBlogCard: 'html'}) // outerHTML
)
.done(function(thumbnail){
  $('.hoge').text(thumbnail);
  /*
  <a href="http://">
    <img class="thumb" src="http://.jpg">
  </a>
  */
});

jquery.oembed's People

Contributors

cartman0 avatar

Stargazers

Daiki Takaya avatar hiro / connec / THETIME avatar

Watchers

hiro / connec / THETIME avatar James Cloos avatar  avatar

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.