2012-04-11 100 views
4

我有一個經典的ASP頁面,具有jQuery的功能,並有它的TinyMCE編輯器。我希望能夠拼寫檢查編輯器,但我看到的每個示例都使用PHP或ASP.net。Tinymce拼寫檢查實現

我遇到了這個頁面:http://achorniy.wordpress.com/2009/08/11/tinymce-spellchecker-in-java/但是我對SVN並不熟悉,所以我不太確定如何按照步驟操作,並且我讀過它可能不適用於IE。

有沒有其他選項可以拼寫檢查我的tinymce編輯器?

非常感謝您的幫助。

+0

你得到這個工作? – RogueSpear00 2012-04-13 13:27:44

+0

@ RogueSpear00對不起,我以爲你會看到下面的註釋。我已經部分工作了,但在對James Newtons的ASP代理進行更新後,它無法正常工作。看到我的評論如下。感謝您的跟蹤!我希望很快得到解決 – Cineno28 2012-04-16 13:07:15

回答

1

只需使用該插件拼寫檢查

http://www.tinymce.com/wiki.php/Plugin:spellchecker

+0

感謝您的答覆。我注意到,但看到PHP被列爲需求之一。我仍然可以使用這與經典的ASP? – Cineno28 2012-04-11 16:03:32

+0

@ Cineno28 - 看起來TinyMCE並不直接支持經典的ASP進行拼寫檢查。它使用拼寫檢查器的PHP模塊。但是,對於文本框集成它確實工作正常。這裏是他們的論壇帖子的鏈接,它有一些黑客,你可以使用:http://www.tinymce.com/forum/viewtopic.php?id=15662 – RogueSpear00 2012-04-11 20:44:39

+0

@ Cineno28 - 我繼續前進,並嘗試提供的例子從那個鏈接中,我成功地使用了TinyMCE拼寫檢查器。 – RogueSpear00 2012-04-11 20:57:16

4

首先,我不知道這是否是好的,甚至捎帶關閉SG 86的回答,因此,如果它不是不chastize我...

我用SG 86的例子,發現你不能直接使用TinyMCE提供的拼寫檢查功能,但是如果你使用了論壇用戶提供的黑客,它確實能夠成功工作。

  1. 安裝和設置TinyMCE的從論壇用戶
  2. 按照說明

所有信用卡此解決方案與TinyMCE的應到原論壇用戶@http://tinymce.com/forum/viewtopic.php?id=15662


我建議設置googiespell首先與asp一起使用簡單的textarea: googiespell這裏:http://orangoo.com/labs/GoogieSpell/

ASP腳本此頁面上有詹姆斯·牛頓的ASP代理:http://orangoo.com/labs/GoogieSpell/Documentation/ 所以一旦你得到了這個在這裏工作是你如何用TinyMCE的 在你的JavaScript設置整合這個拼寫檢查的配置:

<script language="javascript"> 

tinyMCE.init({ 
    theme : "advanced", 
    mode : "textareas", 
    plugins : "spellchecker", 
    theme_advanced_buttons3_add : "spellchecker", 
    spellchecker_rpc_url : "/googiespell/spell.asp", 
    spellchecker_languages : "+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv" 
}); 

</script> 

編輯線:

spellchecker_rpc_url : "/googiespell/spell.asp", 

以指向您的spell.asp文件位於您的應用程序

用下面的代碼替換spell.asp的內容:

<% 

Dim ByteCount, BinRead 
ByteCount = Request.TotalBytes 
BinRead = Request.BinaryRead(ByteCount) 
rawData = RSBinaryToString(BinRead) 

'get language 
if instr(rawData, """params"":[""") > 1 then 
    lang = mid(rawData, InStr(rawData,"[")+2, 2) 
else 
    lang = "en" 
end if 

