changed git call from https to git readonly
[atutor.git] / mods / atutor_opencaps / opencaps / js / AC_QuickTime.js
1 /*\r\rFile: AC_QuickTime.js\r\rAbstract: This file contains functions to generate OBJECT and EMBED tags for QuickTime content.\r\rVersion: <1.2>\r\rDisclaimer: IMPORTANT:  This Apple software is supplied to you by Apple\rComputer, Inc. ("Apple") in consideration of your agreement to the\rfollowing terms, and your use, installation, modification or\rredistribution of this Apple software constitutes acceptance of these\rterms.  If you do not agree with these terms, please do not use,\rinstall, modify or redistribute this Apple software.\r\rIn consideration of your agreement to abide by the following terms, and\rsubject to these terms, Apple grants you a personal, non-exclusive\rlicense, under Apple's copyrights in this original Apple software (the\r"Apple Software"), to use, reproduce, modify and redistribute the Apple\rSoftware, with or without modifications, in source and/or binary forms;\rprovided that if you redistribute the Apple Software in its entirety and\rwithout modifications, you must retain this notice and the following\rtext and disclaimers in all such redistributions of the Apple Software. \rNeither the name, trademarks, service marks or logos of Apple Computer,\rInc. may be used to endorse or promote products derived from the Apple\rSoftware without specific prior written permission from Apple.  Except\ras expressly stated in this notice, no other rights or licenses, express\ror implied, are granted by Apple herein, including but not limited to\rany patent rights that may be infringed by your derivative works or by\rother works in which the Apple Software may be incorporated.\r\rThe Apple Software is provided by Apple on an "AS IS" basis.  APPLE\rMAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION\rTHE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS\rFOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND\rOPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.\r\rIN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL\rOR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\rSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\rINTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,\rMODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED\rAND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),\rSTRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE\rPOSSIBILITY OF SUCH DAMAGE.\r\rCopyright å© 2006-2007 Apple Computer, Inc., All Rights Reserved\r\r*/ \r\r/*\r * This file contains functions to generate OBJECT and EMBED tags for QuickTime content. \r */\r\r/************** LOCALIZABLE GLOBAL VARIABLES ****************/\r\rvar gArgCountErr =      'The "%%" function requires an even number of arguments.'\r                              +       '\nArguments should be in the form "atttributeName", "attributeValue", ...';\r\r/******************** END LOCALIZABLE **********************/\r\rvar gTagAttrs                              = null;\rvar gQTGeneratorVersion         = 1.2;\rvar gQTBehaviorID                        = "qt_event_source";\rvar gQTEventsEnabled               = false;\r\rfunction AC_QuickTimeVersion()        { return gQTGeneratorVersion; }\r\rfunction _QTComplain(callingFcnName, errMsg)\r{\r    errMsg = errMsg.replace("%%", callingFcnName);\r     alert(errMsg);\r}\r\rfunction _QTIsMSIE()\r{\r    var ua = navigator.userAgent.toLowerCase();\r       var msie = /msie/.test(ua) && !/opera/.test(ua);\r\r      return msie;\r}\r\r\rfunction _QTGenerateBehavior()\r{\r      return objTag = '<!--[if IE]>'\r                          + '<object id="' + gQTBehaviorID + '" classid="clsid:CB927D12-4FF7-4a9e-A169-56E4B8A75598"></object>'\r                          + '<![endif]-->';\r}\r\rfunction _QTPageHasBehaviorObject(callingFcnName, args)\r{\r        var haveBehavior = false;\r      var objects = document.getElementsByTagName('object');\r \r       for ( var ndx = 0, obj; obj = objects[ndx]; ndx++ )\r    {\r              if ( obj.getAttribute('classid') == "clsid:CB927D12-4FF7-4a9e-A169-56E4B8A75598" )\r             {\r                      if ( obj.getAttribute('id') == gQTBehaviorID )\r                         haveBehavior = false;\r                  break;\r         }\r      }\r\r     return haveBehavior;\r}\r\r\rfunction _QTShouldInsertBehavior()\r{\r  var             shouldDo = false;\r\r     if ( gQTEventsEnabled && _QTIsMSIE() && !_QTPageHasBehaviorObject() )\r          shouldDo = true;\r       \r       return shouldDo;\r}\r\r\rfunction _QTAddAttribute(prefix, slotName, tagName)\r{\r     var             value;\r\r        value = gTagAttrs[prefix + slotName];\r  if ( null == value )\r           value = gTagAttrs[slotName];\r\r  if ( null != value )\r   {\r              if ( 0 == slotName.indexOf(prefix) && (null == tagName) )\r                      tagName = slotName.substring(prefix.length); \r          if ( null == tagName ) \r                        tagName = slotName;\r            return ' ' + tagName + '="' + value + '"';\r     }\r      else\r           return "";\r}\r\rfunction _QTAddObjectAttr(slotName, tagName)\r{\r   // don't bother if it is only for the embed tag\r        if ( 0 == slotName.indexOf("emb#") )\r           return "";\r\r    if ( 0 == slotName.indexOf("obj#") && (null == tagName) )\r              tagName = slotName.substring(4); \r\r     return _QTAddAttribute("obj#", slotName, tagName);\r}\r\rfunction _QTAddEmbedAttr(slotName, tagName)\r{\r    // don't bother if it is only for the object tag\r       if ( 0 == slotName.indexOf("obj#") )\r           return "";\r\r    if ( 0 == slotName.indexOf("emb#") && (null == tagName) )\r              tagName = slotName.substring(4); \r\r     return _QTAddAttribute("emb#", slotName, tagName);\r}\r\r\rfunction _QTAddObjectParam(slotName, generateXHTML)\r{\r   var             paramValue;\r    var             paramStr = "";\r var             endTagChar = (generateXHTML) ? ' />' : '>';\r\r   if ( -1 == slotName.indexOf("emb#") )\r  {\r              // look for the OBJECT-only param first. if there is none, look for a generic one\r              paramValue = gTagAttrs["obj#" + slotName];\r             if ( null == paramValue )\r                      paramValue = gTagAttrs[slotName];\r\r             if ( 0 == slotName.indexOf("obj#") )\r                   slotName = slotName.substring(4); \r     \r               if ( null != paramValue )\r                      paramStr = '<param name="' + slotName + '" value="' + paramValue + '"' + endTagChar;\r   }\r\r     return paramStr;\r}\r\rfunction _QTDeleteTagAttrs()\r{\r     for ( var ndx = 0; ndx < arguments.length; ndx++ )\r     {\r              var attrName = arguments[ndx];\r         delete gTagAttrs[attrName];\r            delete gTagAttrs["emb#" + attrName];\r           delete gTagAttrs["obj#" + attrName];\r   }\r}\r\r\r// generate an embed and object tag, return as a string\rfunction _QTGenerate(callingFcnName, generateXHTML, args)\r{\r      // is the number of optional arguments even?\r   if ( args.length < 4 || (0 != (args.length % 2)) )\r     {\r              _QTComplain(callingFcnName, gArgCountErr);\r             return "";\r     }\r      \r       // allocate an array, fill in the required attributes with fixed place params and defaults\r     gTagAttrs = new Object();\r      gTagAttrs["src"] = args[0];\r    gTagAttrs["width"] = args[1];\r  gTagAttrs["height"] = args[2];\r gTagAttrs["classid"] = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";\r           //Impportant note: It is recommended that you use this exact classid in order to ensure a seamless experience for all viewers\r  gTagAttrs["pluginspage"] = "http://www.apple.com/quicktime/download/";\r\r        // set up codebase attribute with specified or default version before parsing args so\r  //  anything passed in will override\r   var activexVers = args[3]\r      if ( (null == activexVers) || ("" == activexVers) )\r            activexVers = "7,3,0,0";\r       gTagAttrs["codebase"] = "http://www.apple.com/qtactivex/qtplugin.cab#version=" + activexVers;\r\r var     attrName,\r              attrValue;\r\r    // add all of the optional attributes to the array\r     for ( var ndx = 4; ndx < args.length; ndx += 2)\r        {\r              attrName = args[ndx].toLowerCase();\r            attrValue = args[ndx + 1];\r\r            gTagAttrs[attrName] = attrValue;\r\r              if ( ("postdomevents" == attrName) && (attrValue.toLowerCase() != "false") )\r           {\r                      gQTEventsEnabled = true;\r                       if ( _QTIsMSIE() )\r                             gTagAttrs["obj#style"] = "behavior:url(#" + gQTBehaviorID + ")";\r               }\r      }\r\r     // init both tags with the required and "special" attributes\r   var objTag =  '<object '\r                                       + _QTAddObjectAttr("classid")\r                                  + _QTAddObjectAttr("width")\r                                    + _QTAddObjectAttr("height")\r                                   + _QTAddObjectAttr("codebase")\r                                 + _QTAddObjectAttr("name")\r                                     + _QTAddObjectAttr("id")\r                                       + _QTAddObjectAttr("tabindex")\r                                 + _QTAddObjectAttr("hspace")\r                                   + _QTAddObjectAttr("vspace")\r                                   + _QTAddObjectAttr("border")\r                                   + _QTAddObjectAttr("align")\r                                    + _QTAddObjectAttr("class")\r                                    + _QTAddObjectAttr("title")\r                                    + _QTAddObjectAttr("accesskey")\r                                        + _QTAddObjectAttr("noexternaldata")\r                                   + _QTAddObjectAttr("obj#style")\r                                        + '>'\r                                  + _QTAddObjectParam("src", generateXHTML);\r     var embedTag = '<embed '\r                                       + _QTAddEmbedAttr("src")\r                                       + _QTAddEmbedAttr("width")\r                                     + _QTAddEmbedAttr("height")\r                                    + _QTAddEmbedAttr("pluginspage")\r                                       + _QTAddEmbedAttr("name")\r                                      + _QTAddEmbedAttr("id")\r                                        + _QTAddEmbedAttr("align")\r                                     + _QTAddEmbedAttr("tabindex");\r\r        // delete the attributes/params we have already added\r  _QTDeleteTagAttrs("src","width","height","pluginspage","classid","codebase","name","tabindex",\r                                 "hspace","vspace","border","align","noexternaldata","class","title","accesskey","id","style");\r\r        // and finally, add all of the remaining attributes to the embed and object\r    for ( var attrName in gTagAttrs )\r      {\r              attrValue = gTagAttrs[attrName];\r               if ( null != attrValue )\r               {\r                      embedTag += _QTAddEmbedAttr(attrName);\r                 objTag += _QTAddObjectParam(attrName, generateXHTML);\r          }\r      } \r\r    // end both tags, we're done\r   return objTag + embedTag + '></em' + 'bed></ob' + 'ject' + '>';\r}\r\r\r// return the object/embed as a string\rfunction QT_GenerateOBJECTText()\r{\r  var     txt = _QTGenerate("QT_GenerateOBJECTText", false, arguments);\r  if ( _QTShouldInsertBehavior() )\r               txt = _QTGenerateBehavior() + txt;\r     return txt;\r}\r\rfunction QT_GenerateOBJECTText_XHTML()\r{\r        var     txt = _QTGenerate("QT_GenerateOBJECTText_XHTML", true, arguments);\r     if ( _QTShouldInsertBehavior() )\r               txt = _QTGenerateBehavior() + txt;\r     return txt;\r}\r\rfunction QT_WriteOBJECT()\r{\r     var     txt = _QTGenerate("QT_WriteOBJECT", false, arguments);\r if ( _QTShouldInsertBehavior() )\r               document.writeln(_QTGenerateBehavior());\r       document.writeln(txt);\r}\r\rfunction QT_WriteOBJECT_XHTML()\r{\r    var     txt = _QTGenerate("QT_WriteOBJECT_XHTML", true, arguments);\r    if ( _QTShouldInsertBehavior() )\r               document.writeln(_QTGenerateBehavior());\r       document.writeln(txt);\r}\r\rfunction QT_GenerateBehaviorOBJECT()\r{\r       return _QTGenerateBehavior();\r}\r\rfunction QT_ReplaceElementContents()\r{\r        var element = arguments[0];\r    var args = [];\r\r        // copy all other arguments we want to pass through to the fcn\r for ( var ndx = 1; ndx < arguments.length; ndx++ )\r             args.push(arguments[ndx]);\r\r    var     txt = _QTGenerate("QT_ReplaceElementContents", false, args);\r   if ( txt.length > 0 )\r          element.innerHTML = txt;\r}\r\r\rfunction QT_ReplaceElementContents_XHTML()\r{\r      var element = arguments[0];\r    var args = [];\r\r        // copy all other arguments we want to pass through to the fcn\r for ( var ndx = 1; ndx < arguments.length; ndx++ )\r             args.push(arguments[ndx]);\r\r    var     txt = _QTGenerate("QT_ReplaceElementContents_XHTML", true, args);\r      if ( txt.length > 0 )\r          element.innerHTML = txt;\r}\r\r