Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/app/static/js/wymeditor/plugins/fullscreen/jquery.wymeditor.fullscreen.js
blob: 275c816990fee6eab7254ca13b5888eb6a81c76f (plain)
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
/*
 * WYMeditor : what you see is What You Mean web-based editor
 * Copyright (c) 2005 - 2009 Jean-Francois Hovinne, http://www.wymeditor.org/
 * Dual licensed under the MIT (MIT-license.txt)
 * and GPL (GPL-license.txt) licenses.
 *
 * For further information visit:
 *        http://www.wymeditor.org/
 *
 * File Name:
 *        jquery.wymeditor.fullscreen.js
 *        Fullscreen plugin for WYMeditor
 *
 * File Authors:
 *        Luis Santos (luis.santos a-t openquest dotpt)
 *        Jonatan Lundin (jonatan.lundin a-t gmail dotcom)
 *        Gerd Riesselmann (gerd a-t gyro-php dot org) : Fixed issue with new skin layout
 */

//Extend WYMeditor
WYMeditor.editor.prototype.fullscreen = function() {
    var wym = this,
        $box = jQuery(this._box),
        $iframe = jQuery(this._iframe),
        $overlay = null,
        $window = jQuery(window),
        
        editorMargin = 15;     // Margin from window (without padding)

    
    //construct the button's html
    var html = "<li class='wym_tools_fullscreen'>"
             + "<a name='Fullscreen' href='#'"
             + " style='background-image:"
             + " url(" + wym._options.basePath +"plugins/fullscreen/icon_fullscreen.gif)'>"
             + "Fullscreen"
             + "</a></li>";

    //add the button to the tools box
    $box.find(wym._options.toolsSelector + wym._options.toolsListSelector)
        .append(html);
        
    function resize () {
                // Calculate margins
            var uiHeight = $box.outerHeight(true) 
                                - $iframe.outerHeight(true),
                editorPadding = $box.outerWidth() - $box.width(),
                
                // Calculate heights
                screenHeight = $window.height(),
                iframeHeight = (screenHeight 
                                    - uiHeight 
                                    - (editorMargin * 2)) + 'px',
                
                // Calculate witdths
                screenWidth = $window.width(),
                boxWidth = (screenWidth 
                                - editorPadding
                                - (editorMargin * 2)) + 'px';
            
            $box.css('width', boxWidth);
            $iframe.css('height', iframeHeight);
            $overlay.css({
                'height': screenHeight + 'px',
                'width': screenWidth + 'px'
            });
    };

    //handle click event
    $box.find('li.wym_tools_fullscreen a').click(function() {
        if ($box.css('position') != 'fixed') {
            // Store previous inline styles
            $box.data('wym-inline-css', $box.attr('style'));
            $iframe.data('wym-inline-css', $iframe.attr('style'));
            
            // Create overlay
            $overlay = jQuery('<div id="wym-fullscreen-overlay"></div>')
                .appendTo('body').css({
                    'position': 'fixed',
                    'background-color': 'rgb(0, 0, 0)',
                    'opacity': '0.75',
                    'z-index': '98',
                    'top': '0px',
                    'left': '0px'
                });
            
            // Possition the editor
            $box.css({
                'position': 'fixed', 
                'z-index': '99',
                'top': editorMargin + 'px',
                'left': editorMargin + 'px'
            });
            
            // Bind event listeners
            $window.bind('resize', resize);
            $box.find('li.wym_tools_html a').bind('click', resize);
            
            // Force resize
            resize();
        } else {
            // Unbind event listeners
            $window.unbind('resize', resize);
            $box.find('li.wym_tools_html a').unbind('click', resize);
            
            // Remove inline styles
            $box.css({
                'position': 'static', 
                'z-index': '', 
                'width': '', 
                'top': '', 
                'left': ''
            });
            $iframe.css('height', '');

            // Remove overlay
            $overlay.remove();
            $overlay = null;
            
            // Retore previous inline styles
            $box.attr('style', $box.data('wym-inline-css'));
            $iframe.attr('style', $iframe.data('wym-inline-css'));
        }

        return false;
    });
};