Changeset 1325
- Timestamp:
- 09/23/10 15:24:54 (3 years ago)
- Location:
- trunk/js
- Files:
-
- 3 edited
-
bin-debug/jwplayer.js (modified) (7 diffs)
-
jwplayer.min.js (modified) (1 diff)
-
src/utils/jwplayer.utils.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/js/bin-debug/jwplayer.js
r1318 r1325 26 26 var args = jwplayer.utils.extend['arguments']; 27 27 if (args.length > 1) { 28 for (var i =1; i < args.length; i++){28 for (var i = 1; i < args.length; i++) { 29 29 for (element in args[i]) { 30 30 args[0][element] = args[i][element]; 31 31 } 32 32 } 33 return args[0]; 33 return args[0]; 34 34 } 35 35 return null; … … 53 53 54 54 /** Loads an XML file into a DOM object **/ 55 jwplayer.utils.ajax = function(xmldocpath, completecallback, errorcallback) {55 jwplayer.utils.ajax = function(xmldocpath, completecallback, errorcallback) { 56 56 var xmlhttp; 57 if (window.XMLHttpRequest) {58 // IE>7, Firefox, Chrome, Opera, Safari57 if (window.XMLHttpRequest) { 58 // IE>7, Firefox, Chrome, Opera, Safari 59 59 xmlhttp = new XMLHttpRequest(); 60 60 } else { 61 // IE661 // IE6 62 62 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 63 63 } 64 64 xmlhttp.onreadystatechange = function() { 65 if (xmlhttp.readyState === 4 && xmlhttp.status === 200){ 65 if (xmlhttp.readyState === 4) { 66 if (xmlhttp.status === 200) { 66 67 if (completecallback) { 67 68 completecallback(xmlhttp); … … 71 72 errorcallback(xmldocpath); 72 73 } 74 } 73 75 } 74 76 }; 75 77 xmlhttp.open("GET", xmldocpath, true); 76 xmlhttp.send( );78 xmlhttp.send(null); 77 79 return xmlhttp; 78 80 }; 79 81 80 82 /** Loads a file **/ 81 jwplayer.utils.load = function(domelement, completecallback, errorcallback) {83 jwplayer.utils.load = function(domelement, completecallback, errorcallback) { 82 84 domelement.onreadystatechange = function() { 83 if (domelement.readyState === 4) {84 if (domelement.status === 200) {85 if (domelement.readyState === 4) { 86 if (domelement.status === 200) { 85 87 if (completecallback) { 86 88 completecallback(); … … 96 98 97 99 /** Finds tags in a DOM, returning a new DOM **/ 98 jwplayer.utils.find = function(dom, tag) {100 jwplayer.utils.find = function(dom, tag) { 99 101 return dom.getElementsByTagName(tag); 100 102 }; … … 110 112 * Detects whether the current browser is IE (version 8 or below). 111 113 * Technique from http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html 112 * Note - this detection no longer works for IE9. 114 * Note - this detection no longer works for IE9. 113 115 **/ 114 116 jwplayer.utils.isIE = function() { … … 119 121 * Detects whether the current browser is mobile Safari. 120 122 **/ 121 122 jwplayer.utils.isIOS = function(){ 123 var agent = navigator.userAgent.toLowerCase(); 124 return (agent.match(/iP(hone|ad)/i) !== null); 125 }; 123 jwplayer.utils.isIOS = function() { 124 var agent = navigator.userAgent.toLowerCase(); 125 return (agent.match(/iP(hone|ad)/i) !== null); 126 }; 126 127 127 128 /** 128 * Detects whether the browser can handle HTML5 video. 129 * Detects whether the browser can handle HTML5 video. 129 130 * Using this as a proxy for detecting all HTML5 features needed for the JW HTML5 Player. Do we need more granularity? 130 131 */ … … 139 140 jwplayer.utils.hasFlash = function() { 140 141 return (typeof navigator.plugins != "undefined" && typeof navigator.plugins['Shockwave Flash'] != "undefined") || (typeof window.ActiveXObject != "undefined"); 141 };/** 142 }; 143 /** 142 144 * Parser for the JW Player. 143 145 * -
trunk/js/jwplayer.min.js
r1318 r1325 1 jwplayer=function(a){return jwplayer.constructor(a)};jwplayer.constructor=function(a){};$jw=jwplayer;jwplayer.utils=function(){};jwplayer.utils.typeOf=function(b){var a=typeof b;if(a==="object"){if(b){if(b instanceof Array){a="array"}}else{a="null"}}return a};jwplayer.utils.extend=function(){var a=jwplayer.utils.extend["arguments"];if(a.length>1){for(var b=1;b<a.length;b++){for(element in a[b]){a[0][element]=a[b][element]}}return a[0]}return null};jwplayer.utils.html=function(a,b){a.innerHTML=b};jwplayer.utils.append=function(a,b){a.appendChild(b)};jwplayer.utils.wrap=function(a,b){a.parentNode.replaceChild(b,a);b.appendChild(a)};jwplayer.utils.ajax=function(d,c,a){var b;if(window.XMLHttpRequest){b=new XMLHttpRequest()}else{b=new ActiveXObject("Microsoft.XMLHTTP")}b.onreadystatechange=function(){if(b.readyState===4 &&b.status===200){if(c){c(b)}}else{if(a){a(d)}}};b.open("GET",d,true);b.send();return b};jwplayer.utils.load=function(b,c,a){b.onreadystatechange=function(){if(b.readyState===4){if(b.status===200){if(c){c()}}else{if(a){a()}}}}};jwplayer.utils.find=function(b,a){return b.getElementsByTagName(a)};jwplayer.utils.append=function(a,b){a.appendChild(b)};jwplayer.utils.isIE=function(){return(!+"\v1")};jwplayer.utils.isIOS=function(){var a=navigator.userAgent.toLowerCase();return(a.match(/iP(hone|ad)/i)!==null)};jwplayer.utils.hasHTML5=function(){return !!document.createElement("video").canPlayType};jwplayer.utils.hasFlash=function(){return(typeof navigator.plugins!="undefined"&&typeof navigator.plugins["Shockwave Flash"]!="undefined")||(typeof window.ActiveXObject!="undefined")};(function(e){e.utils.mediaparser=function(){};var g={element:{width:"width",height:"height",id:"id","class":"className",name:"name"},media:{src:"file",preload:"preload",autoplay:"autostart",loop:"repeat",controls:"controls"},source:{src:"file",type:"type",media:"media","data-jw-width":"width","data-jw-bitrate":"bitrate"},video:{poster:"image"}};var f={};e.utils.mediaparser.parseMedia=function(i){return d(i)};function c(j,i){if(i===undefined){i=g[j]}else{e.utils.extend(i,g[j])}return i}function d(m,i){if(f[m.tagName.toLowerCase()]&&(i===undefined)){return f[m.tagName.toLowerCase()](m)}else{i=c("element",i);var n={};for(var j in i){if(j!="length"){var l=m.getAttribute(j);if(!(l===""||l===undefined||l===null)){n[i[j]]=m.getAttribute(j)}}}var k=m.style["#background-color"];if(k&&!(k=="transparent"||k=="rgba(0, 0, 0, 0)")){n.screencolor=k}return n}}function h(o,k){k=c("media",k);var m=[];if(e.utils.isIE()){var l=o.nextSibling;if(l!==undefined){while(l.tagName.toLowerCase()=="source"){m.push(a(l));l=l.nextSibling}}}else{var j=e.utils.selectors("source",o);for(var n in j){if(!isNaN(n)){m.push(a(j[n]))}}}var p=d(o,k);if(p.file!==undefined){m[0]={file:p.file}}p.levels=m;return p}function a(k,j){j=c("source",j);var i=d(k,j);i.width=i.width?i.width:0;i.bitrate=i.bitrate?i.bitrate:0;return i}function b(k,j){j=c("video",j);var i=h(k,j);return i}e.utils.mediaparser.replaceMediaElement=function(i,k){if(e.utils.isIE()){var l=false;var n=[];var m=i.nextSibling;while(m&&!l){n.push(m);m=m.nextSibling;if(m.nodeType==1&&m.tagName.toLowerCase()==("/")+i.tagName.toLowerCase()){l=true}}if(l){while(n.length>0){var j=n.pop();j.parentNode.removeChild(j)}}i.outerHTML=k}};f.media=h;f.audio=h;f.source=a;f.video=b})(jwplayer);jwplayer.utils.selectors=function(a,c){if(c===undefined){c=document}a=jwplayer.utils.strings.trim(a);var b=a.charAt(0);if(b=="#"){return c.getElementById(a.substr(1))}else{if(b=="."){if(c.getElementsByClassName){return c.getElementsByClassName(a.substr(1))}else{return jwplayer.utils.selectors.getElementsByTagAndClass("*",a.substr(1))}}else{if(a.indexOf(".")>0){selectors=a.split(".");return jwplayer.utils.selectors.getElementsByTagAndClass(selectors[0],selectors[1])}else{return c.getElementsByTagName(a)}}}return null};jwplayer.utils.selectors.getElementsByTagAndClass=function(d,g,f){elements=[];if(f===undefined){f=document}var e=f.getElementsByTagName(d);for(var c=0;c<e.length;c++){if(e[c].className!==undefined){var b=e[c].className.split(" ");for(var a=0;a<b.length;a++){if(b[a]==g){elements.push(e[c])}}}}return elements};jwplayer.utils.strings=function(){};jwplayer.utils.strings.trim=function(a){return a.replace(/^\s*/,"").replace(/\s*$/,"")};(function(b){var a=[];b.constructor=function(c){return b.api.selectPlayer(c)};b.api=function(){};b.api.events={API_READY:"jwplayerAPIReady",JWPLAYER_READY:"jwplayerReady",JWPLAYER_FULLSCREEN:"jwplayerFullscreen",JWPLAYER_RESIZE:"jwplayerResize",JWPLAYER_ERROR:"jwplayerError",JWPLAYER_MEDIA_BUFFER:"jwplayerMediaBuffer",JWPLAYER_MEDIA_BUFFER_FULL:"jwplayerMediaBufferFull",JWPLAYER_MEDIA_ERROR:"jwplayerMediaError",JWPLAYER_MEDIA_LOADED:"jwplayerMediaLoaded",JWPLAYER_MEDIA_COMPLETE:"jwplayerMediaComplete",JWPLAYER_MEDIA_TIME:"jwplayerMediaTime",JWPLAYER_MEDIA_VOLUME:"jwplayerMediaVolume",JWPLAYER_MEDIA_META:"jwplayerMediaMeta",JWPLAYER_MEDIA_MUTE:"jwplayerMediaMute",JWPLAYER_PLAYER_STATE:"jwplayerPlayerState",JWPLAYER_PLAYLIST_LOADED:"jwplayerPlaylistLoaded",JWPLAYER_PLAYLIST_ITEM:"jwplayerPlaylistItem"};b.api.events.state={BUFFERING:"BUFFERING",IDLE:"IDLE",PAUSED:"PAUSED",PLAYING:"PLAYING"};b.api.PlayerAPI=function(d){this.container=d;this.id=d.id;var j={};var n={};var c=[];var g=undefined;var i=false;var h=[];var l=d.outerHTML;var m={};this.setPlayer=function(o){g=o};this.stateListener=function(o,p){if(!n[o]){n[o]=[];this.eventListener(b.api.events.JWPLAYER_PLAYER_STATE,f(o))}n[o].push(p);return this};function f(o){return function(q){var p=q.newstate,s=q.oldstate;if(p==o){var r=n[p];if(r){for(var t in r){if(typeof r[t]=="function"){r[t].call(this,{oldstate:s,newstate:p})}}}}}}this.addInternalListener=function(o,p){o.jwAddEventListener(p,'function(dat) { jwplayer("'+this.id+'").dispatchEvent("'+p+'", dat); }')};this.eventListener=function(o,p){if(!j[o]){j[o]=[];if(g&&i){this.addInternalListener(g,o)}}j[o].push(p);return this};this.dispatchEvent=function(q){if(j[q]){var p=e(q,arguments[1]);for(var o in j[q]){if(typeof j[q][o]=="function"){j[q][o].call(this,p)}}}};function e(p,o){var q=b.utils.extend({},o);if(p==b.api.events.JWPLAYER_FULLSCREEN){q.fullscreen=q.message;delete q.message}else{if(typeof q.data=="object"){q=b.utils.extend(q,q.data);delete q.data}}return q}this.callInternal=function(p,o){if(i){if(typeof g!="undefined"&&typeof g[p]=="function"){if(o!==undefined){return(g[p])(o)}else{return(g[p])()}}return null}else{h.push({method:p,parameters:o})}};this.playerReady=function(q){i=true;if(!g){this.setPlayer(document.getElementById(q.id))}for(var o in j){this.addInternalListener(g,o)}this.eventListener(b.api.events.JWPLAYER_PLAYLIST_ITEM,function(r){m={}});this.eventListener(b.api.events.JWPLAYER_MEDIA_META,function(r){b.utils.extend(m,r.metadata)});this.dispatchEvent(b.api.events.API_READY);while(h.length>0){var p=h.shift();this.callInternal(p.method,p.parameters)}};this.getItemMeta=function(){return m};this.destroy=function(){j={};h=[];if(this.container.outerHTML!=l){b.api.destroyPlayer(this.id,l)}};function k(q,s,r){var o=[];if(!s){s=0}if(!r){r=q.length-1}for(var p=s;p<=r;p++){o.push(q[p])}return o}};b.api.PlayerAPI.prototype={container:undefined,options:undefined,id:undefined,getBuffer:function(){return this.callInternal("jwGetBuffer")},getDuration:function(){return this.callInternal("jwGetDuration")},getFullscreen:function(){return this.callInternal("jwGetFullscreen")},getHeight:function(){return this.callInternal("jwGetHeight")},getLockState:function(){return this.callInternal("jwGetLockState")},getMeta:function(){return this.getItemMeta()},getMute:function(){return this.callInternal("jwGetMute")},getPlaylist:function(){return this.callInternal("jwGetPlaylist")},getPlaylistItem:function(c){if(c==undefined){c=0}return this.getPlaylist()[c]},getPosition:function(){return this.callInternal("jwGetPosition")},getState:function(){return this.callInternal("jwGetState")},getVolume:function(){return this.callInternal("jwGetVolume")},getWidth:function(){return this.callInternal("jwGetWidth")},setFullscreen:function(c){this.callInternal("jwSetFullscreen",c);return this},setMute:function(c){this.callInternal("jwSetMute",c);return this},lock:function(){return this},unlock:function(){return this},load:function(c){this.callInternal("jwLoad",c);return this},playlistItem:function(c){this.callInternal("jwPlaylistItem",c);return this},playlistPrev:function(){this.callInternal("jwPlaylistPrev");return this},playlistNext:function(){this.callInternal("jwPlaylistNext");return this},resize:function(d,c){this.container.width=d;this.container.height=c;return this},play:function(c){if(typeof c==="undefined"){var c=this.getState();if(c==b.api.events.state.PLAYING||c==b.api.events.state.BUFFERING){this.callInternal("jwPause")}else{this.callInternal("jwPlay")}}else{this.callInternal("jwPlay",c)}return this},pause:function(){var c=this.getState();switch(c){case b.api.events.state.PLAYING:case b.api.events.state.BUFFERING:this.callInternal("jwPause");break;case b.api.events.state.PAUSED:this.callInternal("jwPlay");break}return this},stop:function(){this.callInternal("jwStop");return this},seek:function(c){this.callInternal("jwSeek",c);return this},setVolume:function(c){this.callInternal("jwSetVolume",c);return this},onBufferChange:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_BUFFER,c)},onBufferFull:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_BUFFER_FULL,c)},onError:function(c){return this.eventListener(b.api.events.JWPLAYER_ERROR,c)},onFullscreen:function(c){return this.eventListener(b.api.events.JWPLAYER_FULLSCREEN,c)},onMeta:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_META,c)},onMute:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_MUTE,c)},onPlaylist:function(c){return this.eventListener(b.api.events.JWPLAYER_PLAYLIST_LOADED,c)},onPlaylistItem:function(c){return this.eventListener(b.api.events.JWPLAYER_PLAYLIST_ITEM,c)},onReady:function(c){return this.eventListener(b.api.events.API_READY,c)},onResize:function(c){return this.eventListener(b.api.events.JWPLAYER_RESIZE,c)},onComplete:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_COMPLETE,c)},onTime:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_TIME,c)},onVolume:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_VOLUME,c)},onBuffer:function(c){return this.stateListener(b.api.events.state.BUFFERING,c)},onPause:function(c){return this.stateListener(b.api.events.state.PAUSED,c)},onPlay:function(c){return this.stateListener(b.api.events.state.PLAYING,c)},onIdle:function(c){return this.stateListener(b.api.events.state.IDLE,c)},setup:function(c){return this},remove:function(){this.destroy()},initializePlugin:function(c,d){return this}};b.api.selectPlayer=function(d){var c;if(d==undefined){d=0}if(d.nodeType){c=d}else{if(typeof d=="string"){c=document.getElementById(d)}}if(c){var e=b.api.playerById(c.id);if(e){return e}else{return b.api.addPlayer(new b.api.PlayerAPI(c))}}else{if(typeof d=="number"){return b.getPlayers()[d]}}return null};b.api.playerById=function(d){for(var c in a){if(a[c].id==d){return a[c]}}return null};b.api.addPlayer=function(d){for(var c in a){if(a[c]==d){return d}}a.push(d);return d};b.api.destroyPlayer=function(f,d){var e=-1;for(var h in a){if(a[h].id==f){e=h;continue}}if(e>=0){var c=document.getElementById(a[e].id);if(c){if(d){c.outerHTML=d}else{var g=document.createElement("div");g.setAttribute("id",c.id);c.parentNode.replaceChild(g,c)}}a.splice(e,1)}return null};b.getPlayers=function(){return a.slice(0)}})(jwplayer);var _userPlayerReady=(typeof playerReady=="function")?playerReady:undefined;playerReady=function(b){var a=jwplayer.api.playerById(b.id);if(a){a.playerReady(b)}if(_userPlayerReady){_userPlayerReady.call(this,b)}};(function(a){a.embed=function(){};a.embed.Embedder=function(c){this.constructor(c)};a.embed.defaults={width:400,height:300,players:[{type:"flash",src:"player.swf"},{type:"html5"}],components:{controlbar:{position:"over"}}};a.embed.Embedder.prototype={config:undefined,api:undefined,events:{},players:undefined,constructor:function(d){this.api=d;var c=a.utils.mediaparser.parseMedia(this.api.container);this.config=this.parseConfig(a.utils.extend({},a.embed.defaults,c,this.api.config))},embedPlayer:function(){var c=this.players[0];if(c&&c.type){switch(c.type){case"flash":if(a.utils.hasFlash()){if(this.config.levels||this.config.playlist){this.api.onReady(this.loadAfterReady(this.config))}this.config.id=this.api.id;var e=a.embed.embedFlash(document.getElementById(this.api.id),c,this.config);this.api.container=e;this.api.setPlayer(e)}else{this.players.splice(0,1);return this.embedPlayer()}break;case"html5":if(a.utils.hasHTML5()){var d=a.embed.embedHTML5(document.getElementById(this.api.id),c,this.config);this.api.container=document.getElementById(this.api.id);this.api.setPlayer(d)}else{this.players.splice(0,1);return this.embedPlayer()}break}}else{this.api.container.innerHTML="<p>No suitable players found</p>"}this.setupEvents();return this.api},setupEvents:function(){for(evt in this.events){if(typeof this.api[evt]=="function"){(this.api[evt]).call(this.api,this.events[evt])}}},loadAfterReady:function(c){return function(e){if(c.playlist){this.load(c.playlist)}else{if(c.levels){var d=this.getPlaylistItem(0);if(!d){d={file:c.levels[0].file,provider:"video"}}if(!d.image){d.image=c.image}d.levels=c.levels;this.load(d)}}}},parseConfig:function(c){var d=a.utils.extend({},c);if(d.events){this.events=d.events;delete d.events}if(d.players){this.players=d.players;delete d.players}if(d.plugins){if(typeof d.plugins=="object"){d=a.utils.extend(d,a.embed.parsePlugins(d.plugins))}}return d}};a.embed.embedFlash=function(e,i,d){var j=a.utils.extend({},d);var g=j.width;delete j.width;var c=j.height;delete j.height;if(j.levels&&j.levels.length&&j.file===undefined){}delete j.levels;delete j.playlist;a.embed.parseConfigBlock(j,"components");a.embed.parseConfigBlock(j,"providers");if(a.utils.isIE()){var f='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+g+'" height="'+c+'" id="'+e.id+'" name="'+e.id+'">';f+='<param name="movie" value="'+i.src+'">';f+='<param name="allowfullscreen" value="true">';f+='<param name="allowscriptaccess" value="always">';f+='<param name="flashvars" value="'+a.embed.jsonToFlashvars(j)+'">';f+="</object>";if(e.tagName.toLowerCase()=="video"){a.utils.mediaparser.replaceMediaElement(e,f)}else{e.outerHTML=f}return document.getElementById(e.id)}else{var h=document.createElement("object");h.setAttribute("type","application/x-shockwave-flash");h.setAttribute("data",i.src);h.setAttribute("width",g);h.setAttribute("height",c);h.setAttribute("id",e.id);h.setAttribute("name",e.id);a.embed.appendAttribute(h,"allowfullscreen","true");a.embed.appendAttribute(h,"allowscriptaccess","always");a.embed.appendAttribute(h,"flashvars",a.embed.jsonToFlashvars(j));e.parentNode.replaceChild(h,e);return h}};a.embed.embedHTML5=function(d,f,e){if(a.html5){d.innerHTML="<p>Embedded HTML5 player goes here</p>";var c=a.utils.extend({screencolor:"0x000000"},e);a.embed.parseConfigBlock(c,"components");if(c.levels&&!c.sources){c.sources=e.levels}return new (a.html5(d)).setup(c)}else{return null}};a.embed.appendAttribute=function(d,c,e){var f=document.createElement("param");f.setAttribute("name",c);f.setAttribute("value",e);d.appendChild(f)};a.embed.jsonToFlashvars=function(d){var c="";for(key in d){c+=key+"="+escape(d[key])+"&"}return c.substring(0,c.length-1)};a.embed.parsePlugins=function(e){if(!e){return{}}var g={},f=[];for(plugin in e){var d=plugin.indexOf("-")>0?plugin.substring(0,plugin.indexOf("-")):plugin;var c=e[plugin];f.push(plugin);for(param in c){g[d+"."+param]=c[param]}}g.plugins=f.join(",");return g};a.embed.parseConfigBlock=function(f,e){if(f[e]){var h=f[e];for(var d in h){var c=h[d];if(typeof c=="string"){f[d]=c}else{for(var g in c){f[d+"."+g]=c[g]}}}delete f[e]}};a.api.PlayerAPI.prototype.setup=function(d,e){if(d&&d.flashplayer&&!d.players){d.players=[{type:"flash",src:d.flashplayer},{type:"html5"}];delete d.flashplayer}if(e&&!d.players){if(typeof e=="string"){d.players=[{type:"flash",src:e}]}else{if(e instanceof Array){d.players=e}else{if(typeof e=="object"&&e.type){d.players=[e]}}}}var c=this.id;this.remove();var f=a(c);f.config=d;return(new a.embed.Embedder(f)).embedPlayer()};function b(){if(!document.body){return setTimeout(b,15)}var c=a.utils.selectors.getElementsByTagAndClass("video","jwplayer");for(var d=0;d<c.length;d++){var e=c[d];a(e.id).setup({players:[{type:"flash",src:"/jwplayer/player.swf"},{type:"html5"}]})}}b()})(jwplayer);1 jwplayer=function(a){return jwplayer.constructor(a)};jwplayer.constructor=function(a){};$jw=jwplayer;jwplayer.utils=function(){};jwplayer.utils.typeOf=function(b){var a=typeof b;if(a==="object"){if(b){if(b instanceof Array){a="array"}}else{a="null"}}return a};jwplayer.utils.extend=function(){var a=jwplayer.utils.extend["arguments"];if(a.length>1){for(var b=1;b<a.length;b++){for(element in a[b]){a[0][element]=a[b][element]}}return a[0]}return null};jwplayer.utils.html=function(a,b){a.innerHTML=b};jwplayer.utils.append=function(a,b){a.appendChild(b)};jwplayer.utils.wrap=function(a,b){a.parentNode.replaceChild(b,a);b.appendChild(a)};jwplayer.utils.ajax=function(d,c,a){var b;if(window.XMLHttpRequest){b=new XMLHttpRequest()}else{b=new ActiveXObject("Microsoft.XMLHTTP")}b.onreadystatechange=function(){if(b.readyState===4){if(b.status===200){if(c){c(b)}}else{if(a){a(d)}}}};b.open("GET",d,true);b.send(null);return b};jwplayer.utils.load=function(b,c,a){b.onreadystatechange=function(){if(b.readyState===4){if(b.status===200){if(c){c()}}else{if(a){a()}}}}};jwplayer.utils.find=function(b,a){return b.getElementsByTagName(a)};jwplayer.utils.append=function(a,b){a.appendChild(b)};jwplayer.utils.isIE=function(){return(!+"\v1")};jwplayer.utils.isIOS=function(){var a=navigator.userAgent.toLowerCase();return(a.match(/iP(hone|ad)/i)!==null)};jwplayer.utils.hasHTML5=function(){return !!document.createElement("video").canPlayType};jwplayer.utils.hasFlash=function(){return(typeof navigator.plugins!="undefined"&&typeof navigator.plugins["Shockwave Flash"]!="undefined")||(typeof window.ActiveXObject!="undefined")};(function(e){e.utils.mediaparser=function(){};var g={element:{width:"width",height:"height",id:"id","class":"className",name:"name"},media:{src:"file",preload:"preload",autoplay:"autostart",loop:"repeat",controls:"controls"},source:{src:"file",type:"type",media:"media","data-jw-width":"width","data-jw-bitrate":"bitrate"},video:{poster:"image"}};var f={};e.utils.mediaparser.parseMedia=function(i){return d(i)};function c(j,i){if(i===undefined){i=g[j]}else{e.utils.extend(i,g[j])}return i}function d(m,i){if(f[m.tagName.toLowerCase()]&&(i===undefined)){return f[m.tagName.toLowerCase()](m)}else{i=c("element",i);var n={};for(var j in i){if(j!="length"){var l=m.getAttribute(j);if(!(l===""||l===undefined||l===null)){n[i[j]]=m.getAttribute(j)}}}var k=m.style["#background-color"];if(k&&!(k=="transparent"||k=="rgba(0, 0, 0, 0)")){n.screencolor=k}return n}}function h(o,k){k=c("media",k);var m=[];if(e.utils.isIE()){var l=o.nextSibling;if(l!==undefined){while(l.tagName.toLowerCase()=="source"){m.push(a(l));l=l.nextSibling}}}else{var j=e.utils.selectors("source",o);for(var n in j){if(!isNaN(n)){m.push(a(j[n]))}}}var p=d(o,k);if(p.file!==undefined){m[0]={file:p.file}}p.levels=m;return p}function a(k,j){j=c("source",j);var i=d(k,j);i.width=i.width?i.width:0;i.bitrate=i.bitrate?i.bitrate:0;return i}function b(k,j){j=c("video",j);var i=h(k,j);return i}e.utils.mediaparser.replaceMediaElement=function(i,k){if(e.utils.isIE()){var l=false;var n=[];var m=i.nextSibling;while(m&&!l){n.push(m);m=m.nextSibling;if(m.nodeType==1&&m.tagName.toLowerCase()==("/")+i.tagName.toLowerCase()){l=true}}if(l){while(n.length>0){var j=n.pop();j.parentNode.removeChild(j)}}i.outerHTML=k}};f.media=h;f.audio=h;f.source=a;f.video=b})(jwplayer);jwplayer.utils.selectors=function(a,c){if(c===undefined){c=document}a=jwplayer.utils.strings.trim(a);var b=a.charAt(0);if(b=="#"){return c.getElementById(a.substr(1))}else{if(b=="."){if(c.getElementsByClassName){return c.getElementsByClassName(a.substr(1))}else{return jwplayer.utils.selectors.getElementsByTagAndClass("*",a.substr(1))}}else{if(a.indexOf(".")>0){selectors=a.split(".");return jwplayer.utils.selectors.getElementsByTagAndClass(selectors[0],selectors[1])}else{return c.getElementsByTagName(a)}}}return null};jwplayer.utils.selectors.getElementsByTagAndClass=function(d,g,f){elements=[];if(f===undefined){f=document}var e=f.getElementsByTagName(d);for(var c=0;c<e.length;c++){if(e[c].className!==undefined){var b=e[c].className.split(" ");for(var a=0;a<b.length;a++){if(b[a]==g){elements.push(e[c])}}}}return elements};jwplayer.utils.strings=function(){};jwplayer.utils.strings.trim=function(a){return a.replace(/^\s*/,"").replace(/\s*$/,"")};(function(b){var a=[];b.constructor=function(c){return b.api.selectPlayer(c)};b.api=function(){};b.api.events={API_READY:"jwplayerAPIReady",JWPLAYER_READY:"jwplayerReady",JWPLAYER_FULLSCREEN:"jwplayerFullscreen",JWPLAYER_RESIZE:"jwplayerResize",JWPLAYER_ERROR:"jwplayerError",JWPLAYER_MEDIA_BUFFER:"jwplayerMediaBuffer",JWPLAYER_MEDIA_BUFFER_FULL:"jwplayerMediaBufferFull",JWPLAYER_MEDIA_ERROR:"jwplayerMediaError",JWPLAYER_MEDIA_LOADED:"jwplayerMediaLoaded",JWPLAYER_MEDIA_COMPLETE:"jwplayerMediaComplete",JWPLAYER_MEDIA_TIME:"jwplayerMediaTime",JWPLAYER_MEDIA_VOLUME:"jwplayerMediaVolume",JWPLAYER_MEDIA_META:"jwplayerMediaMeta",JWPLAYER_MEDIA_MUTE:"jwplayerMediaMute",JWPLAYER_PLAYER_STATE:"jwplayerPlayerState",JWPLAYER_PLAYLIST_LOADED:"jwplayerPlaylistLoaded",JWPLAYER_PLAYLIST_ITEM:"jwplayerPlaylistItem"};b.api.events.state={BUFFERING:"BUFFERING",IDLE:"IDLE",PAUSED:"PAUSED",PLAYING:"PLAYING"};b.api.PlayerAPI=function(d){this.container=d;this.id=d.id;var j={};var n={};var c=[];var g=undefined;var i=false;var h=[];var l=d.outerHTML;var m={};this.setPlayer=function(o){g=o};this.stateListener=function(o,p){if(!n[o]){n[o]=[];this.eventListener(b.api.events.JWPLAYER_PLAYER_STATE,f(o))}n[o].push(p);return this};function f(o){return function(q){var p=q.newstate,s=q.oldstate;if(p==o){var r=n[p];if(r){for(var t in r){if(typeof r[t]=="function"){r[t].call(this,{oldstate:s,newstate:p})}}}}}}this.addInternalListener=function(o,p){o.jwAddEventListener(p,'function(dat) { jwplayer("'+this.id+'").dispatchEvent("'+p+'", dat); }')};this.eventListener=function(o,p){if(!j[o]){j[o]=[];if(g&&i){this.addInternalListener(g,o)}}j[o].push(p);return this};this.dispatchEvent=function(q){if(j[q]){var p=e(q,arguments[1]);for(var o in j[q]){if(typeof j[q][o]=="function"){j[q][o].call(this,p)}}}};function e(p,o){var q=b.utils.extend({},o);if(p==b.api.events.JWPLAYER_FULLSCREEN){q.fullscreen=q.message;delete q.message}else{if(typeof q.data=="object"){q=b.utils.extend(q,q.data);delete q.data}}return q}this.callInternal=function(p,o){if(i){if(typeof g!="undefined"&&typeof g[p]=="function"){if(o!==undefined){return(g[p])(o)}else{return(g[p])()}}return null}else{h.push({method:p,parameters:o})}};this.playerReady=function(q){i=true;if(!g){this.setPlayer(document.getElementById(q.id))}for(var o in j){this.addInternalListener(g,o)}this.eventListener(b.api.events.JWPLAYER_PLAYLIST_ITEM,function(r){m={}});this.eventListener(b.api.events.JWPLAYER_MEDIA_META,function(r){b.utils.extend(m,r.metadata)});this.dispatchEvent(b.api.events.API_READY);while(h.length>0){var p=h.shift();this.callInternal(p.method,p.parameters)}};this.getItemMeta=function(){return m};this.destroy=function(){j={};h=[];if(this.container.outerHTML!=l){b.api.destroyPlayer(this.id,l)}};function k(q,s,r){var o=[];if(!s){s=0}if(!r){r=q.length-1}for(var p=s;p<=r;p++){o.push(q[p])}return o}};b.api.PlayerAPI.prototype={container:undefined,options:undefined,id:undefined,getBuffer:function(){return this.callInternal("jwGetBuffer")},getDuration:function(){return this.callInternal("jwGetDuration")},getFullscreen:function(){return this.callInternal("jwGetFullscreen")},getHeight:function(){return this.callInternal("jwGetHeight")},getLockState:function(){return this.callInternal("jwGetLockState")},getMeta:function(){return this.getItemMeta()},getMute:function(){return this.callInternal("jwGetMute")},getPlaylist:function(){return this.callInternal("jwGetPlaylist")},getPlaylistItem:function(c){if(c==undefined){c=0}return this.getPlaylist()[c]},getPosition:function(){return this.callInternal("jwGetPosition")},getState:function(){return this.callInternal("jwGetState")},getVolume:function(){return this.callInternal("jwGetVolume")},getWidth:function(){return this.callInternal("jwGetWidth")},setFullscreen:function(c){this.callInternal("jwSetFullscreen",c);return this},setMute:function(c){this.callInternal("jwSetMute",c);return this},lock:function(){return this},unlock:function(){return this},load:function(c){this.callInternal("jwLoad",c);return this},playlistItem:function(c){this.callInternal("jwPlaylistItem",c);return this},playlistPrev:function(){this.callInternal("jwPlaylistPrev");return this},playlistNext:function(){this.callInternal("jwPlaylistNext");return this},resize:function(d,c){this.container.width=d;this.container.height=c;return this},play:function(c){if(typeof c==="undefined"){var c=this.getState();if(c==b.api.events.state.PLAYING||c==b.api.events.state.BUFFERING){this.callInternal("jwPause")}else{this.callInternal("jwPlay")}}else{this.callInternal("jwPlay",c)}return this},pause:function(){var c=this.getState();switch(c){case b.api.events.state.PLAYING:case b.api.events.state.BUFFERING:this.callInternal("jwPause");break;case b.api.events.state.PAUSED:this.callInternal("jwPlay");break}return this},stop:function(){this.callInternal("jwStop");return this},seek:function(c){this.callInternal("jwSeek",c);return this},setVolume:function(c){this.callInternal("jwSetVolume",c);return this},onBufferChange:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_BUFFER,c)},onBufferFull:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_BUFFER_FULL,c)},onError:function(c){return this.eventListener(b.api.events.JWPLAYER_ERROR,c)},onFullscreen:function(c){return this.eventListener(b.api.events.JWPLAYER_FULLSCREEN,c)},onMeta:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_META,c)},onMute:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_MUTE,c)},onPlaylist:function(c){return this.eventListener(b.api.events.JWPLAYER_PLAYLIST_LOADED,c)},onPlaylistItem:function(c){return this.eventListener(b.api.events.JWPLAYER_PLAYLIST_ITEM,c)},onReady:function(c){return this.eventListener(b.api.events.API_READY,c)},onResize:function(c){return this.eventListener(b.api.events.JWPLAYER_RESIZE,c)},onComplete:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_COMPLETE,c)},onTime:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_TIME,c)},onVolume:function(c){return this.eventListener(b.api.events.JWPLAYER_MEDIA_VOLUME,c)},onBuffer:function(c){return this.stateListener(b.api.events.state.BUFFERING,c)},onPause:function(c){return this.stateListener(b.api.events.state.PAUSED,c)},onPlay:function(c){return this.stateListener(b.api.events.state.PLAYING,c)},onIdle:function(c){return this.stateListener(b.api.events.state.IDLE,c)},setup:function(c){return this},remove:function(){this.destroy()},initializePlugin:function(c,d){return this}};b.api.selectPlayer=function(d){var c;if(d==undefined){d=0}if(d.nodeType){c=d}else{if(typeof d=="string"){c=document.getElementById(d)}}if(c){var e=b.api.playerById(c.id);if(e){return e}else{return b.api.addPlayer(new b.api.PlayerAPI(c))}}else{if(typeof d=="number"){return b.getPlayers()[d]}}return null};b.api.playerById=function(d){for(var c in a){if(a[c].id==d){return a[c]}}return null};b.api.addPlayer=function(d){for(var c in a){if(a[c]==d){return d}}a.push(d);return d};b.api.destroyPlayer=function(f,d){var e=-1;for(var h in a){if(a[h].id==f){e=h;continue}}if(e>=0){var c=document.getElementById(a[e].id);if(c){if(d){c.outerHTML=d}else{var g=document.createElement("div");g.setAttribute("id",c.id);c.parentNode.replaceChild(g,c)}}a.splice(e,1)}return null};b.getPlayers=function(){return a.slice(0)}})(jwplayer);var _userPlayerReady=(typeof playerReady=="function")?playerReady:undefined;playerReady=function(b){var a=jwplayer.api.playerById(b.id);if(a){a.playerReady(b)}if(_userPlayerReady){_userPlayerReady.call(this,b)}};(function(a){a.embed=function(){};a.embed.Embedder=function(c){this.constructor(c)};a.embed.defaults={width:400,height:300,players:[{type:"flash",src:"player.swf"},{type:"html5"}],components:{controlbar:{position:"over"}}};a.embed.Embedder.prototype={config:undefined,api:undefined,events:{},players:undefined,constructor:function(d){this.api=d;var c=a.utils.mediaparser.parseMedia(this.api.container);this.config=this.parseConfig(a.utils.extend({},a.embed.defaults,c,this.api.config))},embedPlayer:function(){var c=this.players[0];if(c&&c.type){switch(c.type){case"flash":if(a.utils.hasFlash()){if(this.config.levels||this.config.playlist){this.api.onReady(this.loadAfterReady(this.config))}this.config.id=this.api.id;var e=a.embed.embedFlash(document.getElementById(this.api.id),c,this.config);this.api.container=e;this.api.setPlayer(e)}else{this.players.splice(0,1);return this.embedPlayer()}break;case"html5":if(a.utils.hasHTML5()){var d=a.embed.embedHTML5(document.getElementById(this.api.id),c,this.config);this.api.container=document.getElementById(this.api.id);this.api.setPlayer(d)}else{this.players.splice(0,1);return this.embedPlayer()}break}}else{this.api.container.innerHTML="<p>No suitable players found</p>"}this.setupEvents();return this.api},setupEvents:function(){for(evt in this.events){if(typeof this.api[evt]=="function"){(this.api[evt]).call(this.api,this.events[evt])}}},loadAfterReady:function(c){return function(e){if(c.playlist){this.load(c.playlist)}else{if(c.levels){var d=this.getPlaylistItem(0);if(!d){d={file:c.levels[0].file,provider:"video"}}if(!d.image){d.image=c.image}d.levels=c.levels;this.load(d)}}}},parseConfig:function(c){var d=a.utils.extend({},c);if(d.events){this.events=d.events;delete d.events}if(d.players){this.players=d.players;delete d.players}if(d.plugins){if(typeof d.plugins=="object"){d=a.utils.extend(d,a.embed.parsePlugins(d.plugins))}}return d}};a.embed.embedFlash=function(e,i,d){var j=a.utils.extend({},d);var g=j.width;delete j.width;var c=j.height;delete j.height;if(j.levels&&j.levels.length&&j.file===undefined){}delete j.levels;delete j.playlist;a.embed.parseConfigBlock(j,"components");a.embed.parseConfigBlock(j,"providers");if(a.utils.isIE()){var f='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+g+'" height="'+c+'" id="'+e.id+'" name="'+e.id+'">';f+='<param name="movie" value="'+i.src+'">';f+='<param name="allowfullscreen" value="true">';f+='<param name="allowscriptaccess" value="always">';f+='<param name="flashvars" value="'+a.embed.jsonToFlashvars(j)+'">';f+="</object>";if(e.tagName.toLowerCase()=="video"){a.utils.mediaparser.replaceMediaElement(e,f)}else{e.outerHTML=f}return document.getElementById(e.id)}else{var h=document.createElement("object");h.setAttribute("type","application/x-shockwave-flash");h.setAttribute("data",i.src);h.setAttribute("width",g);h.setAttribute("height",c);h.setAttribute("id",e.id);h.setAttribute("name",e.id);a.embed.appendAttribute(h,"allowfullscreen","true");a.embed.appendAttribute(h,"allowscriptaccess","always");a.embed.appendAttribute(h,"flashvars",a.embed.jsonToFlashvars(j));e.parentNode.replaceChild(h,e);return h}};a.embed.embedHTML5=function(d,f,e){if(a.html5){d.innerHTML="<p>Embedded HTML5 player goes here</p>";var c=a.utils.extend({screencolor:"0x000000"},e);a.embed.parseConfigBlock(c,"components");if(c.levels&&!c.sources){c.sources=e.levels}return new (a.html5(d)).setup(c)}else{return null}};a.embed.appendAttribute=function(d,c,e){var f=document.createElement("param");f.setAttribute("name",c);f.setAttribute("value",e);d.appendChild(f)};a.embed.jsonToFlashvars=function(d){var c="";for(key in d){c+=key+"="+escape(d[key])+"&"}return c.substring(0,c.length-1)};a.embed.parsePlugins=function(e){if(!e){return{}}var g={},f=[];for(plugin in e){var d=plugin.indexOf("-")>0?plugin.substring(0,plugin.indexOf("-")):plugin;var c=e[plugin];f.push(plugin);for(param in c){g[d+"."+param]=c[param]}}g.plugins=f.join(",");return g};a.embed.parseConfigBlock=function(f,e){if(f[e]){var h=f[e];for(var d in h){var c=h[d];if(typeof c=="string"){f[d]=c}else{for(var g in c){f[d+"."+g]=c[g]}}}delete f[e]}};a.api.PlayerAPI.prototype.setup=function(d,e){if(d&&d.flashplayer&&!d.players){d.players=[{type:"flash",src:d.flashplayer},{type:"html5"}];delete d.flashplayer}if(e&&!d.players){if(typeof e=="string"){d.players=[{type:"flash",src:e}]}else{if(e instanceof Array){d.players=e}else{if(typeof e=="object"&&e.type){d.players=[e]}}}}var c=this.id;this.remove();var f=a(c);f.config=d;return(new a.embed.Embedder(f)).embedPlayer()};function b(){if(!document.body){return setTimeout(b,15)}var c=a.utils.selectors.getElementsByTagAndClass("video","jwplayer");for(var d=0;d<c.length;d++){var e=c[d];a(e.id).setup({players:[{type:"flash",src:"/jwplayer/player.swf"},{type:"html5"}]})}}b()})(jwplayer); -
trunk/js/src/utils/jwplayer.utils.js
r1318 r1325 22 22 var args = jwplayer.utils.extend['arguments']; 23 23 if (args.length > 1) { 24 for (var i =1; i < args.length; i++){24 for (var i = 1; i < args.length; i++) { 25 25 for (element in args[i]) { 26 26 args[0][element] = args[i][element]; 27 27 } 28 28 } 29 return args[0]; 29 return args[0]; 30 30 } 31 31 return null; … … 49 49 50 50 /** Loads an XML file into a DOM object **/ 51 jwplayer.utils.ajax = function(xmldocpath, completecallback, errorcallback) {51 jwplayer.utils.ajax = function(xmldocpath, completecallback, errorcallback) { 52 52 var xmlhttp; 53 if (window.XMLHttpRequest) {54 // IE>7, Firefox, Chrome, Opera, Safari53 if (window.XMLHttpRequest) { 54 // IE>7, Firefox, Chrome, Opera, Safari 55 55 xmlhttp = new XMLHttpRequest(); 56 56 } else { 57 // IE657 // IE6 58 58 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 59 59 } 60 60 xmlhttp.onreadystatechange = function() { 61 if (xmlhttp.readyState === 4 && xmlhttp.status === 200){ 61 if (xmlhttp.readyState === 4) { 62 if (xmlhttp.status === 200) { 62 63 if (completecallback) { 63 64 completecallback(xmlhttp); … … 67 68 errorcallback(xmldocpath); 68 69 } 70 } 69 71 } 70 72 }; 71 73 xmlhttp.open("GET", xmldocpath, true); 72 xmlhttp.send( );74 xmlhttp.send(null); 73 75 return xmlhttp; 74 76 }; 75 77 76 78 /** Loads a file **/ 77 jwplayer.utils.load = function(domelement, completecallback, errorcallback) {79 jwplayer.utils.load = function(domelement, completecallback, errorcallback) { 78 80 domelement.onreadystatechange = function() { 79 if (domelement.readyState === 4) {80 if (domelement.status === 200) {81 if (domelement.readyState === 4) { 82 if (domelement.status === 200) { 81 83 if (completecallback) { 82 84 completecallback(); … … 92 94 93 95 /** Finds tags in a DOM, returning a new DOM **/ 94 jwplayer.utils.find = function(dom, tag) {96 jwplayer.utils.find = function(dom, tag) { 95 97 return dom.getElementsByTagName(tag); 96 98 }; … … 106 108 * Detects whether the current browser is IE (version 8 or below). 107 109 * Technique from http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html 108 * Note - this detection no longer works for IE9. 110 * Note - this detection no longer works for IE9. 109 111 **/ 110 112 jwplayer.utils.isIE = function() { … … 115 117 * Detects whether the current browser is mobile Safari. 116 118 **/ 117 118 jwplayer.utils.isIOS = function(){ 119 var agent = navigator.userAgent.toLowerCase(); 120 return (agent.match(/iP(hone|ad)/i) !== null); 121 }; 119 jwplayer.utils.isIOS = function() { 120 var agent = navigator.userAgent.toLowerCase(); 121 return (agent.match(/iP(hone|ad)/i) !== null); 122 }; 122 123 123 124 /** 124 * Detects whether the browser can handle HTML5 video. 125 * Detects whether the browser can handle HTML5 video. 125 126 * Using this as a proxy for detecting all HTML5 features needed for the JW HTML5 Player. Do we need more granularity? 126 127 */
Note: See TracChangeset
for help on using the changeset viewer.
