fullAvatarEditor.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. function fullAvatarEditor() {
  2. var id = 'fullAvatarEditor' //flash文件的ID
  3. var file = 'plugins/photoEditor/fullAvatarEditor.swf'; //flash文件的路径
  4. var version = "10.1.0"; //播放该flash所需的最低版本
  5. var expressInstall = 'plugins/photoEditor/expressInstall.swf'; //expressInstall.swf的路径
  6. var width = 630; //flash文件的宽度
  7. var height = 430; //flash文件的高度
  8. var container = id; //装载flash文件的容器(如div)的id
  9. var flashvars = {};
  10. var callback = function(){};
  11. var heightChanged = false;
  12. //智能获取参数,字符类型为装载flash文件的容器(如div)的id,第一个数字类型的为高度,第二个为宽度,第一个object类型的为参数对象,如此4个参数的顺序可随意。
  13. for(var i = 0; i < arguments.length; i++)
  14. {
  15. var a = arguments[i];
  16. if(typeof a == 'string')
  17. {
  18. if (a.substring(a.length - 'plugins/photoEditor/fullAvatarEditor.swf'.length) == 'plugins/photoEditor/fullAvatarEditor.swf')
  19. {
  20. file = a;
  21. }
  22. else if (a.substring(a.length - 'plugins/photoEditor/expressInstall.swf'.length) == 'plugins/photoEditor/expressInstall.swf')
  23. {
  24. expressInstall = a;
  25. }
  26. else
  27. {
  28. container = a;
  29. }
  30. }
  31. else if(typeof a == 'number')
  32. {
  33. if(heightChanged)
  34. {
  35. width = a;
  36. }
  37. else
  38. {
  39. height = a;
  40. heightChanged = true;
  41. }
  42. }
  43. else if(typeof a == 'function')
  44. {
  45. callback = a;
  46. }
  47. else
  48. {
  49. flashvars = a;
  50. }
  51. }
  52. var vars = {
  53. id : id
  54. };
  55. //合并参数
  56. for (var name in flashvars)
  57. {
  58. if(flashvars[name] != null)
  59. {
  60. if(name == 'upload_url' || name == 'src_url')
  61. {
  62. vars[name] = encodeURIComponent(flashvars[name]);
  63. }
  64. else
  65. {
  66. vars[name] = flashvars[name];
  67. }
  68. }
  69. }
  70. var params = {
  71. menu : 'true',
  72. scale : 'noScale',
  73. allowFullscreen : 'true',
  74. allowScriptAccess : 'always',
  75. wmode : 'transparent'
  76. };
  77. var attributes = {
  78. id : vars.id,
  79. name: vars.id
  80. };
  81. var swf = null;
  82. var callbackFn = function (e) {
  83. swf = e.ref;
  84. swf.eventHandler = function(json){
  85. callback.call(swf, json);
  86. };
  87. };
  88. swfobject.embedSWF(
  89. file,
  90. container,
  91. width,
  92. height,
  93. version,
  94. expressInstall,
  95. vars,
  96. params,
  97. attributes,
  98. callbackFn
  99. );
  100. return swf;
  101. }