Created
December 2, 2008 06:57
-
-
Save sullenfish/31033 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
var QTMoo = new Class({ | |
version: 0.1, | |
Implements: Options, | |
options: { | |
ACQTCompatibile: false, | |
ACQTVersion: '1.2' | |
}, | |
initialize: function(options){ | |
this.setOptions(options); | |
if (this.options.ACQTCompatibile){ | |
this.generateACQTCompatibilityLayer(this.options.ACQTVersion); | |
} | |
}, | |
generateACQTCompatibilityLayer: function(version){ | |
switch (version){ | |
case '1.2': | |
window.AC_QuickTimeVersion = this.AC_QuickTimeVersion.bind(this); | |
break; | |
default: | |
} | |
}, | |
AC_QuickTimeVersion: function(){ | |
return this.options.ACQTVersion; | |
} | |
}); | |
var _QTMoo = new Class({ | |
Implements: [Events, Options], | |
options: { | |
gTagAttrs: null, | |
gQTBehaviorID: 'qt_event_source', | |
gQTEventsEnabled: false, | |
gArgCountErr: 'The "{callingFunction}" function requires an even number of arguments.\nArguments should be in the form "atttributeName", "attributeValue", ...' | |
}, | |
gQTGeneratorVersion: '1.2', | |
initialize: function(args){ | |
this.setOptions(args); | |
this.gTagAttrs = this.options.gTagAttrs; | |
this.gQTBehaviorID = this.options.gQTBehaviorID; | |
this.gQTEventsEnabled = this.options.gQTEventsEnabled; | |
this.gArgCountErr = this.options.gArgCountErr; | |
}, | |
AC_QuickTimeVersion: function(){ | |
return this.gQTGeneratorVersion; | |
}, | |
_QTComplain: function(callingFcnName, errMsg){ | |
alert(errMsg.substitute({callingFunction: callingFcnName})); | |
}, | |
_QTIsMSIE: function(){ | |
//var ua = navigator.userAgent.toLowerCase(); | |
//var msie = /msie/.test(ua) && !/opera/.test(ua); | |
//return msie; | |
return ($defined(Browser.Engine.trident)); | |
}, | |
_QTGenerateBehavior: function(){ | |
return this.objTag = '<!--[if IE]>' | |
+ '<object id="' + this.gQTBehaviorID + '" classid="clsid:CB927D12-4FF7-4a9e-A169-56E4B8A75598">' | |
+ '</object>' | |
+ '<![endif]-->'; | |
}, | |
_QTPageHasBehaviorObject: function(callingFcnName, args){ | |
var haveBehavior = false; | |
//var objects = document.getElementsByTagName('object'); | |
var objects = $$('object'); | |
for ( var ndx = 0, obj; obj = objects[ndx]; ndx++ ) | |
{ | |
if ( obj.getAttribute('classid') == "clsid:CB927D12-4FF7-4a9e-A169-56E4B8A75598" ) | |
{ | |
if ( obj.getAttribute('id') == gQTBehaviorID ) | |
haveBehavior = false; | |
break; | |
} | |
} | |
return haveBehavior; | |
}, | |
_QTShouldInsertBehavior: function(){ | |
var shouldDo = false; | |
if ( this.gQTEventsEnabled && this._QTIsMSIE() && !this._QTPageHasBehaviorObject() ) | |
shouldDo = true; | |
return shouldDo; | |
}, | |
_QTAddAttribute: function(prefix, slotName, tagName){ | |
var value; | |
value = this.gTagAttrs[prefix + slotName]; | |
if ( null == value ) | |
value = this.gTagAttrs[slotName]; | |
if ( null != value ) | |
{ | |
if ( 0 == slotName.indexOf(prefix) && (null == tagName) ) | |
tagName = slotName.substring(prefix.length); | |
if ( null == tagName ) | |
tagName = slotName; | |
return ' ' + tagName + '="' + value + '"'; | |
} | |
else | |
return ""; | |
}, | |
_QTAddObjectAttr: function(slotName, tagName){ | |
// don't bother if it is only for the embed tag | |
if ( 0 == slotName.indexOf("emb#") ) | |
return ""; | |
if ( 0 == slotName.indexOf("obj#") && (null == tagName) ) | |
tagName = slotName.substring(4); | |
return this._QTAddAttribute("obj#", slotName, tagName); | |
}, | |
_QTAddEmbedAttr: function(slotName, tagName){ | |
// don't bother if it is only for the object tag | |
if ( 0 == slotName.indexOf("obj#") ) | |
return ""; | |
if ( 0 == slotName.indexOf("emb#") && (null == tagName) ) | |
tagName = slotName.substring(4); | |
return this._QTAddAttribute("emb#", slotName, tagName); | |
}, | |
_QTAddObjectParam: function(slotName, generateXHTML){ | |
var paramValue; | |
var paramStr = ""; | |
var endTagChar = (generateXHTML) ? ' />' : '>'; | |
if ( -1 == slotName.indexOf("emb#") ) | |
{ | |
// look for the OBJECT-only param first. if there is none, look for a generic one | |
paramValue = this.gTagAttrs["obj#" + slotName]; | |
if ( null == paramValue ) | |
paramValue = this.gTagAttrs[slotName]; | |
if ( 0 == slotName.indexOf("obj#") ) | |
slotName = slotName.substring(4); | |
if ( null != paramValue ) | |
paramStr = '<param name="' + slotName + '" value="' + paramValue + '"' + endTagChar; | |
} | |
return paramStr; | |
}, | |
_QTDeleteTagAttrs: function(){ | |
for ( var ndx = 0; ndx < arguments.length; ndx++ ){ | |
var attrName = arguments[ndx]; | |
delete this.gTagAttrs[attrName]; | |
delete this.gTagAttrs["emb#" + attrName]; | |
delete this.gTagAttrs["obj#" + attrName]; | |
} | |
}, | |
// generate an embed and object tag, return as a string | |
_QTGenerate: function(callingFcnName, generateXHTML, args){ | |
// is the number of optional arguments even? | |
if ( args.length < 4 || (0 != (args.length % 2)) ) | |
{ | |
this._QTComplain(callingFcnName, this.gArgCountErr); | |
return ""; | |
} | |
// allocate an array, fill in the required attributes with fixed place params and defaults | |
this.gTagAttrs = new Object(); | |
this.gTagAttrs["src"] = args[0]; | |
this.gTagAttrs["width"] = args[1]; | |
this.gTagAttrs["height"] = args[2]; | |
this.gTagAttrs["classid"] = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"; | |
//Impportant note: It is recommended that you use this exact classid in order to ensure a seamless experience for all viewers | |
this.gTagAttrs["pluginspage"] = "http://www.apple.com/quicktime/download/"; | |
// set up codebase attribute with specified or default version before parsing args so | |
// anything passed in will override | |
var activexVers = args[3] | |
if ( (null == activexVers) || ("" == activexVers) ) | |
activexVers = "7,3,0,0"; | |
this.gTagAttrs["codebase"] = "http://www.apple.com/qtactivex/qtplugin.cab#version=" + activexVers; | |
var attrName, | |
attrValue; | |
// add all of the optional attributes to the array | |
for ( var ndx = 4; ndx < args.length; ndx += 2) | |
{ | |
attrName = args[ndx].toLowerCase(); | |
attrValue = args[ndx + 1]; | |
this.gTagAttrs[attrName] = attrValue; | |
if ( ("postdomevents" == attrName) && (attrValue.toLowerCase() != "false") ) | |
{ | |
this.gQTEventsEnabled = true; | |
if ( this._QTIsMSIE() ) | |
this.gTagAttrs["obj#style"] = "behavior:url(#" + this.gQTBehaviorID + ")"; | |
} | |
} | |
// init both tags with the required and "special" attributes | |
this.objTag = '<object ' | |
+ this._QTAddObjectAttr("classid") | |
+ this._QTAddObjectAttr("width") | |
+ this._QTAddObjectAttr("height") | |
+ this._QTAddObjectAttr("codebase") | |
+ this._QTAddObjectAttr("name") | |
+ this._QTAddObjectAttr("id") | |
+ this._QTAddObjectAttr("tabindex") | |
+ this._QTAddObjectAttr("hspace") | |
+ this._QTAddObjectAttr("vspace") | |
+ this._QTAddObjectAttr("border") | |
+ this._QTAddObjectAttr("align") | |
+ this._QTAddObjectAttr("class") | |
+ this._QTAddObjectAttr("title") | |
+ this._QTAddObjectAttr("accesskey") | |
+ this._QTAddObjectAttr("noexternaldata") | |
+ this._QTAddObjectAttr("obj#style") | |
+ '>' | |
+ this._QTAddObjectParam("src", generateXHTML); | |
this.embedTag = '<embed ' | |
+ this._QTAddEmbedAttr("src") | |
+ this._QTAddEmbedAttr("width") | |
+ this._QTAddEmbedAttr("height") | |
+ this._QTAddEmbedAttr("pluginspage") | |
+ this._QTAddEmbedAttr("name") | |
+ this._QTAddEmbedAttr("id") | |
+ this._QTAddEmbedAttr("align") | |
+ this._QTAddEmbedAttr("tabindex"); | |
// delete the attributes/params we have already added | |
this._QTDeleteTagAttrs("src","width","height","pluginspage","classid","codebase","name","tabindex", | |
"hspace","vspace","border","align","noexternaldata","class","title","accesskey","id","style"); | |
// and finally, add all of the remaining attributes to the embed and object | |
for ( var attrName in this.gTagAttrs ) | |
{ | |
attrValue = this.gTagAttrs[attrName]; | |
if ( null != attrValue ) | |
{ | |
this.embedTag += this._QTAddEmbedAttr(attrName); | |
this.objTag += this._QTAddObjectParam(attrName, generateXHTML); | |
} | |
} | |
// end both tags, we're done | |
return this.objTag + this.embedTag + '></em' + 'bed></ob' + 'ject' + '>'; | |
}, | |
// return the object/embed as a string | |
QT_GenerateOBJECTText: function(){ | |
var txt = this._QTGenerate("QT_GenerateOBJECTText", false, arguments); | |
if ( this._QTShouldInsertBehavior() ) | |
txt = this._QTGenerateBehavior() + txt; | |
return txt; | |
}, | |
QT_GenerateOBJECTText_XHTML: function(){ | |
var txt = this._QTGenerate("QT_GenerateOBJECTText_XHTML", true, arguments); | |
if ( this._QTShouldInsertBehavior() ) | |
txt = this._QTGenerateBehavior() + txt; | |
return txt; | |
}, | |
QT_WriteOBJECT: function(){ | |
var txt = this._QTGenerate("QT_WriteOBJECT", false, arguments); | |
if ( this._QTShouldInsertBehavior() ) | |
document.writeln(this._QTGenerateBehavior()); | |
document.writeln(txt); | |
}, | |
QT_WriteOBJECT_XHTML: function(){ | |
var txt = this._QTGenerate("QT_WriteOBJECT_XHTML", true, arguments); | |
if ( this._QTShouldInsertBehavior() ) | |
document.writeln(this._QTGenerateBehavior()); | |
document.writeln(txt); | |
}, | |
QT_GenerateBehaviorOBJECT: function(){ | |
return this._QTGenerateBehavior(); | |
}, | |
QT_ReplaceElementContents: function(){ | |
var element = $(arguments[0]); | |
var args = []; | |
// copy all other arguments we want to pass through to the fcn | |
for ( var ndx = 1; ndx < arguments.length; ndx++ ) | |
args.push(arguments[ndx]); | |
var txt = this._QTGenerate("QT_ReplaceElementContents", false, args); | |
if ( txt.length > 0 ) { | |
element.set('html', txt); | |
} | |
//element.innerHTML = txt; | |
}, | |
QT_ReplaceElementContents_XHTML: function(){ | |
var element = $(arguments[0]); | |
var args = []; | |
// copy all other arguments we want to pass through to the fcn | |
for ( var ndx = 1; ndx < arguments.length; ndx++ ) | |
args.push(arguments[ndx]); | |
var txt = this._QTGenerate("QT_ReplaceElementContents_XHTML", true, args); | |
if ( txt.length > 0 ){ | |
element.set('html', txt); | |
} | |
//element.innerHTML = txt; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment