fullscreen.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. /*jslint nomen:false,onevar:false*/
  2. /*global Trex,TrexMessage,$tx,$tom,$A,Editor*/
  3. /*global showAttachBox,hideAttachBox,
  4. showFullScreen,showNormalScreen,resizeScreen*/
  5. (function () {
  6. var _DOC = document, _WIN = window, _DOC_EL = _DOC.documentElement,
  7. _FALSE = false, _TRUE = true, _NULL = null, _UNDEFINED;
  8. Trex.Class.overwrite(Trex.Tool.FullScreen, {
  9. oninitialized: function () {
  10. var _editor = this.editor, _config = this.config;
  11. var _wrapper = _editor.getWrapper();
  12. if (!_wrapper) {
  13. return;
  14. }
  15. var _fullscreen;
  16. var _toolHandler = function () {
  17. if (!_fullscreen) {
  18. _fullscreen = new Trex.FullScreen(_editor, _config);
  19. }
  20. _fullscreen.execute();
  21. };
  22. this.executeTool = _toolHandler;
  23. if (_config.switched) { //기본이 전체화면
  24. if (!_fullscreen) {
  25. _fullscreen = new Trex.FullScreen(_editor, _config);
  26. }
  27. _fullscreen.showFullScreen();
  28. }
  29. this.resetWeave();
  30. this.weave.bind(this)(new Trex.Button(this.buttonCfg), _NULL, _toolHandler);
  31. this.bindKeyboard({ // ctrl + m - 넓게쓰기
  32. ctrlKey: _TRUE,
  33. keyCode: 77
  34. }, _toolHandler);
  35. _editor.observeKey({ // ctrl + m - 넓게쓰기
  36. ctrlKey: _TRUE,
  37. altKey: _FALSE,
  38. shiftKey: _FALSE,
  39. keyCode: 77
  40. }, _toolHandler);
  41. }
  42. });
  43. TrexMessage.addMsg({
  44. '@fullscreen.attach.close.btn': "파일첨부박스",
  45. '@fullscreen.noti.btn': "일반 글쓰기로",
  46. '@fullscreen.noti.span': "넓게쓰기 버튼을 다시 누르시면 처음 글쓰기 창 크기로 돌아갑니다."
  47. });
  48. Trex.MarkupTemplate.add('fullscreen.notice', '<div class="tx-fullscreen-notice"><span>@fullscreen.noti.span</span><a href="#">@fullscreen.noti.btn</a></div>');
  49. Trex.MarkupTemplate.add('fullscreen.linebox', '<div class="tx-fullscreen-line">' +
  50. '<div class="tx-fullscreen-line-division">' +
  51. '<div class="tx-fullscreen-line-left">&nbsp;</div>' +
  52. '<div class="tx-fullscreen-line-right">&nbsp;</div>' +
  53. '</div>' +
  54. '<div class="tx-fullscreen-line-box">' +
  55. '<div class="tx-fullscreen-line-left">&nbsp;</div>' +
  56. '<div class="tx-fullscreen-line-right">&nbsp;</div>' +
  57. '<a href="#">@fullscreen.attach.close.btn</a>' +
  58. '</div>' +
  59. '</div>');
  60. Trex.FullScreen = Trex.Class.create({
  61. initialize: function (editor, config) {
  62. if (!editor) {
  63. return;
  64. }
  65. this.isInit = _FALSE;
  66. this.isFullScreen = _FALSE;
  67. this.editor = editor;
  68. this.rootConfig = this.editor.initialConfig;
  69. this.wrapper = editor.getWrapper();
  70. this.canvas = editor.getCanvas();
  71. this.toolbar = editor.getToolbar();
  72. this.attachBox = editor.getAttachBox();
  73. this.elSavedHiddens = [];
  74. this.minHeight = config.minHeight;
  75. this.minWidth = config.minWidth;
  76. this.useAttachBox = (!!this.attachBox.elBox);
  77. this.isAttachBoxDisplay = _FALSE;
  78. var self = this;
  79. this.resizeHandler = function () {
  80. if (self.isFullScreen) {
  81. self.resizeContainer();
  82. }
  83. };
  84. this.toolbar.observeJob(Trex.Ev.__CMD_ADVANCED_FOLD, this.resizeHandler);
  85. this.toolbar.observeJob(Trex.Ev.__CMD_ADVANCED_SPREAD, this.resizeHandler);
  86. if (typeof showAttachBox === "function") {
  87. this.showAttachBoxAtServiceForSave = showAttachBox; //NOTE: fullscreen 모드에서는 다른 모양의 첨부박스를 사용한다.
  88. }
  89. if (typeof hideAttachBox === "function") {
  90. this.hideAttachBoxAtServiceForSave = hideAttachBox; //NOTE: fullscreen 모드에서는 다른 모양의 첨부박스를 사용한다.
  91. }
  92. },
  93. execute: function () {
  94. if (this.isFullScreen) {
  95. this.showNormalScreen();
  96. } else {
  97. this.showFullScreen();
  98. }
  99. },
  100. onAttachClick: function () {
  101. this.attachClickHandler(!this.isAttachBoxDisplay);
  102. this.resizeContainer();
  103. },
  104. attachClickHandler: function (isAttachBoxDisplay) {
  105. if (isAttachBoxDisplay) {
  106. this.showAttachBox();
  107. this.attachBox.fireJobs(Trex.Ev.__ATTACHBOX_FULLSCREEN_SHOW);
  108. } else {
  109. this.hideAttachBox();
  110. this.attachBox.fireJobs(Trex.Ev.__ATTACHBOX_FULLSCREEN_HIDE);
  111. }
  112. },
  113. showNormalScreen: function () {
  114. if (!this.isFullScreen) {
  115. return;
  116. }
  117. this._showScrollbar();
  118. //Service Specific
  119. this.showNormalScreenAtService();
  120. var _wrapper = this.wrapper;
  121. if (!_wrapper) {
  122. return;
  123. }
  124. _wrapper.style.width = '';
  125. $tx.removeClassName(_wrapper, 'tx-editor-fullscreen');
  126. this.elSavedHiddens.each(function (el) {
  127. el.style.visibility = 'visible';
  128. });
  129. if (parent) {
  130. try {
  131. $tx.stopObserving(parent, 'resize', this.resizeHandler);
  132. } catch (e) {
  133. }
  134. } else {
  135. $tx.stopObserving(window, 'resize', this.resizeHandler);
  136. }
  137. this.canvas.setCanvasSize({
  138. height: this.panelNormalHeight.toPx()
  139. });
  140. //첨부파일박스
  141. if (this.useAttachBox) {
  142. this.attachClickHandler(this.attachBox.checkDisplay());
  143. }
  144. //NOTE: Service Specific
  145. if (this.showAttachBoxAtServiceForSave) {
  146. _WIN.showAttachBox = this.showAttachBoxAtServiceForSave;
  147. }
  148. if (this.hideAttachBoxAtServiceForSave) {
  149. _WIN.hideAttachBox = this.hideAttachBoxAtServiceForSave;
  150. }
  151. var length = this.relativeParents.length;
  152. for (var i = 0; i < length; i += 1) {
  153. var element = this.relativeParents.pop();
  154. var value = this.relativeValues.pop();
  155. $tx.setStyle(element, {
  156. position: value
  157. });
  158. }
  159. this.isFullScreen = _FALSE;
  160. if (!$tx.msie) {
  161. var btnElemId = "tx_fullscreen" + this.rootConfig.initializedId;
  162. setTimeout(function () {
  163. var _elIcon = $tom.collect($tx(btnElemId), "a");
  164. _elIcon.focus();
  165. }, 500);
  166. }
  167. this.canvas.fireJobs(Trex.Ev.__CANVAS_NORMAL_SCREEN_CHANGE);
  168. },
  169. showFullScreen: function () {
  170. var self = this;
  171. if (this.isFullScreen) {
  172. return;
  173. }
  174. if (!this.isInit) {
  175. this.generate();
  176. }
  177. this._hideScrollbar();
  178. //Service Specific
  179. this.showFullScreenAtService();
  180. if (this.showAttachBoxAtServiceForSave) {
  181. _WIN.showAttachBox = function () {
  182. self.showAttachBox();
  183. self.resizeContainer();
  184. };
  185. }
  186. if (this.hideAttachBoxAtServiceForSave) {
  187. _WIN.hideAttachBox = function () {
  188. self.hideAttachBox();
  189. self.resizeContainer();
  190. };
  191. }
  192. var _wrapper = this.wrapper;
  193. if (!_wrapper) {
  194. return;
  195. }
  196. $tx.addClassName(_wrapper, 'tx-editor-fullscreen');
  197. //Hide select,activeX
  198. var _savedHiddens = [];
  199. ["select", "embed", "object"].each(function (name) {
  200. var _elHdns = $A(_DOC.getElementsByTagName(name));
  201. _elHdns.each(function (el) {
  202. el.style.visibility = 'hidden';
  203. _savedHiddens.push(el);
  204. });
  205. });
  206. this.elSavedHiddens = _savedHiddens;
  207. //attach file box
  208. if (this.useAttachBox) {
  209. this.attachClickHandler(this.attachBox.checkDisplay());
  210. }
  211. var _panel = this.canvas.getCurrentPanel();
  212. this.panelNormalHeight = _panel.getPosition().height;
  213. if (window.parent) {
  214. $tx.observe(window.parent, 'resize', this.resizeHandler);
  215. } else {
  216. $tx.observe(window, 'resize', this.resizeHandler);
  217. }
  218. // make trace element and move container to body's direct child
  219. _WIN.wrapper = _wrapper;
  220. this.relativeParents = [];
  221. this.relativeValues = [];
  222. var parentOfWarpper = _wrapper.offsetParent;
  223. while (parentOfWarpper && parentOfWarpper.tagName && parentOfWarpper.tagName !== "HTML" && parentOfWarpper.tagName !== "BODY") {
  224. var position = $tx.getStyle(parentOfWarpper, "position");
  225. if (position.toLowerCase() === "relative") {
  226. this.relativeParents.push(parentOfWarpper);
  227. this.relativeValues.push(position);
  228. $tx.setStyle(parentOfWarpper, {
  229. position: "static"
  230. });
  231. }
  232. parentOfWarpper = parentOfWarpper.offsetParent;
  233. }
  234. this.isFullScreen = _TRUE;
  235. this.resizeContainer();
  236. this.canvas.fireJobs(Trex.Ev.__CANVAS_FULL_SCREEN_CHANGE);
  237. },
  238. _hideScrollbar: function () {
  239. if (_DOC_EL.scrollTop || _DOC_EL.scrollLeft) {
  240. _DOC_EL.scrollTop = 0;
  241. _DOC_EL.scrollLeft = 0;
  242. }
  243. if (_DOC.body.scrollTop || _DOC.body.scrollLeft) {
  244. _DOC.body.scrollTop = 0;
  245. _DOC.body.scrollLeft = 0;
  246. }
  247. _DOC_EL.style.overflow = 'hidden'; //Remove basic scrollbars
  248. _DOC.body.style.overflow = 'hidden';
  249. },
  250. _showScrollbar: function () {
  251. if ($tx.msie && $tx.msie_ver <= 8) {
  252. // FTDUEDTR-1453
  253. setTimeout(function(){
  254. _DOC_EL.style.overflow = '';
  255. _DOC.body.style.overflow = '';
  256. }, 50);
  257. } else {
  258. _DOC_EL.style.overflow = '';
  259. _DOC.body.style.overflow = '';
  260. }
  261. },
  262. generate: function () {
  263. if (this.isInit) {
  264. return;
  265. }
  266. if (!this.wrapper) {
  267. return;
  268. }
  269. this.generateNoti();
  270. this.generateLineBox();
  271. this.isInit = _TRUE;
  272. },
  273. generateNoti: function () {
  274. var self = this;
  275. var _elNoti = Trex.MarkupTemplate.get("fullscreen.notice").evaluateAsDom({});
  276. $tom.insertFirst(this.wrapper, _elNoti);
  277. var _elNotiBtn = $tom.collect(_elNoti, 'a');
  278. $tx.observe(_elNotiBtn, 'click', function () {
  279. if (self.isFullScreen) {
  280. self.showNormalScreen();
  281. } else {
  282. self.showFullScreen();
  283. }
  284. });
  285. },
  286. generateLineBox: function () {
  287. if (!this.useAttachBox) {
  288. return;
  289. }
  290. var _elCanvas = this.canvas.elContainer;
  291. var _elLine = Trex.MarkupTemplate.get("fullscreen.linebox").evaluateAsDom({});
  292. $tom.insertNext(_elLine, _elCanvas);
  293. var _attr = {
  294. className: "tx-fullscreen-line-box"
  295. };
  296. if ($tx.msie_ver <= '5.5') {
  297. _attr.align = "center";
  298. }
  299. var _elLineBox = $tom.collect(_elLine, 'div.tx-fullscreen-line-box');
  300. if ($tx.msie_ver <= '5.5') {
  301. _elLineBox.align = "center";
  302. }
  303. var _elLineBtn = $tom.collect(_elLineBox, "a");
  304. this.elLineBtn = _elLineBtn;
  305. $tx.observe(_elLineBtn, 'click', this.onAttachClick.bind(this));
  306. },
  307. getAttachBoxPosition: function () {
  308. if (this.isAttachBoxDisplay) {
  309. return $tom.getPosition(this.attachBox.elBox);
  310. } else {
  311. return {
  312. x: 0,
  313. y: 0,
  314. width: 0,
  315. height: 0
  316. };
  317. }
  318. },
  319. getPostAreaBoxPosition: function () {
  320. var elem = $tx("tx_fullscreen_post_area");
  321. if (elem) {
  322. return $tx.getDimensions(elem);
  323. } else {
  324. return {
  325. x: 0,
  326. y: 0,
  327. width: 0,
  328. height: 0
  329. };
  330. }
  331. },
  332. resizeContainer: function () {
  333. if (!this.isFullScreen) {
  334. return _FALSE;
  335. }
  336. this.resizeScreenAtService();
  337. var panelHeight, panelWidth;
  338. panelHeight = this.getPanelHeight();
  339. this.canvas.setCanvasSize({
  340. height: panelHeight.toPx()
  341. });
  342. if (this.wrapper) {
  343. panelWidth = this.getPanelWidth();
  344. this.wrapper.style.width = panelWidth.toPx();
  345. }
  346. return _TRUE;
  347. },
  348. getPanelHeight: function () {
  349. var _panelHeight = 0;
  350. var _panelPosY = this.canvas.getCanvasPos().y;
  351. var lineHeight = this.useAttachBox ? 17 : 0;
  352. if (_DOC_EL.clientHeight > 0) {
  353. _panelHeight = _DOC_EL.clientHeight - _panelPosY - lineHeight;
  354. } else {
  355. _panelHeight = _DOC_EL.offsetHeight - _panelPosY - lineHeight;
  356. }
  357. var _postArea = this.getPostAreaBoxPosition();
  358. _panelHeight -= _postArea.height;
  359. var _attachBoxPosition = this.getAttachBoxPosition();
  360. if (_attachBoxPosition.height > 0) {
  361. _panelHeight -= _attachBoxPosition.height + 20; //cuz margin
  362. }
  363. return Math.max(_panelHeight, this.minHeight);
  364. },
  365. getPanelWidth: function () {
  366. var _panelWidth = 0;
  367. if (_DOC_EL.clientWidth > 0) {
  368. _panelWidth = _DOC_EL.clientWidth;
  369. } else {
  370. _panelWidth = _DOC_EL.offsetWidth;
  371. }
  372. return Math.max(_panelWidth, this.minWidth);
  373. },
  374. showAttachBox: function () {
  375. if (this.attachBox.useBox) {
  376. $tx.addClassName(this.elLineBtn, "tx-attach-close");
  377. $tx.show(this.attachBox.elBox);
  378. this.isAttachBoxDisplay = _TRUE;
  379. }
  380. },
  381. hideAttachBox: function () {
  382. if (this.attachBox.useBox) {
  383. $tx.removeClassName(this.elLineBtn, "tx-attach-close");
  384. $tx.hide(this.attachBox.elBox);
  385. this.isAttachBoxDisplay = _FALSE;
  386. }
  387. },
  388. showFullScreenAtService: function () {
  389. if (typeof showFullScreen === "function") {
  390. showFullScreen();
  391. }
  392. },
  393. showNormalScreenAtService: function () {
  394. if (typeof showNormalScreen === "function") {
  395. showNormalScreen();
  396. }
  397. },
  398. resizeScreenAtService: function () {
  399. if (typeof resizeScreen === "function") {
  400. resizeScreen();
  401. }
  402. }
  403. });
  404. var thisToolName = 'fullscreen';
  405. Editor.forEachEditor(function (editor) {
  406. editor.getTool()[thisToolName].oninitialized();
  407. });
  408. Editor.editorForAsyncLoad.getTool()[thisToolName].executeTool();
  409. }());