/*
* jQuery Media Plugin for converting elements into rich media content.
*
* Examples and documentation at: http://malsup.com/jquery/media/
* Copyright (c) 2007-2010 M. Alsup
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* @author: M. Alsup
* @version: 0.99 (05-JUN-2013)
* @requires jQuery v1.1.2 or later
* $Id: jquery.media.js 2460 2007-07-23 02:53:15Z malsup $
*
* Supported Media Players:
* - Flash
* - Quicktime
* - Real Player
* - Silverlight
* - Windows Media Player
* - iframe
*
* Supported Media Formats:
* Any types supported by the above players, such as:
* Video: asf, avi, flv, mov, mpg, mpeg, mp4, qt, smil, swf, wmv, 3g2, 3gp
* Audio: aif, aac, au, gsm, mid, midi, mov, mp3, m4a, snd, rm, wav, wma
* Other: bmp, html, pdf, psd, qif, qtif, qti, tif, tiff, xaml
*
* Thanks to Mark Hicken and Brent Pedersen for helping me debug this on the Mac!
* Thanks to Dan Rossi for numerous bug reports and code bits!
* Thanks to Skye Giordano for several great suggestions!
* Thanks to Richard Connamacher for excellent improvements to the non-IE behavior!
*/
/*global SWFObject alert Sys */
/*jshint forin:false */
;(function($) {
"use strict";
var mode = document.documentMode || 0;
var msie = /MSIE/.test(navigator.userAgent);
var lameIE = msie && (/MSIE (6|7|8)\.0/.test(navigator.userAgent) || mode < 9);
/**
* Chainable method for converting elements into rich media.
*
* @param options
* @param callback fn invoked for each matched element before conversion
* @param callback fn invoked for each matched element after conversion
*/
$.fn.media = function(options, f1, f2) {
if (options == 'undo') {
return this.each(function() {
var $this = $(this);
var html = $this.data('media.origHTML');
if (html)
$this.replaceWith(html);
});
}
return this.each(function() {
if (typeof options == 'function') {
f2 = f1;
f1 = options;
options = {};
}
var o = getSettings(this, options);
// pre-conversion callback, passes original element and fully populated options
if (typeof f1 == 'function') f1(this, o);
var r = getTypesRegExp();
var m = r.exec(o.src.toLowerCase()) || [''];
var fn;
if (o.type)
m[0] = o.type;
else
m.shift();
for (var i=0; i < m.length; i++) {
fn = m[i].toLowerCase();
if (isDigit(fn[0])) fn = 'fn' + fn; // fns can't begin with numbers
if (!$.fn.media[fn])
continue; // unrecognized media type
// normalize autoplay settings
var player = $.fn.media[fn+'_player'];
if (!o.params) o.params = {};
if (player) {
var num = player.autoplayAttr == 'autostart';
o.params[player.autoplayAttr || 'autoplay'] = num ? (o.autoplay ? 1 : 0) : o.autoplay ? true : false;
}
var $div = $.fn.media[fn](this, o);
$div.css('backgroundColor', o.bgColor).width(o.width);
if (o.canUndo) {
var $temp = $('<div></div>').append(this);
$div.data('media.origHTML', $temp.html()); // store original markup
}
// post-conversion callback, passes original element, new div element and fully populated options
if (typeof f2 == 'function') f2(this, $div[0], o, player.name);
break;
}
});
};
/**
* Non-chainable method for adding or changing file format / player mapping
* @name mapFormat
* @param String format File format extension (ie: mov, wav, mp3)
* @param String player Player name to use for the format (one of: flash, quicktime, realplayer, winmedia, silverlight or iframe
*/
$.fn.media.mapFormat = function(format, player) {
if (!format || !player || !$.fn.media.defaults.players[player]) return; // invalid
format = format.toLowerCase();
if (isDigit(format[0])) format = 'fn' + format;
$.fn.media[format] = $.fn.media[player];
$.fn.media[format+'_player'] = $.fn.media.defaults.players[player];
};
// global defautls; override as needed
$.fn.media.defaults = {
standards: true, // use object tags only (no embeds for non-IE browsers)
canUndo: true, // tells plugin to store the original markup so it can be reverted via: $(sel).mediaUndo()
width: 400,
height: 400,
autoplay: 0, // normalized cross-player setting
bgColor: '#ffffff', // background color
params: { wmode: 'transparent'}, // added to object element as param elements; added to embed element as attrs
attrs: {}, // added to object and embed elements as attrs
flvKeyName: 'file', // key used for object src param (thanks to Andrea Ercolino)
flashvars: {}, // added to flash content as flashvars param/attr
flashVersion: '7', // required flash version
expressInstaller: null, // src for express installer
// default flash video and mp3 player (@see: http://jeroenwijering.com/?item=Flash_Media_Player)
flvPlayer: 'mediaplayer.swf',
mp3Player: 'mediaplayer.swf',
// @see http://msdn2.microsoft.com/en-us/library/bb412401.aspx
silverlight: {
inplaceInstallPrompt: 'true', // display in-place install prompt?
isWindowless: 'true', // windowless mode (false for wrapping markup)
framerate: '24', // maximum framerate
version: '0.9', // Silverlight version
onError: null, // onError callback
onLoad: null, // onLoad callback
initParams: null, // object init params
userContext: null // callback arg passed to the load callback
}
};
// Media Players; think twice before overriding
$.fn.media.defaults.players = {
flash: {
name: 'flash',
title: 'Flash',
types: 'flv,mp3,swf',
mimetype: 'application/x-shockwave-flash',
pluginspage: 'http://www.adobe.com/go/getflashplayer',
ieAttrs: {
classid: 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000',
type: 'application/x-oleobject',
codebase: 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + $.fn.media.defaults.flashVersion
}
},
quicktime: {
name: 'quicktime',
title: 'QuickTime',
mimetype: 'video/quicktime',
pluginspage: 'http://www.apple.com/quicktime/download/',
types: 'aif,aiff,aac,au,bmp,gsm,mov,mid,midi,mpg,mpeg,mp4,m4a,psd,qt,qtif,qif,qti,snd,tif,tiff,wav,3g2,3gp',
ieAttrs: {
classid: 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
codebase: 'http://www.apple.com/qtactivex/qtplugin.cab'
}
},
realplayer: {
name: 'real',
title: 'RealPlayer',
types: 'ra,ram,rm,rpm,rv,smi,smil',
mimetype: 'audio/x-pn-realaudio-plugin',
pluginspage: 'http://www.real.com/player/',
autoplayAttr: 'autostart',
ieAttrs: {
classid: 'clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA'
}
},
winmedia: {
name: 'winmedia',
title: 'Windows Media',
types: 'asx,asf,avi,wma,wmv',
mimetype: isFirefoxWMPPluginInstalled() ? 'application/x-ms-wmp' : 'application/x-mplayer2',
pluginspage: 'http://www.microsoft.com/Windows/MediaPlayer/',
autoplayAttr: 'autostart',
oUrl: 'url',
ieAttrs: {
classid: 'clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6',
type: 'application/x-oleobject'
}
},
// special cases
img: {
name: 'img',
title: 'Image',
types: 'gif,png,jpg'
},
iframe: {
name: 'iframe',
types: 'html,pdf'
},
silverlight: {
name: 'silverlight',
types: 'xaml'
}
};
//
// everything below here is private
//
// detection script for FF WMP plugin (http://www.therossman.org/experiments/wmp_play.html)
// (hat tip to Mark Ross for this script)
function isFirefoxWMPPluginInstalled() {
var plugs = navigator.plugins || [];
for (var i = 0; i < plugs.length; i++) {
var plugin = plugs[i];
if (plugin['filename'] == 'np-mswmp.dll')
return true;
}
return false;
}
var counter = 1;
for (var player in $.fn.media.defaults.players) {
var types = $.fn.media.defaults.players[player].types;
$.each(types.split(','), function(i,o) {
if (isDigit(o[0])) o = 'fn' + o;
$.fn.media[o] = $.fn.media[player] = getGenerator(player);
$.fn.media[o+'_player'] = $.fn.media.defaults.players[player];
});
}
function getTypesRegExp() {
var types
Ctrl+C+V程序猿
- 粉丝: 59
- 资源: 44
最新资源
- 可直接运行 MATLAB数学建模学习资料 模拟算法MATLAB代码实现.rar
- 基于 Java+SQLServer 实现的医药售卖系统课程设计
- HCNP(HCDP)华为认证资深网络工程师-路由交换方向培训 -IESN中文理论书-内文.pdf
- 新版FPGA课程大纲,芯片硬件开发用的大纲
- ROS2下OpenCV识别物体区域和视频捕捉的样例
- STM32-EMBPI.PDF
- Font Awesome图标字体库提供可缩放矢量图标,它可以被定制大小、颜色、阴影以及任何可以用CSS的样式
- Bluefield 2固件镜像版本,fw-MBF2M345A-VENOT-ES-Ax-24.40.1000.bin
- 雪颜奇迹幻白双重莹白焕采霜50ML-1016-FA.rar
- Qt的QDOCK高级用法源码,包含linux和windows版本,从开源库下载
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