Giter VIP home page Giter VIP logo

oantoniojr / jquery.html5loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gianlucaguarini/jquery.html5loader

0.0 2.0 0.0 1.33 MB

jQuery.html5Loader can preload images, html5 video and audio sources, script and text files. This plugin needs a JSON file to get the files that it has to preload, and it provides an easy API to communicate the state of loading.

Home Page: https://gianlucaguarini.github.com/jquery.html5loader/

jquery.html5loader's Introduction

Introduction

jQuery.html5Loader can preload images, html5 video and audio sources, script and text files. This plugin needs a JSON file to get the files that it has to preload (or at least you can use also a javascript object), and it provides an easy API to communicate the state of loading.

Features

  • smart: it loads just the sources supported by the client running the script.
  • flexible: it returns the current percentage and the object loaded, so you could be free to show this info as you like
  • fun: inside the package you could find some preloading animation examples, customizable and ready to use

Demo

https://gianlucaguarini.github.com/jquery.html5loader/

jQuery.html5loader in production

USAGE

1 Create a JSON file like this, containing all the files you need to preload ( size in bytes ):


{
		"files": [
			{
				"type":"SCRIPT",
				"source":"../path/to/your/script.js",
				"size":4.096
			},
			{
				"type":"IMAGE",
				"source":"../path/to/your/image.jpg",
				"size":620
			},
			{
				"type":"TEXT",
				"source":"../path/to/your/text.txt",
				"size":44
			},
			{
				"type":"VIDEO",
				"sources": {
					"webm":{
						"source":"../path/to/your/video.webm",
						"size":5054.976
					},
					"ogg":{
						"source":"../path/to/your/video.ogg",
						"size":2932.736
					},
					"mp4":{
						"source":"../path/to/your/video.mp4",
						"size":9285.632
					}
				}
			},
			{
				"type":"AUDIO",
				"sources": {
					"mp3":{
						"source":"../path/to/your/audio.mp3",
						"size":9285.632
					},
					"ogg":{
						"source":"../path/to/your/audio.ogg",
						"size":2089.688
					}
				}
			}
		]
	}

2 Import the plugin into your page:


<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="../js/jQuery.html5Loader.js"></script>

3 Initialize the plugin setting the callback functions:


$.html5Loader({
			filesToLoad:		'../js/files.json', // this could be a JSON or simply a javascript object
			onBeforeLoad:       function () {},
			onComplete:         function () {},
			onElementLoaded:    function ( obj, elm) { },
			onUpdate:           function ( percentage ) {}		
});	

API

Methods

  • onBeforeLoad It is triggered before the loading process starts
  • onComplete It is triggered when the plugin finishes to load all the sources
  • onMediaError This function is invoked in case of any error occurred during the media element fetch
    • obj original object passed to the plugin
    • elm html output (for type "SCRIPT" and "TEXT" this value is just a string)
  • onElementLoaded It is triggered anytime a new element of the json array is loaded, (ATTENTION IF AN ELEMENT IS NOT SUPPORTED IT WILL NEVER PASS TROUGH THIS FUNCTION).
    • obj original object passed to the plugin
    • elm html output (for type "SCRIPT" and "TEXT" this value is just a string)
  • onUpdate it is triggered anytime new bytes are loaded
    • percentage the percentage currently loaded

KNOWN ISSUES

  • Internet Explorer 9 and 10 do not return any value using the method canPlayType on a video or audio element ( http://modernizr.com/docs/#audio ). For these browsers we don't preload any HTML5 media format
  • on mobile devices and on the iPad the preloading of any video or audio element is skipped because those devices can't preload those elements since a user interacts with them

TODO LIST

  • create a nodejs script that is able to read files in a folder exporting the JSON file needed to preload them

jquery.html5loader's People

Contributors

gianlucaguarini avatar

Watchers

 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.