fullscreen.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. (function($)
  2. {
  3. $.Redactor.prototype.fullscreen = function()
  4. {
  5. return {
  6. init: function()
  7. {
  8. this.fullscreen.isOpen = false;
  9. var button = this.button.add('fullscreen', 'Fullscreen');
  10. this.button.addCallback(button, this.fullscreen.toggle);
  11. if (this.opts.fullscreen) this.fullscreen.toggle();
  12. },
  13. enable: function()
  14. {
  15. this.button.changeIcon('fullscreen', 'normalscreen');
  16. this.button.setActive('fullscreen');
  17. this.fullscreen.isOpen = true;
  18. if (this.opts.toolbarExternal)
  19. {
  20. this.fullscreen.toolcss = {};
  21. this.fullscreen.boxcss = {};
  22. this.fullscreen.toolcss.width = this.$toolbar.css('width');
  23. this.fullscreen.toolcss.top = this.$toolbar.css('top');
  24. this.fullscreen.toolcss.position = this.$toolbar.css('position');
  25. this.fullscreen.boxcss.top = this.$box.css('top');
  26. }
  27. this.fullscreen.height = this.$editor.height();
  28. if (this.opts.maxHeight) this.$editor.css('max-height', '');
  29. if (this.opts.minHeight) this.$editor.css('min-height', '');
  30. if (!this.$fullscreenPlaceholder) this.$fullscreenPlaceholder = $('<div/>');
  31. this.$fullscreenPlaceholder.insertAfter(this.$box);
  32. this.$box.appendTo(document.body);
  33. this.$box.addClass('redactor-box-fullscreen');
  34. $('body, html').css('overflow', 'hidden');
  35. this.fullscreen.resize();
  36. $(window).on('resize.redactor.fullscreen', $.proxy(this.fullscreen.resize, this));
  37. $(document).scrollTop(0, 0);
  38. $('.redactor-toolbar-tooltip').hide();
  39. this.$editor.focus();
  40. this.observe.load();
  41. },
  42. disable: function()
  43. {
  44. this.button.removeIcon('fullscreen', 'normalscreen');
  45. this.button.setInactive('fullscreen');
  46. this.fullscreen.isOpen = false;
  47. $(window).off('resize.redactor.fullscreen');
  48. $('body, html').css('overflow', '');
  49. this.$box.insertBefore(this.$fullscreenPlaceholder);
  50. this.$fullscreenPlaceholder.remove();
  51. this.$box.removeClass('redactor-box-fullscreen').css({ width: 'auto', height: 'auto' });
  52. this.code.sync();
  53. if (this.opts.toolbarExternal)
  54. {
  55. this.$box.css('top', this.fullscreen.boxcss.top);
  56. this.$toolbar.css({
  57. 'width': this.fullscreen.toolcss.width,
  58. 'top': this.fullscreen.toolcss.top,
  59. 'position': this.fullscreen.toolcss.position
  60. });
  61. }
  62. if (this.opts.minHeight) this.$editor.css('minHeight', this.opts.minHeight);
  63. if (this.opts.maxHeight) this.$editor.css('maxHeight', this.opts.maxHeight);
  64. $('.redactor-toolbar-tooltip').hide();
  65. this.$editor.css('height', 'auto');
  66. this.$editor.focus();
  67. this.observe.load();
  68. },
  69. toggle: function()
  70. {
  71. if (this.fullscreen.isOpen)
  72. {
  73. this.fullscreen.disable();
  74. }
  75. else
  76. {
  77. this.fullscreen.enable();
  78. }
  79. },
  80. resize: function()
  81. {
  82. if (!this.fullscreen.isOpen) return;
  83. var toolbarHeight = this.$toolbar.height();
  84. var height = $(window).height() - toolbarHeight - this.utils.normalize(this.$editor.css('padding-top')) - this.utils.normalize(this.$editor.css('padding-bottom'));
  85. this.$box.width($(window).width()).height(height);
  86. if (this.opts.toolbarExternal)
  87. {
  88. this.$toolbar.css({
  89. 'top': '0px',
  90. 'position': 'absolute',
  91. 'width': '100%'
  92. });
  93. this.$box.css('top', toolbarHeight + 'px');
  94. }
  95. this.$editor.height(height);
  96. }
  97. };
  98. };
  99. })(jQuery);