script.min.js 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309
  1. // * date 2011/10/19 *
  2. /**
  3. * misc
  4. */
  5. // ------ TRACE ------
  6. function trace(s,o){
  7. if(window.console && window.console.debug){
  8. arguments.length === 2 ? window.console.debug(s,o) : window.console.debug(s);
  9. }else if(window.console && window.console.log){
  10. arguments.length === 2 ? window.console.log(s,o) : window.console.log(s);
  11. }
  12. };
  13. // ------ LOADJSCSSFILE ------
  14. function loadjscssfile(filename, filetype){
  15. if (filetype=="js"){ //if filename is a external JavaScript file
  16. var fileref=document.createElement('script')
  17. fileref.setAttribute("type","text/javascript")
  18. fileref.setAttribute("src", filename)
  19. }
  20. else if (filetype=="css"){ //if filename is an external CSS file
  21. var fileref=document.createElement("link")
  22. fileref.setAttribute("rel", "stylesheet")
  23. fileref.setAttribute("type", "text/css")
  24. fileref.setAttribute("href", filename)
  25. }
  26. if (typeof fileref!="undefined")
  27. document.getElementsByTagName("head")[0].appendChild(fileref)
  28. }
  29. // ------ TIMEOUT
  30. function Timeout(fn, interval) {
  31. var id = setTimeout(fn, interval);
  32. this.cleared = false;
  33. this.clear = function () {
  34. this.cleared = true;
  35. clearTimeout(id);
  36. };
  37. }
  38. // ------ HEXTORGB convert hex to rgb color ------
  39. function HexToRGB(h){
  40. if(h.charAt(0)=="#"){
  41. var coul = h.substring(1,7);
  42. var r = parseInt(coul.substring(0,2),16);
  43. var g = parseInt(coul.substring(2,4),16);
  44. var b = parseInt(coul.substring(4,6),16);
  45. return 'rgb('+r+', '+g+', '+b+')';
  46. }else{
  47. return null;
  48. }
  49. }
  50. // ------ PAIR check if number is pair of impair ------
  51. function pair(n){return typeof n=='number'?(n%2==0?true:false):null;}
  52. // ------ RANDOM ------
  53. function random(n1,n2){
  54. return arguments.length === 1 && typeof n1 === 'number'? Math.random()*n1 : ( arguments.length === 2 && typeof n1 === typeof n2 && typeof n1 === 'number' ? n1 + Math.random()*(n2-n1) : NaN );
  55. }
  56. function randomInt(n1,n2){
  57. var rand = arguments.length === 1 && typeof n1 === 'number'? Math.random()*n1 : ( arguments.length === 2 && typeof n1 === typeof n2 && typeof n1 === 'number' ? n1 + Math.random()*(n2-n1) : NaN );
  58. return parseInt(rand);
  59. }
  60. // ------ ROUNDED ------
  61. function round(n,granularity){
  62. if(arguments.length == 1){
  63. n = Math.round(n);
  64. }else{
  65. granularity = granularity.toString();
  66. granularity = granularity.replace(/./gi, 0);
  67. granularity = granularity.replace(/^./gi, 1);
  68. granularity = parseInt(granularity);
  69. n = Math.round(n*granularity)/granularity;
  70. }
  71. return n;
  72. }
  73. // ------ FLOOR ------
  74. function floor(n,granularity){
  75. if(arguments.length == 1){
  76. n = Math.floor(n);
  77. }else{
  78. granularity = granularity.toString();
  79. granularity = granularity.replace(/./gi, 0);
  80. granularity = granularity.replace(/^./gi, 1);
  81. granularity = parseInt(granularity);
  82. n = Math.floor(n*granularity)/granularity;
  83. }
  84. return n;
  85. }
  86. // ------ CEIL ------
  87. function ceil(n,granularity){
  88. if(arguments.length == 1){
  89. n = Math.ceil(n);
  90. }else{
  91. granularity = granularity.toString();
  92. granularity = granularity.replace(/./gi, 0);
  93. granularity = granularity.replace(/^./gi, 1);
  94. granularity = parseInt(granularity);
  95. n = Math.ceil(n*granularity)/granularity;
  96. }
  97. return n;
  98. }
  99. /**
  100. * String
  101. */
  102. // ------ TRIM remove multiple, leading or trailing spaces ------
  103. String.prototype.trim = function() {
  104. return this.replace(/(^\s*)|(\s*$)/gi,"").replace(/[ ]{2,}/gi," ").replace(/\n /,"\n");
  105. }
  106. // ------ remove all accents, for sort() by example ------
  107. var Latinise={};Latinise.latin_map={"Á":"A","Ă":"A","Ắ":"A","Ặ":"A","Ằ":"A","Ẳ":"A","Ẵ":"A","Ǎ":"A","Â":"A","Ấ":"A","Ậ":"A","Ầ":"A","Ẩ":"A","Ẫ":"A","Ä":"A","Ǟ":"A","Ȧ":"A","Ǡ":"A","Ạ":"A","Ȁ":"A","À":"A","Ả":"A","Ȃ":"A","Ā":"A","Ą":"A","Å":"A","Ǻ":"A","Ḁ":"A","Ⱥ":"A","Ã":"A","Ꜳ":"AA","Æ":"AE","Ǽ":"AE","Ǣ":"AE","Ꜵ":"AO","Ꜷ":"AU","Ꜹ":"AV","Ꜻ":"AV","Ꜽ":"AY","Ḃ":"B","Ḅ":"B","Ɓ":"B","Ḇ":"B","Ƀ":"B","Ƃ":"B","Ć":"C","Č":"C","Ç":"C","Ḉ":"C","Ĉ":"C","Ċ":"C","Ƈ":"C","Ȼ":"C","Ď":"D","Ḑ":"D","Ḓ":"D","Ḋ":"D","Ḍ":"D","Ɗ":"D","Ḏ":"D","Dz":"D","Dž":"D","Đ":"D","Ƌ":"D","DZ":"DZ","DŽ":"DZ","É":"E","Ĕ":"E","Ě":"E","Ȩ":"E","Ḝ":"E","Ê":"E","Ế":"E","Ệ":"E","Ề":"E","Ể":"E","Ễ":"E","Ḙ":"E","Ë":"E","Ė":"E","Ẹ":"E","Ȅ":"E","È":"E","Ẻ":"E","Ȇ":"E","Ē":"E","Ḗ":"E","Ḕ":"E","Ę":"E","Ɇ":"E","Ẽ":"E","Ḛ":"E","Ꝫ":"ET","Ḟ":"F","Ƒ":"F","Ǵ":"G","Ğ":"G","Ǧ":"G","Ģ":"G","Ĝ":"G","Ġ":"G","Ɠ":"G","Ḡ":"G","Ǥ":"G","Ḫ":"H","Ȟ":"H","Ḩ":"H","Ĥ":"H","Ⱨ":"H","Ḧ":"H","Ḣ":"H","Ḥ":"H","Ħ":"H","Í":"I","Ĭ":"I","Ǐ":"I","Î":"I","Ï":"I","Ḯ":"I","İ":"I","Ị":"I","Ȉ":"I","Ì":"I","Ỉ":"I","Ȋ":"I","Ī":"I","Į":"I","Ɨ":"I","Ĩ":"I","Ḭ":"I","Ꝺ":"D","Ꝼ":"F","Ᵹ":"G","Ꞃ":"R","Ꞅ":"S","Ꞇ":"T","Ꝭ":"IS","Ĵ":"J","Ɉ":"J","Ḱ":"K","Ǩ":"K","Ķ":"K","Ⱪ":"K","Ꝃ":"K","Ḳ":"K","Ƙ":"K","Ḵ":"K","Ꝁ":"K","Ꝅ":"K","Ĺ":"L","Ƚ":"L","Ľ":"L","Ļ":"L","Ḽ":"L","Ḷ":"L","Ḹ":"L","Ⱡ":"L","Ꝉ":"L","Ḻ":"L","Ŀ":"L","Ɫ":"L","Lj":"L","Ł":"L","LJ":"LJ","Ḿ":"M","Ṁ":"M","Ṃ":"M","Ɱ":"M","Ń":"N","Ň":"N","Ņ":"N","Ṋ":"N","Ṅ":"N","Ṇ":"N","Ǹ":"N","Ɲ":"N","Ṉ":"N","Ƞ":"N","Nj":"N","Ñ":"N","NJ":"NJ","Ó":"O","Ŏ":"O","Ǒ":"O","Ô":"O","Ố":"O","Ộ":"O","Ồ":"O","Ổ":"O","Ỗ":"O","Ö":"O","Ȫ":"O","Ȯ":"O","Ȱ":"O","Ọ":"O","Ő":"O","Ȍ":"O","Ò":"O","Ỏ":"O","Ơ":"O","Ớ":"O","Ợ":"O","Ờ":"O","Ở":"O","Ỡ":"O","Ȏ":"O","Ꝋ":"O","Ꝍ":"O","Ō":"O","Ṓ":"O","Ṑ":"O","Ɵ":"O","Ǫ":"O","Ǭ":"O","Ø":"O","Ǿ":"O","Õ":"O","Ṍ":"O","Ṏ":"O","Ȭ":"O","Ƣ":"OI","Ꝏ":"OO","Ɛ":"E","Ɔ":"O","Ȣ":"OU","Ṕ":"P","Ṗ":"P","Ꝓ":"P","Ƥ":"P","Ꝕ":"P","Ᵽ":"P","Ꝑ":"P","Ꝙ":"Q","Ꝗ":"Q","Ŕ":"R","Ř":"R","Ŗ":"R","Ṙ":"R","Ṛ":"R","Ṝ":"R","Ȑ":"R","Ȓ":"R","Ṟ":"R","Ɍ":"R","Ɽ":"R","Ꜿ":"C","Ǝ":"E","Ś":"S","Ṥ":"S","Š":"S","Ṧ":"S","Ş":"S","Ŝ":"S","Ș":"S","Ṡ":"S","Ṣ":"S","Ṩ":"S","Ť":"T","Ţ":"T","Ṱ":"T","Ț":"T","Ⱦ":"T","Ṫ":"T","Ṭ":"T","Ƭ":"T","Ṯ":"T","Ʈ":"T","Ŧ":"T","Ɐ":"A","Ꞁ":"L","Ɯ":"M","Ʌ":"V","Ꜩ":"TZ","Ú":"U","Ŭ":"U","Ǔ":"U","Û":"U","Ṷ":"U","Ü":"U","Ǘ":"U","Ǚ":"U","Ǜ":"U","Ǖ":"U","Ṳ":"U","Ụ":"U","Ű":"U","Ȕ":"U","Ù":"U","Ủ":"U","Ư":"U","Ứ":"U","Ự":"U","Ừ":"U","Ử":"U","Ữ":"U","Ȗ":"U","Ū":"U","Ṻ":"U","Ų":"U","Ů":"U","Ũ":"U","Ṹ":"U","Ṵ":"U","Ꝟ":"V","Ṿ":"V","Ʋ":"V","Ṽ":"V","Ꝡ":"VY","Ẃ":"W","Ŵ":"W","Ẅ":"W","Ẇ":"W","Ẉ":"W","Ẁ":"W","Ⱳ":"W","Ẍ":"X","Ẋ":"X","Ý":"Y","Ŷ":"Y","Ÿ":"Y","Ẏ":"Y","Ỵ":"Y","Ỳ":"Y","Ƴ":"Y","Ỷ":"Y","Ỿ":"Y","Ȳ":"Y","Ɏ":"Y","Ỹ":"Y","Ź":"Z","Ž":"Z","Ẑ":"Z","Ⱬ":"Z","Ż":"Z","Ẓ":"Z","Ȥ":"Z","Ẕ":"Z","Ƶ":"Z","IJ":"IJ","Œ":"OE","ᴀ":"A","ᴁ":"AE","ʙ":"B","ᴃ":"B","ᴄ":"C","ᴅ":"D","ᴇ":"E","ꜰ":"F","ɢ":"G","ʛ":"G","ʜ":"H","ɪ":"I","ʁ":"R","ᴊ":"J","ᴋ":"K","ʟ":"L","ᴌ":"L","ᴍ":"M","ɴ":"N","ᴏ":"O","ɶ":"OE","ᴐ":"O","ᴕ":"OU","ᴘ":"P","ʀ":"R","ᴎ":"N","ᴙ":"R","ꜱ":"S","ᴛ":"T","ⱻ":"E","ᴚ":"R","ᴜ":"U","ᴠ":"V","ᴡ":"W","ʏ":"Y","ᴢ":"Z","á":"a","ă":"a","ắ":"a","ặ":"a","ằ":"a","ẳ":"a","ẵ":"a","ǎ":"a","â":"a","ấ":"a","ậ":"a","ầ":"a","ẩ":"a","ẫ":"a","ä":"a","ǟ":"a","ȧ":"a","ǡ":"a","ạ":"a","ȁ":"a","à":"a","ả":"a","ȃ":"a","ā":"a","ą":"a","ᶏ":"a","ẚ":"a","å":"a","ǻ":"a","ḁ":"a","ⱥ":"a","ã":"a","ꜳ":"aa","æ":"ae","ǽ":"ae","ǣ":"ae","ꜵ":"ao","ꜷ":"au","ꜹ":"av","ꜻ":"av","ꜽ":"ay","ḃ":"b","ḅ":"b","ɓ":"b","ḇ":"b","ᵬ":"b","ᶀ":"b","ƀ":"b","ƃ":"b","ɵ":"o","ć":"c","č":"c","ç":"c","ḉ":"c","ĉ":"c","ɕ":"c","ċ":"c","ƈ":"c","ȼ":"c","ď":"d","ḑ":"d","ḓ":"d","ȡ":"d","ḋ":"d","ḍ":"d","ɗ":"d","ᶑ":"d","ḏ":"d","ᵭ":"d","ᶁ":"d","đ":"d","ɖ":"d","ƌ":"d","ı":"i","ȷ":"j","ɟ":"j","ʄ":"j","dz":"dz","dž":"dz","é":"e","ĕ":"e","ě":"e","ȩ":"e","ḝ":"e","ê":"e","ế":"e","ệ":"e","ề":"e","ể":"e","ễ":"e","ḙ":"e","ë":"e","ė":"e","ẹ":"e","ȅ":"e","è":"e","ẻ":"e","ȇ":"e","ē":"e","ḗ":"e","ḕ":"e","ⱸ":"e","ę":"e","ᶒ":"e","ɇ":"e","ẽ":"e","ḛ":"e","ꝫ":"et","ḟ":"f","ƒ":"f","ᵮ":"f","ᶂ":"f","ǵ":"g","ğ":"g","ǧ":"g","ģ":"g","ĝ":"g","ġ":"g","ɠ":"g","ḡ":"g","ᶃ":"g","ǥ":"g","ḫ":"h","ȟ":"h","ḩ":"h","ĥ":"h","ⱨ":"h","ḧ":"h","ḣ":"h","ḥ":"h","ɦ":"h","ẖ":"h","ħ":"h","ƕ":"hv","í":"i","ĭ":"i","ǐ":"i","î":"i","ï":"i","ḯ":"i","ị":"i","ȉ":"i","ì":"i","ỉ":"i","ȋ":"i","ī":"i","į":"i","ᶖ":"i","ɨ":"i","ĩ":"i","ḭ":"i","ꝺ":"d","ꝼ":"f","ᵹ":"g","ꞃ":"r","ꞅ":"s","ꞇ":"t","ꝭ":"is","ǰ":"j","ĵ":"j","ʝ":"j","ɉ":"j","ḱ":"k","ǩ":"k","ķ":"k","ⱪ":"k","ꝃ":"k","ḳ":"k","ƙ":"k","ḵ":"k","ᶄ":"k","ꝁ":"k","ꝅ":"k","ĺ":"l","ƚ":"l","ɬ":"l","ľ":"l","ļ":"l","ḽ":"l","ȴ":"l","ḷ":"l","ḹ":"l","ⱡ":"l","ꝉ":"l","ḻ":"l","ŀ":"l","ɫ":"l","ᶅ":"l","ɭ":"l","ł":"l","lj":"lj","ſ":"s","ẜ":"s","ẛ":"s","ẝ":"s","ḿ":"m","ṁ":"m","ṃ":"m","ɱ":"m","ᵯ":"m","ᶆ":"m","ń":"n","ň":"n","ņ":"n","ṋ":"n","ȵ":"n","ṅ":"n","ṇ":"n","ǹ":"n","ɲ":"n","ṉ":"n","ƞ":"n","ᵰ":"n","ᶇ":"n","ɳ":"n","ñ":"n","nj":"nj","ó":"o","ŏ":"o","ǒ":"o","ô":"o","ố":"o","ộ":"o","ồ":"o","ổ":"o","ỗ":"o","ö":"o","ȫ":"o","ȯ":"o","ȱ":"o","ọ":"o","ő":"o","ȍ":"o","ò":"o","ỏ":"o","ơ":"o","ớ":"o","ợ":"o","ờ":"o","ở":"o","ỡ":"o","ȏ":"o","ꝋ":"o","ꝍ":"o","ⱺ":"o","ō":"o","ṓ":"o","ṑ":"o","ǫ":"o","ǭ":"o","ø":"o","ǿ":"o","õ":"o","ṍ":"o","ṏ":"o","ȭ":"o","ƣ":"oi","ꝏ":"oo","ɛ":"e","ᶓ":"e","ɔ":"o","ᶗ":"o","ȣ":"ou","ṕ":"p","ṗ":"p","ꝓ":"p","ƥ":"p","ᵱ":"p","ᶈ":"p","ꝕ":"p","ᵽ":"p","ꝑ":"p","ꝙ":"q","ʠ":"q","ɋ":"q","ꝗ":"q","ŕ":"r","ř":"r","ŗ":"r","ṙ":"r","ṛ":"r","ṝ":"r","ȑ":"r","ɾ":"r","ᵳ":"r","ȓ":"r","ṟ":"r","ɼ":"r","ᵲ":"r","ᶉ":"r","ɍ":"r","ɽ":"r","ↄ":"c","ꜿ":"c","ɘ":"e","ɿ":"r","ś":"s","ṥ":"s","š":"s","ṧ":"s","ş":"s","ŝ":"s","ș":"s","ṡ":"s","ṣ":"s","ṩ":"s","ʂ":"s","ᵴ":"s","ᶊ":"s","ȿ":"s","ɡ":"g","ᴑ":"o","ᴓ":"o","ᴝ":"u","ť":"t","ţ":"t","ṱ":"t","ț":"t","ȶ":"t","ẗ":"t","ⱦ":"t","ṫ":"t","ṭ":"t","ƭ":"t","ṯ":"t","ᵵ":"t","ƫ":"t","ʈ":"t","ŧ":"t","ᵺ":"th","ɐ":"a","ᴂ":"ae","ǝ":"e","ᵷ":"g","ɥ":"h","ʮ":"h","ʯ":"h","ᴉ":"i","ʞ":"k","ꞁ":"l","ɯ":"m","ɰ":"m","ᴔ":"oe","ɹ":"r","ɻ":"r","ɺ":"r","ⱹ":"r","ʇ":"t","ʌ":"v","ʍ":"w","ʎ":"y","ꜩ":"tz","ú":"u","ŭ":"u","ǔ":"u","û":"u","ṷ":"u","ü":"u","ǘ":"u","ǚ":"u","ǜ":"u","ǖ":"u","ṳ":"u","ụ":"u","ű":"u","ȕ":"u","ù":"u","ủ":"u","ư":"u","ứ":"u","ự":"u","ừ":"u","ử":"u","ữ":"u","ȗ":"u","ū":"u","ṻ":"u","ų":"u","ᶙ":"u","ů":"u","ũ":"u","ṹ":"u","ṵ":"u","ᵫ":"ue","ꝸ":"um","ⱴ":"v","ꝟ":"v","ṿ":"v","ʋ":"v","ᶌ":"v","ⱱ":"v","ṽ":"v","ꝡ":"vy","ẃ":"w","ŵ":"w","ẅ":"w","ẇ":"w","ẉ":"w","ẁ":"w","ⱳ":"w","ẘ":"w","ẍ":"x","ẋ":"x","ᶍ":"x","ý":"y","ŷ":"y","ÿ":"y","ẏ":"y","ỵ":"y","ỳ":"y","ƴ":"y","ỷ":"y","ỿ":"y","ȳ":"y","ẙ":"y","ɏ":"y","ỹ":"y","ź":"z","ž":"z","ẑ":"z","ʑ":"z","ⱬ":"z","ż":"z","ẓ":"z","ȥ":"z","ẕ":"z","ᵶ":"z","ᶎ":"z","ʐ":"z","ƶ":"z","ɀ":"z","ff":"ff","ffi":"ffi","ffl":"ffl","fi":"fi","fl":"fl","ij":"ij","œ":"oe","st":"st","ₐ":"a","ₑ":"e","ᵢ":"i","ⱼ":"j","ₒ":"o","ᵣ":"r","ᵤ":"u","ᵥ":"v","ₓ":"x"};
  108. String.prototype.latinise=function(){return this.replace(/[^A-Za-z0-9\[\] ]/g,function(a){return Latinise.latin_map[a]||a})};
  109. String.prototype.latinize=String.prototype.latinise;
  110. String.prototype.isLatin=function(){return this==this.latinise()}
  111. /**
  112. * Array
  113. */
  114. // ------ UNIQUE reduces duplicates ------
  115. array_unique = function(ar){
  116. var r = new Array();
  117. o:for(var i = 0, n = ar.length; i < n; i++)
  118. {
  119. for(var x = 0, y = r.length; x < y; x++)
  120. {
  121. if(r[x]==ar[i])
  122. {
  123. continue o;
  124. }
  125. }
  126. r[r.length] = ar[i];
  127. }
  128. return r;
  129. };
  130. // ------ SUBSTRACT substract two array ------
  131. array_subtract = function(ara1,ara2) {
  132. var aRes = new Array() ;
  133. for (var i = ara1.length-1; i >= 0; i--)
  134. if(array_contains(ara2,ara1[i]))
  135. aRes.push(ara1[i]);
  136. return aRes ;
  137. }
  138. /*
  139. SHUFFLE Add a shuffle function to Array object prototype
  140. author: Stephane Roucheray
  141. src: http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/
  142. found 2011/09/08.
  143. */
  144. array_shuffle = function(ar){
  145. var i = ar.length, j, temp;
  146. if ( i == 0 ) return;
  147. while ( --i ) {
  148. j = Math.floor( Math.random() * ( i + 1 ) );
  149. temp = ar[i];
  150. ar[i] = ar[j];
  151. ar[j] = temp;
  152. }
  153. return ar;
  154. };
  155. // ------ CONTAINS ------
  156. array_contains = function(ar, obj) {
  157. var i = ar.length;
  158. while (i--)
  159. if (ar[i] === obj)
  160. return true;
  161. return false;
  162. };
  163. // ------ REMOVE ------
  164. // /!\ Found on the Internet, not sure of efficiency.
  165. // Array.prototype.remove = function(v) {
  166. // var x, _i, _len, _results;
  167. // _results = [];
  168. // for (_i = 0, _len = this.length; _i < _len; _i++) {
  169. // x = this[_i];
  170. // if (x !== v) {
  171. // _results.push(x);
  172. // }
  173. // }
  174. // return _results;
  175. // };
  176. array_remove = function(ar){
  177. var what, a= arguments, L= a.length, ax;
  178. while(L && ar.length){
  179. what= a[--L];
  180. while((ax= ar.indexOf(what))!= -1){
  181. ar.splice(ax, 1);
  182. }
  183. }
  184. return ar;
  185. };
  186. // for IE
  187. // if(!Array.prototype.indexOf){
  188. // Array.prototype.indexOf= function(what, i){
  189. // i= i || 0;
  190. // var L= this.length;
  191. // while(i< L){
  192. // if(this[i]=== what) return i;
  193. // ++i;
  194. // }
  195. // return -1;
  196. // };
  197. // }
  198. array_indexOf = function(ar, what, i){
  199. i= i || 0;
  200. var L= ar.length;
  201. while(i< L){
  202. if(ar[i]=== what) return i;
  203. ++i;
  204. }
  205. return -1;
  206. };
  207. // ------ SUBSTRACT substract two array ------
  208. function array_subtract(ara1,ara2) {
  209. var aRes = new Array() ;
  210. for (var i = ara1.length-1; i >= 0; i--)
  211. if( !array_contains(ara1[i],ara2) )
  212. aRes.push(ara1[i]);
  213. return aRes ;
  214. };
  215. /**
  216. * Objects
  217. *
  218. */
  219. // ------ OBJECTSIZE get the length of objects ------
  220. function objectSize(o) {
  221. var len = o.length ? --o.length : 0;
  222. for (var k in o)
  223. len++;
  224. return len;
  225. }
  226. // Object.prototype.size = function () {
  227. // // var len = this.length ? --this.length : -1; // POURQUOI NE FONCTIONNE PAS?
  228. // var len = this.length ? --this.length : -2;
  229. // for (var k in this)
  230. // len++;
  231. // return len;
  232. // }
  233. function objectIsEmpty(obj){
  234. for (var prop in obj) {
  235. if (obj.hasOwnProperty(prop))
  236. return false;
  237. }
  238. return true;
  239. };
  240. // ------ OBJECTGETKEY get key of index ------
  241. function objectGetKey(o,index){
  242. var i = 0;
  243. for (var k in o){
  244. if (k === 'length' || !o.hasOwnProperty(k))
  245. continue;
  246. if(i == index)
  247. return k;
  248. i ++;
  249. }
  250. }
  251. // Object.prototype.getKey = function(index){
  252. // var i = 0;
  253. // for (var key in this){
  254. // if (key === 'length' || !this.hasOwnProperty(key))
  255. // continue;
  256. // if(i == index)
  257. // return key;
  258. // i ++;
  259. // }
  260. // }
  261. // ------ OBJECTSORT sort object ------
  262. function objectSort(o,value) {
  263. var connection = new Array();
  264. for (var i = objectSize(o) - 1; i >= 0; i--){
  265. var k = objectGetKey(o,i);
  266. for (var j = objectSize(o[k].wit) - 1; j >= 0; j--){
  267. var k2 = objectGetKey(o[k].wit,j);
  268. if (k2==value) {
  269. var the_wit = parseFloat(o[k].wit[k2]);
  270. connection.push( {wit:the_wit,nid:k} );
  271. };
  272. };
  273. };
  274. connection.sort(function(a,b){
  275. // return (a.wit - b.wit);//ascending
  276. return (b.wit - a.wit);//descending
  277. });
  278. var o_sort = {};
  279. for (var i = connection.length - 1; i >= 0; i--){
  280. // o_sort[connection[i].wit+'-'+connection[i].nid] = o[connection[i].nid];
  281. o_sort[connection[i].nid] = o[connection[i].nid];
  282. };
  283. return o_sort;
  284. }
  285. /**
  286. * trigo
  287. */
  288. // -------- getElementAngle ----------
  289. // L'angle 0 correspond au nord (vers le haut)
  290. // Exemple : getElementAngle(posElementX, posElementY, posSourisX, posSourisY)
  291. // Ceci retournera l'angle de l'élément par rapport à la position de la souris
  292. function getElementAngle(x1, y1, x2, y2) {
  293. var adj = x2 - x1;
  294. var opp = y2 - y1;
  295. var angle = Math.abs(Math.atan(opp/adj) * 180/Math.PI);
  296. if (adj > 0 && opp < 0 ) {
  297. angle = 90 - angle;
  298. }
  299. else if (adj >= 0 && opp >= 0) {
  300. angle += 90;
  301. }
  302. else if (adj < 0 && opp >= 0) {
  303. angle = 180 + (90 - angle);
  304. }
  305. else {
  306. angle += 270;
  307. }
  308. return angle;
  309. }
  310. // * date 2011/10/19 *
  311. /**
  312. * misc
  313. */
  314. // ------ TRACE ------
  315. function trace(s,o){
  316. if(window.console && window.console.debug){
  317. arguments.length === 2 ? window.console.debug(s,o) : window.console.debug(s);
  318. }else if(console && console.log){
  319. arguments.length === 2 ? console.log(s,o) : console.log(s);
  320. }
  321. };
  322. // ------ LOADJSCSSFILE ------
  323. function loadjscssfile(filename, filetype){
  324. if (filetype=="js"){ //if filename is a external JavaScript file
  325. var fileref=document.createElement('script')
  326. fileref.setAttribute("type","text/javascript")
  327. fileref.setAttribute("src", filename)
  328. }
  329. else if (filetype=="css"){ //if filename is an external CSS file
  330. var fileref=document.createElement("link")
  331. fileref.setAttribute("rel", "stylesheet")
  332. fileref.setAttribute("type", "text/css")
  333. fileref.setAttribute("href", filename)
  334. }
  335. if (typeof fileref!="undefined")
  336. document.getElementsByTagName("head")[0].appendChild(fileref)
  337. };
  338. // ------ TIMEOUT
  339. function Timeout(fn, interval) {
  340. var id = setTimeout(fn, interval);
  341. this.cleared = false;
  342. this.clear = function () {
  343. this.cleared = true;
  344. clearTimeout(id);
  345. };
  346. }
  347. // ------ HEXTORGB convert hex to rgb color ------
  348. function HexToRGB(h){
  349. if(h.charAt(0)=="#"){
  350. var coul = h.substring(1,7);
  351. var r = parseInt(coul.substring(0,2),16);
  352. var g = parseInt(coul.substring(2,4),16);
  353. var b = parseInt(coul.substring(4,6),16);
  354. return 'rgb('+r+', '+g+', '+b+')';
  355. }else{
  356. return null;
  357. }
  358. }
  359. // ------ PAIR check if number is pair of impair ------
  360. function pair(n){return typeof n=='number'?(n%2==0?true:false):null;}
  361. // ------ RANDOM ------
  362. function random(n1,n2){
  363. return arguments.length === 1 && typeof n1 === 'number'? Math.random()*n1 : ( arguments.length === 2 && typeof n1 === typeof n2 && typeof n1 === 'number' ? n1 + Math.random()*(n2-n1) : NaN );
  364. }
  365. function randomInt(n1,n2){
  366. var rand = arguments.length === 1 && typeof n1 === 'number'? Math.random()*n1 : ( arguments.length === 2 && typeof n1 === typeof n2 && typeof n1 === 'number' ? n1 + Math.random()*(n2-n1) : NaN );
  367. return parseInt(rand);
  368. }
  369. // ------ ROUNDED ------
  370. function round(n,granularity){
  371. if(arguments.length == 1){
  372. n = Math.round(n);
  373. }else{
  374. granularity = granularity.toString();
  375. granularity = granularity.replace(/./gi, 0);
  376. granularity = granularity.replace(/^./gi, 1);
  377. granularity = parseInt(granularity);
  378. n = Math.round(n*granularity)/granularity;
  379. }
  380. return n;
  381. }
  382. // ------ FLOOR ------
  383. function floor(n,granularity){
  384. if(arguments.length == 1){
  385. n = Math.floor(n);
  386. }else{
  387. granularity = granularity.toString();
  388. granularity = granularity.replace(/./gi, 0);
  389. granularity = granularity.replace(/^./gi, 1);
  390. granularity = parseInt(granularity);
  391. n = Math.floor(n*granularity)/granularity;
  392. }
  393. return n;
  394. }
  395. // ------ CEIL ------
  396. function ceil(n,granularity){
  397. if(arguments.length == 1){
  398. n = Math.ceil(n);
  399. }else{
  400. granularity = granularity.toString();
  401. granularity = granularity.replace(/./gi, 0);
  402. granularity = granularity.replace(/^./gi, 1);
  403. granularity = parseInt(granularity);
  404. n = Math.ceil(n*granularity)/granularity;
  405. }
  406. return n;
  407. }
  408. /**
  409. * String
  410. */
  411. // ------ TRIM remove multiple, leading or trailing spaces ------
  412. String.prototype.trim = function() {
  413. return this.replace(/(^\s*)|(\s*$)/gi,"").replace(/[ ]{2,}/gi," ").replace(/\n /,"\n");
  414. }
  415. // ------ remove all accents, for sort() by example ------
  416. var Latinise={};Latinise.latin_map={"Á":"A","Ă":"A","Ắ":"A","Ặ":"A","Ằ":"A","Ẳ":"A","Ẵ":"A","Ǎ":"A","Â":"A","Ấ":"A","Ậ":"A","Ầ":"A","Ẩ":"A","Ẫ":"A","Ä":"A","Ǟ":"A","Ȧ":"A","Ǡ":"A","Ạ":"A","Ȁ":"A","À":"A","Ả":"A","Ȃ":"A","Ā":"A","Ą":"A","Å":"A","Ǻ":"A","Ḁ":"A","Ⱥ":"A","Ã":"A","Ꜳ":"AA","Æ":"AE","Ǽ":"AE","Ǣ":"AE","Ꜵ":"AO","Ꜷ":"AU","Ꜹ":"AV","Ꜻ":"AV","Ꜽ":"AY","Ḃ":"B","Ḅ":"B","Ɓ":"B","Ḇ":"B","Ƀ":"B","Ƃ":"B","Ć":"C","Č":"C","Ç":"C","Ḉ":"C","Ĉ":"C","Ċ":"C","Ƈ":"C","Ȼ":"C","Ď":"D","Ḑ":"D","Ḓ":"D","Ḋ":"D","Ḍ":"D","Ɗ":"D","Ḏ":"D","Dz":"D","Dž":"D","Đ":"D","Ƌ":"D","DZ":"DZ","DŽ":"DZ","É":"E","Ĕ":"E","Ě":"E","Ȩ":"E","Ḝ":"E","Ê":"E","Ế":"E","Ệ":"E","Ề":"E","Ể":"E","Ễ":"E","Ḙ":"E","Ë":"E","Ė":"E","Ẹ":"E","Ȅ":"E","È":"E","Ẻ":"E","Ȇ":"E","Ē":"E","Ḗ":"E","Ḕ":"E","Ę":"E","Ɇ":"E","Ẽ":"E","Ḛ":"E","Ꝫ":"ET","Ḟ":"F","Ƒ":"F","Ǵ":"G","Ğ":"G","Ǧ":"G","Ģ":"G","Ĝ":"G","Ġ":"G","Ɠ":"G","Ḡ":"G","Ǥ":"G","Ḫ":"H","Ȟ":"H","Ḩ":"H","Ĥ":"H","Ⱨ":"H","Ḧ":"H","Ḣ":"H","Ḥ":"H","Ħ":"H","Í":"I","Ĭ":"I","Ǐ":"I","Î":"I","Ï":"I","Ḯ":"I","İ":"I","Ị":"I","Ȉ":"I","Ì":"I","Ỉ":"I","Ȋ":"I","Ī":"I","Į":"I","Ɨ":"I","Ĩ":"I","Ḭ":"I","Ꝺ":"D","Ꝼ":"F","Ᵹ":"G","Ꞃ":"R","Ꞅ":"S","Ꞇ":"T","Ꝭ":"IS","Ĵ":"J","Ɉ":"J","Ḱ":"K","Ǩ":"K","Ķ":"K","Ⱪ":"K","Ꝃ":"K","Ḳ":"K","Ƙ":"K","Ḵ":"K","Ꝁ":"K","Ꝅ":"K","Ĺ":"L","Ƚ":"L","Ľ":"L","Ļ":"L","Ḽ":"L","Ḷ":"L","Ḹ":"L","Ⱡ":"L","Ꝉ":"L","Ḻ":"L","Ŀ":"L","Ɫ":"L","Lj":"L","Ł":"L","LJ":"LJ","Ḿ":"M","Ṁ":"M","Ṃ":"M","Ɱ":"M","Ń":"N","Ň":"N","Ņ":"N","Ṋ":"N","Ṅ":"N","Ṇ":"N","Ǹ":"N","Ɲ":"N","Ṉ":"N","Ƞ":"N","Nj":"N","Ñ":"N","NJ":"NJ","Ó":"O","Ŏ":"O","Ǒ":"O","Ô":"O","Ố":"O","Ộ":"O","Ồ":"O","Ổ":"O","Ỗ":"O","Ö":"O","Ȫ":"O","Ȯ":"O","Ȱ":"O","Ọ":"O","Ő":"O","Ȍ":"O","Ò":"O","Ỏ":"O","Ơ":"O","Ớ":"O","Ợ":"O","Ờ":"O","Ở":"O","Ỡ":"O","Ȏ":"O","Ꝋ":"O","Ꝍ":"O","Ō":"O","Ṓ":"O","Ṑ":"O","Ɵ":"O","Ǫ":"O","Ǭ":"O","Ø":"O","Ǿ":"O","Õ":"O","Ṍ":"O","Ṏ":"O","Ȭ":"O","Ƣ":"OI","Ꝏ":"OO","Ɛ":"E","Ɔ":"O","Ȣ":"OU","Ṕ":"P","Ṗ":"P","Ꝓ":"P","Ƥ":"P","Ꝕ":"P","Ᵽ":"P","Ꝑ":"P","Ꝙ":"Q","Ꝗ":"Q","Ŕ":"R","Ř":"R","Ŗ":"R","Ṙ":"R","Ṛ":"R","Ṝ":"R","Ȑ":"R","Ȓ":"R","Ṟ":"R","Ɍ":"R","Ɽ":"R","Ꜿ":"C","Ǝ":"E","Ś":"S","Ṥ":"S","Š":"S","Ṧ":"S","Ş":"S","Ŝ":"S","Ș":"S","Ṡ":"S","Ṣ":"S","Ṩ":"S","Ť":"T","Ţ":"T","Ṱ":"T","Ț":"T","Ⱦ":"T","Ṫ":"T","Ṭ":"T","Ƭ":"T","Ṯ":"T","Ʈ":"T","Ŧ":"T","Ɐ":"A","Ꞁ":"L","Ɯ":"M","Ʌ":"V","Ꜩ":"TZ","Ú":"U","Ŭ":"U","Ǔ":"U","Û":"U","Ṷ":"U","Ü":"U","Ǘ":"U","Ǚ":"U","Ǜ":"U","Ǖ":"U","Ṳ":"U","Ụ":"U","Ű":"U","Ȕ":"U","Ù":"U","Ủ":"U","Ư":"U","Ứ":"U","Ự":"U","Ừ":"U","Ử":"U","Ữ":"U","Ȗ":"U","Ū":"U","Ṻ":"U","Ų":"U","Ů":"U","Ũ":"U","Ṹ":"U","Ṵ":"U","Ꝟ":"V","Ṿ":"V","Ʋ":"V","Ṽ":"V","Ꝡ":"VY","Ẃ":"W","Ŵ":"W","Ẅ":"W","Ẇ":"W","Ẉ":"W","Ẁ":"W","Ⱳ":"W","Ẍ":"X","Ẋ":"X","Ý":"Y","Ŷ":"Y","Ÿ":"Y","Ẏ":"Y","Ỵ":"Y","Ỳ":"Y","Ƴ":"Y","Ỷ":"Y","Ỿ":"Y","Ȳ":"Y","Ɏ":"Y","Ỹ":"Y","Ź":"Z","Ž":"Z","Ẑ":"Z","Ⱬ":"Z","Ż":"Z","Ẓ":"Z","Ȥ":"Z","Ẕ":"Z","Ƶ":"Z","IJ":"IJ","Œ":"OE","ᴀ":"A","ᴁ":"AE","ʙ":"B","ᴃ":"B","ᴄ":"C","ᴅ":"D","ᴇ":"E","ꜰ":"F","ɢ":"G","ʛ":"G","ʜ":"H","ɪ":"I","ʁ":"R","ᴊ":"J","ᴋ":"K","ʟ":"L","ᴌ":"L","ᴍ":"M","ɴ":"N","ᴏ":"O","ɶ":"OE","ᴐ":"O","ᴕ":"OU","ᴘ":"P","ʀ":"R","ᴎ":"N","ᴙ":"R","ꜱ":"S","ᴛ":"T","ⱻ":"E","ᴚ":"R","ᴜ":"U","ᴠ":"V","ᴡ":"W","ʏ":"Y","ᴢ":"Z","á":"a","ă":"a","ắ":"a","ặ":"a","ằ":"a","ẳ":"a","ẵ":"a","ǎ":"a","â":"a","ấ":"a","ậ":"a","ầ":"a","ẩ":"a","ẫ":"a","ä":"a","ǟ":"a","ȧ":"a","ǡ":"a","ạ":"a","ȁ":"a","à":"a","ả":"a","ȃ":"a","ā":"a","ą":"a","ᶏ":"a","ẚ":"a","å":"a","ǻ":"a","ḁ":"a","ⱥ":"a","ã":"a","ꜳ":"aa","æ":"ae","ǽ":"ae","ǣ":"ae","ꜵ":"ao","ꜷ":"au","ꜹ":"av","ꜻ":"av","ꜽ":"ay","ḃ":"b","ḅ":"b","ɓ":"b","ḇ":"b","ᵬ":"b","ᶀ":"b","ƀ":"b","ƃ":"b","ɵ":"o","ć":"c","č":"c","ç":"c","ḉ":"c","ĉ":"c","ɕ":"c","ċ":"c","ƈ":"c","ȼ":"c","ď":"d","ḑ":"d","ḓ":"d","ȡ":"d","ḋ":"d","ḍ":"d","ɗ":"d","ᶑ":"d","ḏ":"d","ᵭ":"d","ᶁ":"d","đ":"d","ɖ":"d","ƌ":"d","ı":"i","ȷ":"j","ɟ":"j","ʄ":"j","dz":"dz","dž":"dz","é":"e","ĕ":"e","ě":"e","ȩ":"e","ḝ":"e","ê":"e","ế":"e","ệ":"e","ề":"e","ể":"e","ễ":"e","ḙ":"e","ë":"e","ė":"e","ẹ":"e","ȅ":"e","è":"e","ẻ":"e","ȇ":"e","ē":"e","ḗ":"e","ḕ":"e","ⱸ":"e","ę":"e","ᶒ":"e","ɇ":"e","ẽ":"e","ḛ":"e","ꝫ":"et","ḟ":"f","ƒ":"f","ᵮ":"f","ᶂ":"f","ǵ":"g","ğ":"g","ǧ":"g","ģ":"g","ĝ":"g","ġ":"g","ɠ":"g","ḡ":"g","ᶃ":"g","ǥ":"g","ḫ":"h","ȟ":"h","ḩ":"h","ĥ":"h","ⱨ":"h","ḧ":"h","ḣ":"h","ḥ":"h","ɦ":"h","ẖ":"h","ħ":"h","ƕ":"hv","í":"i","ĭ":"i","ǐ":"i","î":"i","ï":"i","ḯ":"i","ị":"i","ȉ":"i","ì":"i","ỉ":"i","ȋ":"i","ī":"i","į":"i","ᶖ":"i","ɨ":"i","ĩ":"i","ḭ":"i","ꝺ":"d","ꝼ":"f","ᵹ":"g","ꞃ":"r","ꞅ":"s","ꞇ":"t","ꝭ":"is","ǰ":"j","ĵ":"j","ʝ":"j","ɉ":"j","ḱ":"k","ǩ":"k","ķ":"k","ⱪ":"k","ꝃ":"k","ḳ":"k","ƙ":"k","ḵ":"k","ᶄ":"k","ꝁ":"k","ꝅ":"k","ĺ":"l","ƚ":"l","ɬ":"l","ľ":"l","ļ":"l","ḽ":"l","ȴ":"l","ḷ":"l","ḹ":"l","ⱡ":"l","ꝉ":"l","ḻ":"l","ŀ":"l","ɫ":"l","ᶅ":"l","ɭ":"l","ł":"l","lj":"lj","ſ":"s","ẜ":"s","ẛ":"s","ẝ":"s","ḿ":"m","ṁ":"m","ṃ":"m","ɱ":"m","ᵯ":"m","ᶆ":"m","ń":"n","ň":"n","ņ":"n","ṋ":"n","ȵ":"n","ṅ":"n","ṇ":"n","ǹ":"n","ɲ":"n","ṉ":"n","ƞ":"n","ᵰ":"n","ᶇ":"n","ɳ":"n","ñ":"n","nj":"nj","ó":"o","ŏ":"o","ǒ":"o","ô":"o","ố":"o","ộ":"o","ồ":"o","ổ":"o","ỗ":"o","ö":"o","ȫ":"o","ȯ":"o","ȱ":"o","ọ":"o","ő":"o","ȍ":"o","ò":"o","ỏ":"o","ơ":"o","ớ":"o","ợ":"o","ờ":"o","ở":"o","ỡ":"o","ȏ":"o","ꝋ":"o","ꝍ":"o","ⱺ":"o","ō":"o","ṓ":"o","ṑ":"o","ǫ":"o","ǭ":"o","ø":"o","ǿ":"o","õ":"o","ṍ":"o","ṏ":"o","ȭ":"o","ƣ":"oi","ꝏ":"oo","ɛ":"e","ᶓ":"e","ɔ":"o","ᶗ":"o","ȣ":"ou","ṕ":"p","ṗ":"p","ꝓ":"p","ƥ":"p","ᵱ":"p","ᶈ":"p","ꝕ":"p","ᵽ":"p","ꝑ":"p","ꝙ":"q","ʠ":"q","ɋ":"q","ꝗ":"q","ŕ":"r","ř":"r","ŗ":"r","ṙ":"r","ṛ":"r","ṝ":"r","ȑ":"r","ɾ":"r","ᵳ":"r","ȓ":"r","ṟ":"r","ɼ":"r","ᵲ":"r","ᶉ":"r","ɍ":"r","ɽ":"r","ↄ":"c","ꜿ":"c","ɘ":"e","ɿ":"r","ś":"s","ṥ":"s","š":"s","ṧ":"s","ş":"s","ŝ":"s","ș":"s","ṡ":"s","ṣ":"s","ṩ":"s","ʂ":"s","ᵴ":"s","ᶊ":"s","ȿ":"s","ɡ":"g","ᴑ":"o","ᴓ":"o","ᴝ":"u","ť":"t","ţ":"t","ṱ":"t","ț":"t","ȶ":"t","ẗ":"t","ⱦ":"t","ṫ":"t","ṭ":"t","ƭ":"t","ṯ":"t","ᵵ":"t","ƫ":"t","ʈ":"t","ŧ":"t","ᵺ":"th","ɐ":"a","ᴂ":"ae","ǝ":"e","ᵷ":"g","ɥ":"h","ʮ":"h","ʯ":"h","ᴉ":"i","ʞ":"k","ꞁ":"l","ɯ":"m","ɰ":"m","ᴔ":"oe","ɹ":"r","ɻ":"r","ɺ":"r","ⱹ":"r","ʇ":"t","ʌ":"v","ʍ":"w","ʎ":"y","ꜩ":"tz","ú":"u","ŭ":"u","ǔ":"u","û":"u","ṷ":"u","ü":"u","ǘ":"u","ǚ":"u","ǜ":"u","ǖ":"u","ṳ":"u","ụ":"u","ű":"u","ȕ":"u","ù":"u","ủ":"u","ư":"u","ứ":"u","ự":"u","ừ":"u","ử":"u","ữ":"u","ȗ":"u","ū":"u","ṻ":"u","ų":"u","ᶙ":"u","ů":"u","ũ":"u","ṹ":"u","ṵ":"u","ᵫ":"ue","ꝸ":"um","ⱴ":"v","ꝟ":"v","ṿ":"v","ʋ":"v","ᶌ":"v","ⱱ":"v","ṽ":"v","ꝡ":"vy","ẃ":"w","ŵ":"w","ẅ":"w","ẇ":"w","ẉ":"w","ẁ":"w","ⱳ":"w","ẘ":"w","ẍ":"x","ẋ":"x","ᶍ":"x","ý":"y","ŷ":"y","ÿ":"y","ẏ":"y","ỵ":"y","ỳ":"y","ƴ":"y","ỷ":"y","ỿ":"y","ȳ":"y","ẙ":"y","ɏ":"y","ỹ":"y","ź":"z","ž":"z","ẑ":"z","ʑ":"z","ⱬ":"z","ż":"z","ẓ":"z","ȥ":"z","ẕ":"z","ᵶ":"z","ᶎ":"z","ʐ":"z","ƶ":"z","ɀ":"z","ff":"ff","ffi":"ffi","ffl":"ffl","fi":"fi","fl":"fl","ij":"ij","œ":"oe","st":"st","ₐ":"a","ₑ":"e","ᵢ":"i","ⱼ":"j","ₒ":"o","ᵣ":"r","ᵤ":"u","ᵥ":"v","ₓ":"x"};
  417. String.prototype.latinise=function(){return this.replace(/[^A-Za-z0-9\[\] ]/g,function(a){return Latinise.latin_map[a]||a})};
  418. String.prototype.latinize=String.prototype.latinise;
  419. String.prototype.isLatin=function(){return this==this.latinise()}
  420. /**
  421. * Array
  422. */
  423. // ------ UNIQUE reduces duplicates ------
  424. array_unique = function(ar){
  425. var r = new Array();
  426. o:for(var i = 0, n = ar.length; i < n; i++)
  427. {
  428. for(var x = 0, y = r.length; x < y; x++)
  429. {
  430. if(r[x]==ar[i])
  431. {
  432. continue o;
  433. }
  434. }
  435. r[r.length] = ar[i];
  436. }
  437. return r;
  438. };
  439. // ------ SUBSTRACT substract two array ------
  440. array_subtract = function(ara1,ara2) {
  441. var aRes = new Array() ;
  442. for (var i = ara1.length-1; i >= 0; i--)
  443. if(array_contains(ara2,ara1[i]))
  444. aRes.push(ara1[i]);
  445. return aRes ;
  446. }
  447. /*
  448. SHUFFLE Add a shuffle function to Array object prototype
  449. author: Stephane Roucheray
  450. src: http://sroucheray.org/blog/2009/11/array-sort-should-not-be-used-to-shuffle-an-array/
  451. found 2011/09/08.
  452. */
  453. array_shuffle = function(ar){
  454. var i = ar.length, j, temp;
  455. if ( i == 0 ) return;
  456. while ( --i ) {
  457. j = Math.floor( Math.random() * ( i + 1 ) );
  458. temp = ar[i];
  459. ar[i] = ar[j];
  460. ar[j] = temp;
  461. }
  462. return ar;
  463. };
  464. // ------ CONTAINS ------
  465. array_contains = function(ar, obj) {
  466. var i = ar.length;
  467. while (i--)
  468. if (ar[i] === obj)
  469. return true;
  470. return false;
  471. };
  472. // ------ REMOVE ------
  473. // /!\ Found on the Internet, not sure of efficiency.
  474. // Array.prototype.remove = function(v) {
  475. // var x, _i, _len, _results;
  476. // _results = [];
  477. // for (_i = 0, _len = this.length; _i < _len; _i++) {
  478. // x = this[_i];
  479. // if (x !== v) {
  480. // _results.push(x);
  481. // }
  482. // }
  483. // return _results;
  484. // };
  485. array_remove = function(ar){
  486. var what, a= arguments, L= a.length, ax;
  487. while(L && ar.length){
  488. what= a[--L];
  489. while((ax= ar.indexOf(what))!= -1){
  490. ar.splice(ax, 1);
  491. }
  492. }
  493. return ar;
  494. };
  495. // for IE
  496. // if(!Array.prototype.indexOf){
  497. // Array.prototype.indexOf= function(what, i){
  498. // i= i || 0;
  499. // var L= this.length;
  500. // while(i< L){
  501. // if(this[i]=== what) return i;
  502. // ++i;
  503. // }
  504. // return -1;
  505. // };
  506. // }
  507. array_indexOf = function(ar, what, i){
  508. i= i || 0;
  509. var L= ar.length;
  510. while(i< L){
  511. if(ar[i]=== what) return i;
  512. ++i;
  513. }
  514. return -1;
  515. };
  516. // ------ SUBSTRACT substract two array ------
  517. function array_subtract(ara1,ara2) {
  518. var aRes = new Array() ;
  519. for (var i = ara1.length-1; i >= 0; i--)
  520. if( !array_contains(ara1[i],ara2) )
  521. aRes.push(ara1[i]);
  522. return aRes ;
  523. };
  524. /**
  525. * Objects
  526. *
  527. */
  528. // ------ OBJECTSIZE get the length of objects ------
  529. function objectSize(o) {
  530. var len = o.length ? --o.length : 0;
  531. for (var k in o)
  532. len++;
  533. return len;
  534. }
  535. // Object.prototype.size = function () {
  536. // // var len = this.length ? --this.length : -1; // POURQUOI NE FONCTIONNE PAS?
  537. // var len = this.length ? --this.length : -2;
  538. // for (var k in this)
  539. // len++;
  540. // return len;
  541. // }
  542. function objectIsEmpty(obj){
  543. for (var prop in obj) {
  544. if (obj.hasOwnProperty(prop))
  545. return false;
  546. }
  547. return true;
  548. };
  549. // ------ OBJECTGETKEY get key of index ------
  550. function objectGetKey(o,index){
  551. var i = 0;
  552. for (var k in o){
  553. if (k === 'length' || !o.hasOwnProperty(k))
  554. continue;
  555. if(i == index)
  556. return k;
  557. i ++;
  558. }
  559. }
  560. // Object.prototype.getKey = function(index){
  561. // var i = 0;
  562. // for (var key in this){
  563. // if (key === 'length' || !this.hasOwnProperty(key))
  564. // continue;
  565. // if(i == index)
  566. // return key;
  567. // i ++;
  568. // }
  569. // }
  570. // ------ OBJECTSORT sort object ------
  571. function objectSort(o,value) {
  572. var connection = new Array();
  573. for (var i = objectSize(o) - 1; i >= 0; i--){
  574. var k = objectGetKey(o,i);
  575. for (var j = objectSize(o[k].wit) - 1; j >= 0; j--){
  576. var k2 = objectGetKey(o[k].wit,j);
  577. if (k2==value) {
  578. var the_wit = parseFloat(o[k].wit[k2]);
  579. connection.push( {wit:the_wit,nid:k} );
  580. };
  581. };
  582. };
  583. connection.sort(function(a,b){
  584. // return (a.wit - b.wit);//ascending
  585. return (b.wit - a.wit);//descending
  586. });
  587. var o_sort = {};
  588. for (var i = connection.length - 1; i >= 0; i--){
  589. // o_sort[connection[i].wit+'-'+connection[i].nid] = o[connection[i].nid];
  590. o_sort[connection[i].nid] = o[connection[i].nid];
  591. };
  592. return o_sort;
  593. }
  594. /**
  595. * trigo
  596. */
  597. // -------- getElementAngle ----------
  598. // L'angle 0 correspond au nord (vers le haut)
  599. // Exemple : getElementAngle(posElementX, posElementY, posSourisX, posSourisY)
  600. // Ceci retournera l'angle de l'élément par rapport à la position de la souris
  601. function getElementAngle(x1, y1, x2, y2) {
  602. var adj = x2 - x1;
  603. var opp = y2 - y1;
  604. var angle = Math.abs(Math.atan(opp/adj) * 180/Math.PI);
  605. if (adj > 0 && opp < 0 ) {
  606. angle = 90 - angle;
  607. }
  608. else if (adj >= 0 && opp >= 0) {
  609. angle += 90;
  610. }
  611. else if (adj < 0 && opp >= 0) {
  612. angle = 180 + (90 - angle);
  613. }
  614. else {
  615. angle += 270;
  616. }
  617. return angle;
  618. }
  619. // @koala-prepend "gui_ck_fw/gui.js"
  620. // @codekit-prepend "gui.js"
  621. (function($) {
  622. Drupal.behaviors.init_theme = {};
  623. Drupal.behaviors.init_theme.attach = function (context) {
  624. // Growl-style system messages
  625. $('#messages-and-help > div.messages:not(.processed)')
  626. .addClass('processed')
  627. .each(function() {
  628. // If a message meets these criteria, we don't autoclose
  629. // - contains a link
  630. // - is an error or warning
  631. // - contains a lenghthy amount of text
  632. if ($('a', this).size() || $(this).is('.error') || $(this).is('.warning') || $(this).text().length > 100) {
  633. $(this).prepend("<span class='close'>X</span>");
  634. $('span.close', this).click(function() {
  635. $(this).parent().slideUp('fast');
  636. });
  637. }
  638. else {
  639. // This essentially adds a 3 second pause before hiding the message.
  640. $(this).animate({opacity:1}, 5000, 'linear', function() {
  641. $(this).slideUp('fast');
  642. });
  643. }
  644. });
  645. };
  646. Drupal.behaviors.materio = {};
  647. Drupal.behaviors.materio.attach = function(context) {};
  648. MaterioBaseTheme = function(){
  649. var _settings = Drupal.settings,
  650. _themeSettings = _settings.materiobasetheme,
  651. _strings = _themeSettings.strings,
  652. _History = window.History,
  653. _this = this,
  654. _$content = $('#content'),
  655. _jsp,
  656. _$tooltip = $('<div id="tooltip" class="op-hidden">').appendTo('body'),
  657. _$homeUtilities, _$homeBlockDidactique, _hoverHomeDidactique = false, _homeTimeInterval,
  658. _touch = $('html').is('.touch'),
  659. _statePushed = false,
  660. // touch scroll
  661. position = {x:null,y:null},
  662. translate3d_content = 0,
  663. _isLoggedIn = !$('body').is('.not-logged-in'),
  664. _isFrontNotLogged = $('body').is('.front.not-logged-in'),
  665. _isMembershipForm = $('body').is('.page-node-11186'), //$('body').is('.page-node-11187') || ,
  666. // _isBreveMateriauNodePage = $('body').is('.node-type-breve') || $('body').is('.node-type-materiau');
  667. _isBreveMateriauNodePage = _themeSettings.page_callback == 'node_page_view' && (_themeSettings.node_type == 'materiau' || _themeSettings.node_type == 'breve'),
  668. _resizeTimer,
  669. _max_480 = function(){ return (viewport().width < 479); },
  670. _480_768 = function(){ return ( !_max_480() && _max_768() ); },
  671. _max_768 = function(){ return (viewport().width < 767); },
  672. _768_980 = function(){ return ( !_max_768() && _max_980() ); },
  673. _max_980 = function(){ return (viewport().width < 979); },
  674. _980_1200 = function(){ return ( !_max_980() && _max_1200() ); },
  675. _max_1200 = function(){ return (viewport().width < 1199); },
  676. _previewIsOpen = false,
  677. _viewmodes = {
  678. bookmark : 50,
  679. cardsmall : 100,
  680. cardmedium : 210,
  681. cardbig : 425,
  682. cardfull : 850
  683. };
  684. // DEV
  685. var v1, v2, v3, v4, v5; // generic variable used in many cases to avoid to create new memory block with new vars
  686. function init(){
  687. // trace('init MaterioBaseTheme');
  688. checkIE();
  689. initHistoryNav();
  690. if(_isFrontNotLogged)
  691. initHome();
  692. if(_isMembershipForm)
  693. initMembershipForm();
  694. initForms();
  695. initLayout();
  696. initInfinitScroller();
  697. initEvents();
  698. initKeyboardShortcuts();
  699. initViewmodes();
  700. if(_isBreveMateriauNodePage)
  701. $.event.trigger({ type : 'resultschanged', container : '#content>.inner-content'});
  702. setTimeout(function(){
  703. $.event.trigger({ type : 'theme-ready' });
  704. },100);
  705. };
  706. /**
  707. * checkIE
  708. *
  709. */
  710. function checkIE(){
  711. // alert('check ie');
  712. if($('.oldie body').size() && !readCookie('oldie_checked')){
  713. setTimeout(function(){
  714. createCookie('oldie_checked', 1);
  715. alert('Afin de profiter pleinement des fonctionalités de materio.com, nous vous invitons a mettre a jour votre navigateur dans ça denière version. Celui ci n\'étant pas compatible avec les technologie employer par materio.com, vous risquer de rencontrer des difficulter de navigation.');
  716. }, 4000);
  717. }
  718. };
  719. /**
  720. * history navigation
  721. */
  722. function initHistoryNav(){
  723. var state = _History.getState();
  724. // _History.log('initial:', state.data, state.title, state.url);
  725. _History.Adapter.bind(window,'statechange',onHistoryStateChange);
  726. $(document).bind('new-history-page', onNewHistoryPage);
  727. };
  728. function onNewHistoryPage(event){
  729. //trace('theme :: onNewHistoryPage', event);
  730. var title = event.title.replace(/<(?:.|\n)*?>/gm, '') + ' | ' + _strings.site_name;
  731. // trace('MaterioBaseTheme :: onNewHistoryPage : title', title);
  732. _statePushed = true;
  733. _History.pushState({content:event.content, pagetitle:event.title}, title, event.path);
  734. };
  735. function onHistoryStateChange(event){
  736. // trace('theme :: onHistoryStateChange', event);
  737. var state = _History.getState();
  738. // _History.log('statechange:', state.data, state.title, state.url);
  739. // google analytics
  740. $.event.trigger({
  741. type : 'record-stat',
  742. path : state.url
  743. });
  744. // TODO: History : empty content if we go back to the homepage
  745. // change the current url for feedbacks
  746. $('input[name=location]','#feedback-form').attr('value', state.url);
  747. $.event.trigger({
  748. type:'materio-page-title-refresh-block',
  749. title : state.data.pagetitle
  750. });
  751. // this condition is to avoid retriggering probleme when a module pushState and then is retriggered by state-changed
  752. if(!_statePushed){
  753. _statePushed = false;
  754. $('.inner-content',_$content).html(state.data.content);
  755. $.event.trigger('history-state-change');
  756. }
  757. };
  758. /**
  759. * home
  760. */
  761. function initHome(){
  762. $('img.lazy', '#block-materio-didactique-materio-didactique-home').each(function(){
  763. var $img = $(this);
  764. $img.attr('src', $img.attr('data-original'));
  765. });
  766. if(_max_768()){
  767. initHomeDidactiqueMobile();
  768. }else{
  769. initHomeDidactiqueDesktop();
  770. }
  771. };
  772. function initHomeDidactiqueMobile(){
  773. // trace('initHomeDidactiqueMobile');
  774. _$homeBlockDidactique = $('#block-materio-didactique-materio-didactique-home');
  775. $('.node-didactique', _$homeBlockDidactique)
  776. .find('.field-name-title-field')
  777. .bind('click', clickOnHomeDidactiqueTitle);
  778. };
  779. function clickOnHomeDidactiqueTitle(e){
  780. // trace('clickOnHomeDidactiqueTitle');
  781. var $node = $(this).parent('.node-didactique');
  782. if($node.is('.opened')){
  783. $node.removeClass('opened');//.slideUp();
  784. }else{
  785. $('.node-didactique', _$homeBlockDidactique).removeClass('opened');//.slideUp();
  786. $node.addClass('opened');//.slideDown();
  787. $('html,body').animate({scrollTop: $node.offset().top - $('#header').h()});
  788. }
  789. };
  790. function initHomeDidactiqueDesktop(){
  791. // trace("initHomeDidactiqueDesktop");
  792. _$homeUtilities = $('#utilities');
  793. _$homeBlockDidactique = $('#block-materio-didactique-materio-didactique-home')
  794. .append('<div class="slides"/>')
  795. .append('<div class="tabs"/>')
  796. // .append('<i class="icon-circle-arrow-up"/><i class="icon-circle-arrow-down"/>')
  797. .bind('mouseenter', function(event) { _hoverHomeDidactique = true; })
  798. .bind('mouseleave', function(event) { _hoverHomeDidactique = false; });
  799. $('.node-didactique',_$homeBlockDidactique).each(function(index) {
  800. if(index){
  801. $(this).addClass('op-hidden');
  802. }else{
  803. $(this).addClass('op-visible');
  804. }
  805. $('.field-name-title-field', this)
  806. .clone()
  807. .addClass(index ? '' : 'active')
  808. .click(function(event){
  809. $(this).addClass('active').siblings().removeClass('active');
  810. _$homeBlockDidactique.find('.node-didactique').removeClass('op-visible').addClass('op-hidden').eq(index).removeClass('op-hidden').addClass('op-visible');
  811. })
  812. .appendTo($('.tabs', _$homeBlockDidactique));
  813. }).appendTo($('.slides', _$homeBlockDidactique));
  814. if(!_touch){
  815. $(document).bind('scroll', function(event){
  816. if($(window).scrollTop() == 0) {
  817. if(_$homeUtilities.is('.closed')){
  818. _$homeUtilities.removeClass('closed');//.removeClass('scroll-closed');
  819. launchHomeDidactiqueInterval();
  820. initLayout();
  821. }
  822. }else{
  823. if(!_$homeUtilities.is('.closed')){
  824. _$homeUtilities.addClass('closed');//.addClass('scroll-closed');
  825. clearInterval(_homeTimeInterval);
  826. initLayout();
  827. }
  828. }
  829. });
  830. }
  831. // launchHomeDidactiqueInterval();
  832. $(document)
  833. .bind('cbox_complete', function(){ clearInterval(_homeTimeInterval); })
  834. .bind('cbox_closed', function(){ launchHomeDidactiqueInterval(); });
  835. $('.side.oops a').click(function(event) {
  836. event.preventDefault();
  837. // $(document).scrollTop(0);
  838. // $('#edit-mail', "#block-materio-user-user-register").focus();
  839. window.location.href = $(this).attr('href');
  840. return false;
  841. });
  842. };
  843. function launchHomeDidactiqueInterval(){
  844. _homeTimeInterval = setInterval(function(){
  845. if(!_hoverHomeDidactique){
  846. var $next = $('.tabs .active', _$homeBlockDidactique).next();
  847. if(!$next.length)
  848. $next = $('.tabs .active', _$homeBlockDidactique).siblings().eq(0);
  849. $next.trigger('click');
  850. }
  851. }, 15000);
  852. };
  853. /**
  854. * layout
  855. */
  856. function initLayout(){
  857. if(!_max_768()){
  858. var height = $('#header').h() + $('#tasks').h();
  859. if(!_max_480() && !_touch ){
  860. height += $('#utilities').h()+15;
  861. }
  862. //$('#main').css('margin-top', height+15);
  863. // $('#container').css('padding-top', height+15);
  864. if(!$('html').is(".ie8")){
  865. $('#container').animate({'padding-top':height}, 300);
  866. }
  867. }
  868. };
  869. /**
  870. * infinit scroll
  871. */
  872. function initInfinitScroller(){
  873. // trace("initInfinitScroller");
  874. $.event.trigger({
  875. type : 'init-scroller-pager',
  876. pager : $('ul.pager', '#content')
  877. });
  878. $(document).bind('scroll', function(event){
  879. // trace('scroll event binded');
  880. checkInfinitScroller();
  881. });
  882. };
  883. function checkInfinitScroller(){
  884. // trace('checkInfinitScroller');
  885. // if(!_touch){
  886. // }else{
  887. if($(window).scrollTop() + $(window).height() > getDocHeight() - 200) {
  888. infinitScrollPager();
  889. }
  890. // }
  891. };
  892. function infinitScrollPager(){
  893. // trace('MaterioBaseTheme :: infinitScrollPager');
  894. if($('ul.pager', '#content').length){
  895. var $nextpage = $('ul.pager .pager-current', '#content').next(),
  896. href = $('a', $nextpage).attr('href');
  897. if(href){
  898. $.event.trigger({ type : 'record-stat', path : href }); // google analytics
  899. $.event.trigger({ type : 'load-scroller-pager', href : href });
  900. }
  901. }
  902. };
  903. /**
  904. * events
  905. */
  906. function initEvents(){
  907. //trace('MaterioBaseTheme :: initEvents');
  908. $(document)
  909. .bind('init-layout', initLayout)
  910. .bind('loading-content', onLoadingContent)
  911. .bind('loaded-content', onLoadedContent)
  912. .bind('resultschanged', onResultsChanged)
  913. .bind('resultscompleted', onResultsCompleted)
  914. .bind('mybookmarks-block-updated', onMybookmarksBlockUpdate)
  915. .bind('mylists-block-builded', onMyListsBlockBuilded)
  916. .bind('mylists-block-updated', onMyListsBlockUpdate)
  917. .bind('flagGlobalAfterLinkUpdate', onAfterFlaging)
  918. .bind('record-stat', onRecordStat)
  919. .bind('view-mode-changed', onViewModeChanged)
  920. .bind('ajax-register-block-loaded', onAjaxRegisterBlockLoaded);
  921. $(window)
  922. .bind('resize', onResizeWindow);
  923. initFlagsEvent();
  924. $('#block-user-login h2, #block-menu-menu-top-menu h2').bind('click', function(event) {
  925. event.preventDefault();
  926. $(this).parent('.block').toggleClass('hovered');
  927. $('.hovered').not($(this).parent('.block')).removeClass('hovered');
  928. return false;
  929. });
  930. $('#block-materio-search-api-materio-search-api-viewmode .viewmode-link').bind('vm-clicked-active', function(event) {
  931. $(this).parents('.block').toggleClass('hovered');
  932. $('.hovered').not($(this).parents('.block')).removeClass('hovered');
  933. });
  934. $('#block-materio-search-api-materio-search-api-viewmode .viewmode-link').bind('vm-clicked', function(event) {
  935. $(this).parents('.block').removeClass('hovered');
  936. $('.hovered').not($(this).parents('.block')).removeClass('hovered');
  937. });
  938. };
  939. function onLoadingContent(event){
  940. _$content.addClass('faded');
  941. $('#materio-search-api-search-form').addClass('loading');
  942. };
  943. function onLoadedContent(event){
  944. // trace('MaterioBaseTheme :: onLoadedContent',event);
  945. _$content.removeClass('faded');
  946. $('#materio-search-api-search-form').removeClass('loading');
  947. };
  948. function onResultsChanged(event){
  949. // trace('MaterioBaseTheme :: onResultsChanged',event);
  950. $(document).scrollTop(0);
  951. focusCard($('#content .search-results, #content .actuality-items').children('.node:first-child'));
  952. onResultsCompleted(event);
  953. };
  954. function onResultsCompleted(event){
  955. // trace('theme :: onResultsCompleted', event);
  956. checkInfinitScroller();
  957. if(event.container != undefined){
  958. // trace('theme :: container is ok : '+event.container)
  959. setTimeout(function(){ // why this time out ?
  960. initCards(event.container);
  961. setUpGrid(event.container);
  962. }, 100);
  963. }
  964. };
  965. function initCards(container){
  966. //TODO : refactore this function, to much features in there
  967. //trace('theme :: initCards', container);
  968. var $container = $(container);
  969. $container.children('.node:not(.listened)')
  970. .bind('mouseenter focused mousemove click mouseleave', onCardEventDispatcher)
  971. .each(function(i){
  972. protectFigures(this);
  973. if(_isLoggedIn){
  974. if(!$container.is('.modal-content')){
  975. // do not add preview btn if we are already on a preview
  976. initPreview(this);
  977. }else{
  978. // if we are on preview mode add a close btn (only for associated materials)
  979. if(!$(this).is(":first-child")){
  980. var $closebtn = $('<section><i class="icon-remove"></i></section>');
  981. $closebtn.bind('click', function(){
  982. $(this).parents('.node-materiau').remove();
  983. });
  984. $('nav.nav', this).append($closebtn);
  985. }
  986. }
  987. }
  988. })
  989. .addClass('listened');
  990. };
  991. function setUpGrid(container){
  992. var $card, top, old_top, col = 0, line = 0;
  993. $(container).children('.node')
  994. .each(function(i){
  995. $card = $(this);
  996. top = $card.offset().top;
  997. if(old_top != top){
  998. line ++;
  999. old_top = top;
  1000. col = 0;
  1001. }
  1002. col ++;
  1003. $card.attr('column', col).attr('line', line);
  1004. });
  1005. };
  1006. function onViewModeChanged(event){
  1007. if(_isBreveMateriauNodePage){
  1008. // if(!_isloadingresults){
  1009. $.event.trigger('loading-content');
  1010. var url = _settings.basePath+_settings.pathPrefix+'materio_search_api_ajax/node/'+_themeSettings.node_nid;
  1011. $.getJSON(url,
  1012. function(json){
  1013. //trace('json', json);
  1014. $.event.trigger('loaded-content');
  1015. $('#content>.inner-content').html(json.node);
  1016. $.event.trigger({ type : 'resultschanged', container : '#content>.inner-content'});
  1017. });
  1018. // }
  1019. }
  1020. };
  1021. /**
  1022. * CARDS
  1023. */
  1024. function onCardEventDispatcher(event){
  1025. // trace('onCardEvent', event);
  1026. var vmode = event.currentTarget.className.match(/vm-([a-z|A-Z]+)/);
  1027. var cf = 'on_'+event.type+'_card';
  1028. var f = 'on_'+event.type+'_'+vmode[1];
  1029. if(typeof _this[cf] == 'function')
  1030. _this[cf].call(this, event);
  1031. if(typeof _this[f] == 'function')
  1032. _this[f].call(this, event);
  1033. };
  1034. // function initLayoutCardDispatcher($card){
  1035. // // trace('$card', $card);
  1036. // var vmode = $card.attr('class').match(/vm-([a-z|A-Z]+)/);
  1037. // var f = 'init_layout_'+vmode[1];
  1038. // if(typeof _this[f] == 'function')
  1039. // _this[f].call(this, $card);
  1040. // };
  1041. /**
  1042. * commons Cards
  1043. */
  1044. // MaterioBaseTheme.prototype.init_layout_card = function($card){
  1045. // trace('initLayoutCardBig');
  1046. // };
  1047. // MaterioBaseTheme.prototype.on_mouseenter_card = function(event){
  1048. // //trace('MaterioBaseTheme :: on_mouseenter_card', event);
  1049. // };
  1050. MaterioBaseTheme.prototype.on_mousemove_card = function(event){
  1051. //trace('on_mousemove_Card', event);
  1052. focusCard($(this));
  1053. };
  1054. // MaterioBaseTheme.prototype.on_click_card = function(event){
  1055. // trace('on_click_card', event);
  1056. // };
  1057. // MaterioBaseTheme.prototype.on_mouseleave_card = function(event){
  1058. // // trace('on_mouseleave_Card', event);
  1059. // };
  1060. /**
  1061. * cards small
  1062. */
  1063. // MaterioBaseTheme.prototype.init_layout_cardsmall = function($card){
  1064. // trace('initLayoutCardBig');
  1065. // };
  1066. MaterioBaseTheme.prototype.on_mouseenter_cardsmall = function(event){
  1067. //trace('MaterioBaseTheme :: on_mouseenter_cardsmall', event);
  1068. showLazyLoadedImages(event.currentTarget);
  1069. };
  1070. MaterioBaseTheme.prototype.on_focused_cardsmall = function(event){
  1071. // trace('theme :: on_focused_cardsmall',event);
  1072. v1 = $(this);
  1073. v2 = v1.offset();
  1074. _$tooltip
  1075. .html($('.group-header', this).clone().addClass('smallcard'))
  1076. .css({
  1077. top:v2.top,//- event.layerY,
  1078. left:v2.left + 5 + ($(this).w())// - event.layerX
  1079. })
  1080. .removeClass('op-hidden').addClass('op-visible');
  1081. };
  1082. MaterioBaseTheme.prototype.on_mousemove_cardsmall = function(event){
  1083. // trace('on_mousemove_Card', event);
  1084. horiHoverImagesSwitcher(event);
  1085. _$tooltip
  1086. .css({
  1087. top:event.pageY - _$tooltip.h() -5,// - event.layerY,
  1088. left:event.pageX + 5 + ($(this).w() - event.layerX)
  1089. });
  1090. };
  1091. // MaterioBaseTheme.prototype.on_click_cardsmall = function(event){
  1092. // trace('on_click_cardsmall', event);
  1093. // };
  1094. MaterioBaseTheme.prototype.on_mouseleave_cardsmall = function(event){
  1095. // trace('on_mouseleave_Card', event);
  1096. $('.images img.op-visible', this)
  1097. .removeClass('op-visible').addClass('op-hidden')
  1098. .eq(0)
  1099. .removeClass('op-hidden').addClass('op-visible');
  1100. if($(this).is('.focused'))
  1101. _$tooltip.removeClass('op-visible').addClass('op-hidden');
  1102. };
  1103. /**
  1104. * cards medium
  1105. */
  1106. // MaterioBaseTheme.prototype.init_layout_cardmedium = function($card){
  1107. // trace('initLayoutCardMedium');
  1108. // var ch = $card.h() - $('.group-header', $card).h() -30;
  1109. // columnsPage($('.field-name-field-description, .field-name-body', $card), 210, ch);
  1110. // };
  1111. MaterioBaseTheme.prototype.on_mouseenter_cardmedium = function(event){
  1112. // trace('on_mouseenter_cardmedium');
  1113. // show lazy images
  1114. showLazyLoadedImages(event.currentTarget);
  1115. // columnize texts
  1116. $card = $(event.currentTarget);
  1117. if(!$('.columnized', $card).size() && !$('body').is('.role-7', 'role-2') ){
  1118. var ch = $card.h() - $('.group-header', $card).h() -30;
  1119. columnsPage($('.field-name-field-description, .field-name-body', $card), 210, ch);
  1120. $('.group-side-4', $card).wrapInner('<div class="column-wrapper">').find('.field-item').addClass('dontsplit');
  1121. columnsPage($('.group-side-4 .column-wrapper', $card), 210, ch);
  1122. }
  1123. // add associated materials links
  1124. prepareAssociatedMaterials(event.currentTarget);
  1125. };
  1126. MaterioBaseTheme.prototype.on_mousemove_cardmedium = function(event){
  1127. //trace('on_mousemove_cardmedium');
  1128. horiHoverImagesSwitcher(event);
  1129. };
  1130. MaterioBaseTheme.prototype.on_click_cardmedium = function(event){
  1131. // trace('on_click_cardmedium', event);
  1132. if(!$(event.target).is('.flag') && !$(event.target).parent().is('.flag'))
  1133. sideSwitcher(event);
  1134. };
  1135. MaterioBaseTheme.prototype.on_mouseleave_cardmedium = function(event){
  1136. v1 = $('.side.op-visible');
  1137. if(v1.is('.oops','.upgrade') || $('.upgrade', v1).size()){
  1138. sideSwitcher(event, 0);
  1139. }
  1140. };
  1141. /**
  1142. * cards Big
  1143. */
  1144. // MaterioBaseTheme.prototype.init_layout_cardbig = function($card){
  1145. //trace('initLayoutCardBig');
  1146. // columnsPage($('.field-name-field-description, .field-name-body', $card), 425, 270);
  1147. // };
  1148. MaterioBaseTheme.prototype.on_mouseenter_cardbig = function(event){
  1149. // trace('on_mouseenter_cardbig');
  1150. showLazyLoadedImages(event.currentTarget);
  1151. if(!$('.columnized', event.currentTarget).size()){
  1152. columnsPage($('.field-name-field-description, .field-name-body', event.currentTarget), 425, 270);
  1153. $('.group-4', event.currentTarget).wrapInner('<div class="column-wrapper">').find('.field-item').addClass('dontsplit');
  1154. columnsPage($('.group-4 .column-wrapper', event.currentTarget), 425, 270);
  1155. }
  1156. // add associated materials links
  1157. prepareAssociatedMaterials(event.currentTarget);
  1158. };
  1159. MaterioBaseTheme.prototype.on_mousemove_cardbig = function(event){
  1160. // trace('on_mousemove_cardbig');
  1161. horiHoverImagesSwitcher(event);
  1162. };
  1163. MaterioBaseTheme.prototype.on_click_cardbig = function(event){
  1164. //trace('on_click_cardbig');
  1165. sideSwitcher(event);
  1166. };
  1167. MaterioBaseTheme.prototype.on_mouseleave_cardbig = function(event){
  1168. if($('.side.op-visible').is('.oops') || $('.side.op-visible').is('.upgrade')){
  1169. sideSwitcher(event, 0);
  1170. }
  1171. };
  1172. /**
  1173. * cards Full
  1174. */
  1175. // MaterioBaseTheme.prototype.init_layout_cardfull = function($card){
  1176. // trace('initLayoutCardFull');
  1177. // };
  1178. MaterioBaseTheme.prototype.on_mouseenter_cardfull = function(event){
  1179. // trace('on_mouseenter_cardfull');
  1180. showLazyLoadedImages(event.currentTarget);
  1181. // add associated materials links
  1182. prepareAssociatedMaterials(event.currentTarget);
  1183. };
  1184. MaterioBaseTheme.prototype.on_mousemove_cardfull = function(event){
  1185. // trace('on_mousemove_cardfull');
  1186. horiHoverImagesSwitcher(event);
  1187. };
  1188. // MaterioBaseTheme.prototype.on_click_cardfull = function(event){
  1189. // trace('on_click_cardfull');
  1190. // };
  1191. // MaterioBaseTheme.prototype.on_mouseleave_cardfull = function(event){
  1192. // trace('on_mouseleave_cardfull');
  1193. // };
  1194. /**
  1195. * horiHoverImagesSwitcher
  1196. */
  1197. function horiHoverImagesSwitcher(event){
  1198. // trace('horiHoverImagesSwitcher', event);
  1199. var $curtar = $(event.currentTarget);
  1200. // TODO : event.layerX doesn't exists in IE8 so we have to calculate the mouse position from offsetX, pageY, etc
  1201. // var layerX = event.layerX ? event.layerX : event.clientX - event.currentTarget.offsetLeft;
  1202. var layerX = event.clientX - event.currentTarget.offsetLeft;
  1203. // trace("layerX", layerX);
  1204. if(layerX && $curtar.is('.image-ready') ){ // && !$curtar.is('.image-buged')
  1205. var $imgs = $('.group-images figure', event.currentTarget);
  1206. if($(event.target).parents('.group-images').length){
  1207. var imgw = $imgs.eq(0).w(),
  1208. rapport = imgw/$imgs.length,
  1209. mx = layerX > imgw ? imgw-1 : layerX,
  1210. rapport_pos = Math.floor(mx / rapport);
  1211. // trace('rapport_pos = '+rapport_pos+' | event.layerX = '+event.layerX);
  1212. rapport_pos = rapport_pos < 0 ? 0 : ( rapport_pos > ($imgs.length - 1) ? $imgs.length - 1 : rapport_pos);
  1213. if(!$imgs.eq(rapport_pos).is('.op-visible')){
  1214. // google analytics
  1215. $.event.trigger({
  1216. type : 'record-stat',
  1217. categorie : 'Card event',
  1218. action : 'image slide switch',
  1219. label : rapport_pos
  1220. });
  1221. $imgs
  1222. .removeClass('op-visible').addClass('op-hidden')
  1223. .eq(rapport_pos)
  1224. .removeClass('op-hidden').addClass('op-visible');
  1225. }
  1226. }else{
  1227. // $curtar.addClass('image-buged');
  1228. $imgs.removeClass('op-visible').addClass('op-hidden');
  1229. $imgs.eq(0).removeClass('op-hidden').addClass('op-visible');
  1230. }
  1231. }
  1232. };
  1233. /**
  1234. * protectImages
  1235. */
  1236. function protectFigures(context){
  1237. // trace('protectFigures');
  1238. context = context == null ? 'body' : context;
  1239. $('figure:not(.protected)', context)
  1240. .append('<img class="blank" src="'+_settings.basePath+_themeSettings.themePath+'/img/blank.gif" />')
  1241. .addClass('protected')
  1242. .bind("contextmenu", function(e){
  1243. alert("Cette image est soumise au droit d'auteur.");
  1244. return false;
  1245. });
  1246. };
  1247. /**
  1248. * initPreview
  1249. */
  1250. function initPreview(node){
  1251. $('nav.nav', node).append($('<section class="preview"><i class="fi-eye"></i></section>').bind('click', onClickPreviewCardBtn));
  1252. };
  1253. function onClickPreviewCardBtn(event){
  1254. // trace('theme :: onClickPreviewCardBtn', event);
  1255. event.preventDefault();
  1256. //trace('Theme :: previewCard', event);
  1257. previewCard($(this).parents('.node'));
  1258. return false;
  1259. };
  1260. function previewCard($card){
  1261. // trace('theme :: previewCard',$card);
  1262. // get the nid from card class
  1263. var matches = $card.attr('class').match(/\bnode-(\d+)\b/);
  1264. // select viewmode regarding the window size
  1265. var viewmode = false;
  1266. var cur_vm = getCurrentViewmode();
  1267. for(var vm in _viewmodes)
  1268. if(vm != cur_vm && _viewmodes[vm] > _viewmodes[cur_vm] && _viewmodes[vm] < $(window).width())
  1269. viewmode = vm;
  1270. // ajax load card's node
  1271. if(typeof matches[1] !== undefined && viewmode){
  1272. $.event.trigger('loading-content');
  1273. $.getJSON(_settings.basePath+_settings.pathPrefix+'materio_search_api_ajax/node/'+matches[1],
  1274. {viewmode:viewmode},
  1275. function(json){
  1276. //trace('json', json);
  1277. $.event.trigger('loaded-content');
  1278. previewLoaded(json);
  1279. });
  1280. }
  1281. };
  1282. function previewLoaded(json){
  1283. var $modal = $('<div>').addClass('modal-content').append(json.node);
  1284. var $modal_wrapper = $('.modal-wrapper');
  1285. if(!$modal_wrapper.size())
  1286. $modal_wrapper = $('<div>').addClass('modal-wrapper').append($('<div>').addClass('modal-bg')).appendTo('body');
  1287. $modal_wrapper
  1288. .append($modal)
  1289. .bind('click', function(event) {
  1290. _previewIsOpen = false;
  1291. $(this).remove();
  1292. });
  1293. $modal.bind('click', function(event) {
  1294. event.stopPropagation();
  1295. });
  1296. _previewIsOpen = true;
  1297. initCards('.modal-content');
  1298. $.event.trigger({ type : 'previewloaded', container : '.modal-content'});
  1299. };
  1300. /**
  1301. * GRID
  1302. */
  1303. function moveGridFocus(event, side){
  1304. var $old_focused = $('#content .search-results, #content .actuality-items')
  1305. .children('.node.focused').first();
  1306. var $new_focused;
  1307. switch(side){
  1308. case 'r':
  1309. $new_focused = $old_focused.next();
  1310. break;
  1311. case 'l':
  1312. $new_focused = $old_focused.prev();
  1313. break;
  1314. case 'u':
  1315. case 'd':
  1316. var dir = side == "d" ? 1 : -1;
  1317. var column = $old_focused.attr('column');
  1318. while( ($new_focused == undefined || !$new_focused.size()) && column > 0){
  1319. $new_focused = $('.node[column='+column+'][line='+(parseInt($old_focused.attr('line'))+dir)+']');
  1320. column --;
  1321. }
  1322. break;
  1323. }
  1324. focusCard($new_focused);
  1325. docScrollTo($new_focused);
  1326. };
  1327. function focusCard($card){
  1328. // trace('theme :: focusCard', $card);
  1329. if(!$card.size() || $card.is('.focused') || $card.parents('.modal-content').size())
  1330. return;
  1331. $('#content .search-results, #content .actuality-items')
  1332. .children('.node.focused')
  1333. .removeClass('focused');
  1334. $card.addClass('focused');
  1335. if(_previewIsOpen){
  1336. previewCard($card);
  1337. }
  1338. $card.trigger('focused');
  1339. };
  1340. /**
  1341. * lazyloadimages
  1342. */
  1343. // function initLazyLoad(context){
  1344. // $('figure:first-child img.lazy', context).lazyload();//{
  1345. // container:'#content'
  1346. // });
  1347. // TODO: propage this event to the card near it to anticipate the mouseenter
  1348. // $(context).bind('mousemove', showLazyLoadedImages);
  1349. // };
  1350. function showLazyLoadedImages(context){
  1351. //trace('MaterioBaseTheme :: initLazyLoad : mouseenter', this);
  1352. var $this = $(context);
  1353. if( !$this.is('.lazy-processed') ){
  1354. $this
  1355. .addClass('lazy-processed')
  1356. // .find('figure img.lazy')
  1357. .find('img.lazy')
  1358. .each(function(index){
  1359. var $img = $(this);
  1360. $img.attr('src', $img.attr('data-original')).removeAttr('data-original');
  1361. });
  1362. setTimeout(function(){
  1363. $this.addClass('image-ready');
  1364. }, 300);
  1365. }
  1366. };
  1367. /**
  1368. * prepareAssociatedMaterials
  1369. */
  1370. function prepareAssociatedMaterials(card){
  1371. // trace('prepareAssociatedMaterials', card);
  1372. $('.field-name-field-materiau-ref a:not(.prepared)', card).addClass("prepared").bind('click', onClickAssociatedMaterial);
  1373. };
  1374. /**
  1375. * onClickAssociatedMaterial
  1376. */
  1377. function onClickAssociatedMaterial(event){
  1378. // trace("onClickAssociatedMaterial");
  1379. event.preventDefault();
  1380. var $this = $(this);
  1381. // trace('href', $(this).attr('href'));
  1382. var nid = $this.attr('href').match(/^\/(fr|en)\/node\/(\d+)$/)[2];
  1383. // trace("nid", nid);
  1384. var $prt = $this.parents('.node-materiau');
  1385. if($prt.parent().is('.modal-content')){
  1386. // if we are on preview mode
  1387. // remove already loaded associated
  1388. $prt.parent().find('.node-'+nid+'.associated').remove();
  1389. loadAssociatedNode($prt, nid);
  1390. }else{
  1391. // if we are on normal grid mode
  1392. var $n = $prt.nextUntil('.node-materiau:not(.associated)').filter('.node-'+nid);
  1393. // trace('n', $n);
  1394. if($n.size()){
  1395. // trace('focus', nid);
  1396. // focus on already loaded node
  1397. focusCard($n);
  1398. // docScrollTo($isnodeexisting);
  1399. }else{
  1400. // trace('load associated', nid);
  1401. loadAssociatedNode($prt, nid);
  1402. }
  1403. }
  1404. return false;
  1405. };
  1406. function loadAssociatedNode($prt, nid){
  1407. // console.log('loadAssociatedNode | nid = '+nid);
  1408. var viewmode = $prt.attr('class').match(/vm-([^\s]+)/);
  1409. // trace('viewmode match', viewmode);
  1410. // if(!_isloadingresults){
  1411. $.event.trigger('loading-content');
  1412. var url = _settings.basePath+_settings.pathPrefix+'materio_search_api_ajax/node/'+nid;
  1413. $.getJSON(url,
  1414. {viewmode:viewmode[1]},
  1415. function(json){
  1416. //trace('json', json);
  1417. $.event.trigger('loaded-content');
  1418. displayAssociated($prt, $(json.node));
  1419. $.event.trigger({
  1420. type : 'resultscompleted',
  1421. container : '#content .actuality-items, #content .search-results'
  1422. });
  1423. });
  1424. // }
  1425. };
  1426. function displayAssociated($prt, $n){
  1427. $n.addClass('associated').addClass('just-added');
  1428. $prt.after($n);
  1429. initCards($prt.parent());
  1430. (function($n){
  1431. setTimeout(function(){
  1432. $n.removeClass('just-added');
  1433. focusCard($n);
  1434. }, 100);
  1435. }($n));
  1436. };
  1437. /**
  1438. * sideSwitcher
  1439. */
  1440. function sideSwitcher(event, delta){
  1441. var $sides = $('.side', event.currentTarget);
  1442. if($sides.length > 1){
  1443. if( typeof delta == 'undefined'){
  1444. var delta = 0;
  1445. $sides.each(function(i) {
  1446. if($(this).is('.op-visible')){
  1447. delta = i+1;
  1448. return false;
  1449. }
  1450. });
  1451. delta = delta == 0 ? 1 : (delta == $sides.length ? 0 : delta);
  1452. }
  1453. // google analytics
  1454. $.event.trigger({
  1455. type : 'record-stat',
  1456. categorie : 'Card event',
  1457. action : 'side switch',
  1458. label : delta
  1459. });
  1460. $sides.addClass('op-hidden').removeClass('op-visible')
  1461. .eq(delta).removeClass('op-hidden').addClass('op-visible');
  1462. }
  1463. };
  1464. /**
  1465. * columnsPage
  1466. */
  1467. function columnsPage($elmt, cw, ch){
  1468. // trace('columnsPage');
  1469. var cls = Math.ceil($elmt.h()/ch);
  1470. $elmt
  1471. .addClass('columnized')
  1472. .width(cw*cls)
  1473. .columnize({
  1474. width:cw,
  1475. height:ch,
  1476. lastNeverTallest:true
  1477. });
  1478. if(cls > 1){
  1479. $elmt.find('.column').each(function(index) {
  1480. var $this = $(this);
  1481. if(!$this.find('*').length){
  1482. $this.prev().addClass('last');
  1483. $this.remove();
  1484. return true;
  1485. }
  1486. });
  1487. $elmt.find('.column').each(function(index) {
  1488. var $this = $(this);
  1489. if(!$this.is('.first'))
  1490. $this.children('*:first-child').prepend('<span cw="'+cw+'" col="'+(index-1)+'" class="column-switcher prev-column">‹</span> ...');
  1491. if(!$this.is('.last'))
  1492. $this.children('*:last-child').append('... <span cw="'+cw+'" col="'+(index+1)+'" class="column-switcher next-column">›</span>');
  1493. });
  1494. $('.column-switcher', $elmt).bind('click', onColumnSwitcherClick);
  1495. }
  1496. };
  1497. function onColumnSwitcherClick(event){
  1498. event.preventDefault();
  1499. //trace('onColumnSwitcherClick', event);
  1500. var $this = $(event.currentTarget),
  1501. $columnized = $this.parents('.columnized');
  1502. // google analytics
  1503. $.event.trigger({
  1504. type : 'record-stat',
  1505. categorie : 'Card event',
  1506. action : 'column switch',
  1507. label : $this.attr('col')
  1508. });
  1509. $columnized.css({
  1510. marginLeft : -1 * $this.attr('cw') * $this.attr('col') +'px'
  1511. });
  1512. return false;
  1513. }
  1514. /**
  1515. * initViewmodes
  1516. */
  1517. function initViewmodes(){
  1518. checkViewmodesResponsive();
  1519. };
  1520. function checkViewmodesResponsive(){
  1521. if(_480_768()){
  1522. if($('.viewmode-link.active').is('.viewmode-cardfull')){
  1523. $('.viewmode-cardbig').trigger('click');
  1524. }
  1525. }else if(_max_480()){
  1526. if($('.viewmode-link.active').is('.viewmode-cardbig, .viewmode-cardfull')){
  1527. $('.viewmode-cardmedium').trigger('click');
  1528. }
  1529. }
  1530. };
  1531. function getCurrentViewmode(){
  1532. for(var vm in _viewmodes)
  1533. if($('.viewmode-link.active.viewmode-'+vm).size())
  1534. return vm;
  1535. };
  1536. /**
  1537. * FLAGS
  1538. */
  1539. function initFlagsEvent(){
  1540. $('.bookmarks, .mylists .flaged').children('.node:not(.listened)')
  1541. .bind('mouseenter mousemove click mouseleave', onCardEventDispatcher)
  1542. // .each(function(event){ initLayoutCardDispatcher($(this)); })
  1543. .addClass('listened');
  1544. };
  1545. function onAfterFlaging(event){
  1546. //trace('MaterioBaseTheme :: onAfterFlaging', event);
  1547. // WARNING to use event variables i had to hack flag.js from flag module (change the event declaration)
  1548. var $target = $(event.link).parents('article.node');
  1549. if(event.flagStatus == 'flag'){
  1550. $target.addClass('flaged');
  1551. }else if(event.flagStatus == 'unflag'){
  1552. if($('.flag-lists-entity-links a.unflag-action', $target).length == 0)
  1553. $target.removeClass('flaged');
  1554. }
  1555. };
  1556. function onMybookmarksBlockUpdate(event){
  1557. initFlagsEvent();
  1558. initLayout();
  1559. };
  1560. function onClickList(event){
  1561. //trace('onClickList', event);
  1562. var $link = $(event.currentTarget).addClass('active'),
  1563. name = $link.attr('name'),
  1564. $block = $link.parents('.block'),
  1565. $flaged = $('.flaged.'+name, $block).addClass('active');
  1566. $link.siblings().removeClass('active');
  1567. $flaged.siblings().removeClass('active');
  1568. createCookie('materiomyflaglistsopened', name, 1);
  1569. $flaged.parents('.mylists').height($flaged.h());
  1570. initLayout();
  1571. };
  1572. function onMyListsBlockUpdate(event){
  1573. //trace('MaterioBaseTheme :: onMyListsBlockUpdate', event);
  1574. initFlagsEvent();
  1575. // initLazyLoad(this);
  1576. // TODO: refresh contents (search results) to see new flaglist links.
  1577. initLayout();
  1578. };
  1579. function onMyListsBlockBuilded(event){
  1580. //trace('MaterioBaseTheme :: onMyListsBlockBuilded', event);
  1581. // initLazyLoad(event.block);
  1582. showLazyLoadedImages(event.block);
  1583. };
  1584. /**
  1585. * cards bookmark
  1586. */
  1587. // MaterioBaseTheme.prototype.init_layout_bookmark = function($card){
  1588. // trace('initLayoutCardBig');
  1589. // };
  1590. MaterioBaseTheme.prototype.on_mouseenter_bookmark = function(event){
  1591. //trace('on_mouseenter_bookmark', event);
  1592. _$tooltip
  1593. .html($('.group-header', this).clone())
  1594. .css({
  1595. top:event.pageY - _$tooltip.h() -5,//- event.layerY,
  1596. left:event.pageX + 5 + ($(this).w() - event.layerX)
  1597. })
  1598. .removeClass('op-hidden').addClass('op-visible');
  1599. };
  1600. MaterioBaseTheme.prototype.on_mousemove_bookmark = function(event){
  1601. // trace('on_mousemove_Card', event);
  1602. // if(event.layerX)
  1603. // horiHoverImagesSwitcher(event);
  1604. _$tooltip
  1605. .css({
  1606. top:event.pageY - _$tooltip.h() -5,// - event.layerY,
  1607. left:event.pageX + 5 + ($(this).w() - event.layerX)
  1608. });
  1609. };
  1610. // MaterioBaseTheme.prototype.on_click_bookmark = function(event){
  1611. // trace('on_click_bookmark', event);
  1612. // };
  1613. MaterioBaseTheme.prototype.on_mouseleave_bookmark = function(event){
  1614. // trace('on_mouseleave_Card', event);
  1615. $('.images img.op-visible', this)
  1616. .removeClass('op-visible').addClass('op-hidden')
  1617. .eq(0)
  1618. .removeClass('op-hidden').addClass('op-visible');
  1619. _$tooltip.removeClass('op-visible').addClass('op-hidden');
  1620. };
  1621. /**
  1622. * keyboradshortcuts
  1623. */
  1624. function initKeyboardShortcuts(){
  1625. $(document)
  1626. .bind('keydown', 'Shift+:',shortcut_focusSearchField)
  1627. .bind('keydown', '/',shortcut_focusSearchField)
  1628. .bind('keydown', 'Alt+1',shortcut_viewmodeSmall)
  1629. .bind('keydown', 'Alt+2',shortcut_viewmodeMedium)
  1630. .bind('keydown', 'Alt+3',shortcut_viewmodeBig)
  1631. .bind('keydown', 'Alt+4',shortcut_viewmodeFull)
  1632. .bind('keydown', 'space',shortcut_togglePreview)
  1633. .bind('keydown', 'esc',shortcut_closeModaleContent)
  1634. .bind('keydown', 'up',shortcut_onUpArrow)
  1635. .bind('keydown', 'right',shortcut_onRightArrow)
  1636. .bind('keydown', 'down',shortcut_onDownArrow)
  1637. .bind('keydown', 'left',shortcut_onLeftArrow);
  1638. };
  1639. function shortcut_focusSearchField(e){
  1640. // trace("focusSearchField");
  1641. if($('#edit-searchfield').size()){
  1642. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1643. stat_event.action = 'slash';
  1644. stat_event.label = 'Focus on search text field';
  1645. $.event.trigger(stat_event);
  1646. $('#edit-searchfield').focus();
  1647. e.stopPropagation();
  1648. e.preventDefault();
  1649. return false;
  1650. }
  1651. };
  1652. function shortcut_viewmodeSmall(e){
  1653. if($('a.viewmode-link.viewmode-cardsmall').size()){
  1654. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1655. stat_event.action = 'Alt+1';
  1656. stat_event.label = 'Change view mode : card small';
  1657. $.event.trigger(stat_event);
  1658. $('a.viewmode-link.viewmode-cardsmall').click();
  1659. return false;
  1660. }
  1661. };
  1662. function shortcut_viewmodeMedium(e){
  1663. if($('a.viewmode-link.viewmode-cardmedium').size()){
  1664. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1665. stat_event.action = 'Alt+2';
  1666. stat_event.label = 'Change view mode : card medium';
  1667. $.event.trigger(stat_event);
  1668. $('a.viewmode-link.viewmode-cardmedium').click();
  1669. return false;
  1670. }
  1671. };
  1672. function shortcut_viewmodeBig(e){
  1673. if($('a.viewmode-link.viewmode-cardbig').size()){
  1674. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1675. stat_event.action = 'Alt+3';
  1676. stat_event.label = 'Change view mode : card big';
  1677. $.event.trigger(stat_event);
  1678. $('a.viewmode-link.viewmode-cardbig').click();
  1679. return false;
  1680. }
  1681. };
  1682. function shortcut_viewmodeFull(e){
  1683. if($('a.viewmode-link.viewmode-cardfull').size()){
  1684. var stat_event = { type : 'record-stat', categorie : 'Shortcuts'};
  1685. stat_event.action = 'Alt+4';
  1686. stat_event.label = 'Change view mode : card full';
  1687. $.event.trigger(stat_event);
  1688. $('a.viewmode-link.viewmode-cardfull').click();
  1689. return false;
  1690. }
  1691. };
  1692. function shortcut_togglePreview(e){
  1693. // trace('theme :: shortcut_togglePreview', e);
  1694. $.event.trigger({
  1695. type : 'record-stat',
  1696. categorie : 'Shortcuts',
  1697. action : 'Space',
  1698. label : 'Space toggle preview'
  1699. });
  1700. if(_previewIsOpen){
  1701. if($('body>.modal-wrapper').size()){
  1702. $('body>.modal-wrapper').click();
  1703. _previewIsOpen = false;
  1704. return false;
  1705. }
  1706. }else{
  1707. previewCard($('#content .search-results, #content .actuality-items').children('.node.focused:first'));
  1708. }
  1709. };
  1710. function shortcut_closeModaleContent(e){
  1711. if($('body>.modal-wrapper').size()){
  1712. $.event.trigger({
  1713. type : 'record-stat',
  1714. categorie : 'Shortcuts',
  1715. action : 'Esc',
  1716. label : 'Esc from modal content'
  1717. });
  1718. $('body>.modal-wrapper').click();
  1719. _previewIsOpen = false;
  1720. return false;
  1721. }
  1722. };
  1723. function shortcut_onUpArrow(e){
  1724. // trace('theme :: shortcut_onTopArrow', e);
  1725. moveGridFocus(e, 'u');
  1726. };
  1727. function shortcut_onRightArrow(e){
  1728. // trace('theme :: shortcut_onRightArrow', e);
  1729. moveGridFocus(e, 'r');
  1730. };
  1731. function shortcut_onDownArrow(e){
  1732. // trace('theme :: shortcut_onDownArrow', e);
  1733. moveGridFocus(e, 'd');
  1734. };
  1735. function shortcut_onLeftArrow(e){
  1736. // trace('theme :: shortcut_onLeftArrow', e);
  1737. moveGridFocus(e, "l");
  1738. };
  1739. /**
  1740. * Misc
  1741. */
  1742. function onResizeWindow(e){
  1743. clearInterval(_resizeTimer);
  1744. _resizeTimer = setTimeout(function(){
  1745. initLayout();
  1746. checkViewmodesResponsive();
  1747. setUpGrid("#content .actuality-items, #content .search-results");
  1748. }, 200);
  1749. };
  1750. /**
  1751. * Statics
  1752. */
  1753. function initMembershipForm() {
  1754. switch(window.location.hash){
  1755. case '#flocon':
  1756. $('#edit-submitted-column-left-membership-options-1').attr('checked', 'checked');
  1757. // $options.trigger('change');
  1758. break;
  1759. case '#etoile':
  1760. $('#edit-submitted-column-left-membership-options-2').attr('checked', 'checked');
  1761. break;
  1762. case '#4etoiles':
  1763. $('#edit-submitted-column-left-membership-options-3').attr('checked', 'checked');
  1764. break;
  1765. // default:
  1766. // switchMembershipShipFormFields($options);
  1767. // break
  1768. }
  1769. $('#webform-component-column-left--membership-options')
  1770. .change(function(event){
  1771. //trace('changed');
  1772. if( $('input[type="radio"]:checked', this).is('#edit-submitted-column-left-membership-options-3') ){
  1773. $('#webform-component-column-right--collaborators').show();
  1774. }else{
  1775. $('#webform-component-column-right--collaborators').hide();
  1776. }
  1777. $('div.form-item.selected', this).removeClass('selected');
  1778. $('input[type="radio"]:checked', this).parents('div.form-item').addClass('selected');
  1779. })
  1780. .trigger('change');
  1781. // $('#webform-component-column-left--membership-options input[checked="checked"]').parents('div.form-item').addClass('selected');
  1782. };
  1783. /** helpers */
  1784. $.fn.h = function(){
  1785. if(this.css('height') == undefined)
  1786. return 0;
  1787. return parseInt(this.css('height')) + parseInt(this.css('padding-top')) + parseInt(this.css('padding-bottom'));
  1788. };
  1789. $.fn.w = function(){
  1790. if(this.css('width') == undefined)
  1791. return 0;
  1792. return parseInt(this.css('width')) + parseInt(this.css('padding-left')) + parseInt(this.css('padding-right'));
  1793. };
  1794. function getDocHeight() {
  1795. var D = document;
  1796. return Math.max(
  1797. Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
  1798. Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
  1799. Math.max(D.body.clientHeight, D.documentElement.clientHeight)
  1800. );
  1801. };
  1802. // http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
  1803. function viewport() {
  1804. var e = window, a = 'inner';
  1805. if (!('innerWidth' in window )) {
  1806. a = 'client';
  1807. e = document.documentElement || document.body;
  1808. }
  1809. return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
  1810. };
  1811. /**
  1812. * Forms
  1813. */
  1814. function initForms(){
  1815. $('#edit-searchfield:not(.processed)')
  1816. .bind('focus', function(event) {
  1817. var $this = $(this);
  1818. //$this.attr('value', 'test');
  1819. // trace('value', $this.val());
  1820. // trace('default', $this.attr('default'));
  1821. if($this.val() == $this.attr('default'))
  1822. $this.val('');
  1823. })
  1824. .bind('focusout', function(event) {
  1825. var $this = $(this);
  1826. if($this.val() == "")
  1827. $this.val($this.attr('default'));
  1828. })
  1829. .addClass('processed');
  1830. hideLabelsFromRegisterForm();
  1831. };
  1832. function hideLabelsFromRegisterForm () {
  1833. var $this, id,label, description;
  1834. $('input.form-text', '#block-user-login, #block-materio-user-user-register, , #block-materio-user-user-createaccount').each(function(i) {
  1835. $this = $(this);
  1836. id = $this.attr('id');
  1837. label = $('label[for='+id+']').hide().text();
  1838. description = $this.parent().find('.description').hide().text();
  1839. if($this.attr('placeholder') == '')
  1840. $this.attr('placeholder',label);
  1841. $this.attr('title',description);
  1842. });
  1843. };
  1844. function onAjaxRegisterBlockLoaded (event) {
  1845. // console.log('onAjaxRegisterBlockLoaded');
  1846. hideLabelsFromRegisterForm();
  1847. };
  1848. /**
  1849. * cookies
  1850. */
  1851. function createCookie(name,value,days) {
  1852. if (days) {
  1853. var date = new Date();
  1854. date.setTime(date.getTime()+(days*24*60*60*1000));
  1855. var expires = "; expires="+date.toGMTString();
  1856. }
  1857. else var expires = "";
  1858. document.cookie = name+"="+value+expires+"; path=/";
  1859. };
  1860. function readCookie(name) {
  1861. var nameEQ = name + "=";
  1862. var ca = document.cookie.split(';');
  1863. for(var i=0;i < ca.length;i++) {
  1864. var c = ca[i];
  1865. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  1866. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  1867. }
  1868. return null;
  1869. };
  1870. function eraseCookie(name) {
  1871. createCookie(name,"",-1);
  1872. };
  1873. /**
  1874. * google analytics
  1875. */
  1876. function onRecordStat(event){
  1877. //trace('onRecordStat', event);
  1878. // path, category, action, opt_label, opt_value
  1879. if(typeof _gaq !== 'undefined'){
  1880. if(event.path){
  1881. _gaq.push(['_trackPageview', event.path]);
  1882. }else{
  1883. _gaq.push(['_trackEvent', event.categorie, event.action, event.label, event.value]);
  1884. }
  1885. }
  1886. };
  1887. /**
  1888. * docScrollTo
  1889. */
  1890. function docScrollTo($e){
  1891. // $(document).scrollTop($e.offset().top);
  1892. if($e.size())
  1893. $('html,body').animate({
  1894. scrollTop: $e.offset().top - $(window).height()*0.5 + $e.height()*0.5
  1895. }, 500);
  1896. };
  1897. init();
  1898. };
  1899. $(document).ready(function() {
  1900. var materiobasetheme = new MaterioBaseTheme();
  1901. });
  1902. /**
  1903. * Attach collapse behavior to the feedback form block.
  1904. */
  1905. Drupal.behaviors.feedbackForm = {
  1906. attach: function (context) {
  1907. $('#block-feedback-form', context).once('feedback', function () {
  1908. var $block = $(this);
  1909. $block.find('span.feedback-link')
  1910. .prepend('<span id="feedback-form-toggle">feedback</span> ')
  1911. .css('cursor', 'pointer')
  1912. .toggle(function () {
  1913. Drupal.feedbackFormToggle($block, false);
  1914. },
  1915. function() {
  1916. Drupal.feedbackFormToggle($block, true);
  1917. }
  1918. );
  1919. $block.find('form').hide();
  1920. $block.show();
  1921. });
  1922. }
  1923. };
  1924. /**
  1925. * Collapse or uncollapse the feedback form block.
  1926. */
  1927. Drupal.feedbackFormToggle = function ($block, enable) {
  1928. $block.find('form').slideToggle('medium');
  1929. if (enable) {
  1930. $('#feedback-form-toggle', $block).html('feedback');
  1931. }
  1932. else {
  1933. $('#feedback-form-toggle', $block).html('feedback (close)');
  1934. }
  1935. };
  1936. })(jQuery);