source: trunk/library/ckeditor/plugins/aspell/dialogs/aspell.js @ 5081

Revision 5081, 5.6 KB checked in by airton, 13 years ago (diff)

Ticket #2086 - Troca do atual editor de emails do expresso - Adicionando a biblioteca ckeditor

  • Property svn:executable set to *
Line 
1
2var FCKLang;
3var OnSpellerControlsLoad;
4
5CKEDITOR.dialog.add('aspell', function( editor )
6{
7        var number = CKEDITOR.tools.getNextNumber(),
8                iframeId = 'cke_frame_' + number,
9                textareaId = 'cke_data_' + number,
10                interval,
11                errorMsg = editor.lang.spellCheck.notAvailable;
12       
13        var spellHTML =
14        // Input for exchanging data CK<--->spellcheck
15                '<textarea name="'+textareaId+'" id="'+textareaId+
16                '" style="display: none;"></textarea>' +
17        // Spellcheck iframe
18                '<iframe src="" style="width:485px; height:380px"' +
19                ' frameborder="0" name="' + iframeId + '" id="' + iframeId + '"' +
20                ' allowtransparency="1"></iframe>';
21       
22        function spellTime(dialog, errorMsg)
23        {
24                var i = 0;
25                return function()
26                {
27                        if (typeof window.spellChecker == 'function')
28                        {
29                                // Call from window.setInteval expected at once.
30                                if (typeof interval != 'undefined')
31                                        window.clearInterval(interval);
32                               
33                                // Create spellcheck object, set options/attributes
34                                var oSpeller = new spellChecker(document.getElementById(textareaId));
35                                oSpeller.spellCheckScript = editor.plugins.aspell.path+'spellerpages/server-scripts/spellchecker.php';
36                                oSpeller.OnFinished = function (numChanges) { oSpeller_OnFinished(dialog, numChanges) };
37                                oSpeller.popUpUrl = editor.plugins.aspell.path+'spellerpages/spellchecker.html';
38                                oSpeller.popUpName = iframeId;
39                                oSpeller.popUpProps = null;
40                               
41                                // Place language in global variable;
42                                // A bit of a hack, but how does e.g. controls.html know which language to use?
43                                FCKLang = {};
44                                // spellChecker.js
45                                FCKLang.DlgSpellNoChanges     = CKEDITOR.lang[editor.langCode].spellCheck.noChanges;
46                                FCKLang.DlgSpellNoMispell     = CKEDITOR.lang[editor.langCode].spellCheck.noMispell;
47                                FCKLang.DlgSpellOneChange     = CKEDITOR.lang[editor.langCode].spellCheck.oneChange;
48                                FCKLang.DlgSpellManyChanges   = CKEDITOR.lang[editor.langCode].spellCheck.manyChanges;
49                                // controls.html
50                                FCKLang.DlgSpellNotInDic      = CKEDITOR.lang[editor.langCode].spellCheck.notInDic;
51                                FCKLang.DlgSpellChangeTo      = CKEDITOR.lang[editor.langCode].spellCheck.changeTo;
52                                FCKLang.DlgSpellBtnIgnore     = CKEDITOR.lang[editor.langCode].spellCheck.btnIgnore;
53                                FCKLang.DlgSpellBtnIgnoreAll  = CKEDITOR.lang[editor.langCode].spellCheck.btnIgnoreAll;
54                                FCKLang.DlgSpellBtnReplace    = CKEDITOR.lang[editor.langCode].spellCheck.btnReplace;
55                                FCKLang.DlgSpellBtnReplaceAll = CKEDITOR.lang[editor.langCode].spellCheck.btnReplaceAll;
56                                FCKLang.DlgSpellBtnUndo       = CKEDITOR.lang[editor.langCode].spellCheck.btnUndo;
57                                // controlWindow.js
58                                FCKLang.DlgSpellNoSuggestions = CKEDITOR.lang[editor.langCode].spellCheck.noSuggestions;
59                                // spellchecker.html
60                                FCKLang.DlgSpellProgress      = CKEDITOR.lang[editor.langCode].spellCheck.progress;
61                                // End language
62                               
63                                // Start spellcheck!
64                                oSpeller.openChecker();
65                        }
66                        else if (i++ == 180) // Timeout: 180 * 250ms = 45s.
67                        {
68                                alert(errorMsg);
69                                dialog.hide();
70                        }
71                };
72        }
73       
74        function oSpeller_OnFinished(dialog, numberOCorrections)
75        {
76                if (numberOCorrections > 0)
77                {
78                        editor.focus();
79                        editor.fire('saveSnapshot'); // Best way I could find to trigger undo steps.
80                        dialog.getParentEditor().setData(document.getElementById(textareaId).value);
81                        editor.fire('saveSnapshot'); // But there's a blank one between!
82                }
83                dialog.hide();
84        }
85       
86        // Fx and IE don't see the same sizes, it seems. That or Fx is allowing everything to grow.
87        var minW = 485;
88        var minH = 380;
89        if (document.all)
90        {
91                minW = 510;
92                minH = 405;
93        }
94       
95        return {
96                title: editor.lang.spellCheck.title,
97                minWidth: minW,
98                minHeight: minH,
99                buttons: [ CKEDITOR.dialog.cancelButton ],
100                onShow: function()
101                {
102                        // Put spellcheck input and iframe in the dialog content
103                        var contentArea = this.getContentElement('general', 'content').getElement();
104                        contentArea.setHtml(spellHTML);
105                       
106                        // Define spellcheck init function
107                        OnSpellerControlsLoad = function (controlsWindow)
108                        {
109                                // Translate the dialog box texts
110                                var spans  = controlsWindow.document.getElementsByTagName('span');
111                                var inputs = controlsWindow.document.getElementsByTagName('input');
112                                var i, attr;
113                               
114                                for (i=0; i < spans.length; i++)
115                                {
116                                        attr = spans[i].getAttribute && spans[i].getAttribute('fckLang');
117                                        if (attr)
118                                                spans[i].innerHTML = FCKLang[attr];
119                                }
120                                for (i=0; i < inputs.length; i++)
121                                {
122                                        attr = inputs[i].getAttribute && inputs[i].getAttribute('fckLang');
123                                        if (attr)
124                                                inputs[i].value = FCKLang[attr];
125                                }
126                        }
127                       
128                        // Add spellcheck script to head
129                        CKEDITOR.document.getHead().append(CKEDITOR.document.createElement('script', {
130                                attributes: {
131                                        type: 'text/javascript',
132                                        src: editor.plugins.aspell.path+'spellerpages/spellChecker.js'
133                        }}));
134                       
135                        // Get the data to be checked.
136                        var sData = editor.getData();
137                        //CKEDITOR.document.getById(textareaId).setValue(sData); <-- doesn't work for some reason
138                        document.getElementById(textareaId).value = sData;
139                       
140                        // Wait for spellcheck script to load, then execute
141                        interval = window.setInterval(spellTime(this, errorMsg), 250);
142                },
143                onHide: function()
144                {
145                        window.ooo = undefined;
146                        window.int_framsetLoaded = undefined;
147                        window.framesetLoaded = undefined;
148                        window.is_window_opened = false;
149                       
150                        OnSpellerControlsLoad = null;
151                        FCKLang = null;
152                },
153                contents: [
154                        {
155                                id: 'general',
156                                label: editor.lang.spellCheck.title,
157                                padding: 0,
158                                elements: [
159                                        {
160                                                type: 'html',
161                                                id: 'content',
162                                                style: 'width:485;height:380px',
163                                                html: '<div></div>'
164                                        }
165                                ]
166                        }
167                ]
168        };
169});
Note: See TracBrowser for help on using the repository browser.