PageSourceSearch

https://oriente.de/components/com_jshopping/js/jquery/jquery.media.js

js oriente.de collected 2026-10-02 12:14:08 UTC 18,047 bytes, 499 lines download raw bytes

1/*
2 * jQuery Media Plugin for converting elements into rich media content.
3 *
4 * Examples and documentation at: http://malsup.com/jquery/media/
5 * Copyright (c) 2007 M. Alsup
6 * Dual licensed under the MIT and GPL licenses:
7 * http://www.opensource.org/licenses/mit-license.php
8 * http://www.gnu.org/licenses/gpl.html
9 *
10 * @author: M. Alsup
11 * @version: 0.73 (12/04/2007)
12 * @requires jQuery v1.1.2 or later
13 * $Id: jquery.media.js 2460 2007-07-23 02:53:15Z malsup $
14 *
15 * Supported Media Players:
16 *    - Flash
17 *    - Quicktime
18 *    - Real Player
19 *    - Silverlight
20 *    - Windows Media Player
21 *    - iframe
22 *
23 * Supported Media Formats:
24 *   Any types supported by the above players, such as:
25 *     Video: asf, avi, flv, mov, mpg, mpeg, mp4, qt, smil, swf, wmv, 3g2, 3gp
26 *     Audio: aif, aac, au, gsm, mid, midi, mov, mp3, m4a, snd, rm, wav, wma
27 *     Other: bmp, html, pdf, psd, qif, qtif, qti, tif, tiff, xaml
28 *
29 * Thanks to Mark Hicken and Brent Pedersen for helping me debug this on the Mac!
30 *
31 * change work ext file + mediaplayer path change
32 */
33(function($) {
34if ( !$.uaMatch ) {
35	$.uaMatch = function( ua ) {
36		ua = ua.toLowerCase();
37		var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
38			/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
39			/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
40			/(msie) ([\w.]+)/.exec( ua ) ||
41			ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
42			[];
43		return {
44			browser: match[ 1 ] || "",
45			version: match[ 2 ] || "0"
46		};
47	};
48}
49
50if ( !$.browser ) {
51	matched = $.uaMatch( navigator.userAgent );
52	browser = {};
53
54	if ( matched.browser ) {
55		browser[ matched.browser ] = true;
56		browser.version = matched.version;
57	}
58
59	// Chrome is Webkit, but Webkit is also Safari.
60	if ( browser.chrome ) {
61		browser.webkit = true;
62	} else if ( browser.webkit ) {
63		browser.safari = true;
64	}
65
66	$.browser = browser;
67}
68
69/**
70 * Chainable method for converting elements into rich media.
71 *
72 * @name media
73 * @param Object options Options object
74 * @param Function callback fn invoked for each matched element before conversion
75 * @param Function callback fn invoked for each matched element after conversion
76 * @cat Plugins/media
77 */
78$.fn.media = function(options, f1, f2) {
79    return this.each(function() {
80        
81        if (typeof options == 'function') {
82            f2 = f1;
83            f1 = options;
84            options = {};
85        }
86        var o = getSettings(this, options);
87        // pre-conversion callback, passes original element and fully populated options
88        if (typeof f1 == 'function') f1(this, o);
89        
90        var r = getTypesRegExp();
91        var m = r.exec(o.src.toLowerCase()) || [''];
92        o.type ? m[0] = o.type : m.shift();
93        for (var i=0; i < m.length; i++) {
94            fn = m[i].toLowerCase();
95            
96            if (isDigit(fn[0])) fn = 'fn' + fn; // fns can't begin with numbers
97            if (!$.fn.media[fn]) 
98                continue;  // unrecognized media type
99            // normalize autoplay settings
100            var player = $.fn.media[fn+'_player'];
101            if (!o.params) o.params = {};
102            if (player) {
103                var num = player.autoplayAttr == 'autostart';
104                o.params[player.autoplayAttr || 'autoplay'] = num ? (o.autoplay ? 1 : 0) : o.autoplay ? true : false;
105            }
106            var $div = $.fn.media[fn](this, o);
107
108            $div.css('backgroundColor', o.bgColor).width(o.width);
109            
110            // post-conversion callback, passes original element, new div element and fully populated options
111            if (typeof f2 == 'function') f2(this, $div[0], o, player.name);
112            break;
113        }
114    });
115};
116
117/**
118 * Chainable method for preparing elements to display rich media with
119 * a page overlay.
120 *
121 * @name mediabox
122 * @param Object options Options object
123 * @param Object css values for the media div
124 * @cat Plugins/media
125 */
126$.fn.mediabox = function(options, css) {
127    return this.click(function() {
128        if (typeof $.blockUI == 'undefined' || typeof $.blockUI.version == 'undefined' || $.blockUI.version < 1.26) {
129            if (typeof $.fn.mediabox.warning != 'undefined') return this; // one warning is enough
130            $.fn.mediabox.warning = 1;
131            alert('The mediabox method requires blockUI v1.26 or later.');
132            return false;
133        }
134        var o, p, div=0, $e = $(this).clone();
135        $e.appendTo('body').hide().css({margin: 0});
136        options = $.extend({}, options, { autoplay: 1 }); // force autoplay in box mode
137        $e.media(options, function(){}, function(origEl, newEl, opts, player) {
138            div = newEl;
139            o = opts;
140            p = player;
141        });
142        if (!div) return false;
143        // don't pull element from the dom on Safari
144        var $div = $.browser.safari ? $(div).hide() : $(div).remove();
145
146        if (o.loadingImage)
147            $div.css({
148                backgroundImage:    'url('+o.loadingImage+')',
149                backgroundPosition: 'center center',
150                backgroundRepeat:   'no-repeat'
151            });
152        if (o.boxTitle)
153            $div.prepend('<div style="margin:0;padding:0">' + o.boxTitle + '</div>');
154        
155        if (css) $div.css(css);
156
157        $div.displayBox( { width: o.width, height: o.height }, function(el) {
158            // quirkiness; sometimes media doesn't stop when removed from the DOM (especially in IE)
159            $('object,embed', el).each(function() {
160                try { this.Stop();   } catch(e) {}  // quicktime
161                try { this.DoStop(); } catch(e) {}  // real
162                try { this.controls.stop(); } catch(e) {} // windows media player
163                $(this).remove();
164            });
165        }, p == 'flash'); // <-- mac/ff workaround
166        return false;
167    });
168};
169
170  
171/**
172 * Non-chainable method for adding or changing file format / player mapping
173 * @name mapFormat
174 * @param String format File format extension (ie: mov, wav, mp3)
175 * @param String player Player name to use for the format (one of: flash, quicktime, realplayer, winmedia, silverlight or iframe
176 */
177$.fn.media.mapFormat = function(format, player) {
178    if (!format || !player || !$.fn.media.defaults.players[player]) return; // invalid
179    format = format.toLowerCase();
180    if (isDigit(format[0])) format = 'fn' + format;
181    $.fn.media[format] = $.fn.media[player];
182    $.fn.media[format+'_player'] = $.fn.media.defaults.players[player];
183};
184
185// global defautls; override as needed
186$.fn.media.defaults = {
187    width:         400,
188    height:        400,
189    preferMeta:    1,         // true if markup metadata takes precedence over options object
190    autoplay:      0,         // normalized cross-player setting
191    bgColor:       '#ffffff', // background color
192    params:        {},        // added to object element as param elements; added to embed element as attrs
193    attrs:         {},        // added to object and embed elements as attrs
194    flashvars:     {},        // added to flash content as flashvars param/attr
195    flashVersion:  '7',       // required flash version
196    
197    // MediaBox options
198    boxTitle:      null,      // MediaBox titlebar
199    loadingImage:  null,      // MediaBox loading indicator
200    
201    // default flash video and mp3 player (@see: http://jeroenwijering.com/?item=Flash_Media_Player)
202    flvPlayer:     'mediaplayer.swf',
203    mp3Player:     'mediaplayer.swf',
204    
205    // @see http://msdn2.microsoft.com/en-us/library/bb412401.aspx
206    silverlight: {
207        inplaceInstallPrompt: 'true', // display in-place install prompt?
208        isWindowless:         'true', // windowless mode (false for wrapping markup)
209        framerate:            '24',   // maximum framerate
210        version:              '0.9',  // Silverlight version
211        onError:              null,   // onError callback
212        onLoad:               null,   // onLoad callback
213        initParams:           null,   // object init params
214        userContext:          null    // callback arg passed to the load callback
215    }
216};
217
218// Media Players; think twice before overriding
219$.fn.media.defaults.players = {
220    flash: {
221        name:         'flash',
222        types:        'flv,mp3,swf',
223        oAttrs:   {
224            classid:  'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000',
225            type:     'application/x-oleobject',
226            codebase: 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + $.fn.media.defaults.flashVersion
227        },
228        eAttrs: {
229            type:         'application/x-shockwave-flash',
230            pluginspage:  'http://www.adobe.com/go/getflashplayer'
231        }        
232    },
233    quicktime: {
234        name:         'quicktime',
235        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',
236        oAttrs:   {
237            classid:  'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
238            codebase: 'http://www.apple.com/qtactivex/qtplugin.cab'
239        },
240        eAttrs: {
241            pluginspage:  'http://www.apple.com/quicktime/download/'
242        }
243    },
244    realplayer: {
245        name:         'real',
246        types:        'ra,ram,rm,rpm,rv,smi,smil',
247        autoplayAttr: 'autostart',
248        oAttrs:   {
249            classid:  'clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA'
250        },
251        eAttrs: {
252            type:         'audio/x-pn-realaudio-plugin',
253            pluginspage:  'http://www.real.com/player/'
254        }
255    },
256    winmedia: {
257        name:         'winmedia',
258        types:        'asf,avi,wma,wmv',
259        autoplayAttr: 'autostart',
260        oUrl:         'url',
261        oAttrs:   {
262            classid:  'clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6',
263            type:     'application/x-oleobject'
264        },
265        eAttrs: {
266            type:         $.browser.mozilla && isFirefoxWMPPluginInstalled() ? 'application/x-ms-wmp' : 'application/x-mplayer2',
267            pluginspage:  'http://www.microsoft.com/Windows/MediaPlayer/'
268        }        
269    },
270    // special cases
271    iframe: {
272        name:  'iframe',
273        types: 'html,pdf'
274    },
275    silverlight: {
276        name:  'silverlight',
277        types: 'xaml'
278    }
279};
280
281//
282//  everything below here is private
283//
284
285
286// detection script for FF WMP plugin (http://www.therossman.org/experiments/wmp_play.html)
287// (hat tip to Mark Ross for this script)
288function isFirefoxWMPPluginInstalled() {
289    var plugs = navigator.plugins;
290    for (i = 0; i < plugs.length; i++) {
291        var plugin = plugs[i];
292        if (plugin['filename'] == 'np-mswmp.dll')
293            return true;
294    }
295    return false;
296}
297
298var counter = 1;
299
300for (var player in $.fn.media.defaults.players) {
301    var types = $.fn.media.defaults.players[player].types;
302    $.each(types.split(','), function(i,o) {
303        if (isDigit(o[0])) o = 'fn' + o;
304        $.fn.media[o] = $.fn.media[player] = getGenerator(player);
305        $.fn.media[o+'_player'] = $.fn.media.defaults.players[player];
306    });
307};
308
309function getTypesRegExp() {
310    var types = '';
311    for (var player in $.fn.media.defaults.players) {
312        if (types.length) types += ',';
313        types += $.fn.media.defaults.players[player].types;
314    };    
315    return new RegExp('\\.(' + types.replace(/,/ig,'|') + ')\\b');
316};
317
318function getGenerator(player) {
319    return function(el, options) {
320        return generate(el, options, player);
321    };
322};
323
324function isDigit(c) {
325    return '0123456789'.indexOf(c) > -1;
326};
327
328// flatten all possible options: global defaults, meta, option obj
329function getSettings(el, options) {
330    options = options || {};
331    var $el = $(el);
332    var cls = el.className || '';
333    // support metadata plugin (v1.0 and v2.0)
334    var meta = $.metadata ? $el.metadata() : $.meta ? $el.data() : {};
335    var w = meta.width  || parseInt(((cls.match(/w:(\d+)/)||[])[1]||0));
336    var h = meta.height || parseInt(((cls.match(/h:(\d+)/)||[])[1]||0));
337    if (w) meta.width  = w;
338    if (h) meta.height = h;
339    if (cls) meta.cls = cls;
340
341    var a = $.fn.media.defaults;
342    var b = $.meta && $.fn.media.defaults.preferMeta ? options : meta;
343    var c = b == options ? meta : options;
344
345    var p = { params: { bgColor: options.bgColor || $.fn.media.defaults.bgColor } };
346    var opts = $.extend({}, a, b, c);
347    $.each(['attrs','params','flashvars','silverlight'], function(i,o) {
348        opts[o] = $.extend({}, p[o] || {}, a[o] || {}, b[o] || {}, c[o] || {});
349    });
350
351    if (typeof opts.caption == 'undefined') opts.caption = $el.text();
352
353    // make sure we have a source!
354    opts.src = opts.src || $el.attr('href') || $el.attr('src') || 'unknown';    
355    return opts;
356};
357
358//
359//  Flash Player
360//
361
362// generate flash using SWFObject if possible
363$.fn.media.swf = function(el, opts) {
364    if (typeof SWFObject == 'undefined') {
365        // roll our own
366        if (opts.flashvars) {
367            var a = [];
368            for (var f in opts.flashvars)
369                a.push(f + '=' + opts.flashvars[f]);
370            if (!opts.params) opts.params = {};
371            opts.params.flashvars = a.join('&');
372        }
373        return generate(el, opts, 'flash');
374    }
375
376    var id = el.id ? (' id="'+el.id+'"') : '';
377    var cls = opts.cls ? (' class="' + opts.cls + '"') : '';
378    var $div = $('<div' + id + cls + '>');
379    $(el).after($div).remove();
380
381    var so = new SWFObject(opts.src, 'movie_player_' + counter++, opts.width, opts.height, opts.flashVersion, opts.bgColor);
382    for (var p in opts.params)
383        if (p != 'bgColor') so.addParam(p, opts.params[p]);
384    for (var f in opts.flashvars)
385        so.addVariable(f, opts.flashvars[f]);
386    so.write($div[0]);
387
388    if (opts.caption) $('<div>').appendTo($div).html(opts.caption);
389    return $div;
390};
391
392// map flv and mp3 files to the swf player by default
393$.fn.media.flv = $.fn.media.mp3 = function(el, opts) {
394    var src = opts.src;
395    var player = /\.mp3\b/i.test(src) ? $.fn.media.defaults.mp3Player : $.fn.media.defaults.flvPlayer;    
396    
397    player = liveurl+'components/com_jshopping/js/jquery/'+player; //change path player
398    
399    opts.src = player;
400    opts.src = opts.src + '?file=' + src;
401    opts.flashvars = $.extend({}, { file: src }, opts.flashvars );
402    return $.fn.media.swf(el, opts);
403};
404
405//
406//  Silverlight
407//
408$.fn.media.xaml = function(el, opts) {
409    if (!window.Sys || !window.Sys.Silverlight) {
410        if ($.fn.media.xaml.warning) return;
411        $.fn.media.xaml.warning = 1;
412        alert('You must include the Silverlight.js script.');
413        return;
414    }
415
416    var props = {
417        width: opts.width,
418        height: opts.height,
419        background: opts.bgColor,
420        inplaceInstallPrompt: opts.silverlight.inplaceInstallPrompt,
421        isWindowless: opts.silverlight.isWindowless,
422        framerate: opts.silverlight.framerate,
423        version: opts.silverlight.version
424    };
425    var events = {
426        onError: opts.silverlight.onError,
427        onLoad: opts.silverlight.onLoad
428    };
429
430    var id1 = el.id ? (' id="'+el.id+'"') : '';
431    var id2 = opts.id || 'AG' + counter++;
432    // convert element to div
433    var cls = opts.cls ? (' class="' + opts.cls + '"') : '';
434    var $div = $('<div' + id1 + cls + '>');
435    $(el).after($div).remove();
436    
437    Sys.Silverlight.createObjectEx({
438        source: opts.src,
439        initParams: opts.silverlight.initParams,
440        userContext: opts.silverlight.userContext,
441        id: id2,
442        parentElement: $div[0],
443        properties: props,
444        events: events
445    });
446
447    if (opts.caption) $('<div>').appendTo($div).html(opts.caption);
448    return $div;
449};
450
451//
452// generate object/embed markup
453//
454function generate(el, opts, player) {
455    var $el = $(el);
456    var o = $.fn.media.defaults.players[player];
457    
458    if (player == 'iframe') {
459        var o = $('<iframe' + ' width="' + opts.width + '" height="' + opts.height + '" >');
460        o.attr('src', opts.src);
461        o.css('backgroundColor', o.bgColor);
462    }
463    else if ($.browser.msie) {
464        var a = ['<object width="' + opts.width + '" height="' + opts.height + '" '];
465        for (var key in opts.attrs)
466            a.push(key + '="'+opts.attrs[key]+'" ');
467        for (var key in o.oAttrs || {})
468            a.push(key + '="'+o.oAttrs[key]+'" ');
469        a.push('></ob'+'ject'+'>');
470        var p = ['<param name="' + (o.oUrl || 'src') +'" value="' + opts.src + '">'];
471        for (var key in opts.params)
472            p.push('<param name="'+ key +'" value="' + opts.params[key] + '">');
473        var o = document.createElement(a.join(''));
474        for (var i=0; i < p.length; i++)
475            o.appendChild(document.createElement(p[i]));
476    }
477    else {
478        var a = ['<embed width="' + opts.width + '" height="' + opts.height + '" style="display:block"'];
479        if (opts.src) a.push(' src="' + opts.src + '" ');
480        for (var key in opts.attrs)
481            a.push(key + '="'+opts.attrs[key]+'" ');
482        for (var key in o.eAttrs || {})
483            a.push(key + '="'+o.eAttrs[key]+'" ');
484        for (var key in opts.params)
485            a.push(key + '="'+opts.params[key]+'" ');
486        a.push('></em'+'bed'+'>');
487    }
488    // convert element to div
489    var id = el.id ? (' id="'+el.id+'"') : '';
490    var cls = opts.cls ? (' class="' + opts.cls + '"') : '';
491    var $div = $('<div' + id + cls + '>');
492    $el.after($div).remove();
493    ($.browser.msie || player == 'iframe') ? $div.append(o) : $div.html(a.join(''));
494    if (opts.caption) $('<div>').appendTo($div).html(opts.caption);
495    return $div;
496};
497
498
499})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.