Git Product home page Git Product logo

gfycat.js's Introduction

#gfycat.js

####Version History:

  • 0.1: Initial revision
  • 1.0: Fixes to initialization, cleaned up UI, support for mobile browsers
  • 1.1: Support for autoplaying looping MP4 on iOS 10, GIF view count analytics
  • 1.2: New options: data-hd, data-playback-speed; Custom classes can be added to root element before init

Embed script to generate gfycat embeds on 3rd party websites.

The intent of this Javascript file is to provide a simple way for web publishers to include Gfycat embeds on their websites.

This code is provided on Github, so users can request changes, contribute code, or fork a branch. Please contribute to the project to help improve it with actual real world needs.

###Usage:

Include this script on your webpage right after the opening <body> tag

  <script>
      (function(d, s, id){
         var js, fjs = d.getElementsByTagName(s)[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement(s); js.id = id;
         js.src = "https://assets.gfycat.com/gfycat.js";
         fjs.parentNode.insertBefore(js, fjs);
       }(document, 'script', 'gfycat-js'));
  </script>

Include an embed tag(s)

Example:

<div class="gfyitem" data-title=true data-autoplay=false data-controls=true data-id="BestYellowishElephantseal"></div>

The options are:

  • data-id: the Gfycat id (required)
  • data-controls: include controls for pause/speed/etc (default: false)
  • data-title: show the title on hover (default: false)
  • data-autoplay: automatically start playback on page load (default: true)
  • data-expand (DEPRECATED, please use data-responsive): expand video element to fill the space of its container (default: false)
  • data-responsive: expand video element to fill the space of its container (default: false)
  • data-max-height (works only together with data-responsive=true): set height upper bound for a responsive video
  • data-optimize: play videos when they're 50% visible, and lazy loads gifs (default: true)
  • data-gif: load .gif file instead of video (default: false)
  • data-hd: load high quality video (default: true)
  • data-playback-speed: set video playback speed, values from the interval [0.125, 8] (default: 1)

###Source code

The code is broken down into two files:

  • gfyCollection.js: gfyCollection calls gfyCollection.init() after the script is loaded. Its function is to find every Gfycat embed on the page and create a gfyObject for it.
  • gfyObject.js: a new gfyObject instance is created for each gfycat embed. It contains all of the functions to generate the DOM and manipulate the video.

gfyCollection.init should be called on gfyitem elements which appear on the page after the page load.

The default key the embed script looks for is class="gfyitem", or the class specificed in gfyCollection.init('classname').

Each instance of gfyObject has an init method. It's possible to initialize an object with new data.

html:

<div class="gfyitem" id="BestYellowishElephantseal"></div>

js:

gfyCollection.init();
var collection = gfyCollection.get();
collection[0].init({id: "BareSecondaryFlamingo"});

###Build

npm install
gulp build

###Testing gulp test - runs all the tests once

gulp tdd - watching for file changes and runs all the tests

gfycat.js's People

Contributors

joey5755 avatar koshka avatar lanre-ade avatar all-iver avatar roborourke avatar gfycatjeff 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.