ImageClipper.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. MWF.xApplication.Template = MWF.xApplication.Template || {};
  2. MWF.xApplication.Template.widget = MWF.xApplication.Template.widget || {};
  3. MWF.require("MWF.widget.ImageClipper", null, false);
  4. MWF.xApplication.Template.widget.ImageClipper = new Class({
  5. Implements: [Options, Events],
  6. Extends: MWF.widget.Common,
  7. options: {
  8. "reference" : "",
  9. "referenceType" : "",
  10. "imageUrl" : "",
  11. "description" : "",
  12. "ratioAdjustedEnable" : false,
  13. "title": "Select Image",
  14. "style": "default",
  15. "aspectRatio": 1.5
  16. },
  17. initialize: function(app, options){
  18. this.setOptions(options);
  19. this.app = app;
  20. this.path = "../x_component_Template/widget/$ImageClipper/";
  21. this.cssPath = "../x_component_Template/widget/$ImageClipper/"+this.options.style+"/css.wcss";
  22. this._loadCss();
  23. },
  24. load: function(data){
  25. this.data = data;
  26. var options = {};
  27. var width = "668";
  28. var height = "510";
  29. width = width.toInt();
  30. height = height.toInt();
  31. var size = this.app.content.getSize();
  32. var x = (size.x-width)/2;
  33. var y = (size.y-height)/2;
  34. if (x<0) x = 0;
  35. if (y<0) y = 0;
  36. if (layout.mobile){
  37. x = 20;
  38. y = 0;
  39. }
  40. var _self = this;
  41. MWF.require("MWF.xDesktop.Dialog", function() {
  42. var dlg = new MWF.xDesktop.Dialog({
  43. "title": this.options.title || "Select Image",
  44. "style": options.style || "image",
  45. "top": y,
  46. "left": x - 20,
  47. "fromTop": y,
  48. "fromLeft": x - 20,
  49. "width": width,
  50. "height": height,
  51. "html": "<div></div>",
  52. "maskNode": this.app.content,
  53. "container": this.app.content,
  54. "buttonList": [
  55. {
  56. "text": MWF.LP.process.button.ok,
  57. "action": function () {
  58. _self.image.uploadImage( function( json ){
  59. _self.imageSrc = MWF.xDesktop.getImageSrc( json.id );
  60. _self.imageId = json.id;
  61. _self.fireEvent("change");
  62. this.close();
  63. }.bind(this));
  64. }
  65. },
  66. {
  67. "text": MWF.LP.process.button.cancel,
  68. "action": function () {
  69. this.close();
  70. }
  71. }
  72. ]
  73. });
  74. dlg.show();
  75. this.image = new MWF.widget.ImageClipper(dlg.content.getFirst(), {
  76. "aspectRatio": this.options.aspectRatio,
  77. "description" : this.options.description,
  78. "imageUrl" : this.options.imageUrl,
  79. "ratioAdjustedEnable" : this.options.ratioAdjustedEnable,
  80. "reference" : this.options.reference,
  81. "referenceType": this.options.referenceType,
  82. "resetEnable" : true
  83. });
  84. this.image.load(this.data);
  85. }.bind(this))
  86. }
  87. });