forked from johnsardine/redactor-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfullscreen.js
146 lines (114 loc) · 3.48 KB
/
fullscreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
if (!RedactorPlugins) var RedactorPlugins = {};
RedactorPlugins.fullscreen = {
init: function()
{
this.fullscreen = false;
this.buttonAdd('fullscreen', 'Fullscreen', jQuery.proxy(this.toggleFullscreen, this));
this.buttonSetRight('fullscreen');
if (this.opts.fullscreen) this.toggleFullscreen();
},
toggleFullscreen: function()
{
var html;
if (!this.fullscreen)
{
this.buttonChangeIcon('fullscreen', 'normalscreen');
this.buttonActive('fullscreen');
this.fullscreen = true;
if (this.opts.toolbarExternal)
{
this.toolcss = {};
this.boxcss = {};
this.toolcss.width = this.$toolbar.css('width');
this.toolcss.top = this.$toolbar.css('top');
this.toolcss.position = this.$toolbar.css('position');
this.boxcss.top = this.$box.css('top');
}
this.fsheight = this.$editor.height();
if (this.opts.iframe) html = this.get();
this.tmpspan = jQuery('<span></span>');
this.$box.addClass('redactor_box_fullscreen').after(this.tmpspan);
jQuery('body, html').css('overflow', 'hidden');
jQuery('body').prepend(this.$box);
if (this.opts.iframe) this.fullscreenIframe(html);
this.fullScreenResize();
jQuery(window).resize($.proxy(this.fullScreenResize, this));
jQuery(document).scrollTop(0, 0);
this.focus();
this.observeStart();
}
else
{
this.buttonRemoveIcon('fullscreen', 'normalscreen');
this.buttonInactive('fullscreen');
this.fullscreen = false;
jQuery(window).off('resize', jQuery.proxy(this.fullScreenResize, this));
jQuery('body, html').css('overflow', '');
this.$box.removeClass('redactor_box_fullscreen').css({ width: 'auto', height: 'auto' });
if (this.opts.iframe) html = this.$editor.html();
this.tmpspan.after(this.$box).remove();
if (this.opts.iframe) this.fullscreenIframe(html);
else this.sync();
var height = this.fsheight;
if (this.opts.autoresize) height = 'auto';
if (this.opts.toolbarExternal)
{
this.$box.css('top', this.boxcss.top);
this.$toolbar.css({
'width': this.toolcss.width,
'top': this.toolcss.top,
'position': this.toolcss.position
});
}
if (!this.opts.iframe) this.$editor.css('height', height);
else this.$frame.css('height', height);
this.$editor.css('height', height);
this.focus();
this.observeStart();
}
},
fullscreenIframe: function(html)
{
this.$editor = this.$frame.contents().find('body').attr({
'contenteditable': true,
'dir': this.opts.direction
});
// set document & window
if (this.$editor[0])
{
this.document = this.$editor[0].ownerDocument;
this.window = this.document.defaultView || window;
}
// iframe css
this.iframeAddCss();
if (this.opts.fullpage) this.setFullpageOnInit(html);
else this.set(html);
if (this.opts.wym) this.$editor.addClass('redactor_editor_wym');
},
fullScreenResize: function()
{
if (!this.fullscreen) return false;
var toolbarHeight = this.$toolbar.height();
var pad = this.$editor.css('padding-top').replace('px', '');
var height = $(window).height() - toolbarHeight;
this.$box.width($(window).width() - 2).height(height + toolbarHeight);
if (this.opts.toolbarExternal)
{
this.$toolbar.css({
'top': '0px',
'position': 'absolute',
'width': '100%'
});
this.$box.css('top', toolbarHeight + 'px');
}
if (!this.opts.iframe) this.$editor.height(height - (pad * 2));
else
{
setTimeout(jQuery.proxy(function()
{
this.$frame.height(height);
}, this), 1);
}
this.$editor.height(height);
}
};