ImageViewer.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. o2.widget = o2.widget || {};
  2. o2.widget.ImageViewer = o2.ImageViewer = new Class({
  3. Implements: [Options, Events],
  4. Extends: o2.widget.Common,
  5. options: {
  6. "style": "default",
  7. "path": o2.session.path + "/widget/$ImageViewer/",
  8. "imageUrl": ""
  9. },
  10. initialize: function (container, nodeList, options) {
  11. this.isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
  12. this.container = container;
  13. if(nodeList){
  14. this.nodeList = typeOf(nodeList) === "array" ? nodeList : [nodeList];
  15. }else{
  16. this.nodeList = [container];
  17. }
  18. this.setOptions(options);
  19. // this.path = this.options.path || (o2.session.path + "/widget/$ImageViewer/");
  20. // this.cssPath = this.path + this.options.style + "/css.wcss";
  21. //
  22. // this._loadCss();
  23. this.fireEvent("init");
  24. },
  25. load: function (callback) {
  26. if( Browser.name === 'ie' && !this.isIE11 ){
  27. if(callback)callback();
  28. }else{
  29. var flag = false;
  30. this.nodeList.each(function(node){
  31. if(node)node.getElements("img").each(function(img){
  32. var enablePreview = img.get("data-prv");
  33. if( enablePreview !== "false" && enablePreview !== false ){
  34. flag = true;
  35. img.setStyle("cursor", "pointer");
  36. img.set("preview", "true");
  37. var orgId = img.get("data-orgid");
  38. if(orgId){
  39. img.set("data-originalUrl", o2.xDesktop.getImageSrc(orgId));
  40. }
  41. }
  42. }.bind(this))
  43. }.bind(this));
  44. if( flag ){
  45. this.loadResource(function () {
  46. if(window.Viewer){
  47. new Viewer( this.container, {
  48. url: function (image) {
  49. // var id = image.get("data-orgid") || image.get("data-id");
  50. var id = image.get("data-id");
  51. return id ? o2.xDesktop.getImageSrc(id) : ( image.get("data-src") || image.get("src") )
  52. },
  53. filter: function (image) {
  54. return image.get("preview") === "true";
  55. }
  56. });
  57. }
  58. if(callback)callback();
  59. }.bind(this))
  60. }else{
  61. if(callback)callback();
  62. }
  63. }
  64. },
  65. loadResource : function( callback ){
  66. if( window.Viewer ){
  67. if( callback )callback();
  68. return;
  69. }
  70. COMMON.AjaxModule.loadCss("../o2_lib/viewer/viewer.css", function () {
  71. o2.load( "../o2_lib/viewer/viewer.js", function () {
  72. if(callback)callback();
  73. }.bind(this))
  74. }.bind(this))
  75. }
  76. });