thumbnail.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //缩略图模块
  2. var thumbnail = function (option, success) {
  3. var object = new Thumbnail(option);
  4. success();
  5. return object;
  6. }
  7. function Thumbnail(option) {
  8. var self = this;
  9. this.markControl = option.markControl;
  10. this.maxWidth = option.width != undefined ? option.width : 100;
  11. this.show = false;
  12. this.loading = false;
  13. this.imageHeight = undefined;
  14. this.mousePosition = undefined;
  15. this.init();
  16. this.markControl.on('task.get.before', this, function (event, context, eventObject) {
  17. this.task = undefined;
  18. this.render();
  19. });
  20. this.markControl.on('task.get.success', this, function (event, context, eventObject) {
  21. this.task = context.task;
  22. this.render();
  23. });
  24. this.markControl.on('mark.setting.init', this, function (event, context, setting) {
  25. var show = setting['thumbnail.show'];
  26. if (show != undefined && show == true) {
  27. self.toggle(true);
  28. }
  29. });
  30. }
  31. Thumbnail.prototype.init = function () {
  32. var self = this;
  33. this.container = getDom(this.container_dom, this.markControl).appendTo(this.markControl.container);
  34. this.container.width(this.maxWidth);
  35. this.container.offset({
  36. top: 60,
  37. left: 0
  38. });
  39. this.container.header = getDom(this.container_header_dom, this.markControl).appendTo(this.container);
  40. this.container.header.width('100%');
  41. this.container.content = getDom(this.container_content_dom, this.markControl).appendTo(this.container);
  42. this.container.content.width('100%');
  43. this.imageObject = this.container.content.find('img');
  44. this.imageObject.width('100%');
  45. this.imageObject.bind('mouseover', function (e) {
  46. self.updatePosition(e);
  47. }).bind('mousemove', function (e) {
  48. self.updatePosition(e);
  49. }).bind('mouseout', function (e) {
  50. self.updatePosition();
  51. }).bind('click', function () {
  52. if (self.show == true && self.task != undefined && self.mousePosition != undefined) {
  53. self.markControl.trigger('image.position.change', self.mousePosition.y / self.imageObject.height())
  54. }
  55. });
  56. this.container.draggable({
  57. containment: "window"
  58. });
  59. this.container.header.find('#close-button').click(function () {
  60. self.toggle(false);
  61. self.markControl.trigger('mark.setting.change', {
  62. 'thumbnail.show': false
  63. });
  64. });
  65. this.control = getDom(this.control_dom, this.markControl).appendTo(this.markControl.container.assistant);
  66. this.control.find('#show-thumbnail-button').click(function () {
  67. self.markControl.container.assistant.hide();
  68. self.toggle(true);
  69. self.markControl.trigger('mark.setting.change', {
  70. 'thumbnail.show': true
  71. });
  72. });
  73. this.control.find('#hide-thumbnail-button').click(function () {
  74. self.markControl.container.assistant.hide();
  75. self.toggle(false);
  76. self.markControl.trigger('mark.setting.change', {
  77. 'thumbnail.show': false
  78. });
  79. });
  80. }
  81. Thumbnail.prototype.render = function () {
  82. var self = this;
  83. var imageObject = this.imageObject;
  84. if (this.task != undefined && this.task.imageData != undefined) {
  85. imageObject[0].src = this.task.imageData.src;
  86. if (imageObject[0].height > (self.markControl.container.height() * 0.8)) {
  87. self.container.content.height(self.markControl.container.height() * 0.8);
  88. } else {
  89. self.container.content.height(imageObject[0].height);
  90. }
  91. imageObject.show();
  92. } else {
  93. imageObject[0].src = '';
  94. imageObject.hide();
  95. }
  96. }
  97. Thumbnail.prototype.toggle = function (show) {
  98. if (show == true) {
  99. this.show = true;
  100. this.container.show();
  101. } else {
  102. this.show = false;
  103. this.container.hide();
  104. }
  105. }
  106. Thumbnail.prototype.updatePosition = function (e) {
  107. var position = this.imageObject.offset();
  108. this.mousePosition = e != undefined ? {
  109. x: e.pageX - position.left,
  110. y: e.pageY - position.top
  111. } : undefined;
  112. }
  113. Thumbnail.prototype.container_dom = '<div class="score-board score-board-popover" style="display:none"></div>';
  114. Thumbnail.prototype.container_header_dom = '<div class="header">\
  115. <p class="fl" id="header" data-i18n-text="mark.thumbnail">缩略图</p>\
  116. <a class="header-close" id="close-button" href="#"><img src="{staticServer}/images/close.png"></a>\
  117. </div>';
  118. Thumbnail.prototype.container_content_dom = '<div class="content" style="padding:4px;overflow:scroll"><img src=""></div>';
  119. Thumbnail.prototype.control_dom = '<h3 class="popover-title" data-i18n-text="mark.thumbnail">缩略图</h3>\
  120. <div class="popover-content"><p id="problem-list" class="popover-list">\
  121. <a href="#" id="show-thumbnail-button" data-i18n-text="mark.thumbnail.open">打开</a><a href="#" id="hide-thumbnail-button" data-i18n-text="mark.thumbnail.close">关闭</a>\
  122. </p></div>';