Created
May 15, 2011 20:03
-
-
Save metaskills/973483 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Author: | |
Ken Collins <metaskills.net> | |
Options: | |
id - (string: defaults to 'Quickie_' + unique id) The id of the Quickie object. | |
width - (number: defaults to 1) The width of the Quickie object. | |
height - (number: defaults to 1) The height of the Quickie object. | |
container - (element) The container into which the Quickie object will be injected. | |
attributes - (object) QuickTime attributes for the element. See http://www.apple.com/quicktime/tutorials/embed.html for possible attributes. | |
Returns: | |
- (element) A new HTML object Element with browser appropriate QuickTime embed code. | |
Example: | |
var myQuickie = new Quickie('myMovie.mov', { | |
id: 'myQuicktimeMovie', | |
width: 640, | |
height: 480, | |
container: 'qtmovie', | |
attributes: { | |
controller: true, | |
autoplay: false | |
} | |
}); | |
Credits: | |
Mootools Implementaiton: http://pradador.com/code/quickiejs/ | |
""" | |
class Quickie | |
@instanceCount = 0 | |
constructor: (src, passedOptions = {}) -> | |
defaultOptions = | |
id: null | |
height: 1 | |
width: 1 | |
container: null | |
attributes: {} | |
options = jQuery.extend defaultOptions, passedOptions | |
Quickie.instanceCount++ | |
@id = options.id or "Quickie_#{Quickie.instanceCount}" | |
@container = jQuery(options.container) | |
@attributes = options.attributes | |
@attributes.src = src | |
@height = if @attributes.controller is true then options.height + 16 else options.height | |
@width = options.width | |
@._generateElement() | |
toString: -> | |
$('<div>').append($(@element).clone()).remove().html() | |
_generateElement: -> | |
node = if jQuery.browser.webkit | |
@._buildVideoTag() | |
else if jQuery.browser.msie | |
@._buildObjectTag() | |
else | |
@._buildEmbedTag() | |
node.attr 'id', @id | |
node.attr 'width', @width | |
node.attr 'height', @height | |
@element = node.get(0) | |
_buildVideoTag: -> | |
videoTag = jQuery('<video>') | |
videoTag.attr 'src', @attributes.src | |
videoTag.prop 'autoplay', true if @attributes.autoplay is true | |
videoTag.prop 'loop', true if @attributes.loop is true | |
videoTag | |
_buildObjectTag: -> | |
objectTag = jQuery("<object>") | |
objectTag.attr 'classid', 'clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' | |
objectTag.attr 'codebase', 'http://www.apple.com/qtactivex/qtplugin.cab' | |
for own name, value of @attributes | |
if value? | |
objectTag.append "<param name='#{name}' value='#{value}' />" | |
objectTag | |
_buildEmbedTag: -> | |
embedTag = jQuery('<embed>') | |
embedTag.attr 'pluginspage', 'http://www.apple.com/quicktime/download/' | |
for own name, value of @attributes | |
if value? | |
embedTag.attr name, value | |
embedTag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment