New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

preloader

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

preloader - npm Package Compare versions

Comparing version
3.0.0
to
4.0.0
+1
-1
lib/loaders/LoaderAudio.js

@@ -11,3 +11,3 @@ /**

/**
* LoaderAudio will load an audio file. The content property will contain an audio tag
* LoaderAudio will load an audio file. The content property will contain an audio tag.
*

@@ -14,0 +14,0 @@ * @class LoaderAudio

@@ -152,3 +152,3 @@ /* global XMLHttpRequest, ArrayBuffer, Blob */

*
* @method _dispatchComplete
* @method _dispatchError
* @protected

@@ -255,2 +255,4 @@ * @param {String} msg The error message we'll be dispatching

case LoaderBase.typeBlob:
case LoaderBase.typeVideo:
case LoaderBase.typeAudio:

@@ -303,2 +305,6 @@ if (Blob) {

function checkAndSetType (xhr, loadType) {
if (loadType === LoaderBase.typeVideo || loadType === LoaderBase.typeAudio) {
loadType = LoaderBase.typeBlob;
}
xhr.responseType = loadType;

@@ -305,0 +311,0 @@

@@ -7,7 +7,6 @@ /**

var Class = require('js-oop');
// var FileMeta = require('./FileMeta')
var LoaderBase = require('./LoaderBase');
/**
* LoaderVideo will load a video file. The content property will contain an video tag
* LoaderVideo will load a video file. The content property will contain a video tag.
*

@@ -23,31 +22,12 @@ * @class LoaderVideo

},
load: function (url) {
this.url = url;
this.content = document.createElement(this.loadType);
this.content.setAttribute('preload', 'auto');
this.content.addEventListener(this.options.loadFullVideo ? 'canplaythrough' : 'canplay', this._dispatchComplete);
this.content.addEventListener('progress', this._onProgress);
this.content.setAttribute('src', this.url);
this.content.load();
},
stopLoad: function () {
this.content.setAttribute('src', '');
this.content.load();
},
_onProgress: function (e) {
this._dispatchProgress(this._getProgress());
},
_dispatchComplete: function () {
this.content.removeEventListener(this.options.loadFullVideo ? 'canplaythrough' : 'canplay', this._dispatchComplete);
this.content.removeEventListener('progress', this._onProgress);
this._dispatchProgress(1);
_parseContent: function () {
Class.parent(this);
},
_getProgress: function () {
if (this.content.buffered && this.content.buffered.length > 0 && this.content.buffered.end && this.content.duration) {
return (this.content.buffered.end(0) / this.content.duration);
} else if (this.content.bytesTotal !== undefined && this.content.bytesTotal > 0 && this.content.bufferedBytes !== undefined) {
return this.content.bufferedBytes / this.content.bytesTotal;
if (window.URL && window.URL.createObjectURL) {
var blobURL = window.URL.createObjectURL(this.content);
this.content = document.createElement(this.loadType);
this.content.src = blobURL;
} else {
return 0;
throw new Error('This browser does not support URL.createObjectURL()');
}

@@ -54,0 +34,0 @@ }

{
"name": "preloader",
"version": "3.0.0",
"version": "4.0.0",
"description": "A library for loading common web assets",

@@ -5,0 +5,0 @@ "main": "index.js",

+43
-40

@@ -5,3 +5,3 @@ # Preloader

A library for loading common web assets
A library for loading common web assets

@@ -14,5 +14,5 @@ ## Usage

The preloader is capable of loading almost all types of files, if it does not understand a file type, it will attempt to load it as a basic xhr request. IT extends the [nodejs event emitter](https://nodejs.org/api/events.html) and uses the following events.
The preloader is capable of loading almost all types of files, if it does not understand a file type, it will attempt to load it as a basic xhr request. It extends the [nodejs event emitter](https://nodejs.org/api/events.html) and uses the following events.
```progress```: `Event` Sends updates on loading progress to other part of application (loading ui)
```progress```: `Event` Sends updates on loading progress to other part of application (loading ui)
```complete```: `Event` Notifies loading completion to other part of application

@@ -25,5 +25,3 @@

var loader = preloader({
xhrImages: false,
loadFullAudio: false,
loadFullVideo: false
xhrImages: false
});

@@ -51,80 +49,85 @@ loader.on('progress',function(progress) {

```xhrImages``` Loads images via XHR and converts to a Blob instead of the image tag, default: false
```loadFullAudio``` Specifies is audio should be loaded in full instead of just to the point where they can play, default: false
```loadFillVideo``` Specifies is video should be loaded in full instead of just to the point where they can play, default: false
```onComplete``` A function to attach to the complete event
```xhrImages``` Loads images via XHR and converts to a Blob instead of the image tag, default: false
```onComplete``` A function to attach to the complete event
```onProgress``` A function to attach to the progress event
```throttle``` A integer specifying maximum amount of connections at a time, 0 = infinite
### add(url, options)
### add(url, options)
Generic asset loader function - determines loader to be used based on file-extension
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
### addImage(url ,options)
### addImage(url ,options)
Load image - uses the LoaderImage loader
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
### addJSON(url, options)
### addJSON(url, options)
Load JSON - uses the LoaderJSON loader
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
### addText(url, options)
### addText(url, options)
Load text - uses the LoaderText loader
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
### addVideo(url, options)
### addVideo(url, options)
Load video - uses the LoaderVideo loader
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
### addImage(url, options)
### addAudio(url, options)
Load audio - uses the LoaderAudio loader
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
### addImage(url, options)
Load image - uses the LoaderImage loader
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
```url```: `String` URL of asset
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
### addFromLoaderType(url, loaderType, options)
### addFromLoaderType(url, loaderType, options)
Load asset using custom loader
```url```: `String` URL of asset
```loaderType```: `function` Custom loader function
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
```url```: `String` URL of asset
```loaderType```: `function` Custom loader function
```options```: `Object` Custom options to override the global options created at instantiation, can also pass in `onComplete` and `onProgress` to listen to the events on this particular item.
### setPercentage(url, percentageOfLoad)
### setPercentage(url, percentageOfLoad)
Sets percentage of total load for a given asset
```url```: `String` URL of asset
```percentageOfLoad```: `Number` representing percentage of total load
```url```: `String` URL of asset
```percentageOfLoad```: `Number` representing percentage of total load
### load()
### load()
Begins loading process
### stopLoad()
### stopLoad()
Stops loading process
### get(url)
### get(url)
Retrieves loaded asset from loader
```url```: `String` URL of asset
```Returns```: asset instance
```url```: `String` URL of asset
```Returns```: asset instance

@@ -131,0 +134,0 @@ ### reset()

var preloader = require('../');
var loader = preloader({
xhrImages: false,
loadFullAudio: false,
loadFullVideo: false
});
loader.on('progress', function (progress) {
console.log(progress);
});
loader.on('complete', function () {
var data = loader.get('test_data.json');
console.log('all content loaded:', data.success);
});
loader.add('http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4', {
onComplete: function (content) {
document.body.appendChild(loader.get('http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'));
}
});
loader.add('http://sandbox.thewikies.com/vfe-generator/images/big-buck-bunny_poster.jpg', {
onComplete: function (content) {
document.body.appendChild(content);
}
});
loader.add('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEACAhITMkM1EwMFFCLy8vQiccHBwcJyIXFxcXFyIRDAwMDAwMEQwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwBIjMzNCY0IhgYIhQODg4UFA4ODg4UEQwMDAwMEREMDAwMDAwRDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDP/AABEIAAYABgMBIgACEQEDEQH/xABVAAEBAAAAAAAAAAAAAAAAAAAAAxAAAQQCAwEAAAAAAAAAAAAAAgABAxQEIxIkMxMBAQAAAAAAAAAAAAAAAAAAAAARAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AIE7MwkbOUJDJWx+ZjXATitx2/h2bEWvX5Y0npQ7aIiD/9k=', {
onComplete: function (content) {
document.body.appendChild(content);
}
});
loader.add('test_data.json');
loader.load();
{
"success": true
}

Sorry, the diff of this file is not supported yet