Object.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.embed.Object"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.embed.Object"] = true;
  8. dojo.provide("dojox.embed.Object");
  9. dojo.experimental("dojox.embed.Object");
  10. dojo.require("dijit._Widget");
  11. dojo.require("dojox.embed.Flash");
  12. dojo.require("dojox.embed.Quicktime");
  13. dojo.declare("dojox.embed.Object", dijit._Widget, {
  14. // summary:
  15. // A widget you can use to embed either a Flash or Quicktime
  16. // movie.
  17. //
  18. // example:
  19. // From markup:
  20. // | <div dojoType="dojox.embed.Object" src="path/to/movie.swf"></div>
  21. //
  22. // example:
  23. // Programmatic:
  24. // | var mov=new dojox.embed.Object({
  25. // | src: "path/to/movie.swf"
  26. // | }, node);
  27. //
  28. // width: Number?
  29. // The width of the movie. If not provided, the width of this.domNode is used.
  30. // height: Number?
  31. // The height of the movie. If not provided, the height of this.domNode is used.
  32. // src: String
  33. // The URL of the movie to embed.
  34. // movie: HTMLEmbed
  35. // The eventual reference to the movie embedded. If you are looking to script
  36. // control over the movie, you'd access it this way.
  37. // params: Object
  38. // A property bag that is created postCreate. Any additional attributes you
  39. // define on your domNode will be collected and placed into this, which will
  40. // then be passed to the movie constructor.
  41. // reFlash: RegExp
  42. // Expression used on the src property to determine if this is Flash or Quicktime.
  43. // reQtMovie: RegExp
  44. // Expression used on the src property to determine if this is Flash or Quicktime.
  45. // reQtAudio: RegExp
  46. // Expression used on the src property to determine if this is Flash or Quicktime.
  47. width: 0,
  48. height: 0,
  49. src: "",
  50. movie: null,
  51. params: null,
  52. reFlash: /\.swf|\.flv/gi,
  53. reQtMovie: /\.3gp|\.avi|\.m4v|\.mov|\.mp4|\.mpg|\.mpeg|\.qt/gi,
  54. reQtAudio:/\.aiff|\.aif|\.m4a|\.m4b|\.m4p|\.midi|\.mid|\.mp3|\.mpa|\.wav/gi,
  55. postCreate: function(){
  56. // summary
  57. // Constructs the movie and places it in the document.
  58. if(!this.width || !this.height){
  59. // get the width and height from the domNode
  60. var box=dojo.marginBox(this.domNode);
  61. this.width=box.w, this.height=box.h;
  62. }
  63. // the default embed constructor.
  64. var em=dojox.embed.Flash;
  65. // figure out what kind of movie this is.
  66. if(this.src.match(this.reQtMovie) || this.src.match(this.reQtAudio)){
  67. em=dojox.embed.Quicktime;
  68. }
  69. // loop through any attributes and set up our params object.
  70. if(!this.params){
  71. this.params={};
  72. if(this.domNode.hasAttributes()){
  73. // ignore list
  74. var ignore = {
  75. dojoType: "",
  76. width: "",
  77. height: "",
  78. "class": "",
  79. style: "",
  80. id: "",
  81. src: ""
  82. };
  83. var attrs=this.domNode.attributes;
  84. for(var i=0, l=attrs.length; i<l; i++){
  85. if(!ignore[attrs[i].name]){
  86. this.params[attrs[i].name]=attrs[i].value;
  87. }
  88. }
  89. }
  90. }
  91. // set up our arguments.
  92. var kwArgs={
  93. path: this.src,
  94. width: this.width,
  95. height: this.height,
  96. params: this.params
  97. };
  98. // set up the movie.
  99. this.movie=new (em)(kwArgs, this.domNode);
  100. }
  101. });
  102. }