source: sandbox/2.3-MailArchiver/expressoMail1_2/spell_checker/js/spell_checker_compressed.js @ 6779

Revision 6779, 13.5 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

Line 
1var cp = new cpaint(); cp.set_transfer_mode('post'); cp.set_response_type('text'); var currObj; var spellingSuggestionsDiv = null; if(document.onclick)
2{ var old_onclick = document.onclick; document.onclick = function(e)
3{ checkClickLocation(e); old_onclick(e);}
4}
5else
6{ document.onclick = checkClickLocation;}
7if(window.onload)
8{ var old_onload = window.onload; window.onload = function(e)
9{ setupSpellCheckers(e); old_onload(e);}
10}
11else
12{ window.onload = setupSpellCheckers;}
13function setupSpellCheckers()
14{ var textareas = document.getElementsByTagName('textarea'); var numSpellCheckers = 0; var tempSpellCheckers = Array(); for(var i=0; i < textareas.length; i++)
15{ if(textareas[i].getAttribute("title") == "spellcheck" || textareas[i].getAttribute("title") == "spellcheck_icons")
16{ tempSpellCheckers[numSpellCheckers] = textareas[i]; var tempWidth = tempSpellCheckers[numSpellCheckers].offsetWidth + 'px'; var tempHeight = tempSpellCheckers[numSpellCheckers].offsetHeight + 'px'; eval('spellCheckers' + numSpellCheckers + '= new ajaxSpell("spellCheckers' + numSpellCheckers + '", tempWidth, tempHeight, tempSpellCheckers[' + numSpellCheckers + '].getAttribute("accesskey"), "spellCheckDiv' + numSpellCheckers + '", tempSpellCheckers[' + numSpellCheckers + '].getAttribute("name"), tempSpellCheckers[' + numSpellCheckers + '].id, tempSpellCheckers[' + numSpellCheckers + '].title, tempSpellCheckers[' + numSpellCheckers + '].value);'); numSpellCheckers++;}
17}
18}; function ajaxSpell(varName, width, height, spellUrl, divId, name, id, title, value)
19{ currObj = this; currObj.config = new Array(); currObj.config['varName'] = varName; currObj.config['width'] = width; currObj.config['height'] = height; currObj.config['spellUrl'] = spellUrl; currObj.config['divId'] = divId; currObj.config['name'] = name; currObj.config['id'] = id; currObj.config['title'] = title; currObj.config['value'] = value; currObj.config['value'] = currObj.config['value'].replace(/<br *\/?>/gi, "\n"); currObj.config['useIcons'] = false; if(currObj.config['title'] == "spellcheck_icons")
20{ currObj.config['useIcons'] = true;}
21spellContainer = document.createElement('DIV'); spellContainer.id = currObj.config['divId']; spellContainer.className = 'spell_container'; spellContainer.style.width = currObj.config['width']; oldElement = document.getElementById(currObj.config['id']); oldElement.parentNode.replaceChild(spellContainer, oldElement); currObj.controlPanelDiv = document.createElement('DIV'); currObj.controlPanelDiv.className = 'control_panel'; document.getElementById(currObj.config['divId']).appendChild(currObj.controlPanelDiv); currObj.actionSpan = document.createElement('SPAN'); currObj.actionSpan.className = "action"; currObj.actionSpan.id = "action"; if(currObj.config['useIcons'])
22{ currObj.actionSpan.innerHTML = "<a class=\"check_spelling\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".spellCheck();\"><img src=\"images/spellcheck.png\" width=\"16\" height=\"16\" title=\"Check Spelling &amp; Preview\" alt=\"Check Spelling &amp; Preview\" border=\"0\" /></a>";}
23else
24{ currObj.actionSpan.innerHTML = "<a class=\"check_spelling\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".spellCheck();\">Check Spelling &amp; Preview</a>";}
25currObj.controlPanelDiv.appendChild(currObj.actionSpan); currObj.statusSpan = document.createElement('SPAN'); currObj.statusSpan.className = "status"; currObj.statusSpan.id = "status"; currObj.statusSpan.innerHTML = ""; currObj.controlPanelDiv.appendChild(currObj.statusSpan); oldElement.value = currObj.config['value']; document.getElementById(currObj.config['divId']).appendChild(oldElement); currObj.objToCheck = document.getElementById(currObj.config['id']); currObj.spellingResultsDiv = null; ajaxSpell.prototype.spellCheck = spellCheck; ajaxSpell.prototype.spellCheck_cb = spellCheck_cb; ajaxSpell.prototype.showSuggestions = showSuggestions; ajaxSpell.prototype.showSuggestions_cb = showSuggestions_cb; ajaxSpell.prototype.replaceWord = replaceWord; ajaxSpell.prototype.switchText = switchText; ajaxSpell.prototype.switchText_cb = switchText_cb; ajaxSpell.prototype.resumeEditing = resumeEditing; ajaxSpell.prototype.resetSpellChecker = resetSpellChecker; ajaxSpell.prototype.resetAction = resetAction;}; function setCurrentObject(obj)
26{ currObj = obj;}; function spellCheck_cb(new_data)
27{ with(currObj); new_data = new_data.toString(); var isThereAMisspelling = new_data.charAt(0); new_data = new_data.substring(1); if(currObj.spellingResultsDiv)
28{ currObj.spellingResultsDiv.parentNode.removeChild(spellingResultsDiv);}
29currObj.spellingResultsDiv = document.createElement('DIV'); currObj.spellingResultsDiv.className = 'edit_box'; currObj.spellingResultsDiv.style.width = currObj.objToCheck.style.width; currObj.spellingResultsDiv.style.height = currObj.objToCheck.style.height; currObj.spellingResultsDiv.innerHTML = new_data; currObj.objToCheck.style.display = "none"; currObj.objToCheck.parentNode.insertBefore(currObj.spellingResultsDiv,currObj.objToCheck); currObj.statusSpan.innerHTML = ""; if(currObj.config['useIcons'])
30{ currObj.actionSpan.innerHTML = "<a class=\"resume_editing\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".resumeEditing();\"><img src=\"images/page_white_edit.png\" width=\"16\" height=\"16\" title=\"Resume Editing\" alt=\"Resume Editing\" border=\"0\" /></a>";}
31else
32{ currObj.actionSpan.innerHTML = "<a class=\"resume_editing\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".resumeEditing();\">Resume Editing</a>";}
33if(isThereAMisspelling != "1")
34{ if(currObj.config['useIcons'])
35{ currObj.statusSpan.innerHTML = "<img src=\"images/accept.png\" width=\"16\" height=\"16\" title=\"No Misspellings Found\" alt=\"No Misspellings Found\" border=\"0\" />";}
36else
37{ currObj.statusSpan.innerHTML = "No Misspellings Found";}
38currObj.objToCheck.disabled = false;}
39}; function spellCheck() { with(currObj); var query; if(currObj.spellingResultsDiv)
40{ currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv); currObj.spellingResultsDiv = null;}
41if(currObj.config['useIcons'])
42{ currObj.actionSpan.innerHTML = "<img src=\"images/spellcheck.png\" width=\"16\" height=\"16\" title=\"Check Spelling &amp; Preview\" alt=\"Check Spelling &amp; Preview\" border=\"0\" />";}
43else
44{ currObj.actionSpan.innerHTML = "<a class=\"check_spelling\">Check Spelling &amp; Preview</a>";}
45if(currObj.config['useIcons'])
46{ currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Checking...\" alt=\"Checking...\" border=\"0\" />";}
47else
48{ currObj.statusSpan.innerHTML = "Checking...";}
49query = currObj.objToCheck.value; query = query.replace(/\r?\n/gi, "<br />"); cp.call(currObj.config['spellUrl'], 'spellCheck', spellCheck_cb, query, currObj.config['varName']);}; function addWord(id)
50{ var wordToAdd = document.getElementById(id).innerHTML; with(currObj); if(spellingSuggestionsDiv)
51{ spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv); spellingSuggestionsDiv = null;}
52if(currObj.config['useIcons'])
53{ currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Adding Word...\" alt=\"Adding Word...\" border=\"0\" />";}
54else
55{ currObj.statusSpan.innerHTML = "Adding Word...";}
56cp.call(currObj.config['spellUrl'], 'addWord', addWord_cb, wordToAdd);}; function addWord_cb(returnedData)
57{ alert(returnedData); with(currObj); currObj.statusSpan.innerHTML = ""; resumeEditing(); spellCheck();}; function checkClickLocation(e)
58{ if(spellingSuggestionsDiv)
59{ if(spellingSuggestionsDiv.ignoreNextClick){ spellingSuggestionsDiv.ignoreNextClick = false;}
60else
61{ var theTarget = getTarget(e); if(theTarget != spellingSuggestionsDiv)
62{ spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv); spellingSuggestionsDiv = null;}
63}
64}
65return true;}; function getTarget(e)
66{ var value; if(checkBrowser() == "ie")
67{ value = window.event.srcElement;}
68else
69{ value = e.target;}
70return value;}; function checkBrowser()
71{ var theAgent = navigator.userAgent.toLowerCase(); if(theAgent.indexOf("msie") != -1)
72{ if(theAgent.indexOf("opera") != -1)
73{ return "opera";}
74else
75{ return "ie";}
76}
77else if(theAgent.indexOf("netscape") != -1)
78{ return "netscape";}
79else if(theAgent.indexOf("firefox") != -1)
80{ return "firefox";}
81else if(theAgent.indexOf("mozilla/5.0") != -1)
82{ return "mozilla";}
83else if(theAgent.indexOf("\/") != -1)
84{ if(theAgent.substr(0,theAgent.indexOf('\/')) != 'mozilla')
85{ return navigator.userAgent.substr(0,theAgent.indexOf('\/'));}
86else
87{ return "netscape";}
88}
89else if(theAgent.indexOf(' ') != -1)
90{ return navigator.userAgent.substr(0,theAgent.indexOf(' '));}
91else
92{ return navigator.userAgent;}
93}; function showSuggestions_cb(new_data)
94{ with(currObj); spellingSuggestionsDiv.innerHTML = new_data; spellingSuggestionsDiv.style.display = 'block'; currObj.statusSpan.innerHTML = "";}; function showSuggestions(word, id)
95{ with(currObj); if(currObj.config['useIcons'])
96{ currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Searching...\" alt=\"Searching...\" border=\"0\" />";}
97else
98{ currObj.statusSpan.innerHTML = "Searching...";}
99var x = findPosXById(id); var y = findPosYById(id); var scrollPos = 0; if(checkBrowser() != "ie")
100{ scrollPos = currObj.spellingResultsDiv.scrollTop;}
101if(spellingSuggestionsDiv)
102{ spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);}
103spellingSuggestionsDiv = document.createElement('DIV'); spellingSuggestionsDiv.style.display = "none"; spellingSuggestionsDiv.className = 'suggestion_box'; spellingSuggestionsDiv.style.position = 'absolute'; spellingSuggestionsDiv.style.left = x + 'px'; spellingSuggestionsDiv.style.top = (y+16-scrollPos) + 'px'; spellingSuggestionsDiv.ignoreNextClick = true; document.body.appendChild(spellingSuggestionsDiv); cp.call(currObj.config['spellUrl'], 'showSuggestions', showSuggestions_cb, word, id);}; function replaceWord(id, newWord)
104{ document.getElementById(id).innerHTML = trim(newWord); if(spellingSuggestionsDiv)
105{ spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv); spellingSuggestionsDiv = null;}
106document.getElementById(id).className = "corrected_word";}; function switchText()
107{ with(currObj); var text = currObj.spellingResultsDiv.innerHTML; text = text.replace(/<br *\/?>/gi, "~~~"); text = '*' + text; cp.call(currObj.config['spellUrl'], 'switchText', switchText_cb, text);}; function switchText_cb(new_string)
108{ with(currObj); new_string = new_string.replace(/~~~/gi, "\n"); new_string = new_string.substr(1); currObj.objToCheck.style.display = "none"; currObj.objToCheck.value = new_string; currObj.objToCheck.disabled = false; if(currObj.spellingResultsDiv)
109{ currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv); currObj.spellingResultsDiv = null;}
110currObj.objToCheck.style.display = "block"; currObj.resetAction();}; function resumeEditing()
111{ with(currObj); if(currObj.config['useIcons'])
112{ currObj.actionSpan.innerHTML = "<a class=\"resume_editing\"><img src=\"images/page_white_edit.png\" width=\"16\" height=\"16\" title=\"Resume Editing\" alt=\"Resume Editing\" border=\"0\" /></a>";}
113else
114{ currObj.actionSpan.innerHTML = "<a class=\"resume_editing\">Resume Editing</a>";}
115if(currObj.config['useIcons'])
116{ currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Working...\" alt=\"Working...\" border=\"0\" />";}
117else
118{ currObj.statusSpan.innerHTML = "Working...";}
119if(spellingSuggestionsDiv)
120{ spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv); spellingSuggestionsDiv = null;}
121currObj.switchText();}; function resetAction()
122{ with(currObj); if(currObj.config['useIcons'])
123{ currObj.actionSpan.innerHTML = "<a class=\"check_spelling\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".spellCheck();\"><img src=\"images/spellcheck.png\" width=\"16\" height=\"16\" title=\"Check Spelling &amp; Preview\" alt=\"Check Spelling &amp; Preview\" border=\"0\" /></a>";}
124else
125{ currObj.actionSpan.innerHTML = "<a class=\"check_spelling\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".spellCheck();\">Check Spelling &amp; Preview</a>";}
126currObj.statusSpan.innerHTML = "";}; function resetSpellChecker()
127{ with(currObj); currObj.resetAction(); currObj.objToCheck.value = ""; currObj.objToCheck.style.display = "block"; currObj.objToCheck.disabled = false; if(currObj.spellingResultsDiv)
128{ currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv); currObj.spellingResultsDiv = null;}
129if(spellingSuggestionsDiv)
130{ spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv); spellingSuggestionsDiv = null;}
131currObj.statusSpan.style.display = "none";}; function findPosXById(object)
132{ var curleft = 0; var obj = document.getElementById(object); if(obj.offsetParent)
133{ while(obj.offsetParent)
134{ curleft += obj.offsetLeft - obj.scrollLeft; obj = obj.offsetParent;}
135}
136else if(obj.x)
137{ curleft += obj.x;}
138return curleft;}; function findPosYById(object)
139{ var curtop = 0;var curtop = 0; var obj = document.getElementById(object); if(obj.offsetParent)
140{ while(obj.offsetParent)
141{ curtop += obj.offsetTop - obj.scrollTop; obj = obj.offsetParent;}
142}
143else if(obj.y)
144{ curtop += obj.y;}
145return curtop;}; function trim(s)
146{ while(s.substring(0,1) == ' ')
147{ s = s.substring(1,s.length);}
148while(s.substring(s.length-1,s.length) == ' ')
149{ s = s.substring(0,s.length-1);}
150return s;};
Note: See TracBrowser for help on using the repository browser.