(function ($) { var defaults = { Player: null }; ISPlayers = {}; window.onYouTubePlayerReady = function (playerId) { if ($('a[data-htmlid=' + playerId + ']').length > 0) { var player = document.getElementById(playerId); if (player) { ISPlayers[playerId] = player; $('a[data-htmlid=' + playerId + ']').ISVideo('PlayerReady'); } } } var methods = { Init: function (params) { var options = $.extend({}, defaults, params); return this.each(function () { var $this = $(this), data = $this.data('isvideo'); if (!data) { $(this).data('isvideo', true); $(this).data('isvideooptions', options); if ("youtube" == $(this).data('vtype')) { var htmlid = 'ytplayer' + $(this).data('videoid'); $(this).attr('data-htmlid', htmlid); var embedswfcode = 'http://' + $(this).data('videourl') + '?enablejsapi=1&playerapiid=' + htmlid; $(this).find('.video-code').append('
'); var SWFparams = { allowScriptAccess: "always" }; var atts = { id: htmlid }; swfobject.embedSWF(embedswfcode, 'box' + htmlid, "100%", "280", "8", null, null, SWFparams, atts); $(this).click(function () { $(this).find('img').remove(); $(this).find('.video-link-bg').remove(); $(this).find('.video-code').show(); $(this).unbind("click"); return false; }); } else if ("youtubecode" == $(this).data('vtype')) { $(this).click(function () { $(this).find('img').remove(); $(this).find('.video-link-bg').remove(); $(this).find('.video-code').show(); $(this).unbind("click"); $(this).find('.video-code').html(''); return false; }); } else if ("video" == $(this).data('vtype')) { var videowebm = $(this).data('file').replace(".mp4", ".webm") $(this).find('.video-code').html( '' ); $(this).click(function () { $(this).find('img').remove(); $(this).find('.video-link-bg').remove(); $(this).find('.video-code').show(); $(this).unbind("click"); $(this).find('video')[0].play(); return false; }); } } }); }, Destroy: function () { return this.each(function () { }) }, PlayerReady: function () { return this.each(function () { if ('run' == $(this).data('run')) { if (typeof ISPlayers[$(this).data('htmlid')] != "undefined") { ISPlayers[$(this).data('htmlid')].playVideo(); } } }) }, Play: function () { return this.each(function () { }) }, Pause: function () { return this.each(function () { }) } }; $.fn.ISVideo = function (method) { if (methods[method]) { return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === 'object' || !method) { return methods.Init.apply(this, arguments); } else { $.error('Метод ' + method + ' не существует в jQuery.ISVideo'); } }; })(jQuery);