Няма описание

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var Siema = require("siema");
  4. var index_1 = require("../WhitePage/index");
  5. var uuid_1 = require("../../utils/uuid");
  6. var dom_1 = require("../../utils/dom");
  7. require("./index.less");
  8. var LeftArrowIcon = require('../../assets/bx-left-arrow.svg');
  9. var RightArrowIcon = require('../../assets/bx-right-arrow.svg');
  10. var prefix = 'fcw-board';
  11. var SerializableWhiteboard = (function () {
  12. function SerializableWhiteboard() {
  13. }
  14. return SerializableWhiteboard;
  15. }());
  16. exports.SerializableWhiteboard = SerializableWhiteboard;
  17. var Whiteboard = (function () {
  18. function Whiteboard(target, _a) {
  19. var _b = _a === void 0 ? {} : _a, sources = _b.sources, eventHub = _b.eventHub, mode = _b.mode, visiblePageIndex = _b.visiblePageIndex;
  20. this.id = uuid_1.uuid();
  21. this.sources = [];
  22. this.mode = 'master';
  23. this.isFullscreen = false;
  24. this.pages = [];
  25. this.isInitialized = false;
  26. this.visiblePageIndex = 0;
  27. if (target) {
  28. this.target = target;
  29. }
  30. else {
  31. this.target = document.createElement('div');
  32. document.body.appendChild(this.target);
  33. }
  34. if (!this.target.id) {
  35. this.target.id = this.id;
  36. }
  37. dom_1.addClassName(this.target, prefix);
  38. if (sources) {
  39. this.sources = sources;
  40. }
  41. this.eventHub = eventHub;
  42. if (mode) {
  43. this.mode = mode;
  44. }
  45. if (typeof visiblePageIndex !== 'undefined') {
  46. this.visiblePageIndex = visiblePageIndex;
  47. }
  48. this.init();
  49. }
  50. Object.defineProperty(Whiteboard.prototype, "activePage", {
  51. get: function () {
  52. return this.pages[this.visiblePageIndex];
  53. },
  54. enumerable: true,
  55. configurable: true
  56. });
  57. Whiteboard.prototype.open = function () {
  58. var _this = this;
  59. this.pages.forEach(function (page, i) {
  60. page.open();
  61. if (i !== _this.visiblePageIndex) {
  62. page.hide();
  63. }
  64. });
  65. };
  66. Whiteboard.prototype.close = function () {
  67. if (this.emitInterval) {
  68. clearInterval(this.emitInterval);
  69. }
  70. };
  71. Whiteboard.prototype.show = function () {
  72. if (this.activePage) {
  73. this.activePage.show();
  74. }
  75. };
  76. Whiteboard.prototype.hide = function () {
  77. if (this.activePage) {
  78. this.activePage.hide();
  79. }
  80. };
  81. Whiteboard.prototype.snap = function () {
  82. return {
  83. id: this.id,
  84. sources: this.sources,
  85. pageIds: this.pages.map(function (page) { return page.id; }),
  86. visiblePageIndex: this.visiblePageIndex
  87. };
  88. };
  89. Whiteboard.prototype.init = function () {
  90. this.imgsContainer = dom_1.createDivWithClassName(prefix + "-imgs", this.target);
  91. this.pagesContainer = dom_1.createDivWithClassName(prefix + "-pages", this.target);
  92. if (this.mode === 'master') {
  93. this.initMaster();
  94. this.emitSnapshot();
  95. }
  96. if (this.mode === 'mirror') {
  97. this.initMirror();
  98. }
  99. };
  100. Whiteboard.prototype.initMaster = function () {
  101. var _this = this;
  102. this.sources.forEach(function (source) {
  103. var page = new index_1.WhitePage({ imgSrc: source }, {
  104. mode: _this.mode,
  105. eventHub: _this.eventHub,
  106. parentContainer: _this.pagesContainer
  107. });
  108. page.container.style.visibility = 'hidden';
  109. _this.pages.push(page);
  110. });
  111. this.initSiema();
  112. var controller = dom_1.createDivWithClassName(prefix + "-controller", this.target);
  113. var prevEle = dom_1.createDivWithClassName(prefix + "-flip-arrow", controller);
  114. prevEle.innerHTML = LeftArrowIcon;
  115. var nextEle = dom_1.createDivWithClassName(prefix + "-flip-arrow", controller);
  116. nextEle.innerHTML = RightArrowIcon;
  117. nextEle.addEventListener('click', function () {
  118. var nextPageIndex = _this.visiblePageIndex + 1 > _this.pages.length - 1 ? 0 : _this.visiblePageIndex + 1;
  119. _this.onPageChange(nextPageIndex);
  120. });
  121. prevEle.addEventListener('click', function () {
  122. var nextPageIndex = _this.visiblePageIndex - 1 < 0 ? _this.pages.length - 1 : _this.visiblePageIndex - 1;
  123. _this.onPageChange(nextPageIndex);
  124. });
  125. };
  126. Whiteboard.prototype.initMirror = function () {
  127. var _this = this;
  128. if (!this.eventHub) {
  129. throw new Error('Invalid eventHub');
  130. }
  131. this.eventHub.on('sync', function (ev) {
  132. if (ev.target !== 'whiteboard') {
  133. return;
  134. }
  135. if (ev.event === 'snap') {
  136. if (_this.isInitialized) {
  137. return;
  138. }
  139. _this.onSnapshot(ev.data);
  140. }
  141. if (ev.event === 'changeIndex' && ev.id === _this.id) {
  142. if (_this.isInitialized) {
  143. _this.onPageChange(ev.data);
  144. }
  145. }
  146. });
  147. };
  148. Whiteboard.prototype.initSiema = function () {
  149. var _this = this;
  150. this.sources.forEach(function (source) {
  151. var imgEle = document.createElement('img');
  152. dom_1.addClassName(imgEle, prefix + "-img");
  153. imgEle.src = source;
  154. imgEle.alt = 'Siema image';
  155. _this.imgsContainer.appendChild(imgEle);
  156. });
  157. this.siema = new Siema({
  158. selector: this.imgsContainer,
  159. duration: 200,
  160. easing: 'ease-out',
  161. perPage: 1,
  162. startIndex: 0,
  163. draggable: false,
  164. multipleDrag: true,
  165. threshold: 20,
  166. loop: false,
  167. rtl: false
  168. });
  169. };
  170. Whiteboard.prototype.onPageChange = function (nextPageIndex) {
  171. this.siema.goTo(nextPageIndex);
  172. this.visiblePageIndex = nextPageIndex;
  173. this.pages.forEach(function (page, i) {
  174. if (nextPageIndex === i) {
  175. page.show();
  176. }
  177. else {
  178. page.hide();
  179. }
  180. });
  181. if (this.mode === 'master' && this.eventHub) {
  182. this.eventHub.emit('sync', {
  183. event: 'changeIndex',
  184. id: this.id,
  185. target: 'whiteboard',
  186. data: nextPageIndex
  187. });
  188. }
  189. };
  190. Whiteboard.prototype.emitSnapshot = function () {
  191. var _this = this;
  192. var innerFunc = function () {
  193. if (_this.eventHub) {
  194. _this.eventHub.emit('sync', {
  195. event: 'snap',
  196. id: _this.id,
  197. target: 'whiteboard',
  198. data: _this.snap()
  199. });
  200. }
  201. };
  202. this.emitInterval = setInterval(function () {
  203. innerFunc();
  204. }, 5 * 1000);
  205. setTimeout(innerFunc, 500);
  206. };
  207. Whiteboard.prototype.onSnapshot = function (snap) {
  208. var _this = this;
  209. var id = snap.id, sources = snap.sources, pageIds = snap.pageIds, visiblePageIndex = snap.visiblePageIndex;
  210. if (!this.isInitialized) {
  211. this.id = id;
  212. this.sources = sources;
  213. this.initSiema();
  214. this.sources.forEach(function (source, i) {
  215. var page = new index_1.WhitePage({ imgSrc: source }, {
  216. mode: _this.mode,
  217. eventHub: _this.eventHub,
  218. parentContainer: _this.pagesContainer
  219. });
  220. page.id = pageIds[i];
  221. page.container.style.opacity = 'hidden';
  222. _this.pages.push(page);
  223. page.open();
  224. });
  225. }
  226. this.isInitialized = true;
  227. this.onPageChange(visiblePageIndex);
  228. };
  229. return Whiteboard;
  230. }());
  231. exports.Whiteboard = Whiteboard;