/* * Hyphenator X.Y.Z - client side hyphenation for webbrowsers * Copyright (C) 2010 Mathias Nater, Zürich (mathias at mnn dot ch) * Project and Source hosted on http://code.google.com/p/hyphenator/ * * This JavaScript code is free software: you can redistribute * it and/or modify it under the terms of the GNU Lesser * General Public License (GNU LGPL) as published by the Free Software * Foundation, either version 3 of the License, or (at your option) * any later version. The code is distributed WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. * * As additional permission under GNU GPL version 3 section 7, you * may distribute non-source (e.g., minimized or compacted) forms of * that code without the copy of the GNU GPL normally required by * section 4, provided you include this license notice and a URL * through which recipients can access the Corresponding Source. */ var Hyphenator=(function(window){ var supportedLang={ 'cs':'cs.js', 'da':'da.js', 'bn':'bn.js', 'de':'de.js', 'el':'el-monoton.js', 'el-monoton':'el-monoton.js', 'el-polyton':'el-polyton.js', 'en':'en-us.js', 'en-gb':'en-gb.js', 'en-us':'en-us.js', 'es':'es.js', 'fi':'fi.js', 'fr':'fr.js', 'grc':'grc.js', 'gu':'gu.js', 'hi':'hi.js', 'hu':'hu.js', 'hy':'hy.js', 'it':'it.js', 'kn':'kn.js', 'la':'la.js', 'lt':'lt.js', 'ml':'ml.js', 'nl':'nl.js', 'or':'or.js', 'pa':'pa.js', 'pl':'pl.js', 'pt':'pt.js', 'ru':'ru.js', 'sl':'sl.js', 'sv':'sv.js', 'ta':'ta.js', 'te':'te.js', 'tr':'tr.js', 'uk':'uk.js' }, languageHint=(function(){ var k,r=''; for(k in supportedLang){ if(supportedLang.hasOwnProperty(k)){ r+=k+', '; } } r=r.substring(0,r.length-2); return r; }()), prompterStrings={ 'cs':'Jazyk této internetové stránky nebyl automaticky rozpoznán. Určete prosím její jazyk:', 'da':'Denne websides sprog kunne ikke bestemmes. Angiv venligst sprog:', 'de':'Die Sprache dieser Webseite konnte nicht automatisch bestimmt werden. Bitte Sprache angeben:', 'en':'The language of this website could not be determined automatically. Please indicate the main language:', 'es':'El idioma del sitio no pudo determinarse autom%E1ticamente. Por favor, indique el idioma principal:', 'fi':'Sivun kielt%E4 ei tunnistettu automaattisesti. M%E4%E4rit%E4 sivun p%E4%E4kieli:', 'fr':'La langue de ce site n%u2019a pas pu %EAtre d%E9termin%E9e automatiquement. Veuillez indiquer une langue, s.v.p.%A0:', 'hu':'A weboldal nyelvét nem sikerült automatikusan megállapítani. Kérem adja meg a nyelvet:', 'hy':'Չհաջողվեց հայտնաբերել այս կայքի լեզուն։ Խնդրում ենք նշեք հիմնական լեզուն՝', 'it':'Lingua del sito sconosciuta. Indicare una lingua, per favore:', 'kn':'ಜಾಲ ತಾಣದ ಭಾಷೆಯನ್ನು ನಿರ್ಧರಿಸಲು ಸಾಧ್ಯವಾಗುತ್ತಿಲ್ಲ. ದಯವಿಟ್ಟು ಮುಖ್ಯ ಭಾಷೆಯನ್ನು ಸೂಚಿಸಿ:', 'lt':'Nepavyko automatiškai nustatyti šios svetainės kalbos. Prašome įvesti kalbą:', 'ml':'ഈ വെ%u0D2C%u0D4D%u200Cസൈറ്റിന്റെ ഭാഷ കണ്ടുപിടിയ്ക്കാ%u0D28%u0D4D%u200D കഴിഞ്ഞില്ല. ഭാഷ ഏതാണെന്നു തിരഞ്ഞെടുക്കുക:', 'nl':'De taal van deze website kan niet automatisch worden bepaald. Geef de hoofdtaal op:', 'pt':'A língua deste site não pôde ser determinada automaticamente. Por favor indique a língua principal:', 'ru':'Язык этого сайта не может быть определен автоматически. Пожалуйста укажите язык:', 'sl':'Jezika te spletne strani ni bilo mogoče samodejno določiti. Prosim navedite jezik:', 'sv':'Spr%E5ket p%E5 den h%E4r webbplatsen kunde inte avg%F6ras automatiskt. V%E4nligen ange:', 'tr':'Bu web sitesinin dilini otomatik olarak tespit edilememiştir. Lütfen ana dili gösterir:', 'uk':'Мова цього веб-сайту не може бути визначена автоматично. Будь ласка, вкажіть головну мову:' }, basePath=(function(){ var s=document.getElementsByTagName('script'),i=0,p,src,t; while(!!(t=s[i++])){ if(!t.src){ continue; } src=t.src; p=src.indexOf('Hyphenator.js'); if(p!==-1){ return src.substring(0,p); } } return'http://hyphenator.googlecode.com/svn/trunk/'; }()), isLocal=(function(){ var re=false; if(window.location.href.indexOf(basePath)!==-1){ re=true; } return re; }()), documentLoaded=false, contextWindow=window, doFrames=false, dontHyphenate={'script':true,'code':true,'pre':true,'img':true,'br':true,'samp':true,'kbd':true,'var':true,'abbr':true,'acronym':true,'sub':true,'sup':true,'button':true,'option':true,'label':true,'textarea':true,'input':true}, enableCache=true, storageType='local', storage, enableReducedPatternSet=false, enableRemoteLoading=true, displayToggleBox=false, hyphenateClass='hyphenate', dontHyphenateClass='donthyphenate', min=6, orphanControl=1, isBookmarklet=(function(){ var loc=null,re=false,jsArray=document.getElementsByTagName('script'),i,l; for(i=0,l=jsArray.length;i0){ for(i=0;i0){ return; }else{ init(window); } }; }else if(document.attachEvent){ DOMContentLoaded=function(){ if(document.readyState==="complete"){ document.detachEvent("onreadystatechange",DOMContentLoaded); if(doFrames&&window.frames.length>0){ return; }else{ init(window); } } }; } if(document.addEventListener){ document.addEventListener("DOMContentLoaded",DOMContentLoaded,false); window.addEventListener("load",doOnLoad,false); }else if(document.attachEvent){ document.attachEvent("onreadystatechange",DOMContentLoaded); window.attachEvent("onload",doOnLoad); toplevel=false; try{ toplevel=window.frameElement===null; }catch(e){} if(document.documentElement.doScroll&&toplevel){ doScrollCheck(); } } }, getLang=function(el,fallback){ if(!!el.getAttribute('lang')){ return el.getAttribute('lang').toLowerCase(); } try{ if(!!el.getAttribute('xml:lang')){ return el.getAttribute('xml:lang').toLowerCase(); } }catch(ex){} if(el.tagName!=='HTML'){ return getLang(el.parentNode,true); } if(fallback){ return mainLanguage; } return null; }, autoSetMainLanguage=function(){ var el=contextWindow.document.getElementsByTagName('html')[0], m=contextWindow.document.getElementsByTagName('meta'), i,text,e,ul; mainLanguage=getLang(el,false); if(!mainLanguage){ for(i=0;i0){ Expando.appendDataForElem(elements[elements.length-1],{isLast:true}); } }, convertPatterns=function(lang){ var plen,anfang,ende,pats,pat,key,tmp={}; pats=Hyphenator.languages[lang].patterns; for(plen in pats){ if(pats.hasOwnProperty(plen)){ plen=parseInt(plen,10); anfang=0; ende=plen; while(!!(pat=pats[plen].substring(anfang,ende))){ key=pat.replace(/\d/g,''); tmp[key]=pat; anfang=ende; ende+=plen; } } } Hyphenator.languages[lang].patterns=tmp; Hyphenator.languages[lang].patternsConverted=true; }, convertExceptionsToObject=function(exc){ var w=exc.split(', '), r={}, i,l,key; for(i=0,l=w.length;i=min){ n.data=n.data.replace(Hyphenator.languages[lang].genRegExp,hyphenate); if(orphanControl!==1){ n.data=n.data.replace(/[\S]+ [\S]+$/,function(part){ var h,r; switch(hyphen){ case'|': h='\\|'; break; case'+': h='\\+'; break; case'*': h='\\*'; break; default: h=hyphen; } if(orphanControl>=2){ r=part.split(' '); r[1]=r[1].replace(new RegExp(h,'g'),''); r[1]=r[1].replace(new RegExp(zeroWidthSpace,'g'),''); r=r.join(' '); } if(orphanControl===3){ r=r.replace(/[ ]+/g,String.fromCharCode(160)); } return r; }); } } } } if(hyphenatorSettings.isHidden&&intermediateState==='hidden'){ el.style.visibility='visible'; if(!hyphenatorSettings.hasOwnStyle){ el.setAttribute('style',''); el.removeAttribute('style'); }else{ if(el.style.removeProperty){ el.style.removeProperty('visibility'); }else if(el.style.removeAttribute){ el.style.removeAttribute('visibility'); } } } if(hyphenatorSettings.isLast){ state=3; onHyphenationDone(); } }, removeHyphenationFromElement=function(el){ var h,i=0,n; switch(hyphen){ case'|': h='\\|'; break; case'+': h='\\+'; break; case'*': h='\\*'; break; default: h=hyphen; } while(!!(n=el.childNodes[i++])){ if(n.nodeType===3){ n.data=n.data.replace(new RegExp(h,'g'),''); n.data=n.data.replace(new RegExp(zeroWidthSpace,'g'),''); }else if(n.nodeType===1){ removeHyphenationFromElement(n); } } }, hyphenateDocument=function(){ function bind(fun,arg){ return function(){ return fun(arg); }; } var i=0,el; while(!!(el=elements[i++])){ window.setTimeout(bind(hyphenateElement,el),0); } }, removeHyphenationFromDocument=function(){ var i=0,el; while(!!(el=elements[i++])){ removeHyphenationFromElement(el); } state=4; }, registerOnCopy=function(){ var body=contextWindow.document.getElementsByTagName('body')[0], shadow, selection, range, rangeShadow, restore, oncopyHandler=function(e){ e=e||window.event; var target=e.target||e.srcElement, currDoc=target.ownerDocument, body=currDoc.getElementsByTagName('body')[0], targetWindow='defaultView'in currDoc?currDoc.defaultView:currDoc.parentWindow; if(target.tagName&&dontHyphenate[target.tagName.toLowerCase()]){ return; } shadow=currDoc.createElement('div'); shadow.style.overflow='hidden'; shadow.style.position='absolute'; shadow.style.top='-5000px'; shadow.style.height='1px'; body.appendChild(shadow); if(window.getSelection){ selection=targetWindow.getSelection(); range=selection.getRangeAt(0); shadow.appendChild(range.cloneContents()); removeHyphenationFromElement(shadow); selection.selectAllChildren(shadow); restore=function(){ shadow.parentNode.removeChild(shadow); if(targetWindow.getSelection().setBaseAndExtent){ selection.setBaseAndExtent( range.startContainer, range.startOffset, range.endContainer, range.endOffset ); } }; }else{ selection=targetWindow.document.selection; range=selection.createRange(); shadow.innerHTML=range.htmlText; removeHyphenationFromElement(shadow); rangeShadow=body.createTextRange(); rangeShadow.moveToElementText(shadow); rangeShadow.select(); restore=function(){ shadow.parentNode.removeChild(shadow); if(range.text!==""){ range.select(); } }; } window.setTimeout(restore,0); }; if(!body){ return; } if(window.addEventListener){ body.addEventListener("copy",oncopyHandler,false); }else{ body.attachEvent("oncopy",oncopyHandler); } }; return{ version:'X.Y.Z', languages:{}, config:function(obj){ var assert=function(name,type){ if(typeof obj[name]===type){ return true; }else{ onError(new Error('Config onError: '+name+' must be of type '+type)); return false; } }, key; for(key in obj){ if(obj.hasOwnProperty(key)){ switch(key){ case'classname': if(assert('classname','string')){ hyphenateClass=obj.classname; } break; case'donthyphenateclassname': if(assert('donthyphenateclassname','string')){ dontHyphenateClass=obj.donthyphenateclassname; } break; case'minwordlength': if(assert('minwordlength','number')){ min=obj.minwordlength; } break; case'hyphenchar': if(assert('hyphenchar','string')){ if(obj.hyphenchar==='­'){ obj.hyphenchar=String.fromCharCode(173); } hyphen=obj.hyphenchar; } break; case'urlhyphenchar': if(obj.hasOwnProperty('urlhyphenchar')){ if(assert('urlhyphenchar','string')){ urlhyphen=obj.urlhyphenchar; } } break; case'togglebox': if(assert('togglebox','function')){ toggleBox=obj.togglebox; } break; case'displaytogglebox': if(assert('displaytogglebox','boolean')){ displayToggleBox=obj.displaytogglebox; } break; case'remoteloading': if(assert('remoteloading','boolean')){ enableRemoteLoading=obj.remoteloading; } break; case'enablecache': if(assert('enablecache','boolean')){ enableCache=obj.enablecache; } break; case'enablereducedpatternset': if(assert('enablereducedpatternset','boolean')){ enableReducedPatternSet=obj.enablereducedpatternset; } break; case'onhyphenationdonecallback': if(assert('onhyphenationdonecallback','function')){ onHyphenationDone=obj.onhyphenationdonecallback; } break; case'onerrorhandler': if(assert('onerrorhandler','function')){ onError=obj.onerrorhandler; } break; case'intermediatestate': if(assert('intermediatestate','string')){ intermediateState=obj.intermediatestate; } break; case'selectorfunction': if(assert('selectorfunction','function')){ selectorFunction=obj.selectorfunction; } break; case'safecopy': if(assert('safecopy','boolean')){ safeCopy=obj.safecopy; } break; case'doframes': if(assert('doframes','boolean')){ doFrames=obj.doframes; } break; case'storagetype': if(assert('storagetype','string')){ storageType=obj.storagetype; } break; case'orphancontrol': if(assert('orphancontrol','number')){ orphanControl=obj.orphancontrol; } break; default: onError(new Error('Hyphenator.config: property '+key+' not known.')); } } } }, run:function(){ var process=function(){ try{ if(contextWindow.document.getElementsByTagName('frameset').length>0){ return; } autoSetMainLanguage(); gatherDocumentInfos(); prepare(hyphenateDocument); if(displayToggleBox){ toggleBox(true); } if(safeCopy){ registerOnCopy(); } }catch(e){ onError(e); } },i,haveAccess,fl=window.frames.length; try{ if(storageType!=='none'&& typeof(window.localStorage)!=='undefined'&& typeof(window.sessionStorage)!=='undefined'&& typeof(JSON.stringify)!=='undefined'&& typeof(JSON.parse)!=='undefined'){ switch(storageType){ case'session': storage=window.sessionStorage; break; case'local': storage=window.localStorage; break; default: storage=undefined; break; } } }catch(e){ } if(!documentLoaded&&!Hyphenator.isBookmarklet()){ runOnContentLoaded(window,process); } if(Hyphenator.isBookmarklet()||documentLoaded){ if(doFrames&&fl>0){ for(i=0;i=min){ n.data=n.data.replace(Hyphenator.languages[lang].genRegExp,hyphenate); }else if(n.nodeType===1){ if(n.lang!==''){ Hyphenator.hyphenate(n,n.lang); }else{ Hyphenator.hyphenate(n,lang); } } } } }else{ onError(new Error('Language "'+lang+'" is not loaded.')); } }, getRedPatternSet:function(lang){ return Hyphenator.languages[lang].redPatSet; }, isBookmarklet:function(){ return isBookmarklet; }, getConfigFromURI:function(){ var loc=null,re={},jsArray=document.getElementsByTagName('script'),i,j,l,s,gp,option; for(i=0,l=jsArray.length;i