Git Product home page Git Product logo

getty-embeddy's Introduction

getty-embeddy

npm version Build Status codecov.io

Embed Gettyimages photos (iFrame) into your website using Gettyimages's native oEmbed endpoint.

the concept was as lightweight and direct as possible for smaller footprint so if you want a power horse with > 500 LOC check something like embedza, url-embed or jquery-oembed-all. However, make sure they support Gettyimages!

Feedback and PRs are welcomed.

you made a library for THAT! no chance, I will create my Iframe link on my own!

well, you can't -.-

unlike other social services out there, GettyImages kinda forces you to use oEmbed (or their API) to get the working iframe link.

However, if you managed to generate the url on the fly, please tell me!

Install

$ npm install --save getty-embeddy

Usage

var GettyEmbeddy = require('getty-embeddy');
// all options are optional with the default values shown here:
var gettyEmbeddy = new GettyEmbeddy({
  // undefined to search in whole document or an element to use as parent for better performance (recommended!)
  parentEl: undefined,    
  // all elements with this class will be processed          
  selectorClass: 'js-getty-embeddy-el',
  // which data attr will hold the GettyImages image id
  dataAttr: 'getty-embeddy-id',
  //provide the src (link) attribute for the loading image or false to disable
  //any valid src is accepted (url,base64,svg...)
  loaderImgSrc: 'data:image/gif;base64,R0lGOD....[a small gif loader encoded in base64]',
  // a function to run if embedding fails (image was removed or invalid id etc...)
  // el is the affected element and reason is a string, one of 'no_image_id','invalid_response','connection_error'
  onLoadFail: function (el, reason) {
    if (el && reason && this.options.defaultOnFailHtml && this.options.defaultOnFailHtml.replace) {
      el.innerHTML = this.options.defaultOnFailHtml.replace('__REASON__', reason);
    }
    console.warn('GettyEmbeddy - onLoadFail was called reason:', reason, ' element:', el);
  },
  // if you don't want to provide different onFail function, you can simply change the html here
  // '__REASON__' will be replaced with the fail reason if found
  defaultOnFailHtml: '<span>embedding failed reason:__REASON__</span>',
  // the css to use for the loader element
  loaderCss: 'margin:auto;display:block;top:50%;position:relative;',
  // the time (in milliseconds) to delay the embedAll process for better performance, set to 0 to disable
  embedDelayDuration: 100,
});

gettyEmbeddy.embedAll(); // will scan parentEl for possible embeds and load them (with the 'embedDelayDuration' delay between each embed)
gettyEmbeddy.embed(el); //will check el's data attributes for dataAttr to get image id
gettyEmbeddy.embed(el, '604533586'); // you can provide the id directly if the element doesn't have one or if you need to override it
// gettyEmbeddy.getHtml(gettyId); //TODO

getty-embeddy's People

Contributors

a7madgamal avatar

Stargazers

Tessa Alexander avatar Mark Pitman avatar

Watchers

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.