if instr(rawData, """method"":""checkWords"",") > 1 then 
'return mispelled words 
json = mid(rawData, InStrRev(rawData,"[")) 
json = mid(json, 1, instr(json, "]")) 
json = replace(json, """,""", " ") 
json = replace(json, """", "") 
t = json 

    r = "<?xml version=""1.0"" encoding=""utf-8"" ?><spellrequest textalreadyclipped=""0"" ignoredups=""0"" ignoredigits=""1"" ignoreallcaps=""1""><text>"_ 
     &t&"</text></spellrequest>" 

    r = getURL("https://www.google.com/tbproxy/spell?lang="&lang, r, "","") 
    out = "{""id"":null,""result"":[" 
    wrds = "" 
    for each c in filter(split(r,"<c "),"</c>") 
     'response.write "<br>"&server.htmlencode(c) 
     o = cint(split(split(c,"o=",2)(1),"""")(1))+1 
     l = cint(split(split(c,"l=",2)(1),"""")(1)) 
     s = cint(split(split(c,"s=",2)(1),"""")(1)) 
     out = out & """" & mid(t,o,l)& """, " 
     wrds = "1" 
    next 
    if wrds = "" then 
     out = "{""id"":null,""result"":[],""error"":null}" 
    else 
     out = mid(out, 1, len(out)-2) & "],""error"":null}" 
    end if 

    response.write out 
    response.end 

else 
'return single word corrections 
json = mid(rawData, InStrRev(rawData,"[")) 
json = mid(json, 1, instr(json, "]")) 
json = replace(json, """,""", " ") 
json = replace(json, "en ", "") 
json = replace(json, """", "") 
t = json 

    r = "<?xml version=""1.0"" encoding=""utf-8"" ?><spellrequest textalreadyclipped=""0"" ignoredups=""0"" ignoredigits=""1"" ignoreallcaps=""1""><text>"_ 
     &t&"</text></spellrequest>" 

    r = getURL("https://www.google.com/tbproxy/spell?lang="&lang, r, "","") 

    for each c in filter(split(r,"<c "),"</c>") 
     'response.write "<br>"&server.htmlencode(c) 
     o = cint(split(split(c,"o=",2)(1),"""")(1))+1 
     l = cint(split(split(c,"l=",2)(1),"""")(1)) 
     s = cint(split(split(c,"s=",2)(1),"""")(1)) 
     c = textbetween(">", c, "<") 
     '{"id":null,"result":["Titmice","Times","Tines","Tinnies","Timmy\'s"],"error":null} 
     out = "{""id"":null,""result"":[" 
     wrds = "" 
     for each w in split(c,vbTab) 
      out = out & """" & w & """, " 
      wrds = "1" 
     next 
     if wrds = "" then 
      out = "{""id"":null,""result"":[],""error"":null}" 
     else 
      out = mid(out, 1, len(out)-2) & "],""error"":null}" 
     end if 
    next 
    response.write out 
    response.end 
end if 

if t=empty then t = request.form() 'GoogieSpell is going to put the text in the POST data. 

'show the reply from google for the POST data.  
response.write getURL("https://www.google.com/tbproxy/spell?lang="&lang, t, "","") 



Function TextBetween(sThis, sAnd, sThat) 
    on error resume next 
    TextBetween = split(split(sAnd,sThis,2,1)(1),sThat,2,1)(0) 
end function 

Function RSBinaryToString(xBinary) 
    Dim Binary 
    If vartype(xBinary)=8 Then Binary = MultiByteToBinary(xBinary) Else Binary = xBinary 
    Dim RS, LBinary 
    Const adLongVarChar = 201 
    Set RS = CreateObject("ADODB.Recordset") 
    LBinary = LenB(Binary) 

    If LBinary>0 Then 
    RS.Fields.Append "mBinary", adLongVarChar, LBinary 
    RS.Open 
    RS.AddNew 
    RS("mBinary").AppendChunk Binary 
    RS.Update 
    RSBinaryToString = RS("mBinary") 
    Else 
    RSBinaryToString = "" 
    End If 
End Function 

function getURL(aURL, anyPostData, anyUserName, anyPassword) 
DIM objSrvHTTP,web,method,s 
    on error resume next 
    s="" 
    set objSrvHTTP = Server.CreateObject ("Msxml2.ServerXMLHTTP.3.0") 
    if anyPostData=empty then 
     objSrvHTTP.open "GET",aURL, true, anyUsername, anyPassword 
    else 
     objSrvHTTP.open "POST",aURL, true, anyUsername, anyPassword 
     objSrvHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
    end if 
    objSrvHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)" 
    objSrvHTTP.send anyPostData 
    objSrvHTTP.waitForResponse 7 
    select case objSrvHTTP.readyState 
     case 0 'object created, but no URL opened 
      debug "getURL("&aURL&", "&anyPostData&", "&anyUserName&", "&anyPassword&"): Object Created, no URL opened" 
      err.raise 1, "Object Created, no URL opened" 
      exit function 
     case 1 'loading: URL opened, but no data sent 
      debug "getURL("&aURL&", "&anyPostData&", "&anyUserName&", "&anyPassword&"):URL opened, no data sent" 
      err.raise 2, "URL opened, no data sent" 
      exit function 
     case 2 'loaded: data sent, status and headers available, no response recieved. 
      debug "getURL("&aURL&", "&anyPostData&", "&anyUserName&", "&anyPassword&"):No response from remote host" 
      err.raise 3, "No response from remote host" 
      exit function 
     case 3 'interactive: some data recieved. responseBody and responseText will return partial results. 
      debug "getURL("&aURL&", "&anyPostData&", "&anyUserName&", "&anyPassword&"):Partial response recieved:" 
      debug server.htmlencode(objSrvHTTP.responseText) 
      s = objSrvHTTP.responseText 
      err.raise 4, "Partial response recieved" 
     case 4 'complete: 
      s = objSrvHTTP.responseText 
     end select 
    getURL = s 
end function 

%> 

編輯 - 添加我的頭爲清楚:

<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js" ></script> 
<script type="text/javascript"> 
tinyMCE.init({ 
    mode : "textareas", 
    theme : "advanced", 
    plugins : "spellchecker", 
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,undo,redo,|,copy,paste,|,spellchecker", 
    theme_advanced_buttons2 : "", 
    theme_advanced_buttons3 : "", 
    spellchecker_rpc_url : "googiespell/spell.asp", <--! Needs to point to where the spell.asp script is located on your server. --> 
    spellchecker_languages : "+English=en,Spanish=es" 
}); 

</script> 
+0

我不知道這個網站如何提醒評論的海報,所以我只是在這裏發佈,在SG 86的帖子下面有評論,以防他們沒有看到。再次感謝你的幫助。我覺得我正在接近這個工作。 – Cineno28 2012-04-16 13:08:50

+0

什麼不起作用?我回答了SG的回答中的上述問題。這沒有用嗎?我從上週閱讀了這些評論並作出迴應。 – RogueSpear00 2012-04-16 15:44:40

+0

不工作的部分是當我將James Newton的ASP代理替換爲新的ASP代碼時。我不確定是否應該用這個新代碼編輯他的代理,或者完全用它替換它。我試圖完全替換它,並且我在編輯器上得到了拼寫檢查器,但是它沒有發現任何拼寫糾正可以用牛頓的原始代碼糾正,也沒有錫姆蒂奇。 – Cineno28 2012-04-16 16:46:07

0

JSpellChecker的問題(http://achorniy.wordpress.com/2009/08/11/tinymce-spellchecker-in-java/)爲TinyMCE的拼寫檢查程序的幾個實現提到和使用示例,但它們都是基於java的實現(因此您需要執行一些額外的步驟才能使其在您的環境中工作)

它應該在IE中正常工作,但理想情況下應該託管在與您要使用它的頁面相同的主機,因爲瀏覽器(不僅是IE)可能會阻止跨域的Ajax請求。

如果你不想處理SVN,你可以在這裏下載代碼快照(http://sourceforge.net/p/jspellchecker/code/11/tarball)。它還包含用法示例

0

TinyMCE的提供

spellchecker_rpc_url : "/myspellchcker", 
<--! Needs to point to where the myspellchecker script is located on your server. --> 

下面是Python代碼(寫在ASP等效):

#checker is a pyenchant object - uses enchant which wraps aspell in our case . The code was taken from django's implementation for tinymce spellchecker. 

    def spell_check(self): 
     """Returns a Response that implements the TinyMCE spellchecker protocol. 
     """ 
     try: 
      raw = self.REQUEST['BODY'] 
      input = json.loads(raw) 
      id = input['id'] 
      method = input['method'] 
      params = input['params'] 
      lang = params[0] 
      arg = params[1] 

      if not enchant.dict_exists(str(lang)): 
       raise Exception("dictionary not found for language '%s'" % lang) 

      checker = self.checker 
      if method == 'checkWords': 
       result = [word for word in arg if not checker.check(word)] 
      elif method == 'getSuggestions': 
       result = checker.suggest(arg) 
      elif method == 'learnWord' : 
       result = checker.add(arg) 
      else: 
       raise Exception("Unkown spellcheck method: '%s'" % method) 
      output = { 
       'id': id, 
       'result': result, 
       'error': None, 
      } 
     except Exception: 
      return Exception("Error running spellchecker") 
     self.REQUEST.RESPONSE.setHeader('Content-Type','application/json') 
     return json.dumps(output)