diff --git a/README.md b/README.md index 9b04df4..230633f 100755 --- a/README.md +++ b/README.md @@ -49,16 +49,19 @@ To add breaks in the video, simply add a new time (in seconds) in the list of br }); ### Customize marker style: -The style of the markers could be modified by passing an optional setting "markerStyle" with your preference of css styles. +The style of the markers could be modified by passing an optional setting "markerTip.style" with your preference of css styles. +You can also customise each marker style on it's own. video.markers({ - markerStyle: { - 'width':'8px', - 'background-color': 'red' + markerTip: { + style: { + 'width':'8px', + 'background-color': 'red' + } }, markers: [ {time: 9.5, text: "this"}, - {time: 16, text: "is"}, + {time: 16, text: "is", style: {'background-color': 'yellow'}}, {time: 23.6,text: "so"}, {time: 28, text: "cool"} ] diff --git a/dist/videojs-markers.js b/dist/videojs-markers.js index d89b453..7867c91 100644 --- a/dist/videojs-markers.js +++ b/dist/videojs-markers.js @@ -5,11 +5,6 @@ (function ($, videojs, undefined) { // default setting var defaultSetting = { - markerStyle: { - 'width': '7px', - 'border-radius': '30%', - 'background-color': 'red' - }, markerTip: { display: true, text: function text(marker) { @@ -17,7 +12,8 @@ }, time: function time(marker) { return marker.time; - } + }, + style: {} }, breakOverlay: { display: false, @@ -25,16 +21,11 @@ text: function text(marker) { return "Break overlay: " + marker.overlayText; }, - style: { - 'width': '100%', - 'height': '20%', - 'background-color': 'rgba(0,0,0,0.7)', - 'color': 'white', - 'font-size': '17px' - } + style: {} }, onMarkerClick: function onMarkerClick(marker) {}, onMarkerReached: function onMarkerReached(marker, index) {}, + directInitialize: false, markers: [] }; @@ -94,7 +85,7 @@ function createMarkerDiv(marker) { var markerDiv = $("
"); - markerDiv.css(setting.markerStyle).css({ + markerDiv.css(marker.style ? $.extend({}, setting.markerTip.style, marker.style) : setting.markerTip.style).css({ "margin-left": -parseFloat(markerDiv.css("width")) / 2 + 'px', "left": getPosition(marker) + '%' }).attr("data-marker-key", marker.key).attr("data-marker-time", setting.markerTip.time(marker)); @@ -306,11 +297,6 @@ player.on("timeupdate", onTimeUpdate); } - // setup the plugin after we loaded video's meta data - player.on("loadedmetadata", function () { - initialize(); - }); - // exposed plugin API player.markers = { getMarkers: function getMarkers() { @@ -372,6 +358,15 @@ delete player.markers; } }; + + if (setting.directInitialize) { + initialize(); + } else { + // setup the plugin after we loaded video's meta data + player.on("loadedmetadata", function() { + initialize(); + }); + } } videojs.plugin('markers', registerVideoJsMarkersPlugin); diff --git a/dist/videojs.markers.css b/dist/videojs.markers.css index 7655a64..d5eb776 100644 --- a/dist/videojs.markers.css +++ b/dist/videojs.markers.css @@ -4,6 +4,11 @@ bottom: 0em; opacity: 1; height: 100%; + width: 7px; + border-radius: 30%; + -moz-border-radius: 30%; + -webkit-border-radius: 30%; + background-color: red; transition: opacity .2s ease; -webkit-transition: opacity .2s ease; -moz-transition: opacity .2s ease; @@ -52,6 +57,11 @@ position: absolute; z-index: 100000; top: 0; + width: 100%; + height: 20%; + background-color: rgba(0,0,0,0.7); + color: white; + font-size: 17px; } .vjs-break-overlay .vjs-break-overlay-text { padding: 9px; diff --git a/src/videojs.markers.js b/src/videojs.markers.js index 5f2860f..3815b50 100755 --- a/src/videojs.markers.js +++ b/src/videojs.markers.js @@ -17,11 +17,6 @@ type Marker = { (function($, videojs, undefined) { // default setting const defaultSetting = { - markerStyle: { - 'width':'7px', - 'border-radius': '30%', - 'background-color': 'red', - }, markerTip: { display: true, text: function(marker) { @@ -30,6 +25,7 @@ type Marker = { time: function(marker) { return marker.time; }, + style: {} }, breakOverlay:{ display: false, @@ -37,16 +33,11 @@ type Marker = { text: function(marker) { return "Break overlay: " + marker.overlayText; }, - style: { - 'width':'100%', - 'height': '20%', - 'background-color': 'rgba(0,0,0,0.7)', - 'color': 'white', - 'font-size': '17px', - }, + style: {}, }, onMarkerClick: function(marker) {}, onMarkerReached: function(marker, index) {}, + directInitialize: false, markers: [], }; @@ -107,7 +98,7 @@ type Marker = { function createMarkerDiv(marker: Marker): Object { var markerDiv = $(""); markerDiv - .css(setting.markerStyle) + .css(marker.style ? $.extend({}, setting.markerTip.style, marker.style) : setting.markerTip.style) .css({ "margin-left" : -parseFloat(markerDiv.css("width"))/2 + 'px', "left" : getPosition(marker) + '%', @@ -338,11 +329,6 @@ type Marker = { player.on("timeupdate", onTimeUpdate); } - // setup the plugin after we loaded video's meta data - player.on("loadedmetadata", function() { - initialize(); - }); - // exposed plugin API player.markers = { getMarkers: function(): Array