diff --git a/README.md b/README.md index 325308e..41a431e 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ -videojs-persistvolume -======================== +# videojs-persistvolume A plugin for Video.js that saves user's volume setting using [localStorage](https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage#localStorage), but falls back to cookies if necessary. -###Usage +### Usage Include the plugin: ``` diff --git a/package.json b/package.json new file mode 100644 index 0000000..7bc1c87 --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "videojs-persistvolume", + "main": "videojs.persistvolume.js", + "version": "0.1.3p1", + "license": "MIT", + "homepage": "https://github.com/jbboehr/videojs-persistvolume", + "repository": { + "type": "git", + "url": "git://github.com/jbboehr/videojs-persistvolume.git" + } +} diff --git a/test/example.html b/test/example.html index b908722..c203d80 100644 --- a/test/example.html +++ b/test/example.html @@ -19,9 +19,9 @@ diff --git a/videojs.persistvolume.js b/videojs.persistvolume.js index 21d0fdf..f23e6a2 100644 --- a/videojs.persistvolume.js +++ b/videojs.persistvolume.js @@ -1,5 +1,5 @@ "use strict"; -(function(factory){ +(function(factory) { /*! * Custom Universal Module Definition (UMD) * @@ -8,7 +8,7 @@ * compiler compatible, so string keys are used. */ if (typeof define === 'function' && define['amd']) { - define(['./video'], function(vjs){ factory(window, document, vjs) }); + define(['video.js'], function(vjs){ factory(window, document, vjs) }); // checking that module is an object too because of umdjs/umd#35 } else if (typeof exports === 'object' && typeof module === 'object') { factory(window, document, require('video.js')); @@ -107,17 +107,19 @@ setStorageItem(muteKey, player.muted()); }); - var persistedVolume = getStorageItem(key); - if(persistedVolume !== null){ - player.volume(persistedVolume); - } + player.ready(function() { + var persistedVolume = getStorageItem(key); + if(persistedVolume !== null) { + player.volume(persistedVolume); + } - var persistedMute = getStorageItem(muteKey); - if(persistedMute !== null){ - player.muted('true' === persistedMute); - } + var persistedMute = getStorageItem(muteKey); + if(persistedMute !== null) { + player.muted('true' === persistedMute); + } + }); }; - vjs.plugin("persistvolume", volumePersister); + vjs[ (vjs.registerPlugin ? 'registerPlugin' : 'plugin') ]("persistvolume", volumePersister); -}); \ No newline at end of file +});