Object.js 2.9 KB

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